Improve open URL. Format and remove warning in tests

This commit is contained in:
Jonathan Turner
2019-07-18 06:56:15 +12:00
parent 73b978ad51
commit 00b3106f05
2 changed files with 71 additions and 54 deletions

View File

@ -1,25 +1,27 @@
use std::path::PathBuf;
#[macro_export]
#[macro_export]
macro_rules! nu {
($out:ident, $cwd:expr, $commands:expr) => {
use std::error::Error;
use std::io::prelude::*;
use std::process::{Command, Stdio};
let commands = &*format!("
let commands = &*format!(
"
cd {}
{}
exit",
$cwd,
$commands);
exit",
$cwd, $commands
);
let process = match Command::new(helpers::executable_path())
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn() {
Ok(child) => child,
Err(why) => panic!("Can't run test {}", why.description()),
.spawn()
{
Ok(child) => child,
Err(why) => panic!("Can't run test {}", why.description()),
};
match process.stdin.unwrap().write_all(commands.as_bytes()) {
@ -31,7 +33,7 @@ macro_rules! nu {
match process.stdout.unwrap().read_to_string(&mut _s) {
Err(why) => panic!("couldn't read stdout: {}", why.description()),
Ok(_) => {
Ok(_) => {
let _s = _s.replace("\r\n", "\n");
}
}
@ -41,19 +43,19 @@ macro_rules! nu {
};
}
#[macro_export]
#[macro_export]
macro_rules! nu_error {
($out:ident, $cwd:expr, $commands:expr) => {
use std::error::Error;
use std::io::prelude::*;
use std::process::{Command, Stdio};
let commands = &*format!("
let commands = &*format!(
"
cd {}
{}
exit",
$cwd,
$commands);
exit",
$cwd, $commands
);
let mut process = Command::new(helpers::executable_path())
.stdin(Stdio::piped())
@ -62,20 +64,23 @@ macro_rules! nu_error {
.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");
stdin
.write_all(commands.as_bytes())
.expect("couldn't write to stdin");
let output = process.wait_with_output().expect("couldn't read from stderr");
let output = process
.wait_with_output()
.expect("couldn't read from stderr");
let $out = String::from_utf8_lossy(&output.stderr);
};
}
pub fn executable_path() -> PathBuf {
let mut buf = PathBuf::new();
buf.push("target");
buf.push("debug");
buf.push("nu");
buf
buf.push("target");
buf.push("debug");
buf.push("nu");
buf
}
pub fn in_directory(str: &str) -> &str {