diff --git a/tests/by-util/test_csplit.rs b/tests/by-util/test_csplit.rs index 523ac6bba..d571fb5cf 100644 --- a/tests/by-util/test_csplit.rs +++ b/tests/by-util/test_csplit.rs @@ -1412,9 +1412,8 @@ fn repeat_everything() { "9", "{5}", ]) - .fails() + .fails_with_code(1) .no_stdout() - .code_is(1) .stderr_only("csplit: '9': line number out of range on repetition 5\n"); let count = glob(&at.plus_as_string("xx*")) .expect("there should be some splits created") diff --git a/tests/by-util/test_factor.rs b/tests/by-util/test_factor.rs index b31ba42e2..4f4a8d9fb 100644 --- a/tests/by-util/test_factor.rs +++ b/tests/by-util/test_factor.rs @@ -27,8 +27,8 @@ fn test_invalid_arg() { #[test] fn test_valid_arg_exponents() { - new_ucmd!().arg("-h").succeeds().code_is(0); - new_ucmd!().arg("--exponents").succeeds().code_is(0); + new_ucmd!().arg("-h").succeeds(); + new_ucmd!().arg("--exponents").succeeds(); } #[test] diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index 09589a2b0..29f79e29e 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -98,8 +98,7 @@ fn test_invalid_value_time_style() { new_ucmd!() .arg("--time-style=definitely_invalid_value") .succeeds() - .no_stderr() - .code_is(0); + .no_stderr(); // If it is used, error: new_ucmd!() .arg("-g") @@ -112,8 +111,7 @@ fn test_invalid_value_time_style() { .arg("--time-style=definitely_invalid_value") .arg("--format=single-column") .succeeds() - .no_stderr() - .code_is(0); + .no_stderr(); } #[test] @@ -4110,8 +4108,7 @@ fn test_ls_dangling_symlinks() { // Check padding is the same for real files and dangling links, in non-long formats at.touch("temp_dir/real_file"); - let real_file_res = scene.ucmd().arg("-Li1").arg("temp_dir").fails(); - real_file_res.code_is(1); + let real_file_res = scene.ucmd().arg("-Li1").arg("temp_dir").fails_with_code(1); let real_file_stdout_len = String::from_utf8(real_file_res.stdout().to_owned()) .ok() .unwrap() @@ -4122,8 +4119,7 @@ fn test_ls_dangling_symlinks() { .unwrap() .len(); - let dangle_file_res = scene.ucmd().arg("-Li1").arg("temp_dir").fails(); - dangle_file_res.code_is(1); + let dangle_file_res = scene.ucmd().arg("-Li1").arg("temp_dir").fails_with_code(1); let dangle_stdout_len = String::from_utf8(dangle_file_res.stdout().to_owned()) .ok() .unwrap() diff --git a/tests/by-util/test_tail.rs b/tests/by-util/test_tail.rs index 86ae9a954..61fab0745 100644 --- a/tests/by-util/test_tail.rs +++ b/tests/by-util/test_tail.rs @@ -380,10 +380,9 @@ fn test_follow_stdin_name_retry() { for _ in 0..2 { new_ucmd!() .args(&args) - .run() + .fails_with_code(1) .no_stdout() - .stderr_is("tail: cannot follow '-' by name\n") - .code_is(1); + .stderr_is("tail: cannot follow '-' by name\n"); args.pop(); } } @@ -852,13 +851,12 @@ fn test_follow_missing() { new_ucmd!() .arg(follow_mode) .arg("missing") - .run() + .fails_with_code(1) .no_stdout() .stderr_is( "tail: cannot open 'missing' for reading: No such file or directory\n\ tail: no files remaining\n", - ) - .code_is(1); + ); } } @@ -871,17 +869,15 @@ fn test_follow_name_stdin() { ts.ucmd() .arg("--follow=name") .arg("-") - .run() - .stderr_is("tail: cannot follow '-' by name\n") - .code_is(1); + .fails_with_code(1) + .stderr_is("tail: cannot follow '-' by name\n"); ts.ucmd() .arg("--follow=name") .arg("FILE1") .arg("-") .arg("FILE2") - .run() - .stderr_is("tail: cannot follow '-' by name\n") - .code_is(1); + .fails_with_code(1) + .stderr_is("tail: cannot follow '-' by name\n"); } #[test] @@ -910,9 +906,8 @@ fn test_dir() { let (at, mut ucmd) = at_and_ucmd!(); at.mkdir("DIR"); ucmd.arg("DIR") - .run() - .stderr_is("tail: error reading 'DIR': Is a directory\n") - .code_is(1); + .fails_with_code(1) + .stderr_is("tail: error reading 'DIR': Is a directory\n"); } #[test] @@ -924,14 +919,13 @@ fn test_dir_follow() { ts.ucmd() .arg(mode) .arg("DIR") - .run() + .fails_with_code(1) .no_stdout() .stderr_is( "tail: error reading 'DIR': Is a directory\n\ tail: DIR: cannot follow end of this type of file; giving up on this name\n\ tail: no files remaining\n", - ) - .code_is(1); + ); } } @@ -944,14 +938,13 @@ fn test_dir_follow_retry() { .arg("--follow=descriptor") .arg("--retry") .arg("DIR") - .run() + .fails_with_code(1) .stderr_is( "tail: warning: --retry only effective for the initial open\n\ tail: error reading 'DIR': Is a directory\n\ tail: DIR: cannot follow end of this type of file\n\ tail: no files remaining\n", - ) - .code_is(1); + ); } #[test] @@ -1161,12 +1154,11 @@ fn test_bytes_for_funny_unix_files() { continue; } let args = ["--bytes", "1", file]; - let result = ts.ucmd().args(&args).run(); let exp_result = unwrap_or_return!(expected_result(&ts, &args)); + let result = ts.ucmd().args(&args).succeeds(); result .stdout_is(exp_result.stdout_str()) - .stderr_is(exp_result.stderr_str()) - .code_is(exp_result.code()); + .stderr_is(exp_result.stderr_str()); } } @@ -1194,13 +1186,11 @@ fn test_retry2() { let ts = TestScenario::new(util_name!()); let missing = "missing"; - let result = ts.ucmd().arg(missing).arg("--retry").run(); - result - .stderr_is( - "tail: warning: --retry ignored; --retry is useful only when following\n\ + let result = ts.ucmd().arg(missing).arg("--retry").fails_with_code(1); + result.stderr_is( + "tail: warning: --retry ignored; --retry is useful only when following\n\ tail: cannot open 'missing' for reading: No such file or directory\n", - ) - .code_is(1); + ); } #[test] @@ -4485,9 +4475,8 @@ fn test_follow_when_files_are_pointing_to_same_relative_file_and_file_stays_same fn test_args_sleep_interval_when_illegal_argument_then_usage_error(#[case] sleep_interval: &str) { new_ucmd!() .args(&["--sleep-interval", sleep_interval]) - .run() - .usage_error(format!("invalid number of seconds: '{sleep_interval}'")) - .code_is(1); + .fails_with_code(1) + .usage_error(format!("invalid number of seconds: '{sleep_interval}'")); } #[test] diff --git a/tests/by-util/test_test.rs b/tests/by-util/test_test.rs index 466503b78..acf4df6b5 100644 --- a/tests/by-util/test_test.rs +++ b/tests/by-util/test_test.rs @@ -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"); } diff --git a/tests/by-util/test_timeout.rs b/tests/by-util/test_timeout.rs index a154216db..423d7f041 100644 --- a/tests/by-util/test_timeout.rs +++ b/tests/by-util/test_timeout.rs @@ -17,7 +17,7 @@ fn test_invalid_arg() { fn test_subcommand_return_code() { new_ucmd!().arg("1").arg("true").succeeds(); - new_ucmd!().arg("1").arg("false").run().code_is(1); + new_ucmd!().arg("1").arg("false").fails_with_code(1); } #[test] @@ -93,9 +93,8 @@ fn test_preserve_status() { for arg in ["-p", "--preserve-status"] { new_ucmd!() .args(&[arg, ".1", "sleep", "10"]) - .fails() // 128 + SIGTERM = 128 + 15 - .code_is(128 + 15) + .fails_with_code(128 + 15) .no_output(); } } @@ -108,7 +107,6 @@ fn test_preserve_status_even_when_send_signal() { new_ucmd!() .args(&["-s", cont_spelling, "--preserve-status", ".1", "sleep", "2"]) .succeeds() - .code_is(0) .no_output(); } } @@ -118,12 +116,10 @@ fn test_dont_overflow() { new_ucmd!() .args(&["9223372036854775808d", "sleep", "0"]) .succeeds() - .code_is(0) .no_output(); new_ucmd!() .args(&["-k", "9223372036854775808d", "10", "sleep", "0"]) .succeeds() - .code_is(0) .no_output(); } diff --git a/tests/by-util/test_whoami.rs b/tests/by-util/test_whoami.rs index 04b3ecbe0..1d685fe98 100644 --- a/tests/by-util/test_whoami.rs +++ b/tests/by-util/test_whoami.rs @@ -16,13 +16,12 @@ fn test_invalid_arg() { #[cfg(unix)] fn test_normal() { let ts = TestScenario::new(util_name!()); - let result = ts.ucmd().run(); let exp_result = unwrap_or_return!(expected_result(&ts, &[])); + let result = ts.ucmd().succeeds(); result .stdout_is(exp_result.stdout_str()) - .stderr_is(exp_result.stderr_str()) - .code_is(exp_result.code()); + .stderr_is(exp_result.stderr_str()); } #[test]