2019-12-15 16:15:06 +00:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! nu {
|
|
|
|
(cwd: $cwd:expr, $path:expr, $($part:expr),*) => {{
|
|
|
|
use $crate::fs::DisplayPath;
|
|
|
|
|
|
|
|
let path = format!($path, $(
|
|
|
|
$part.display_path()
|
|
|
|
),*);
|
|
|
|
|
|
|
|
nu!($cwd, &path)
|
|
|
|
}};
|
|
|
|
|
|
|
|
(cwd: $cwd:expr, $path:expr) => {{
|
|
|
|
nu!($cwd, $path)
|
|
|
|
}};
|
|
|
|
|
|
|
|
($cwd:expr, $path:expr) => {{
|
|
|
|
pub use std::error::Error;
|
|
|
|
pub use std::io::prelude::*;
|
|
|
|
pub use std::process::{Command, Stdio};
|
|
|
|
|
|
|
|
let commands = &*format!(
|
|
|
|
"
|
|
|
|
cd {}
|
|
|
|
{}
|
|
|
|
exit",
|
|
|
|
$crate::fs::in_directory($cwd),
|
|
|
|
$crate::fs::DisplayPath::display_path(&$path)
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut process = match Command::new($crate::fs::executable_path())
|
|
|
|
.stdin(Stdio::piped())
|
|
|
|
.stdout(Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
{
|
|
|
|
Ok(child) => child,
|
2019-12-31 07:36:08 +00:00
|
|
|
Err(why) => panic!("Can't run test {}", why.to_string()),
|
2019-12-15 16:15:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let stdin = process.stdin.as_mut().expect("couldn't open stdin");
|
|
|
|
stdin
|
|
|
|
.write_all(commands.as_bytes())
|
|
|
|
.expect("couldn't write to stdin");
|
|
|
|
|
|
|
|
|
|
|
|
let output = process
|
|
|
|
.wait_with_output()
|
|
|
|
.expect("couldn't read from stdout");
|
|
|
|
|
|
|
|
let out = String::from_utf8_lossy(&output.stdout);
|
2020-01-11 20:49:20 +00:00
|
|
|
let out = out.lines().skip(1).collect::<Vec<_>>().join("\n");
|
2019-12-15 16:15:06 +00:00
|
|
|
let out = out.replace("\r\n", "");
|
|
|
|
let out = out.replace("\n", "");
|
|
|
|
out
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! nu_error {
|
|
|
|
(cwd: $cwd:expr, $path:expr, $($part:expr),*) => {{
|
|
|
|
use $crate::fs::DisplayPath;
|
|
|
|
|
|
|
|
let path = format!($path, $(
|
|
|
|
$part.display_path()
|
|
|
|
),*);
|
|
|
|
|
|
|
|
nu_error!($cwd, &path)
|
|
|
|
}};
|
|
|
|
|
|
|
|
(cwd: $cwd:expr, $path:expr) => {{
|
|
|
|
nu_error!($cwd, $path)
|
|
|
|
}};
|
|
|
|
|
|
|
|
($cwd:expr, $path:expr) => {{
|
|
|
|
pub use std::error::Error;
|
|
|
|
pub use std::io::prelude::*;
|
|
|
|
pub use std::process::{Command, Stdio};
|
|
|
|
|
|
|
|
let commands = &*format!(
|
|
|
|
"
|
|
|
|
cd {}
|
|
|
|
{}
|
|
|
|
exit",
|
|
|
|
$crate::fs::in_directory($cwd),
|
|
|
|
$crate::fs::DisplayPath::display_path(&$path)
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut process = Command::new($crate::fs::executable_path())
|
2020-01-12 09:14:10 +00:00
|
|
|
.stdout(Stdio::piped())
|
2019-12-15 16:15:06 +00:00
|
|
|
.stdin(Stdio::piped())
|
|
|
|
.stderr(Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.expect("couldn't run test");
|
|
|
|
|
|
|
|
let stdin = process.stdin.as_mut().expect("couldn't open stdin");
|
|
|
|
stdin
|
|
|
|
.write_all(commands.as_bytes())
|
|
|
|
.expect("couldn't write to stdin");
|
|
|
|
|
|
|
|
let output = process
|
|
|
|
.wait_with_output()
|
2020-01-12 09:14:10 +00:00
|
|
|
.expect("couldn't read from stdout/stderr");
|
2019-12-15 16:15:06 +00:00
|
|
|
|
|
|
|
let out = String::from_utf8_lossy(&output.stderr);
|
|
|
|
out.into_owned()
|
|
|
|
}};
|
|
|
|
}
|