Skip to content

Commit

Permalink
Merge pull request #4252 from tertsdiepraam/track_caller
Browse files Browse the repository at this point in the history
Put `#[track_caller]` on assertion functions in test utils
  • Loading branch information
sylvestre authored Jan 2, 2023
2 parents 36f3507 + 44ea43f commit 75cf8ce
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 106 deletions.
2 changes: 1 addition & 1 deletion tests/by-util/test_cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2277,7 +2277,7 @@ fn test_copy_dir_preserve_permissions_inaccessible_file() {
// V V V V
ucmd.args(&["-p", "-R", "d1", "d2"])
.fails()
.status_code(1)
.code_is(1)
.stderr_only("cp: cannot open 'd1/f' for reading: Permission denied");
assert!(at.dir_exists("d2"));
assert!(!at.file_exists("d2/f"));
Expand Down
2 changes: 1 addition & 1 deletion tests/by-util/test_dd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ fn test_oversized_bs_32_bit() {
.run()
.no_stdout()
.failure()
.status_code(1)
.code_is(1)
.stderr_is(format!("dd: {}=N cannot fit into memory\n", bs_param));
}
}
Expand Down
22 changes: 9 additions & 13 deletions tests/by-util/test_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,21 @@ use crate::common::util::*;
#[test]
fn test_simple_values() {
// null or 0 => EXIT_VALUE == 1
new_ucmd!()
.args(&[""])
.fails()
.status_code(1)
.stdout_only("\n");
new_ucmd!().args(&[""]).fails().code_is(1).stdout_only("\n");
new_ucmd!()
.args(&["0"])
.fails()
.status_code(1)
.code_is(1)
.stdout_only("0\n");
new_ucmd!()
.args(&["00"])
.fails()
.status_code(1)
.code_is(1)
.stdout_only("00\n");
new_ucmd!()
.args(&["-0"])
.fails()
.status_code(1)
.code_is(1)
.stdout_only("-0\n");

// non-null and non-0 => EXIT_VALUE = 0
Expand All @@ -40,7 +36,7 @@ fn test_simple_arithmetic() {
new_ucmd!()
.args(&["1", "-", "1"])
.fails()
.status_code(1)
.code_is(1)
.stdout_only("0\n");

new_ucmd!()
Expand Down Expand Up @@ -130,7 +126,7 @@ fn test_index() {
new_ucmd!()
.args(&["index", "αbcdef", "x"])
.fails()
.status_code(1)
.code_is(1)
.stdout_only("0\n");
new_ucmd!()
.args(&["index", "αbcdef", "α"])
Expand Down Expand Up @@ -213,18 +209,18 @@ fn test_invalid_substr() {
new_ucmd!()
.args(&["substr", "abc", "0", "1"])
.fails()
.status_code(1)
.code_is(1)
.stdout_only("\n");

new_ucmd!()
.args(&["substr", "abc", &(std::usize::MAX.to_string() + "0"), "1"])
.fails()
.status_code(1)
.code_is(1)
.stdout_only("\n");

new_ucmd!()
.args(&["substr", "abc", "0", &(std::usize::MAX.to_string() + "0")])
.fails()
.status_code(1)
.code_is(1)
.stdout_only("\n");
}
6 changes: 3 additions & 3 deletions tests/by-util/test_mknod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ fn test_mknod_character_device_requires_major_and_minor() {
.arg("test_file")
.arg("c")
.fails()
.status_code(1)
.code_is(1)
.stderr_contains("Special files require major and minor device numbers.");
new_ucmd!()
.arg("test_file")
.arg("c")
.arg("1")
.fails()
.status_code(1)
.code_is(1)
.stderr_contains("Special files require major and minor device numbers.");
new_ucmd!()
.arg("test_file")
Expand Down Expand Up @@ -122,6 +122,6 @@ fn test_mknod_invalid_mode() {
.arg("p")
.fails()
.no_stdout()
.status_code(1)
.code_is(1)
.stderr_contains("invalid mode");
}
10 changes: 5 additions & 5 deletions tests/by-util/test_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ fn test_nonexistent_file() {
new_ucmd!()
.arg("nonexistent.txt")
.fails()
.status_code(2)
.code_is(2)
.stderr_only(
#[cfg(not(windows))]
"sort: cannot read: nonexistent.txt: No such file or directory",
Expand Down Expand Up @@ -1015,7 +1015,7 @@ fn test_verifies_out_file() {
.pipe_in(input)
.ignore_stdin_write_error()
.fails()
.status_code(2)
.code_is(2)
.stderr_only(
#[cfg(not(windows))]
"sort: open failed: nonexistent_dir/nonexistent_file: No such file or directory",
Expand All @@ -1036,7 +1036,7 @@ fn test_verifies_files_after_keys() {
"nonexistent_dir/input_file",
])
.fails()
.status_code(2)
.code_is(2)
.stderr_contains("failed to parse key");
}

Expand All @@ -1046,7 +1046,7 @@ fn test_verifies_input_files() {
new_ucmd!()
.args(&["/dev/random", "nonexistent_file"])
.fails()
.status_code(2)
.code_is(2)
.stderr_is("sort: cannot read: nonexistent_file: No such file or directory");
}

Expand Down Expand Up @@ -1104,7 +1104,7 @@ fn test_wrong_args_exit_code() {
new_ucmd!()
.arg("--misspelled")
.fails()
.status_code(2)
.code_is(2)
.stderr_contains("--misspelled");
}

Expand Down
Loading

0 comments on commit 75cf8ce

Please sign in to comment.