Avoid bashisms in tests (#18)

Since `sh` might be different depending on the system, avoid testing
status codes and error messages that are not the same across all `sh`s
This commit is contained in:
Casey Rodarmor 2016-11-05 01:19:54 -07:00 committed by GitHub
parent e4d35a8270
commit adef254b23
2 changed files with 64 additions and 61 deletions

View File

@ -199,11 +199,11 @@ recipe:
*/ */
#[test] #[test]
fn status() { fn status_passthrough() {
let text = let text =
" "
recipe: recipe:
@function f { return 100; }; f"; @exit 100";
integration_test( integration_test(
&[], &[],
text, text,
@ -254,13 +254,13 @@ fn backtick_trimming() {
fn backtick_code_assignment() { fn backtick_code_assignment() {
integration_test( integration_test(
&[], &[],
"b = a\na = `function f { return 100; }; f`\nbar:\n echo '{{`function f { return 200; }; f`}}'", "b = a\na = `exit 100`\nbar:\n echo '{{`exit 200`}}'",
100, 100,
"", "",
"backtick failed with exit code 100 "backtick failed with exit code 100
| |
2 | a = `function f { return 100; }; f` 2 | a = `exit 100`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^
", ",
); );
} }
@ -269,13 +269,13 @@ fn backtick_code_assignment() {
fn backtick_code_interpolation() { fn backtick_code_interpolation() {
integration_test( integration_test(
&[], &[],
"b = a\na = `echo hello`\nbar:\n echo '{{`function f { return 200; }; f`}}'", "b = a\na = `echo hello`\nbar:\n echo '{{`exit 200`}}'",
200, 200,
"", "",
"backtick failed with exit code 200 "backtick failed with exit code 200
| |
4 | echo '{{`function f { return 200; }; f`}}' 4 | echo '{{`exit 200`}}'
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^
", ",
); );
} }
@ -454,29 +454,6 @@ wut:
); );
} }
#[test]
fn export_failure() {
integration_test(
&[],
r#"
export foo = "a"
baz = "c"
export bar = "b"
export abc = foo + bar + baz
wut:
echo $foo $bar $baz
"#,
127,
"",
r#"echo $foo $bar $baz
sh: baz: unbound variable
Recipe "wut" failed with exit code 127
"#,
);
}
#[test] #[test]
fn export_shebang() { fn export_shebang() {
integration_test( integration_test(
@ -497,28 +474,6 @@ wut:
); );
} }
#[test]
fn export_assignment_backtick() {
integration_test(
&[],
r#"
export exported_variable = "A"
b = `echo $exported_variable`
recipe:
echo {{b}}
"#,
127,
"",
"sh: exported_variable: unbound variable
backtick failed with exit code 127
|
3 | b = `echo $exported_variable`
| ^^^^^^^^^^^^^^^^^^^^^^^^^
",
);
}
#[test] #[test]
fn export_recipe_backtick() { fn export_recipe_backtick() {
integration_test( integration_test(

View File

@ -727,7 +727,7 @@ c: b
fn run_shebang() { fn run_shebang() {
// this test exists to make sure that shebang recipes // this test exists to make sure that shebang recipes
// run correctly. although this script is still // run correctly. although this script is still
// executed by sh its behavior depends on the value of a // executed by a shell its behavior depends on the value of a
// variable and continuing even though a command fails, // variable and continuing even though a command fails,
// whereas in plain recipes variables are not available // whereas in plain recipes variables are not available
// in subsequent lines and execution stops when a line // in subsequent lines and execution stops when a line
@ -736,7 +736,7 @@ fn run_shebang() {
a: a:
#!/usr/bin/env sh #!/usr/bin/env sh
code=200 code=200
function x { return $code; } x() { return $code; }
x x
x x
"; ";
@ -752,7 +752,7 @@ a:
#[test] #[test]
fn code_error() { fn code_error() {
match parse_success("fail:\n @function x { return 100; }; x") match parse_success("fail:\n @exit 100")
.run(&["fail"], &Default::default()).unwrap_err() { .run(&["fail"], &Default::default()).unwrap_err() {
RunError::Code{recipe, code} => { RunError::Code{recipe, code} => {
assert_eq!(recipe, "fail"); assert_eq!(recipe, "fail");
@ -766,7 +766,7 @@ fn code_error() {
fn run_args() { fn run_args() {
let text = r#" let text = r#"
a return code: a return code:
@function x { {{return}} {{code + "0"}}; }; x"#; @x() { {{return}} {{code + "0"}}; }; x"#;
match parse_success(text).run(&["a", "return", "15"], &Default::default()).unwrap_err() { match parse_success(text).run(&["a", "return", "15"], &Default::default()).unwrap_err() {
RunError::Code{recipe, code} => { RunError::Code{recipe, code} => {
@ -804,11 +804,11 @@ fn missing_default() {
#[test] #[test]
fn backtick_code() { fn backtick_code() {
match parse_success("a:\n echo {{`function f { return 100; }; f`}}") match parse_success("a:\n echo {{`f() { return 100; }; f`}}")
.run(&["a"], &Default::default()).unwrap_err() { .run(&["a"], &Default::default()).unwrap_err() {
RunError::BacktickCode{code, token} => { RunError::BacktickCode{code, token} => {
assert_eq!(code, 100); assert_eq!(code, 100);
assert_eq!(token.lexeme, "`function f { return 100; }; f`"); assert_eq!(token.lexeme, "`f() { return 100; }; f`");
}, },
other => panic!("expected an code run error, but got: {}", other), other => panic!("expected an code run error, but got: {}", other),
} }
@ -819,7 +819,7 @@ fn unknown_overrides() {
let mut options: RunOptions = Default::default(); let mut options: RunOptions = Default::default();
options.overrides.insert("foo", "bar"); options.overrides.insert("foo", "bar");
options.overrides.insert("baz", "bob"); options.overrides.insert("baz", "bob");
match parse_success("a:\n echo {{`function f { return 100; }; f`}}") match parse_success("a:\n echo {{`f() { return 100; }; f`}}")
.run(&["a"], &options).unwrap_err() { .run(&["a"], &options).unwrap_err() {
RunError::UnknownOverrides{overrides} => { RunError::UnknownOverrides{overrides} => {
assert_eq!(overrides, &["baz", "foo"]); assert_eq!(overrides, &["baz", "foo"]);
@ -828,6 +828,54 @@ fn unknown_overrides() {
} }
} }
#[test]
fn export_assignment_backtick() {
let text = r#"
export exported_variable = "A"
b = `echo $exported_variable`
recipe:
echo {{b}}
"#;
let options = RunOptions {
quiet: true,
..Default::default()
};
match parse_success(text).run(&["recipe"], &options).unwrap_err() {
RunError::BacktickCode{code: _, token} => {
assert_eq!(token.lexeme, "`echo $exported_variable`");
},
other => panic!("expected a backtick code errror, but got: {}", other),
}
}
#[test]
fn export_failure() {
let text = r#"
export foo = "a"
baz = "c"
export bar = "b"
export abc = foo + bar + baz
wut:
echo $foo $bar $baz
"#;
let options = RunOptions {
quiet: true,
..Default::default()
};
match parse_success(text).run(&["wut"], &options).unwrap_err() {
RunError::Code{code: _, recipe} => {
assert_eq!(recipe, "wut");
},
other => panic!("expected a recipe code errror, but got: {}", other),
}
}
#[test] #[test]
fn readme_test() { fn readme_test() {
let mut justfiles = vec![]; let mut justfiles = vec![];