mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Use the new function fails_with_code
Done with ``` $ perl -0777 -i -pe 's/([ \t]+)\.fails\(\)[ \t]*\n[ \t]+\.no_stdout\(\)[ \t]*\n[ \t]+\.code_is\(([0-9]+)\);/\1.fails_with_code(\2)\n\1.no_stdout();/gs' *rs $ sed -i -e "s|.fails()(.*).code_is(|.fails_with_code(|g" *rs $ perl -0777 -i -pe 's/([ \t]+)\.fails\(\)[ \t]*\n[ \t]+\.code_is\(([0-9]+)\);/\1.fails_with_code(\2);/gs' *rs $ perl -0777 -i -pe 's/([ \t]+)\.fails\(\)(.*?)[ \t]+\.code_is\(([0-9]+)\);/\1.fails_with_code(\3)\2;/gs' *rs ... ```
This commit is contained in:
parent
76ad6042b5
commit
18cb7dcf9e
90 changed files with 448 additions and 732 deletions
|
@ -6,12 +6,12 @@ use crate::common::util::TestScenario;
|
|||
|
||||
#[test]
|
||||
fn test_invalid_arg() {
|
||||
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
|
||||
new_ucmd!().arg("--definitely-invalid").fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_input() {
|
||||
new_ucmd!().arg(".").fails().code_is(1);
|
||||
new_ucmd!().arg(".").fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -50,8 +50,7 @@ fn test_fmt_width() {
|
|||
fn test_fmt_width_invalid() {
|
||||
new_ucmd!()
|
||||
.args(&["one-word-per-line.txt", "-w", "apple"])
|
||||
.fails()
|
||||
.code_is(1)
|
||||
.fails_with_code(1)
|
||||
.no_stdout()
|
||||
.stderr_is("fmt: invalid width: 'apple'\n");
|
||||
// an invalid width can be successfully overwritten later:
|
||||
|
@ -86,8 +85,7 @@ fn test_fmt_width_too_big() {
|
|||
for param in ["-w", "--width"] {
|
||||
new_ucmd!()
|
||||
.args(&["one-word-per-line.txt", param, "2501"])
|
||||
.fails()
|
||||
.code_is(1)
|
||||
.fails_with_code(1)
|
||||
.stderr_is("fmt: invalid width: '2501': Numerical result out of range\n");
|
||||
}
|
||||
// However, as a temporary value it is okay:
|
||||
|
@ -102,8 +100,7 @@ fn test_fmt_invalid_width() {
|
|||
for param in ["-w", "--width"] {
|
||||
new_ucmd!()
|
||||
.args(&["one-word-per-line.txt", param, "invalid"])
|
||||
.fails()
|
||||
.code_is(1)
|
||||
.fails_with_code(1)
|
||||
.stderr_contains("invalid width: 'invalid'");
|
||||
}
|
||||
}
|
||||
|
@ -112,8 +109,7 @@ fn test_fmt_invalid_width() {
|
|||
fn test_fmt_positional_width_not_first() {
|
||||
new_ucmd!()
|
||||
.args(&["one-word-per-line.txt", "-10"])
|
||||
.fails()
|
||||
.code_is(1)
|
||||
.fails_with_code(1)
|
||||
.stderr_contains("fmt: invalid option -- 1; -WIDTH is recognized only when it is the first\noption; use -w N instead");
|
||||
}
|
||||
|
||||
|
@ -121,8 +117,7 @@ fn test_fmt_positional_width_not_first() {
|
|||
fn test_fmt_width_not_valid_number() {
|
||||
new_ucmd!()
|
||||
.args(&["-25x", "one-word-per-line.txt"])
|
||||
.fails()
|
||||
.code_is(1)
|
||||
.fails_with_code(1)
|
||||
.stderr_contains("fmt: invalid width: '25x'");
|
||||
}
|
||||
|
||||
|
@ -146,8 +141,7 @@ fn test_fmt_goal_too_big() {
|
|||
for param in ["-g", "--goal"] {
|
||||
new_ucmd!()
|
||||
.args(&["one-word-per-line.txt", "--width=75", param, "76"])
|
||||
.fails()
|
||||
.code_is(1)
|
||||
.fails_with_code(1)
|
||||
.stderr_is("fmt: GOAL cannot be greater than WIDTH.\n");
|
||||
}
|
||||
}
|
||||
|
@ -157,8 +151,7 @@ fn test_fmt_goal_bigger_than_default_width_of_75() {
|
|||
for param in ["-g", "--goal"] {
|
||||
new_ucmd!()
|
||||
.args(&["one-word-per-line.txt", param, "76"])
|
||||
.fails()
|
||||
.code_is(1)
|
||||
.fails_with_code(1)
|
||||
.stderr_is("fmt: GOAL cannot be greater than WIDTH.\n");
|
||||
}
|
||||
}
|
||||
|
@ -190,8 +183,7 @@ fn test_fmt_goal_too_small_to_check_negative_minlength() {
|
|||
fn test_fmt_non_existent_file() {
|
||||
new_ucmd!()
|
||||
.args(&["non-existing"])
|
||||
.fails()
|
||||
.code_is(1)
|
||||
.fails_with_code(1)
|
||||
.stderr_is("fmt: cannot open 'non-existing' for reading: No such file or directory\n");
|
||||
}
|
||||
|
||||
|
@ -200,8 +192,7 @@ fn test_fmt_invalid_goal() {
|
|||
for param in ["-g", "--goal"] {
|
||||
new_ucmd!()
|
||||
.args(&["one-word-per-line.txt", param, "invalid"])
|
||||
.fails()
|
||||
.code_is(1)
|
||||
.fails_with_code(1)
|
||||
// GNU complains about "invalid width", which is confusing.
|
||||
// We intentionally deviate from GNU, and show a more helpful message:
|
||||
.stderr_contains("invalid goal: 'invalid'");
|
||||
|
@ -220,14 +211,12 @@ fn test_fmt_invalid_goal_override() {
|
|||
fn test_fmt_invalid_goal_width_priority() {
|
||||
new_ucmd!()
|
||||
.args(&["one-word-per-line.txt", "-g", "apple", "-w", "banana"])
|
||||
.fails()
|
||||
.code_is(1)
|
||||
.fails_with_code(1)
|
||||
.no_stdout()
|
||||
.stderr_is("fmt: invalid width: 'banana'\n");
|
||||
new_ucmd!()
|
||||
.args(&["one-word-per-line.txt", "-w", "banana", "-g", "apple"])
|
||||
.fails()
|
||||
.code_is(1)
|
||||
.fails_with_code(1)
|
||||
.no_stdout()
|
||||
.stderr_is("fmt: invalid width: 'banana'\n");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue