summaryrefslogtreecommitdiff
path: root/tests/misc/shuf.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tests/misc/shuf.sh')
-rwxr-xr-xtests/misc/shuf.sh23
1 files changed, 14 insertions, 9 deletions
diff --git a/tests/misc/shuf.sh b/tests/misc/shuf.sh
index d7251d1d..c7db14f6 100755
--- a/tests/misc/shuf.sh
+++ b/tests/misc/shuf.sh
@@ -1,7 +1,7 @@
#!/bin/sh
# Ensure that shuf randomizes its input.
-# Copyright (C) 2006-2014 Free Software Foundation, Inc.
+# Copyright (C) 2006-2015 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -47,6 +47,11 @@ test "$t" = 'a b c d e' || { fail=1; echo "not a permutation" 1>&2; }
shuf -er
test $? -eq 1 || fail=1
+# coreutils-8.22 and 8.23 dump core
+# with a single redundant operand with --input-range
+shuf -i0-0 1
+test $? -eq 1 || fail=1
+
# Before coreutils-6.3, this would infloop.
# "seq 1860" produces 8193 (8K + 1) bytes of output.
seq 1860 | shuf > /dev/null || fail=1
@@ -66,7 +71,7 @@ touch unreadable || framework_failure_
chmod 0 unreadable || framework_failure_
if ! test -r unreadable; then
shuf -n0 unreadable || fail=1
- shuf -n1 unreadable && fail=1
+ { shuf -n1 unreadable || test $? -ne 1; } && fail=1
fi
# Multiple -n is accepted, should use the smallest value
@@ -77,25 +82,25 @@ test "$c" -eq 3 || { fail=1; echo "Multiple -n failed">&2 ; }
# Test error conditions
# -i and -e must not be used together
-: | shuf -i0-9 -e A B &&
+: | { shuf -i0-9 -e A B || test $? -ne 1; } &&
{ fail=1; echo "shuf did not detect erroneous -e and -i usage.">&2 ; }
# Test invalid value for -n
-: | shuf -nA &&
+: | { shuf -nA || test $? -ne 1; } &&
{ fail=1; echo "shuf did not detect erroneous -n usage.">&2 ; }
# Test multiple -i
-shuf -i0-9 -n10 -i8-90 &&
+{ shuf -i0-9 -n10 -i8-90 || test $? -ne 1; } &&
{ 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 &&
+ { shuf -i$ARG || test $? -ne 1; } &&
{ fail=1; echo "shuf did not detect erroneous -i$ARG usage.">&2 ; }
done
# multiple -o are forbidden
-shuf -i0-9 -o A -o B &&
+{ shuf -i0-9 -o A -o B || test $? -ne 1; } &&
{ 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 &&
+{ shuf -i0-9 --random-source A --random-source B || test $? -ne 1; } &&
{ fail=1; echo "shuf did not detect multiple --random-source usage.">&2 ; }
# Test --repeat option
@@ -120,7 +125,7 @@ test "$c" = "0 1 2 3 4 5 6 7 8 9" ||
# check --repeat with non-zero low value
shuf --rep -i222-233 -n2000 > exp || framework_failure_
-c=$(cat exp | sort -nu | paste -s -d ' ') || framework_failure_
+c=$(sort -nu exp | paste -s -d ' ') || framework_failure_
test "$c" = "222 223 224 225 226 227 228 229 230 231 232 233" ||
{ fail=1; echo "--repeat produced bad output with non-zero low">&2 ; }