mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37: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
|
@ -1412,9 +1412,8 @@ fn repeat_everything() {
|
||||||
"9",
|
"9",
|
||||||
"{5}",
|
"{5}",
|
||||||
])
|
])
|
||||||
.fails()
|
.fails_with_code(1)
|
||||||
.no_stdout()
|
.no_stdout()
|
||||||
.code_is(1)
|
|
||||||
.stderr_only("csplit: '9': line number out of range on repetition 5\n");
|
.stderr_only("csplit: '9': line number out of range on repetition 5\n");
|
||||||
let count = glob(&at.plus_as_string("xx*"))
|
let count = glob(&at.plus_as_string("xx*"))
|
||||||
.expect("there should be some splits created")
|
.expect("there should be some splits created")
|
||||||
|
|
|
@ -27,8 +27,8 @@ fn test_invalid_arg() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_valid_arg_exponents() {
|
fn test_valid_arg_exponents() {
|
||||||
new_ucmd!().arg("-h").succeeds().code_is(0);
|
new_ucmd!().arg("-h").succeeds();
|
||||||
new_ucmd!().arg("--exponents").succeeds().code_is(0);
|
new_ucmd!().arg("--exponents").succeeds();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -98,8 +98,7 @@ fn test_invalid_value_time_style() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.arg("--time-style=definitely_invalid_value")
|
.arg("--time-style=definitely_invalid_value")
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.no_stderr()
|
.no_stderr();
|
||||||
.code_is(0);
|
|
||||||
// If it is used, error:
|
// If it is used, error:
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.arg("-g")
|
.arg("-g")
|
||||||
|
@ -112,8 +111,7 @@ fn test_invalid_value_time_style() {
|
||||||
.arg("--time-style=definitely_invalid_value")
|
.arg("--time-style=definitely_invalid_value")
|
||||||
.arg("--format=single-column")
|
.arg("--format=single-column")
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.no_stderr()
|
.no_stderr();
|
||||||
.code_is(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[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
|
// Check padding is the same for real files and dangling links, in non-long formats
|
||||||
at.touch("temp_dir/real_file");
|
at.touch("temp_dir/real_file");
|
||||||
|
|
||||||
let real_file_res = scene.ucmd().arg("-Li1").arg("temp_dir").fails();
|
let real_file_res = scene.ucmd().arg("-Li1").arg("temp_dir").fails_with_code(1);
|
||||||
real_file_res.code_is(1);
|
|
||||||
let real_file_stdout_len = String::from_utf8(real_file_res.stdout().to_owned())
|
let real_file_stdout_len = String::from_utf8(real_file_res.stdout().to_owned())
|
||||||
.ok()
|
.ok()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -4122,8 +4119,7 @@ fn test_ls_dangling_symlinks() {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.len();
|
.len();
|
||||||
|
|
||||||
let dangle_file_res = scene.ucmd().arg("-Li1").arg("temp_dir").fails();
|
let dangle_file_res = scene.ucmd().arg("-Li1").arg("temp_dir").fails_with_code(1);
|
||||||
dangle_file_res.code_is(1);
|
|
||||||
let dangle_stdout_len = String::from_utf8(dangle_file_res.stdout().to_owned())
|
let dangle_stdout_len = String::from_utf8(dangle_file_res.stdout().to_owned())
|
||||||
.ok()
|
.ok()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
|
@ -380,10 +380,9 @@ fn test_follow_stdin_name_retry() {
|
||||||
for _ in 0..2 {
|
for _ in 0..2 {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&args)
|
.args(&args)
|
||||||
.run()
|
.fails_with_code(1)
|
||||||
.no_stdout()
|
.no_stdout()
|
||||||
.stderr_is("tail: cannot follow '-' by name\n")
|
.stderr_is("tail: cannot follow '-' by name\n");
|
||||||
.code_is(1);
|
|
||||||
args.pop();
|
args.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -852,13 +851,12 @@ fn test_follow_missing() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.arg(follow_mode)
|
.arg(follow_mode)
|
||||||
.arg("missing")
|
.arg("missing")
|
||||||
.run()
|
.fails_with_code(1)
|
||||||
.no_stdout()
|
.no_stdout()
|
||||||
.stderr_is(
|
.stderr_is(
|
||||||
"tail: cannot open 'missing' for reading: No such file or directory\n\
|
"tail: cannot open 'missing' for reading: No such file or directory\n\
|
||||||
tail: no files remaining\n",
|
tail: no files remaining\n",
|
||||||
)
|
);
|
||||||
.code_is(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -871,17 +869,15 @@ fn test_follow_name_stdin() {
|
||||||
ts.ucmd()
|
ts.ucmd()
|
||||||
.arg("--follow=name")
|
.arg("--follow=name")
|
||||||
.arg("-")
|
.arg("-")
|
||||||
.run()
|
.fails_with_code(1)
|
||||||
.stderr_is("tail: cannot follow '-' by name\n")
|
.stderr_is("tail: cannot follow '-' by name\n");
|
||||||
.code_is(1);
|
|
||||||
ts.ucmd()
|
ts.ucmd()
|
||||||
.arg("--follow=name")
|
.arg("--follow=name")
|
||||||
.arg("FILE1")
|
.arg("FILE1")
|
||||||
.arg("-")
|
.arg("-")
|
||||||
.arg("FILE2")
|
.arg("FILE2")
|
||||||
.run()
|
.fails_with_code(1)
|
||||||
.stderr_is("tail: cannot follow '-' by name\n")
|
.stderr_is("tail: cannot follow '-' by name\n");
|
||||||
.code_is(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -910,9 +906,8 @@ fn test_dir() {
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
at.mkdir("DIR");
|
at.mkdir("DIR");
|
||||||
ucmd.arg("DIR")
|
ucmd.arg("DIR")
|
||||||
.run()
|
.fails_with_code(1)
|
||||||
.stderr_is("tail: error reading 'DIR': Is a directory\n")
|
.stderr_is("tail: error reading 'DIR': Is a directory\n");
|
||||||
.code_is(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -924,14 +919,13 @@ fn test_dir_follow() {
|
||||||
ts.ucmd()
|
ts.ucmd()
|
||||||
.arg(mode)
|
.arg(mode)
|
||||||
.arg("DIR")
|
.arg("DIR")
|
||||||
.run()
|
.fails_with_code(1)
|
||||||
.no_stdout()
|
.no_stdout()
|
||||||
.stderr_is(
|
.stderr_is(
|
||||||
"tail: error reading 'DIR': Is a directory\n\
|
"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: DIR: cannot follow end of this type of file; giving up on this name\n\
|
||||||
tail: no files remaining\n",
|
tail: no files remaining\n",
|
||||||
)
|
);
|
||||||
.code_is(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -944,14 +938,13 @@ fn test_dir_follow_retry() {
|
||||||
.arg("--follow=descriptor")
|
.arg("--follow=descriptor")
|
||||||
.arg("--retry")
|
.arg("--retry")
|
||||||
.arg("DIR")
|
.arg("DIR")
|
||||||
.run()
|
.fails_with_code(1)
|
||||||
.stderr_is(
|
.stderr_is(
|
||||||
"tail: warning: --retry only effective for the initial open\n\
|
"tail: warning: --retry only effective for the initial open\n\
|
||||||
tail: error reading 'DIR': Is a directory\n\
|
tail: error reading 'DIR': Is a directory\n\
|
||||||
tail: DIR: cannot follow end of this type of file\n\
|
tail: DIR: cannot follow end of this type of file\n\
|
||||||
tail: no files remaining\n",
|
tail: no files remaining\n",
|
||||||
)
|
);
|
||||||
.code_is(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1161,12 +1154,11 @@ fn test_bytes_for_funny_unix_files() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let args = ["--bytes", "1", file];
|
let args = ["--bytes", "1", file];
|
||||||
let result = ts.ucmd().args(&args).run();
|
|
||||||
let exp_result = unwrap_or_return!(expected_result(&ts, &args));
|
let exp_result = unwrap_or_return!(expected_result(&ts, &args));
|
||||||
|
let result = ts.ucmd().args(&args).succeeds();
|
||||||
result
|
result
|
||||||
.stdout_is(exp_result.stdout_str())
|
.stdout_is(exp_result.stdout_str())
|
||||||
.stderr_is(exp_result.stderr_str())
|
.stderr_is(exp_result.stderr_str());
|
||||||
.code_is(exp_result.code());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1194,13 +1186,11 @@ fn test_retry2() {
|
||||||
let ts = TestScenario::new(util_name!());
|
let ts = TestScenario::new(util_name!());
|
||||||
let missing = "missing";
|
let missing = "missing";
|
||||||
|
|
||||||
let result = ts.ucmd().arg(missing).arg("--retry").run();
|
let result = ts.ucmd().arg(missing).arg("--retry").fails_with_code(1);
|
||||||
result
|
result.stderr_is(
|
||||||
.stderr_is(
|
"tail: warning: --retry ignored; --retry is useful only when following\n\
|
||||||
"tail: warning: --retry ignored; --retry is useful only when following\n\
|
|
||||||
tail: cannot open 'missing' for reading: No such file or directory\n",
|
tail: cannot open 'missing' for reading: No such file or directory\n",
|
||||||
)
|
);
|
||||||
.code_is(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[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) {
|
fn test_args_sleep_interval_when_illegal_argument_then_usage_error(#[case] sleep_interval: &str) {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["--sleep-interval", sleep_interval])
|
.args(&["--sleep-interval", sleep_interval])
|
||||||
.run()
|
.fails_with_code(1)
|
||||||
.usage_error(format!("invalid number of seconds: '{sleep_interval}'"))
|
.usage_error(format!("invalid number of seconds: '{sleep_interval}'"));
|
||||||
.code_is(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -9,12 +9,12 @@ use crate::common::util::TestScenario;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_empty_test_equivalent_to_false() {
|
fn test_empty_test_equivalent_to_false() {
|
||||||
new_ucmd!().run().code_is(1);
|
new_ucmd!().fails_with_code(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_empty_string_is_false() {
|
fn test_empty_string_is_false() {
|
||||||
new_ucmd!().arg("").run().code_is(1);
|
new_ucmd!().arg("").fails_with_code(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -55,24 +55,24 @@ fn test_some_literals() {
|
||||||
|
|
||||||
// run the inverse of all these tests
|
// run the inverse of all these tests
|
||||||
for test in &tests {
|
for test in &tests {
|
||||||
scenario.ucmd().arg("!").arg(test).run().code_is(1);
|
scenario.ucmd().arg("!").arg(test).fails_with_code(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_double_not_is_false() {
|
fn test_double_not_is_false() {
|
||||||
new_ucmd!().args(&["!", "!"]).run().code_is(1);
|
new_ucmd!().args(&["!", "!"]).fails_with_code(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_and_not_is_false() {
|
fn test_and_not_is_false() {
|
||||||
new_ucmd!().args(&["-a", "!"]).run().code_is(2);
|
new_ucmd!().args(&["-a", "!"]).fails_with_code(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_not_and_is_false() {
|
fn test_not_and_is_false() {
|
||||||
// `-a` is a literal here & has nonzero length
|
// `-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]
|
#[test]
|
||||||
|
@ -105,8 +105,7 @@ fn test_negated_or() {
|
||||||
new_ucmd!().args(&["foo", "-o", "!", "bar"]).succeeds();
|
new_ucmd!().args(&["foo", "-o", "!", "bar"]).succeeds();
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["!", "foo", "-o", "!", "bar"])
|
.args(&["!", "foo", "-o", "!", "bar"])
|
||||||
.run()
|
.fails_with_code(1);
|
||||||
.code_is(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -117,10 +116,10 @@ fn test_string_length_of_nothing() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_string_length_of_empty() {
|
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
|
// STRING equivalent to -n STRING
|
||||||
new_ucmd!().arg("").run().code_is(1);
|
new_ucmd!().arg("").fails_with_code(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -141,14 +140,14 @@ fn test_zero_len_equals_zero_len() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_zero_len_not_equals_zero_len_is_false() {
|
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]
|
#[test]
|
||||||
fn test_double_equal_is_string_comparison_op() {
|
fn test_double_equal_is_string_comparison_op() {
|
||||||
// undocumented but part of the GNU test suite
|
// undocumented but part of the GNU test suite
|
||||||
new_ucmd!().args(&["t", "==", "t"]).succeeds();
|
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]
|
#[test]
|
||||||
|
@ -170,7 +169,7 @@ fn test_string_comparison() {
|
||||||
|
|
||||||
// run the inverse of all these tests
|
// run the inverse of all these tests
|
||||||
for test in &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() {
|
fn test_dangling_string_comparison_is_error() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["missing_something", "="])
|
.args(&["missing_something", "="])
|
||||||
.run()
|
.fails_with_code(2)
|
||||||
.code_is(2)
|
|
||||||
.stderr_is("test: missing argument after '='");
|
.stderr_is("test: missing argument after '='");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,7 +200,7 @@ fn test_string_operator_is_literal_after_bang() {
|
||||||
];
|
];
|
||||||
|
|
||||||
for test in &tests {
|
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
|
// run the inverse of all these tests
|
||||||
for test in &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
|
// run the inverse of all these tests
|
||||||
for test in &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() {
|
fn test_float_inequality_is_error() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["123.45", "-ge", "6"])
|
.args(&["123.45", "-ge", "6"])
|
||||||
.run()
|
.fails_with_code(2)
|
||||||
.code_is(2)
|
|
||||||
.stderr_is("test: invalid integer '123.45'\n");
|
.stderr_is("test: invalid integer '123.45'\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,14 +304,12 @@ fn test_invalid_utf8_integer_compare() {
|
||||||
|
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&[OsStr::new("123"), OsStr::new("-ne"), arg])
|
.args(&[OsStr::new("123"), OsStr::new("-ne"), arg])
|
||||||
.run()
|
.fails_with_code(2)
|
||||||
.code_is(2)
|
|
||||||
.stderr_is("test: invalid integer $'fo\\x80o'\n");
|
.stderr_is("test: invalid integer $'fo\\x80o'\n");
|
||||||
|
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&[arg, OsStr::new("-eq"), OsStr::new("456")])
|
.args(&[arg, OsStr::new("-eq"), OsStr::new("456")])
|
||||||
.run()
|
.fails_with_code(2)
|
||||||
.code_is(2)
|
|
||||||
.stderr_is("test: invalid integer $'fo\\x80o'\n");
|
.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
|
// odd but matches GNU
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["regular_file", "-nt", "regular_file"])
|
.args(&["regular_file", "-nt", "regular_file"])
|
||||||
.run()
|
.fails_with_code(1);
|
||||||
.code_is(1);
|
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["regular_file", "-ot", "regular_file"])
|
.args(&["regular_file", "-ot", "regular_file"])
|
||||||
.run()
|
.fails_with_code(1);
|
||||||
.code_is(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -412,16 +405,14 @@ fn test_file_exists() {
|
||||||
fn test_nonexistent_file_does_not_exist() {
|
fn test_nonexistent_file_does_not_exist() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["-e", "nonexistent_file"])
|
.args(&["-e", "nonexistent_file"])
|
||||||
.run()
|
.fails_with_code(1);
|
||||||
.code_is(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_nonexistent_file_is_not_regular() {
|
fn test_nonexistent_file_is_not_regular() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["-f", "nonexistent_file"])
|
.args(&["-f", "nonexistent_file"])
|
||||||
.run()
|
.fails_with_code(1);
|
||||||
.code_is(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -579,12 +570,12 @@ fn test_file_is_sticky() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_file_is_not_sticky() {
|
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]
|
#[test]
|
||||||
fn test_solo_empty_parenthetical_is_error() {
|
fn test_solo_empty_parenthetical_is_error() {
|
||||||
new_ucmd!().args(&["(", ")"]).run().code_is(2);
|
new_ucmd!().args(&["(", ")"]).fails_with_code(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -631,7 +622,7 @@ fn test_parenthesized_literal() {
|
||||||
fn test_parenthesized_op_compares_literal_parenthesis() {
|
fn test_parenthesized_op_compares_literal_parenthesis() {
|
||||||
// ensure we aren’t treating this case as “string length of literal equal
|
// ensure we aren’t treating this case as “string length of literal equal
|
||||||
// sign”
|
// sign”
|
||||||
new_ucmd!().args(&["(", "=", ")"]).run().code_is(1);
|
new_ucmd!().args(&["(", "=", ")"]).fails_with_code(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -652,13 +643,13 @@ fn test_parenthesized_string_comparison() {
|
||||||
|
|
||||||
// run the inverse of all these tests
|
// run the inverse of all these tests
|
||||||
for test in &tests {
|
for test in &tests {
|
||||||
scenario.ucmd().arg("!").args(&test[..]).run().code_is(1);
|
scenario.ucmd().arg("!").args(&test[..]).fails_with_code(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parenthesized_right_parenthesis_as_literal() {
|
fn test_parenthesized_right_parenthesis_as_literal() {
|
||||||
new_ucmd!().args(&["(", "-f", ")", ")"]).run().code_is(1);
|
new_ucmd!().args(&["(", "-f", ")", ")"]).fails_with_code(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -672,8 +663,7 @@ fn test_file_owned_by_euid() {
|
||||||
fn test_nonexistent_file_not_owned_by_euid() {
|
fn test_nonexistent_file_not_owned_by_euid() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["-O", "nonexistent_file"])
|
.args(&["-O", "nonexistent_file"])
|
||||||
.run()
|
.fails_with_code(1);
|
||||||
.code_is(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -717,8 +707,7 @@ fn test_file_owned_by_egid() {
|
||||||
fn test_nonexistent_file_not_owned_by_egid() {
|
fn test_nonexistent_file_not_owned_by_egid() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["-G", "nonexistent_file"])
|
.args(&["-G", "nonexistent_file"])
|
||||||
.run()
|
.fails_with_code(1);
|
||||||
.code_is(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -747,8 +736,7 @@ fn test_op_precedence_and_or_1() {
|
||||||
fn test_op_precedence_and_or_1_overridden_by_parentheses() {
|
fn test_op_precedence_and_or_1_overridden_by_parentheses() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["(", " ", "-o", "", ")", "-a", ""])
|
.args(&["(", " ", "-o", "", ")", "-a", ""])
|
||||||
.run()
|
.fails_with_code(1);
|
||||||
.code_is(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -762,8 +750,7 @@ fn test_op_precedence_and_or_2() {
|
||||||
fn test_op_precedence_and_or_2_overridden_by_parentheses() {
|
fn test_op_precedence_and_or_2_overridden_by_parentheses() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["", "-a", "(", "", "-o", " ", ")", "-a", " "])
|
.args(&["", "-a", "(", "", "-o", " ", ")", "-a", " "])
|
||||||
.run()
|
.fails_with_code(1);
|
||||||
.code_is(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -788,7 +775,7 @@ fn test_negated_boolean_precedence() {
|
||||||
];
|
];
|
||||||
|
|
||||||
for test in &negative_tests {
|
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!()
|
new_ucmd!()
|
||||||
.args(&["!", "a value", "-o", "another value"])
|
.args(&["!", "a value", "-o", "another value"])
|
||||||
.run()
|
.fails_with_code(1);
|
||||||
.code_is(1);
|
|
||||||
|
|
||||||
// Introducing a UOP — even one that is equivalent to a bare string — causes
|
// Introducing a UOP — even one that is equivalent to a bare string — causes
|
||||||
// bang to invert only the first term
|
// bang to invert only the first term
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["!", "-n", "", "-a", ""])
|
.args(&["!", "-n", "", "-a", ""])
|
||||||
.run()
|
.fails_with_code(1);
|
||||||
.code_is(1);
|
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["!", "", "-a", "-n", ""])
|
.args(&["!", "", "-a", "-n", ""])
|
||||||
.run()
|
.fails_with_code(1);
|
||||||
.code_is(1);
|
|
||||||
|
|
||||||
// for compound Boolean expressions, bang inverts the _next_ expression
|
// for compound Boolean expressions, bang inverts the _next_ expression
|
||||||
// only, not the entire compound expression
|
// only, not the entire compound expression
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["!", "", "-a", "", "-a", ""])
|
.args(&["!", "", "-a", "", "-a", ""])
|
||||||
.run()
|
.fails_with_code(1);
|
||||||
.code_is(1);
|
|
||||||
|
|
||||||
// parentheses can override this
|
// parentheses can override this
|
||||||
new_ucmd!()
|
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
|
// For a Boolean combination of two literals, bang inverts the entire expression
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["!", "a value", "-o", "another value"])
|
.args(&["!", "a value", "-o", "another value"])
|
||||||
.run()
|
.fails_with_code(1);
|
||||||
.code_is(1);
|
|
||||||
|
|
||||||
// only the parenthetical is inverted, not the entire expression
|
// only the parenthetical is inverted, not the entire expression
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
|
@ -867,29 +849,27 @@ fn test_complicated_parenthesized_expression() {
|
||||||
fn test_erroneous_parenthesized_expression() {
|
fn test_erroneous_parenthesized_expression() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["a", "!=", "(", "b", "-a", "b", ")", "!=", "c"])
|
.args(&["a", "!=", "(", "b", "-a", "b", ")", "!=", "c"])
|
||||||
.run()
|
.fails_with_code(2)
|
||||||
.code_is(2)
|
|
||||||
.stderr_is("test: extra argument 'b'\n");
|
.stderr_is("test: extra argument 'b'\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_or_as_filename() {
|
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]
|
#[test]
|
||||||
#[ignore = "TODO: Busybox has this working"]
|
#[ignore = "TODO: Busybox has this working"]
|
||||||
fn test_filename_or_with_equal() {
|
fn test_filename_or_with_equal() {
|
||||||
new_ucmd!()
|
new_ucmd!().args(&["-f", "=", "a", "-o", "b"]).succeeds();
|
||||||
.args(&["-f", "=", "a", "-o", "b"])
|
|
||||||
.run()
|
|
||||||
.code_is(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore = "GNU considers this an error"]
|
#[ignore = "GNU considers this an error"]
|
||||||
fn test_string_length_and_nothing() {
|
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]
|
#[test]
|
||||||
|
@ -905,7 +885,7 @@ fn test_bracket_syntax_failure() {
|
||||||
let scenario = TestScenario::new("[");
|
let scenario = TestScenario::new("[");
|
||||||
let mut ucmd = scenario.ucmd();
|
let mut ucmd = scenario.ucmd();
|
||||||
|
|
||||||
ucmd.args(&["1", "-eq", "2", "]"]).run().code_is(1);
|
ucmd.args(&["1", "-eq", "2", "]"]).fails_with_code(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -915,8 +895,7 @@ fn test_bracket_syntax_missing_right_bracket() {
|
||||||
|
|
||||||
// Missing closing bracket takes precedence over other possible errors.
|
// Missing closing bracket takes precedence over other possible errors.
|
||||||
ucmd.args(&["1", "-eq"])
|
ucmd.args(&["1", "-eq"])
|
||||||
.run()
|
.fails_with_code(2)
|
||||||
.code_is(2)
|
|
||||||
.stderr_is("[: missing ']'\n");
|
.stderr_is("[: missing ']'\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ fn test_invalid_arg() {
|
||||||
fn test_subcommand_return_code() {
|
fn test_subcommand_return_code() {
|
||||||
new_ucmd!().arg("1").arg("true").succeeds();
|
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]
|
#[test]
|
||||||
|
@ -93,9 +93,8 @@ fn test_preserve_status() {
|
||||||
for arg in ["-p", "--preserve-status"] {
|
for arg in ["-p", "--preserve-status"] {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&[arg, ".1", "sleep", "10"])
|
.args(&[arg, ".1", "sleep", "10"])
|
||||||
.fails()
|
|
||||||
// 128 + SIGTERM = 128 + 15
|
// 128 + SIGTERM = 128 + 15
|
||||||
.code_is(128 + 15)
|
.fails_with_code(128 + 15)
|
||||||
.no_output();
|
.no_output();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,7 +107,6 @@ fn test_preserve_status_even_when_send_signal() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["-s", cont_spelling, "--preserve-status", ".1", "sleep", "2"])
|
.args(&["-s", cont_spelling, "--preserve-status", ".1", "sleep", "2"])
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.code_is(0)
|
|
||||||
.no_output();
|
.no_output();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,12 +116,10 @@ fn test_dont_overflow() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["9223372036854775808d", "sleep", "0"])
|
.args(&["9223372036854775808d", "sleep", "0"])
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.code_is(0)
|
|
||||||
.no_output();
|
.no_output();
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["-k", "9223372036854775808d", "10", "sleep", "0"])
|
.args(&["-k", "9223372036854775808d", "10", "sleep", "0"])
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.code_is(0)
|
|
||||||
.no_output();
|
.no_output();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,13 +16,12 @@ fn test_invalid_arg() {
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn test_normal() {
|
fn test_normal() {
|
||||||
let ts = TestScenario::new(util_name!());
|
let ts = TestScenario::new(util_name!());
|
||||||
let result = ts.ucmd().run();
|
|
||||||
let exp_result = unwrap_or_return!(expected_result(&ts, &[]));
|
let exp_result = unwrap_or_return!(expected_result(&ts, &[]));
|
||||||
|
let result = ts.ucmd().succeeds();
|
||||||
|
|
||||||
result
|
result
|
||||||
.stdout_is(exp_result.stdout_str())
|
.stdout_is(exp_result.stdout_str())
|
||||||
.stderr_is(exp_result.stderr_str())
|
.stderr_is(exp_result.stderr_str());
|
||||||
.code_is(exp_result.code());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue