mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
Use the new function 'fails_with_code' v2
This commit is contained in:
parent
0936cee9d5
commit
3e1adf40ee
7 changed files with 79 additions and 121 deletions
|
@ -9,12 +9,12 @@ use crate::common::util::TestScenario;
|
|||
|
||||
#[test]
|
||||
fn test_empty_test_equivalent_to_false() {
|
||||
new_ucmd!().run().code_is(1);
|
||||
new_ucmd!().fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_empty_string_is_false() {
|
||||
new_ucmd!().arg("").run().code_is(1);
|
||||
new_ucmd!().arg("").fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -55,24 +55,24 @@ fn test_some_literals() {
|
|||
|
||||
// run the inverse of all these tests
|
||||
for test in &tests {
|
||||
scenario.ucmd().arg("!").arg(test).run().code_is(1);
|
||||
scenario.ucmd().arg("!").arg(test).fails_with_code(1);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_double_not_is_false() {
|
||||
new_ucmd!().args(&["!", "!"]).run().code_is(1);
|
||||
new_ucmd!().args(&["!", "!"]).fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_and_not_is_false() {
|
||||
new_ucmd!().args(&["-a", "!"]).run().code_is(2);
|
||||
new_ucmd!().args(&["-a", "!"]).fails_with_code(2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_not_and_is_false() {
|
||||
// `-a` is a literal here & has nonzero length
|
||||
new_ucmd!().args(&["!", "-a"]).run().code_is(1);
|
||||
new_ucmd!().args(&["!", "-a"]).fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -105,8 +105,7 @@ fn test_negated_or() {
|
|||
new_ucmd!().args(&["foo", "-o", "!", "bar"]).succeeds();
|
||||
new_ucmd!()
|
||||
.args(&["!", "foo", "-o", "!", "bar"])
|
||||
.run()
|
||||
.code_is(1);
|
||||
.fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -117,10 +116,10 @@ fn test_string_length_of_nothing() {
|
|||
|
||||
#[test]
|
||||
fn test_string_length_of_empty() {
|
||||
new_ucmd!().args(&["-n", ""]).run().code_is(1);
|
||||
new_ucmd!().args(&["-n", ""]).fails_with_code(1);
|
||||
|
||||
// STRING equivalent to -n STRING
|
||||
new_ucmd!().arg("").run().code_is(1);
|
||||
new_ucmd!().arg("").fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -141,14 +140,14 @@ fn test_zero_len_equals_zero_len() {
|
|||
|
||||
#[test]
|
||||
fn test_zero_len_not_equals_zero_len_is_false() {
|
||||
new_ucmd!().args(&["", "!=", ""]).run().code_is(1);
|
||||
new_ucmd!().args(&["", "!=", ""]).fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_double_equal_is_string_comparison_op() {
|
||||
// undocumented but part of the GNU test suite
|
||||
new_ucmd!().args(&["t", "==", "t"]).succeeds();
|
||||
new_ucmd!().args(&["t", "==", "f"]).run().code_is(1);
|
||||
new_ucmd!().args(&["t", "==", "f"]).fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -170,7 +169,7 @@ fn test_string_comparison() {
|
|||
|
||||
// run the inverse of all these tests
|
||||
for test in &tests {
|
||||
scenario.ucmd().arg("!").args(&test[..]).run().code_is(1);
|
||||
scenario.ucmd().arg("!").args(&test[..]).fails_with_code(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,8 +178,7 @@ fn test_string_comparison() {
|
|||
fn test_dangling_string_comparison_is_error() {
|
||||
new_ucmd!()
|
||||
.args(&["missing_something", "="])
|
||||
.run()
|
||||
.code_is(2)
|
||||
.fails_with_code(2)
|
||||
.stderr_is("test: missing argument after '='");
|
||||
}
|
||||
|
||||
|
@ -202,7 +200,7 @@ fn test_string_operator_is_literal_after_bang() {
|
|||
];
|
||||
|
||||
for test in &tests {
|
||||
scenario.ucmd().args(&test[..]).run().code_is(1);
|
||||
scenario.ucmd().args(&test[..]).fails_with_code(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -251,7 +249,7 @@ fn test_some_int_compares() {
|
|||
|
||||
// run the inverse of all these tests
|
||||
for test in &tests {
|
||||
scenario.ucmd().arg("!").args(&test[..]).run().code_is(1);
|
||||
scenario.ucmd().arg("!").args(&test[..]).fails_with_code(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -283,7 +281,7 @@ fn test_negative_int_compare() {
|
|||
|
||||
// run the inverse of all these tests
|
||||
for test in &tests {
|
||||
scenario.ucmd().arg("!").args(&test[..]).run().code_is(1);
|
||||
scenario.ucmd().arg("!").args(&test[..]).fails_with_code(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -291,8 +289,7 @@ fn test_negative_int_compare() {
|
|||
fn test_float_inequality_is_error() {
|
||||
new_ucmd!()
|
||||
.args(&["123.45", "-ge", "6"])
|
||||
.run()
|
||||
.code_is(2)
|
||||
.fails_with_code(2)
|
||||
.stderr_is("test: invalid integer '123.45'\n");
|
||||
}
|
||||
|
||||
|
@ -307,14 +304,12 @@ fn test_invalid_utf8_integer_compare() {
|
|||
|
||||
new_ucmd!()
|
||||
.args(&[OsStr::new("123"), OsStr::new("-ne"), arg])
|
||||
.run()
|
||||
.code_is(2)
|
||||
.fails_with_code(2)
|
||||
.stderr_is("test: invalid integer $'fo\\x80o'\n");
|
||||
|
||||
new_ucmd!()
|
||||
.args(&[arg, OsStr::new("-eq"), OsStr::new("456")])
|
||||
.run()
|
||||
.code_is(2)
|
||||
.fails_with_code(2)
|
||||
.stderr_is("test: invalid integer $'fo\\x80o'\n");
|
||||
}
|
||||
|
||||
|
@ -332,12 +327,10 @@ fn test_file_is_newer_than_and_older_than_itself() {
|
|||
// odd but matches GNU
|
||||
new_ucmd!()
|
||||
.args(&["regular_file", "-nt", "regular_file"])
|
||||
.run()
|
||||
.code_is(1);
|
||||
.fails_with_code(1);
|
||||
new_ucmd!()
|
||||
.args(&["regular_file", "-ot", "regular_file"])
|
||||
.run()
|
||||
.code_is(1);
|
||||
.fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -412,16 +405,14 @@ fn test_file_exists() {
|
|||
fn test_nonexistent_file_does_not_exist() {
|
||||
new_ucmd!()
|
||||
.args(&["-e", "nonexistent_file"])
|
||||
.run()
|
||||
.code_is(1);
|
||||
.fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_nonexistent_file_is_not_regular() {
|
||||
new_ucmd!()
|
||||
.args(&["-f", "nonexistent_file"])
|
||||
.run()
|
||||
.code_is(1);
|
||||
.fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -579,12 +570,12 @@ fn test_file_is_sticky() {
|
|||
|
||||
#[test]
|
||||
fn test_file_is_not_sticky() {
|
||||
new_ucmd!().args(&["-k", "regular_file"]).run().code_is(1);
|
||||
new_ucmd!().args(&["-k", "regular_file"]).fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_solo_empty_parenthetical_is_error() {
|
||||
new_ucmd!().args(&["(", ")"]).run().code_is(2);
|
||||
new_ucmd!().args(&["(", ")"]).fails_with_code(2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -631,7 +622,7 @@ fn test_parenthesized_literal() {
|
|||
fn test_parenthesized_op_compares_literal_parenthesis() {
|
||||
// ensure we aren’t treating this case as “string length of literal equal
|
||||
// sign”
|
||||
new_ucmd!().args(&["(", "=", ")"]).run().code_is(1);
|
||||
new_ucmd!().args(&["(", "=", ")"]).fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -652,13 +643,13 @@ fn test_parenthesized_string_comparison() {
|
|||
|
||||
// run the inverse of all these tests
|
||||
for test in &tests {
|
||||
scenario.ucmd().arg("!").args(&test[..]).run().code_is(1);
|
||||
scenario.ucmd().arg("!").args(&test[..]).fails_with_code(1);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parenthesized_right_parenthesis_as_literal() {
|
||||
new_ucmd!().args(&["(", "-f", ")", ")"]).run().code_is(1);
|
||||
new_ucmd!().args(&["(", "-f", ")", ")"]).fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -672,8 +663,7 @@ fn test_file_owned_by_euid() {
|
|||
fn test_nonexistent_file_not_owned_by_euid() {
|
||||
new_ucmd!()
|
||||
.args(&["-O", "nonexistent_file"])
|
||||
.run()
|
||||
.code_is(1);
|
||||
.fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -717,8 +707,7 @@ fn test_file_owned_by_egid() {
|
|||
fn test_nonexistent_file_not_owned_by_egid() {
|
||||
new_ucmd!()
|
||||
.args(&["-G", "nonexistent_file"])
|
||||
.run()
|
||||
.code_is(1);
|
||||
.fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -747,8 +736,7 @@ fn test_op_precedence_and_or_1() {
|
|||
fn test_op_precedence_and_or_1_overridden_by_parentheses() {
|
||||
new_ucmd!()
|
||||
.args(&["(", " ", "-o", "", ")", "-a", ""])
|
||||
.run()
|
||||
.code_is(1);
|
||||
.fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -762,8 +750,7 @@ fn test_op_precedence_and_or_2() {
|
|||
fn test_op_precedence_and_or_2_overridden_by_parentheses() {
|
||||
new_ucmd!()
|
||||
.args(&["", "-a", "(", "", "-o", " ", ")", "-a", " "])
|
||||
.run()
|
||||
.code_is(1);
|
||||
.fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -788,7 +775,7 @@ fn test_negated_boolean_precedence() {
|
|||
];
|
||||
|
||||
for test in &negative_tests {
|
||||
scenario.ucmd().args(&test[..]).run().code_is(1);
|
||||
scenario.ucmd().args(&test[..]).fails_with_code(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -800,26 +787,22 @@ fn test_bang_bool_op_precedence() {
|
|||
|
||||
new_ucmd!()
|
||||
.args(&["!", "a value", "-o", "another value"])
|
||||
.run()
|
||||
.code_is(1);
|
||||
.fails_with_code(1);
|
||||
|
||||
// Introducing a UOP — even one that is equivalent to a bare string — causes
|
||||
// bang to invert only the first term
|
||||
new_ucmd!()
|
||||
.args(&["!", "-n", "", "-a", ""])
|
||||
.run()
|
||||
.code_is(1);
|
||||
.fails_with_code(1);
|
||||
new_ucmd!()
|
||||
.args(&["!", "", "-a", "-n", ""])
|
||||
.run()
|
||||
.code_is(1);
|
||||
.fails_with_code(1);
|
||||
|
||||
// for compound Boolean expressions, bang inverts the _next_ expression
|
||||
// only, not the entire compound expression
|
||||
new_ucmd!()
|
||||
.args(&["!", "", "-a", "", "-a", ""])
|
||||
.run()
|
||||
.code_is(1);
|
||||
.fails_with_code(1);
|
||||
|
||||
// parentheses can override this
|
||||
new_ucmd!()
|
||||
|
@ -832,8 +815,7 @@ fn test_inverted_parenthetical_bool_op_precedence() {
|
|||
// For a Boolean combination of two literals, bang inverts the entire expression
|
||||
new_ucmd!()
|
||||
.args(&["!", "a value", "-o", "another value"])
|
||||
.run()
|
||||
.code_is(1);
|
||||
.fails_with_code(1);
|
||||
|
||||
// only the parenthetical is inverted, not the entire expression
|
||||
new_ucmd!()
|
||||
|
@ -867,29 +849,27 @@ fn test_complicated_parenthesized_expression() {
|
|||
fn test_erroneous_parenthesized_expression() {
|
||||
new_ucmd!()
|
||||
.args(&["a", "!=", "(", "b", "-a", "b", ")", "!=", "c"])
|
||||
.run()
|
||||
.code_is(2)
|
||||
.fails_with_code(2)
|
||||
.stderr_is("test: extra argument 'b'\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_or_as_filename() {
|
||||
new_ucmd!().args(&["x", "-a", "-z", "-o"]).run().code_is(1);
|
||||
new_ucmd!()
|
||||
.args(&["x", "-a", "-z", "-o"])
|
||||
.fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "TODO: Busybox has this working"]
|
||||
fn test_filename_or_with_equal() {
|
||||
new_ucmd!()
|
||||
.args(&["-f", "=", "a", "-o", "b"])
|
||||
.run()
|
||||
.code_is(0);
|
||||
new_ucmd!().args(&["-f", "=", "a", "-o", "b"]).succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "GNU considers this an error"]
|
||||
fn test_string_length_and_nothing() {
|
||||
new_ucmd!().args(&["-n", "a", "-a"]).run().code_is(2);
|
||||
new_ucmd!().args(&["-n", "a", "-a"]).fails_with_code(2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -905,7 +885,7 @@ fn test_bracket_syntax_failure() {
|
|||
let scenario = TestScenario::new("[");
|
||||
let mut ucmd = scenario.ucmd();
|
||||
|
||||
ucmd.args(&["1", "-eq", "2", "]"]).run().code_is(1);
|
||||
ucmd.args(&["1", "-eq", "2", "]"]).fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -915,8 +895,7 @@ fn test_bracket_syntax_missing_right_bracket() {
|
|||
|
||||
// Missing closing bracket takes precedence over other possible errors.
|
||||
ucmd.args(&["1", "-eq"])
|
||||
.run()
|
||||
.code_is(2)
|
||||
.fails_with_code(2)
|
||||
.stderr_is("[: missing ']'\n");
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue