]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: add more tests for shuf option combinations
authorAssaf Gordon <assafgordon@gmail.com>
Fri, 5 Jul 2013 20:59:44 +0000 (14:59 -0600)
committerPádraig Brady <P@draigBrady.com>
Thu, 11 Jul 2013 00:17:30 +0000 (01:17 +0100)
* test/misc/shuf.sh: Add tests for erroneous conditions
like multiple '-o' and '--random-source'.

tests/misc/shuf.sh

index 3e33b615195d7de60c25706e47307b141e5b741c..492fd41862e2aa17e047686ecb2ad726a5afffed 100755 (executable)
@@ -65,4 +65,33 @@ if ! test -r unreadable; then
   shuf -n1 unreadable && fail=1
 fi
 
+# Multiple -n is accepted, should use the smallest value
+shuf -n10 -i0-9 -n3 -n20 > exp || framework_failure_
+c=$(wc -l < exp) || framework_failure_
+test "$c" -eq 3 || { fail=1; echo "Multiple -n failed">&2 ; }
+
+# Test error conditions
+
+# -i and -e must not be used together
+: | shuf -i -e A B &&
+  { fail=1; echo "shuf did not detect erroneous -e and -i usage.">&2 ; }
+# Test invalid value for -n
+: | shuf -nA &&
+  { fail=1; echo "shuf did not detect erroneous -n usage.">&2 ; }
+# Test multiple -i
+shuf -i0-9 -n10 -i8-90 &&
+  { fail=1; echo "shuf did not detect multiple -i usage.">&2 ; }
+# Test invalid range
+for ARG in '1' 'A' '1-' '1-A'; do
+  shuf -i$ARG &&
+    { fail=1; echo "shuf did not detect erroneous -i$ARG usage.">&2 ; }
+done
+
+# multiple -o are forbidden
+shuf -i0-9 -o A -o B &&
+  { fail=1; echo "shuf did not detect erroneous multiple -o usage.">&2 ; }
+# multiple random-sources are forbidden
+shuf -i0-9 --random-source A --random-source B &&
+  { fail=1; echo "shuf did not detect multiple --random-source usage.">&2 ; }
+
 Exit $fail