Skip to content

Commit

Permalink
Merge pull request #6000 from BenWiederhake/dev-pipein-fails-flake
Browse files Browse the repository at this point in the history
tests: Harden two tests, prevent 4 flaky tests (cat, numfmt, sort, split, tee)
  • Loading branch information
sylvestre authored Feb 28, 2024
2 parents bd6fc2b + b3d8344 commit 769c5ca
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions tests/by-util/test_cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ fn test_piped_to_dev_full() {
s.ucmd()
.set_stdout(dev_full)
.pipe_in_fixture("alpha.txt")
.ignore_stdin_write_error()
.fails()
.stderr_contains("No space left on device");
}
Expand Down Expand Up @@ -224,6 +225,7 @@ fn test_three_directories_and_file_and_stdin() {
"test_directory3",
])
.pipe_in("stdout bytes")
.ignore_stdin_write_error()
.fails()
.stderr_is_fixture("three_directories_and_file_and_stdin.stderr.expected")
.stdout_is(
Expand Down
7 changes: 6 additions & 1 deletion tests/by-util/test_numfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,12 @@ fn test_invalid_stdin_number_returns_status_2() {

#[test]
fn test_invalid_stdin_number_in_middle_of_input() {
new_ucmd!().pipe_in("100\nhello\n200").fails().code_is(2);
new_ucmd!()
.pipe_in("100\nhello\n200")
.ignore_stdin_write_error()
.fails()
.stdout_is("100\n")
.code_is(2);
}

#[test]
Expand Down
12 changes: 10 additions & 2 deletions tests/by-util/test_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,8 +813,6 @@ fn test_check_silent() {

#[test]
fn test_check_unique() {
// Due to a clap bug the combination "-cu" does not work. "-c -u" works.
// See https://github.com/clap-rs/clap/issues/2624
new_ucmd!()
.args(&["-c", "-u"])
.pipe_in("A\nA\n")
Expand All @@ -823,6 +821,16 @@ fn test_check_unique() {
.stderr_only("sort: -:2: disorder: A\n");
}

#[test]
fn test_check_unique_combined() {
new_ucmd!()
.args(&["-cu"])
.pipe_in("A\nA\n")
.fails()
.code_is(1)
.stderr_only("sort: -:2: disorder: A\n");
}

#[test]
fn test_dictionary_and_nonprinting_conflicts() {
let conflicting_args = ["n", "h", "g", "M"];
Expand Down
1 change: 1 addition & 0 deletions tests/by-util/test_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,7 @@ fn test_split_number_oversized_stdin() {
new_ucmd!()
.args(&["--number=3", "---io-blksize=600"])
.pipe_in_fixture("sixhundredfiftyonebytes.txt")
.ignore_stdin_write_error()
.fails()
.stderr_only("split: -: cannot determine input size\n");
}
Expand Down
2 changes: 1 addition & 1 deletion tests/by-util/test_tee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn test_tee_no_more_writeable_1() {
// equals to 'tee /dev/full out2 <multi_read' call
let (at, mut ucmd) = at_and_ucmd!();
let content = (1..=10).fold(String::new(), |mut output, x| {
let _ = writeln!(output, "{x}");
writeln!(output, "{x}").unwrap();
output
});
let file_out = "tee_file_out";
Expand Down

0 comments on commit 769c5ca

Please sign in to comment.