Skip to content

Commit 5a6e9e2

Browse files
committed
all: add tests for usage error exit code
1 parent 975a1d1 commit 5a6e9e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+372
-0
lines changed

tests/by-util/test_arch.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ fn test_arch_help() {
1212
.succeeds()
1313
.stdout_contains("architecture name");
1414
}
15+
16+
#[test]
17+
fn test_invalid_arg() {
18+
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
19+
}

tests/by-util/test_basename.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,8 @@ fn test_simple_format() {
192192
.code_is(1)
193193
.stderr_contains("extra operand 'c'");
194194
}
195+
196+
#[test]
197+
fn test_invalid_arg() {
198+
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
199+
}

tests/by-util/test_chgrp.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ fn test_invalid_option() {
88
new_ucmd!().arg("-w").arg("/").fails();
99
}
1010

11+
#[test]
12+
fn test_invalid_arg() {
13+
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
14+
}
15+
1116
static DIR: &str = "/dev";
1217

1318
// we should always get both arguments, regardless of whether --reference was used

tests/by-util/test_chmod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,11 @@ fn test_no_operands() {
561561
.usage_error("missing operand");
562562
}
563563

564+
#[test]
565+
fn test_invalid_arg() {
566+
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
567+
}
568+
564569
#[test]
565570
fn test_mode_after_dash_dash() {
566571
let (at, ucmd) = at_and_ucmd!();

tests/by-util/test_chown.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ fn test_invalid_option() {
7878
new_ucmd!().arg("-w").arg("-q").arg("/").fails();
7979
}
8080

81+
#[test]
82+
fn test_invalid_arg() {
83+
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
84+
}
85+
8186
#[test]
8287
fn test_chown_only_owner() {
8388
// test chown username file.txt

tests/by-util/test_chroot.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
use crate::common::util::*;
44

5+
#[test]
6+
fn test_invalid_arg() {
7+
new_ucmd!().arg("--definitely-invalid").fails().code_is(125);
8+
}
9+
510
#[test]
611
fn test_missing_operand() {
712
let result = new_ucmd!().run();

tests/by-util/test_cksum.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
use crate::common::util::*;
44

5+
#[test]
6+
fn test_invalid_arg() {
7+
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
8+
}
9+
510
#[test]
611
fn test_single_file() {
712
new_ucmd!()

tests/by-util/test_comm.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
use crate::common::util::*;
44

5+
#[test]
6+
fn test_invalid_arg() {
7+
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
8+
}
9+
510
#[test]
611
fn ab_no_args() {
712
new_ucmd!()

tests/by-util/test_csplit.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ fn generate(from: u32, to: u32) -> String {
77
(from..to).fold(String::new(), |acc, v| format!("{}{}\n", acc, v))
88
}
99

10+
#[test]
11+
fn test_invalid_arg() {
12+
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
13+
}
14+
1015
#[test]
1116
fn test_stdin() {
1217
let (at, mut ucmd) = at_and_ucmd!();

tests/by-util/test_cut.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ static COMPLEX_SEQUENCE: &TestedSequence = &TestedSequence {
3939
sequence: "9-,6-7,-2,4",
4040
};
4141

42+
#[test]
43+
fn test_invalid_arg() {
44+
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
45+
}
46+
4247
#[test]
4348
fn test_byte_sequence() {
4449
for param in ["-b", "--bytes", "--byt"] {

0 commit comments

Comments
 (0)