3 # SUSv3 compliant uniq tests.
4 # Copyright 2005 by Rob Landley <rob@landley.net>
5 # Licensed under GPLv2, see file LICENSE in this source tree.
7 # AUDIT: Full SUSv3 coverage (except internationalization).
11 # testing "test name" "options" "expected result" "file input" "stdin"
12 # file input will be file called "input"
13 # test can create a file "actual" instead of writing to stdout
17 testing
"uniq (exit with error)" "uniq nonexistent 2> /dev/null || echo yes" \
19 testing
"uniq (exit success)" "uniq /dev/null && echo yes" "yes\n" "" ""
21 # Test various data sources and destinations
23 testing
"uniq (default to stdin)" "uniq" "one\ntwo\nthree\n" "" \
24 "one\ntwo\ntwo\nthree\nthree\nthree\n"
25 testing
"uniq - (specify stdin)" "uniq -" "one\ntwo\nthree\n" "" \
26 "one\ntwo\ntwo\nthree\nthree\nthree\n"
27 testing
"uniq input (specify file)" "uniq input" "one\ntwo\nthree\n" \
28 "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
30 testing
"uniq input outfile (two files)" "uniq input actual > /dev/null" \
31 "one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
32 testing
"uniq (stdin) outfile" "uniq - actual" \
33 "one\ntwo\nthree\n" "" "one\ntwo\ntwo\nthree\nthree\nthree\n"
34 # Note: SUSv3 doesn't seem to require support for "-" output, but we do anyway.
35 testing
"uniq input - (specify stdout)" "uniq input -" \
36 "one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
46 # Test various command line options
48 # Leading whitespace is a minor technical violation of the spec,
49 # but since gnu does it...
50 testing
"uniq -c (occurrence count)" "uniq -c | sed 's/^[ \t]*//'" \
51 "1 one\n2 two\n3 three\n" "" \
52 "one\ntwo\ntwo\nthree\nthree\nthree\n"
53 testing
"uniq -d (dups only)" "uniq -d" "two\nthree\n" "" \
54 "one\ntwo\ntwo\nthree\nthree\nthree\n"
56 testing
"uniq -f -s (skip fields and chars)" "uniq -f2 -s 3" \
64 testing
"uniq -w (compare max characters)" "uniq -w 2" \
72 testing
"uniq -s -w (skip fields and compare max chars)" \
81 # -d is "Suppress the writing fo lines that are not repeated in the input."
82 # -u is "Suppress the writing of lines that are repeated in the input."
83 # Therefore, together this means they should produce no output.
84 testing
"uniq -u and -d produce no output" "uniq -d -u" "" "" \
85 "one\ntwo\ntwo\nthree\nthree\nthree\n"