3 # SUSv3 compliant uniq tests.
4 # Copyright 2005 by Rob Landley <rob@landley.net>
5 # Licensed under GPL v2, see file LICENSE for details.
7 # AUDIT: Full SUSv3 coverage (except internationalization).
9 if [ ${#COMMAND} -eq 0 ]; then COMMAND=uniq; fi
15 # testing "test name" "options" "expected result" "file input" "stdin"
16 # file input will be file called "input"
17 # test can create a file "actual" instead of writing to stdout
21 testing "uniq (exit with error)" "nonexistent 2> /dev/null || echo yes" \
23 testing "uniq (exit success)" "/dev/null && echo yes" "yes\n" "" ""
25 # Test various data sources and destinations
27 testing "uniq (default to stdin)" "" "one\ntwo\nthree\n" "" \
28 "one\ntwo\ntwo\nthree\nthree\nthree\n"
29 testing "uniq - (specify stdin)" "-" "one\ntwo\nthree\n" "" \
30 "one\ntwo\ntwo\nthree\nthree\nthree\n"
31 testing "uniq input (specify file)" "input" "one\ntwo\nthree\n" \
32 "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
34 testing "uniq input outfile (two files)" "input actual > /dev/null" \
35 "one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
36 testing "uniq (stdin) outfile" "- actual" \
37 "one\ntwo\nthree\n" "" "one\ntwo\ntwo\nthree\nthree\nthree\n"
38 # Note: SUSv3 doesn't seem to require support for "-" output, but we do anyway.
39 testing "uniq input - (specify stdout)" "input -" \
40 "one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
49 # Test various command line options
51 # Leading whitespace is a minor technical violation of the spec,
52 # but since gnu does it...
53 testing "uniq -c (occurrence count)" "-c | sed 's/^[ \t]*//'" \
54 "1 one\n2 two\n3 three\n" "" \
55 "one\ntwo\ntwo\nthree\nthree\nthree\n"
56 testing "uniq -d (dups only) " "-d" "two\nthree\n" "" \
57 "one\ntwo\ntwo\nthree\nthree\nthree\n"
59 testing "uniq -f -s (skip fields and chars)" "-f2 -s 3" \
68 # -d is "Suppress the writing fo lines that are not repeated in the input."
69 # -u is "Suppress the writing of lines that are repeated in the input."
70 # Therefore, together this means they should produce no output.
71 testing "uniq -u and -d produce no output" "-d -u" "" "" \
72 "one\ntwo\ntwo\nthree\nthree\nthree\n"