]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: shuf: check -o output is preserved when the run fails
authorSylvestre Ledru <sylvestre@debian.org>
Sat, 27 Jun 2026 09:02:51 +0000 (11:02 +0200)
committerPádraig Brady <P@draigBrady.com>
Tue, 30 Jun 2026 17:26:51 +0000 (18:26 +0100)
A failed shuf invocation should leave an existing output file untouched
rather than truncating it before the failure is detected.
* tests/shuf/shuf.sh: Verify that a missing input file or an unreadable
random source leaves an existing -o file unchanged.

Link: https://github.com/coreutils/coreutils/pull/304
tests/shuf/shuf.sh

index 387bbb649c4534a0432f623b0213501a781d9a46..86a44831eae87626e3e0cecc1fb6681bac33ca7f 100755 (executable)
@@ -136,6 +136,17 @@ done
 { shuf -i0-9 --random-source A --random-source B || test $? -ne 1; } &&
   { fail=1; echo "shuf did not detect multiple --random-source usage.">&2 ; }
 
+# A failed run must leave an existing -o output file untouched rather than
+# truncating it before the failure is detected.
+printf 'precious\n' > exp || framework_failure_
+cp exp out || framework_failure_
+returns_ 1 shuf -o out missing-input || fail=1
+compare exp out || { fail=1; echo "shuf truncated -o on input error">&2 ; }
+cp exp out || framework_failure_
+returns_ 1 shuf -o out --random-source=missing-input in || fail=1
+compare exp out ||
+ { fail=1; echo "shuf truncated -o on random-source error">&2 ; }
+
 # Test --repeat option
 
 # --repeat without count should return an indefinite number of lines