just/src/integration.rs

154 lines
2.4 KiB
Rust
Raw Normal View History

2016-10-28 15:25:59 -07:00
extern crate tempdir;
extern crate brev;
use tempdir::TempDir;
use std::process::Command;
fn integration_test(
name: &str,
args: &[&str],
justfile: &str,
expected_status: i32,
expected_stdout: &str,
expected_stderr: &str,
) {
let tmp = TempDir::new(name)
.unwrap_or_else(|err| panic!("tmpdir: failed to create temporary directory: {}", err));
let mut path = tmp.path().to_path_buf();
path.push("justfile");
brev::dump(path, justfile);
let mut binary = std::env::current_dir().unwrap();
binary.push("./target/debug/j");
let output = Command::new(binary)
.current_dir(tmp.path())
.args(args)
.output()
.expect("j invocation failed");
let mut failure = false;
let status = output.status.code().unwrap();
if status != expected_status {
println!("bad status: {} != {}", status, expected_status);
failure = true;
}
let stdout = std::str::from_utf8(&output.stdout).unwrap();
if stdout != expected_stdout {
println!("bad stdout: {:?} != {:?}", stdout, expected_stdout);
failure = true;
}
let stderr = std::str::from_utf8(&output.stderr).unwrap();
if stderr != expected_stderr {
println!("bad stderr: {:?} != {:?}", stderr, expected_stderr);
failure = true;
}
if failure {
panic!("test failed");
}
}
#[test]
2016-10-28 15:59:50 -07:00
fn default() {
2016-10-28 15:25:59 -07:00
integration_test(
2016-10-28 15:59:50 -07:00
"default",
2016-10-28 15:25:59 -07:00
&[],
2016-10-28 15:59:50 -07:00
"default:\n echo hello\nother: \n echo bar",
2016-10-28 15:25:59 -07:00
0,
"hello\n",
"echo hello\n",
)
}
2016-10-28 15:34:01 -07:00
#[test]
fn quiet() {
integration_test(
"quiet",
&[],
"default:\n @echo hello",
0,
"hello\n",
"",
)
}
#[test]
fn order() {
let text = "
b: a
echo b
@mv a b
a:
echo a
@touch F
@touch a
d: c
echo d
@rm c
c: b
echo c
@mv b c";
integration_test(
"order",
&["a", "d"],
text,
0,
"a\nb\nc\nd\n",
"echo a\necho b\necho c\necho d\n",
);
}
2016-10-28 15:59:50 -07:00
#[test]
fn list() {
let text =
"b: a
a:
d: c
c: b";
integration_test(
"list",
&["--list"],
text,
0,
"a b c d\n",
"",
);
}
// #[test]
// fn show() {
// let text =
// r#"hello = "foo"
// recipe:
// echo {{hello}}"#;
// integration_test(
// "show",
// &["--show", "recipe"],
// text,
// 0,
// "foo\n",
// "",
// );
// }
#[test]
fn status() {
let text =
"
recipe:
@function f { return 100; }; f";
integration_test(
"status",
&[],
text,
100,
"",
"Recipe \"recipe\" failed with exit code 100\n",
);
}