Busybox: Upgrade to 1.21.1 (stable). lsof active.
[tomato.git] / release / src / router / busybox / testsuite / uniq.tests
blob83bf382cd2291f6924f3d542c9462db26371778d
1 #!/bin/sh
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).
9 . ./testing.sh
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
15 # Test exit status
17 testing "uniq (exit with error)" "uniq nonexistent 2> /dev/null || echo yes" \
18 "yes\n" "" ""
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" ""
39 #-f skip fields
40 #-s skip chars
41 #-c occurrences
42 #-d dups only
43 #-u
44 #-w max chars
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" \
57 "cc dd ee8
58 aa bb cc9
59 " "" \
60 "cc dd ee8
61 bb cc dd8
62 aa bb cc9
64 testing "uniq -w (compare max characters)" "uniq -w 2" \
65 "cc1
66 " "" \
67 "cc1
68 cc2
69 cc3
72 testing "uniq -s -w (skip fields and compare max chars)" \
73 "uniq -s 2 -w 2" \
74 "aaccaa
75 " "" \
76 "aaccaa
77 aaccbb
78 bbccaa
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"
87 exit $FAILCOUNT