[20] | 1 | #!/bin/sh |
---|
| 2 | |
---|
| 3 | # SUSv3 compliant uniq tests. |
---|
| 4 | # Copyright 2005 by Rob Landley <rob@landley.net> |
---|
| 5 | # Licensed under GPL v2, see file LICENSE for details. |
---|
| 6 | |
---|
| 7 | # AUDIT: Full SUSv3 coverage (except internationalization). |
---|
| 8 | |
---|
| 9 | . testing.sh |
---|
| 10 | |
---|
| 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 |
---|
| 14 | |
---|
| 15 | # Test exit status |
---|
| 16 | |
---|
| 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" "" "" |
---|
| 20 | |
---|
| 21 | # Test various data sources and destinations |
---|
| 22 | |
---|
| 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" "" |
---|
| 29 | |
---|
| 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" "" |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | #-f skip fields |
---|
| 40 | #-s skip chars |
---|
| 41 | #-c occurrences |
---|
| 42 | #-d dups only |
---|
| 43 | #-u |
---|
| 44 | |
---|
| 45 | # Test various command line options |
---|
| 46 | |
---|
| 47 | # Leading whitespace is a minor technical violation of the spec, |
---|
| 48 | # but since gnu does it... |
---|
| 49 | testing "uniq -c (occurrence count)" "uniq -c | sed 's/^[ \t]*//'" \ |
---|
| 50 | "1 one\n2 two\n3 three\n" "" \ |
---|
| 51 | "one\ntwo\ntwo\nthree\nthree\nthree\n" |
---|
| 52 | testing "uniq -d (dups only) " "uniq -d" "two\nthree\n" "" \ |
---|
| 53 | "one\ntwo\ntwo\nthree\nthree\nthree\n" |
---|
| 54 | |
---|
| 55 | testing "uniq -f -s (skip fields and chars)" "uniq -f2 -s 3" \ |
---|
| 56 | "cc dd ee8 |
---|
| 57 | aa bb cc9 |
---|
| 58 | " "" \ |
---|
| 59 | "cc dd ee8 |
---|
| 60 | bb cc dd8 |
---|
| 61 | aa bb cc9 |
---|
| 62 | " |
---|
| 63 | |
---|
| 64 | # -d is "Suppress the writing fo lines that are not repeated in the input." |
---|
| 65 | # -u is "Suppress the writing of lines that are repeated in the input." |
---|
| 66 | # Therefore, together this means they should produce no output. |
---|
| 67 | testing "uniq -u and -d produce no output" "uniq -d -u" "" "" \ |
---|
| 68 | "one\ntwo\ntwo\nthree\nthree\nthree\n" |
---|
| 69 | |
---|
| 70 | exit $FAILCOUNT |
---|