From 868600cac9a20c7c79709e1dcddba85c3e3cfc4d Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Fri, 23 Feb 2024 05:14:29 +0100 Subject: [PATCH 1/5] tee: fail test if string setup fails --- tests/by-util/test_tee.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/by-util/test_tee.rs b/tests/by-util/test_tee.rs index 34076bbf9..c18668278 100644 --- a/tests/by-util/test_tee.rs +++ b/tests/by-util/test_tee.rs @@ -77,7 +77,7 @@ fn test_tee_no_more_writeable_1() { // equals to 'tee /dev/full out2 Date: Fri, 23 Feb 2024 05:19:02 +0100 Subject: [PATCH 2/5] sort: add skipped test for combined flags Now that clap#2624 has been resolved, we can and should test both variants. --- tests/by-util/test_sort.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/by-util/test_sort.rs b/tests/by-util/test_sort.rs index 97c72c7b1..8c2241e51 100644 --- a/tests/by-util/test_sort.rs +++ b/tests/by-util/test_sort.rs @@ -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") @@ -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"]; From bcd2d888a1e3386f96ae4d5151b9e76f525055d2 Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Fri, 23 Feb 2024 05:02:33 +0100 Subject: [PATCH 3/5] cat: don't flake even on exotic pipe buffer sizes See also 9995c637aa5de190ddce0abc4be36d773797f1bc. There is a race condition between the writing thread and the command. It is easily possible that on the developer's machine, the writing thread is always faster, filling the kernel's buffer of the stdin pipe, thus succeeding the write. It is also easily possible that on the busy CI machines, the child command runs first for whatever reason, and exits early, thus killing the pipe, which causes the later write to fail. This results in a flaky test. Let's prevent flaky tests. --- tests/by-util/test_cat.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/by-util/test_cat.rs b/tests/by-util/test_cat.rs index 560709f29..ab8e71899 100644 --- a/tests/by-util/test_cat.rs +++ b/tests/by-util/test_cat.rs @@ -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"); } @@ -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( From 44c59a6d284d3c6829a345fb6058b5383229d6a8 Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Fri, 23 Feb 2024 05:40:29 +0100 Subject: [PATCH 4/5] numfmt: don't flake even on exotic pipe buffer sizes --- tests/by-util/test_numfmt.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/by-util/test_numfmt.rs b/tests/by-util/test_numfmt.rs index 2c2e95d0b..bb80502d5 100644 --- a/tests/by-util/test_numfmt.rs +++ b/tests/by-util/test_numfmt.rs @@ -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] From b3d8344d1d88d7e60a9e68f9dd4a2bc18846a071 Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Fri, 23 Feb 2024 05:23:39 +0100 Subject: [PATCH 5/5] split: don't flake even on exotic pipe buffer sizes --- tests/by-util/test_split.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/by-util/test_split.rs b/tests/by-util/test_split.rs index acb8ab561..4e98a046a 100644 --- a/tests/by-util/test_split.rs +++ b/tests/by-util/test_split.rs @@ -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"); }