tests: remove status_code, which is the same as code_is

This commit is contained in:
Terts Diepraam 2023-01-01 15:33:02 +01:00
parent 267a22e12c
commit 44ea43f058
8 changed files with 67 additions and 106 deletions

View file

@ -2277,7 +2277,7 @@ fn test_copy_dir_preserve_permissions_inaccessible_file() {
// V V V V
ucmd.args(&["-p", "-R", "d1", "d2"])
.fails()
.status_code(1)
.code_is(1)
.stderr_only("cp: cannot open 'd1/f' for reading: Permission denied");
assert!(at.dir_exists("d2"));
assert!(!at.file_exists("d2/f"));

View file

@ -461,7 +461,7 @@ fn test_oversized_bs_32_bit() {
.run()
.no_stdout()
.failure()
.status_code(1)
.code_is(1)
.stderr_is(format!("dd: {}=N cannot fit into memory\n", bs_param));
}
}

View file

@ -5,25 +5,21 @@ use crate::common::util::*;
#[test]
fn test_simple_values() {
// null or 0 => EXIT_VALUE == 1
new_ucmd!()
.args(&[""])
.fails()
.status_code(1)
.stdout_only("\n");
new_ucmd!().args(&[""]).fails().code_is(1).stdout_only("\n");
new_ucmd!()
.args(&["0"])
.fails()
.status_code(1)
.code_is(1)
.stdout_only("0\n");
new_ucmd!()
.args(&["00"])
.fails()
.status_code(1)
.code_is(1)
.stdout_only("00\n");
new_ucmd!()
.args(&["-0"])
.fails()
.status_code(1)
.code_is(1)
.stdout_only("-0\n");
// non-null and non-0 => EXIT_VALUE = 0
@ -40,7 +36,7 @@ fn test_simple_arithmetic() {
new_ucmd!()
.args(&["1", "-", "1"])
.fails()
.status_code(1)
.code_is(1)
.stdout_only("0\n");
new_ucmd!()
@ -130,7 +126,7 @@ fn test_index() {
new_ucmd!()
.args(&["index", "αbcdef", "x"])
.fails()
.status_code(1)
.code_is(1)
.stdout_only("0\n");
new_ucmd!()
.args(&["index", "αbcdef", "α"])
@ -213,18 +209,18 @@ fn test_invalid_substr() {
new_ucmd!()
.args(&["substr", "abc", "0", "1"])
.fails()
.status_code(1)
.code_is(1)
.stdout_only("\n");
new_ucmd!()
.args(&["substr", "abc", &(std::usize::MAX.to_string() + "0"), "1"])
.fails()
.status_code(1)
.code_is(1)
.stdout_only("\n");
new_ucmd!()
.args(&["substr", "abc", "0", &(std::usize::MAX.to_string() + "0")])
.fails()
.status_code(1)
.code_is(1)
.stdout_only("\n");
}

View file

@ -77,14 +77,14 @@ fn test_mknod_character_device_requires_major_and_minor() {
.arg("test_file")
.arg("c")
.fails()
.status_code(1)
.code_is(1)
.stderr_contains("Special files require major and minor device numbers.");
new_ucmd!()
.arg("test_file")
.arg("c")
.arg("1")
.fails()
.status_code(1)
.code_is(1)
.stderr_contains("Special files require major and minor device numbers.");
new_ucmd!()
.arg("test_file")
@ -122,6 +122,6 @@ fn test_mknod_invalid_mode() {
.arg("p")
.fails()
.no_stdout()
.status_code(1)
.code_is(1)
.stderr_contains("invalid mode");
}

View file

@ -844,7 +844,7 @@ fn test_nonexistent_file() {
new_ucmd!()
.arg("nonexistent.txt")
.fails()
.status_code(2)
.code_is(2)
.stderr_only(
#[cfg(not(windows))]
"sort: cannot read: nonexistent.txt: No such file or directory",
@ -1015,7 +1015,7 @@ fn test_verifies_out_file() {
.pipe_in(input)
.ignore_stdin_write_error()
.fails()
.status_code(2)
.code_is(2)
.stderr_only(
#[cfg(not(windows))]
"sort: open failed: nonexistent_dir/nonexistent_file: No such file or directory",
@ -1036,7 +1036,7 @@ fn test_verifies_files_after_keys() {
"nonexistent_dir/input_file",
])
.fails()
.status_code(2)
.code_is(2)
.stderr_contains("failed to parse key");
}
@ -1046,7 +1046,7 @@ fn test_verifies_input_files() {
new_ucmd!()
.args(&["/dev/random", "nonexistent_file"])
.fails()
.status_code(2)
.code_is(2)
.stderr_is("sort: cannot read: nonexistent_file: No such file or directory");
}
@ -1104,7 +1104,7 @@ fn test_wrong_args_exit_code() {
new_ucmd!()
.arg("--misspelled")
.fails()
.status_code(2)
.code_is(2)
.stderr_contains("--misspelled");
}

View file

@ -15,12 +15,12 @@ use std::thread::sleep;
#[test]
fn test_empty_test_equivalent_to_false() {
new_ucmd!().run().status_code(1);
new_ucmd!().run().code_is(1);
}
#[test]
fn test_empty_string_is_false() {
new_ucmd!().arg("").run().status_code(1);
new_ucmd!().arg("").run().code_is(1);
}
#[test]
@ -61,24 +61,24 @@ fn test_some_literals() {
// run the inverse of all these tests
for test in &tests {
scenario.ucmd().arg("!").arg(test).run().status_code(1);
scenario.ucmd().arg("!").arg(test).run().code_is(1);
}
}
#[test]
fn test_double_not_is_false() {
new_ucmd!().args(&["!", "!"]).run().status_code(1);
new_ucmd!().args(&["!", "!"]).run().code_is(1);
}
#[test]
fn test_and_not_is_false() {
new_ucmd!().args(&["-a", "!"]).run().status_code(1);
new_ucmd!().args(&["-a", "!"]).run().code_is(1);
}
#[test]
fn test_not_and_is_false() {
// `-a` is a literal here & has nonzero length
new_ucmd!().args(&["!", "-a"]).run().status_code(1);
new_ucmd!().args(&["!", "-a"]).run().code_is(1);
}
#[test]
@ -96,12 +96,12 @@ fn test_negated_or() {
new_ucmd!()
.args(&["!", "foo", "-o", "bar"])
.run()
.status_code(1);
.code_is(1);
new_ucmd!().args(&["foo", "-o", "!", "bar"]).succeeds();
new_ucmd!()
.args(&["!", "foo", "-o", "!", "bar"])
.run()
.status_code(1);
.code_is(1);
}
#[test]
@ -112,10 +112,10 @@ fn test_string_length_of_nothing() {
#[test]
fn test_string_length_of_empty() {
new_ucmd!().args(&["-n", ""]).run().status_code(1);
new_ucmd!().args(&["-n", ""]).run().code_is(1);
// STRING equivalent to -n STRING
new_ucmd!().arg("").run().status_code(1);
new_ucmd!().arg("").run().code_is(1);
}
#[test]
@ -136,14 +136,14 @@ fn test_zero_len_equals_zero_len() {
#[test]
fn test_zero_len_not_equals_zero_len_is_false() {
new_ucmd!().args(&["", "!=", ""]).run().status_code(1);
new_ucmd!().args(&["", "!=", ""]).run().code_is(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().status_code(1);
new_ucmd!().args(&["t", "==", "f"]).run().code_is(1);
}
#[test]
@ -165,12 +165,7 @@ fn test_string_comparison() {
// run the inverse of all these tests
for test in &tests {
scenario
.ucmd()
.arg("!")
.args(&test[..])
.run()
.status_code(1);
scenario.ucmd().arg("!").args(&test[..]).run().code_is(1);
}
}
@ -180,7 +175,7 @@ fn test_dangling_string_comparison_is_error() {
new_ucmd!()
.args(&["missing_something", "="])
.run()
.status_code(2)
.code_is(2)
.stderr_is("test: missing argument after '='");
}
@ -202,7 +197,7 @@ fn test_string_operator_is_literal_after_bang() {
];
for test in &tests {
scenario.ucmd().args(&test[..]).run().status_code(1);
scenario.ucmd().args(&test[..]).run().code_is(1);
}
}
@ -251,12 +246,7 @@ fn test_some_int_compares() {
// run the inverse of all these tests
for test in &tests {
scenario
.ucmd()
.arg("!")
.args(&test[..])
.run()
.status_code(1);
scenario.ucmd().arg("!").args(&test[..]).run().code_is(1);
}
}
@ -288,12 +278,7 @@ fn test_negative_int_compare() {
// run the inverse of all these tests
for test in &tests {
scenario
.ucmd()
.arg("!")
.args(&test[..])
.run()
.status_code(1);
scenario.ucmd().arg("!").args(&test[..]).run().code_is(1);
}
}
@ -302,7 +287,7 @@ fn test_float_inequality_is_error() {
new_ucmd!()
.args(&["123.45", "-ge", "6"])
.run()
.status_code(2)
.code_is(2)
.stderr_is("test: invalid integer '123.45'");
}
@ -320,7 +305,7 @@ fn test_invalid_utf8_integer_compare() {
cmd.raw.arg(arg);
cmd.run()
.status_code(2)
.code_is(2)
.stderr_is("test: invalid integer $'fo\\x80o'");
let mut cmd = new_ucmd!();
@ -328,7 +313,7 @@ fn test_invalid_utf8_integer_compare() {
cmd.arg("-eq").arg("456");
cmd.run()
.status_code(2)
.code_is(2)
.stderr_is("test: invalid integer $'fo\\x80o'");
}
@ -347,11 +332,11 @@ fn test_file_is_newer_than_and_older_than_itself() {
new_ucmd!()
.args(&["regular_file", "-nt", "regular_file"])
.run()
.status_code(1);
.code_is(1);
new_ucmd!()
.args(&["regular_file", "-ot", "regular_file"])
.run()
.status_code(1);
.code_is(1);
}
#[test]
@ -417,7 +402,7 @@ fn test_nonexistent_file_does_not_exist() {
new_ucmd!()
.args(&["-e", "nonexistent_file"])
.run()
.status_code(1);
.code_is(1);
}
#[test]
@ -425,7 +410,7 @@ fn test_nonexistent_file_is_not_regular() {
new_ucmd!()
.args(&["-f", "nonexistent_file"])
.run()
.status_code(1);
.code_is(1);
}
#[test]
@ -517,7 +502,7 @@ fn test_nonexistent_file_size_test_is_false() {
new_ucmd!()
.args(&["-s", "nonexistent_file"])
.run()
.status_code(1);
.code_is(1);
}
#[test]
@ -583,15 +568,12 @@ fn test_file_is_sticky() {
#[test]
fn test_file_is_not_sticky() {
new_ucmd!()
.args(&["-k", "regular_file"])
.run()
.status_code(1);
new_ucmd!().args(&["-k", "regular_file"]).run().code_is(1);
}
#[test]
fn test_solo_empty_parenthetical_is_error() {
new_ucmd!().args(&["(", ")"]).run().status_code(2);
new_ucmd!().args(&["(", ")"]).run().code_is(2);
}
#[test]
@ -630,7 +612,7 @@ fn test_parenthesized_literal() {
.arg(test)
.arg(")")
.run()
.status_code(1);
.code_is(1);
}
}
@ -638,7 +620,7 @@ fn test_parenthesized_literal() {
fn test_parenthesized_op_compares_literal_parenthesis() {
// ensure we arent treating this case as “string length of literal equal
// sign”
new_ucmd!().args(&["(", "=", ")"]).run().status_code(1);
new_ucmd!().args(&["(", "=", ")"]).run().code_is(1);
}
#[test]
@ -659,21 +641,13 @@ fn test_parenthesized_string_comparison() {
// run the inverse of all these tests
for test in &tests {
scenario
.ucmd()
.arg("!")
.args(&test[..])
.run()
.status_code(1);
scenario.ucmd().arg("!").args(&test[..]).run().code_is(1);
}
}
#[test]
fn test_parenthesized_right_parenthesis_as_literal() {
new_ucmd!()
.args(&["(", "-f", ")", ")"])
.run()
.status_code(1);
new_ucmd!().args(&["(", "-f", ")", ")"]).run().code_is(1);
}
#[test]
@ -688,7 +662,7 @@ fn test_nonexistent_file_not_owned_by_euid() {
new_ucmd!()
.args(&["-O", "nonexistent_file"])
.run()
.status_code(1);
.code_is(1);
}
#[test]
@ -711,7 +685,7 @@ fn test_nonexistent_file_not_owned_by_egid() {
new_ucmd!()
.args(&["-G", "nonexistent_file"])
.run()
.status_code(1);
.code_is(1);
}
#[test]
@ -732,7 +706,7 @@ fn test_op_precedence_and_or_1_overridden_by_parentheses() {
new_ucmd!()
.args(&["(", " ", "-o", "", ")", "-a", ""])
.run()
.status_code(1);
.code_is(1);
}
#[test]
@ -747,7 +721,7 @@ fn test_op_precedence_and_or_2_overridden_by_parentheses() {
new_ucmd!()
.args(&["", "-a", "(", "", "-o", " ", ")", "-a", " "])
.run()
.status_code(1);
.code_is(1);
}
#[test]
@ -772,7 +746,7 @@ fn test_negated_boolean_precedence() {
];
for test in &negative_tests {
scenario.ucmd().args(&test[..]).run().status_code(1);
scenario.ucmd().args(&test[..]).run().code_is(1);
}
}
@ -785,25 +759,25 @@ fn test_bang_bool_op_precedence() {
new_ucmd!()
.args(&["!", "a value", "-o", "another value"])
.run()
.status_code(1);
.code_is(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()
.status_code(1);
.code_is(1);
new_ucmd!()
.args(&["!", "", "-a", "-n", ""])
.run()
.status_code(1);
.code_is(1);
// for compound Boolean expressions, bang inverts the _next_ expression
// only, not the entire compound expression
new_ucmd!()
.args(&["!", "", "-a", "", "-a", ""])
.run()
.status_code(1);
.code_is(1);
// parentheses can override this
new_ucmd!()
@ -817,7 +791,7 @@ fn test_inverted_parenthetical_bool_op_precedence() {
new_ucmd!()
.args(&["!", "a value", "-o", "another value"])
.run()
.status_code(1);
.code_is(1);
// only the parenthetical is inverted, not the entire expression
new_ucmd!()
@ -831,7 +805,7 @@ fn test_dangling_parenthesis() {
new_ucmd!()
.args(&["(", "(", "a", "!=", "b", ")", "-o", "-n", "c"])
.run()
.status_code(2);
.code_is(2);
new_ucmd!()
.args(&["(", "(", "a", "!=", "b", ")", "-o", "-n", "c", ")"])
.succeeds();
@ -852,22 +826,19 @@ fn test_erroneous_parenthesized_expression() {
new_ucmd!()
.args(&["a", "!=", "(", "b", "-a", "b", ")", "!=", "c"])
.run()
.status_code(2)
.code_is(2)
.stderr_is("test: extra argument 'b'");
}
#[test]
fn test_or_as_filename() {
new_ucmd!()
.args(&["x", "-a", "-z", "-o"])
.run()
.status_code(1);
new_ucmd!().args(&["x", "-a", "-z", "-o"]).run().code_is(1);
}
#[test]
#[ignore = "GNU considers this an error"]
fn test_string_length_and_nothing() {
new_ucmd!().args(&["-n", "a", "-a"]).run().status_code(2);
new_ucmd!().args(&["-n", "a", "-a"]).run().code_is(2);
}
#[test]
@ -883,7 +854,7 @@ fn test_bracket_syntax_failure() {
let scenario = TestScenario::new("[");
let mut ucmd = scenario.ucmd();
ucmd.args(&["1", "-eq", "2", "]"]).run().status_code(1);
ucmd.args(&["1", "-eq", "2", "]"]).run().code_is(1);
}
#[test]
@ -894,7 +865,7 @@ fn test_bracket_syntax_missing_right_bracket() {
// Missing closing bracket takes precedence over other possible errors.
ucmd.args(&["1", "-eq"])
.run()
.status_code(2)
.code_is(2)
.stderr_is("[: missing ']'");
}

View file

@ -13,7 +13,7 @@ fn test_invalid_arg() {
fn test_subcommand_return_code() {
new_ucmd!().arg("1").arg("true").succeeds();
new_ucmd!().arg("1").arg("false").run().status_code(1);
new_ucmd!().arg("1").arg("false").run().code_is(1);
}
#[test]

View file

@ -199,12 +199,6 @@ impl CmdResult {
self
}
/// asserts that the command's exit code is the same as the given one
pub fn status_code(&self, code: i32) -> &Self {
assert_eq!(self.code, Some(code));
self
}
/// asserts that the command resulted in empty (zero-length) stderr stream output
/// generally, it's better to use `stdout_only()` instead,
/// but you might find yourself using this function if