1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27: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:
Sylvestre Ledru 2025-03-01 15:29:11 +01:00
parent 76ad6042b5
commit 18cb7dcf9e
90 changed files with 448 additions and 732 deletions

View file

@ -9,29 +9,25 @@ use crate::common::util::TestScenario;
#[test]
fn test_no_arguments() {
new_ucmd!()
.fails()
.code_is(2)
.fails_with_code(2)
.usage_error("missing operand");
}
#[test]
fn test_simple_values() {
// null or 0 => EXIT_VALUE == 1
new_ucmd!().args(&[""]).fails().code_is(1).stdout_only("\n");
new_ucmd!().args(&[""]).fails_with_code(1).stdout_only("\n");
new_ucmd!()
.args(&["0"])
.fails()
.code_is(1)
.fails_with_code(1)
.stdout_only("0\n");
new_ucmd!()
.args(&["00"])
.fails()
.code_is(1)
.fails_with_code(1)
.stdout_only("00\n");
new_ucmd!()
.args(&["-0"])
.fails()
.code_is(1)
.fails_with_code(1)
.stdout_only("-0\n");
// non-null and non-0 => EXIT_VALUE = 0
@ -47,8 +43,7 @@ fn test_simple_arithmetic() {
new_ucmd!()
.args(&["1", "-", "1"])
.fails()
.code_is(1)
.fails_with_code(1)
.stdout_only("0\n");
new_ucmd!()
@ -111,8 +106,7 @@ fn test_parenthesis() {
new_ucmd!()
.args(&["1", "(", ")"])
.fails()
.code_is(2)
.fails_with_code(2)
.stderr_only("expr: syntax error: unexpected argument '('\n");
}
@ -208,8 +202,7 @@ fn test_and() {
fn test_index() {
new_ucmd!()
.args(&["index", "αbcdef", "x"])
.fails()
.code_is(1)
.fails_with_code(1)
.stdout_only("0\n");
new_ucmd!()
.args(&["index", "αbcdef", "α"])
@ -238,8 +231,7 @@ fn test_index() {
new_ucmd!()
.args(&["αbcdef", "index", "α"])
.fails()
.code_is(2)
.fails_with_code(2)
.stderr_only("expr: syntax error: unexpected argument 'index'\n");
}
@ -257,8 +249,7 @@ fn test_length() {
new_ucmd!()
.args(&["abcdef", "length"])
.fails()
.code_is(2)
.fails_with_code(2)
.stderr_only("expr: syntax error: unexpected argument 'length'\n");
}
@ -304,8 +295,7 @@ fn test_substr() {
new_ucmd!()
.args(&["abc", "substr", "1", "1"])
.fails()
.code_is(2)
.fails_with_code(2)
.stderr_only("expr: syntax error: unexpected argument 'substr'\n");
}
@ -313,20 +303,17 @@ fn test_substr() {
fn test_invalid_substr() {
new_ucmd!()
.args(&["substr", "abc", "0", "1"])
.fails()
.code_is(1)
.fails_with_code(1)
.stdout_only("\n");
new_ucmd!()
.args(&["substr", "abc", &(usize::MAX.to_string() + "0"), "1"])
.fails()
.code_is(1)
.fails_with_code(1)
.stdout_only("\n");
new_ucmd!()
.args(&["substr", "abc", "0", &(usize::MAX.to_string() + "0")])
.fails()
.code_is(1)
.fails_with_code(1)
.stdout_only("\n");
}
@ -357,8 +344,7 @@ fn test_invalid_syntax() {
for invalid_syntax in invalid_syntaxes {
new_ucmd!()
.args(&invalid_syntax)
.fails()
.code_is(2)
.fails_with_code(2)
.stderr_contains("syntax error");
}
}