Rob Landley | 14efdc5 | 2005-09-07 04:18:36 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # SUSv3 compliant uniq tests. |
| 4 | # Copyright 2005 by Rob Landley <rob@landley.net> |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 5 | # Licensed under GPLv2, see file LICENSE in this source tree. |
Rob Landley | 14efdc5 | 2005-09-07 04:18:36 +0000 | [diff] [blame] | 6 | |
Rob Landley | 1e51925 | 2005-09-14 14:36:40 +0000 | [diff] [blame] | 7 | # AUDIT: Full SUSv3 coverage (except internationalization). |
Rob Landley | 14efdc5 | 2005-09-07 04:18:36 +0000 | [diff] [blame] | 8 | |
Mike Frysinger | caa7940 | 2009-11-04 18:41:22 -0500 | [diff] [blame] | 9 | . ./testing.sh |
Rob Landley | 14efdc5 | 2005-09-07 04:18:36 +0000 | [diff] [blame] | 10 | |
Rob Landley | 1e51925 | 2005-09-14 14:36:40 +0000 | [diff] [blame] | 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 | |
Rob Landley | 4bb1b04 | 2006-03-16 15:20:45 +0000 | [diff] [blame] | 17 | testing "uniq (exit with error)" "uniq nonexistent 2> /dev/null || echo yes" \ |
Rob Landley | 1e51925 | 2005-09-14 14:36:40 +0000 | [diff] [blame] | 18 | "yes\n" "" "" |
Rob Landley | 4bb1b04 | 2006-03-16 15:20:45 +0000 | [diff] [blame] | 19 | testing "uniq (exit success)" "uniq /dev/null && echo yes" "yes\n" "" "" |
Rob Landley | 1e51925 | 2005-09-14 14:36:40 +0000 | [diff] [blame] | 20 | |
| 21 | # Test various data sources and destinations |
| 22 | |
Rob Landley | 4bb1b04 | 2006-03-16 15:20:45 +0000 | [diff] [blame] | 23 | testing "uniq (default to stdin)" "uniq" "one\ntwo\nthree\n" "" \ |
Rob Landley | 14efdc5 | 2005-09-07 04:18:36 +0000 | [diff] [blame] | 24 | "one\ntwo\ntwo\nthree\nthree\nthree\n" |
Rob Landley | 4bb1b04 | 2006-03-16 15:20:45 +0000 | [diff] [blame] | 25 | testing "uniq - (specify stdin)" "uniq -" "one\ntwo\nthree\n" "" \ |
Rob Landley | 14efdc5 | 2005-09-07 04:18:36 +0000 | [diff] [blame] | 26 | "one\ntwo\ntwo\nthree\nthree\nthree\n" |
Rob Landley | 4bb1b04 | 2006-03-16 15:20:45 +0000 | [diff] [blame] | 27 | testing "uniq input (specify file)" "uniq input" "one\ntwo\nthree\n" \ |
Rob Landley | 14efdc5 | 2005-09-07 04:18:36 +0000 | [diff] [blame] | 28 | "one\ntwo\ntwo\nthree\nthree\nthree\n" "" |
Rob Landley | 1e51925 | 2005-09-14 14:36:40 +0000 | [diff] [blame] | 29 | |
Rob Landley | 4bb1b04 | 2006-03-16 15:20:45 +0000 | [diff] [blame] | 30 | testing "uniq input outfile (two files)" "uniq input actual > /dev/null" \ |
Rob Landley | 14efdc5 | 2005-09-07 04:18:36 +0000 | [diff] [blame] | 31 | "one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" "" |
Rob Landley | 4bb1b04 | 2006-03-16 15:20:45 +0000 | [diff] [blame] | 32 | testing "uniq (stdin) outfile" "uniq - actual" \ |
Rob Landley | 1e51925 | 2005-09-14 14:36:40 +0000 | [diff] [blame] | 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. |
Rob Landley | 4bb1b04 | 2006-03-16 15:20:45 +0000 | [diff] [blame] | 35 | testing "uniq input - (specify stdout)" "uniq input -" \ |
Rob Landley | 1e51925 | 2005-09-14 14:36:40 +0000 | [diff] [blame] | 36 | "one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" "" |
Rob Landley | 14efdc5 | 2005-09-07 04:18:36 +0000 | [diff] [blame] | 37 | |
Rob Landley | 1e51925 | 2005-09-14 14:36:40 +0000 | [diff] [blame] | 38 | |
| 39 | #-f skip fields |
| 40 | #-s skip chars |
| 41 | #-c occurrences |
| 42 | #-d dups only |
Denis Vlasenko | 9213a9e | 2006-09-17 16:28:10 +0000 | [diff] [blame] | 43 | #-u |
Denis Vlasenko | 96b99b8 | 2008-05-03 07:21:27 +0000 | [diff] [blame] | 44 | #-w max chars |
Rob Landley | 1e51925 | 2005-09-14 14:36:40 +0000 | [diff] [blame] | 45 | |
| 46 | # Test various command line options |
| 47 | |
| 48 | # Leading whitespace is a minor technical violation of the spec, |
| 49 | # but since gnu does it... |
Rob Landley | 4bb1b04 | 2006-03-16 15:20:45 +0000 | [diff] [blame] | 50 | testing "uniq -c (occurrence count)" "uniq -c | sed 's/^[ \t]*//'" \ |
Rob Landley | 1e51925 | 2005-09-14 14:36:40 +0000 | [diff] [blame] | 51 | "1 one\n2 two\n3 three\n" "" \ |
Rob Landley | 14efdc5 | 2005-09-07 04:18:36 +0000 | [diff] [blame] | 52 | "one\ntwo\ntwo\nthree\nthree\nthree\n" |
Denys Vlasenko | e414896 | 2009-07-18 17:26:25 +0200 | [diff] [blame] | 53 | testing "uniq -d (dups only)" "uniq -d" "two\nthree\n" "" \ |
Rob Landley | 14efdc5 | 2005-09-07 04:18:36 +0000 | [diff] [blame] | 54 | "one\ntwo\ntwo\nthree\nthree\nthree\n" |
Rob Landley | 1e51925 | 2005-09-14 14:36:40 +0000 | [diff] [blame] | 55 | |
Rob Landley | 4bb1b04 | 2006-03-16 15:20:45 +0000 | [diff] [blame] | 56 | testing "uniq -f -s (skip fields and chars)" "uniq -f2 -s 3" \ |
Rob Landley | 1e51925 | 2005-09-14 14:36:40 +0000 | [diff] [blame] | 57 | "cc dd ee8 |
| 58 | aa bb cc9 |
| 59 | " "" \ |
| 60 | "cc dd ee8 |
| 61 | bb cc dd8 |
| 62 | aa bb cc9 |
| 63 | " |
Denis Vlasenko | 96b99b8 | 2008-05-03 07:21:27 +0000 | [diff] [blame] | 64 | testing "uniq -w (compare max characters)" "uniq -w 2" \ |
| 65 | "cc1 |
| 66 | " "" \ |
| 67 | "cc1 |
| 68 | cc2 |
| 69 | cc3 |
| 70 | " |
| 71 | |
| 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 |
| 79 | " |
Rob Landley | 1e51925 | 2005-09-14 14:36:40 +0000 | [diff] [blame] | 80 | |
| 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. |
Rob Landley | 4bb1b04 | 2006-03-16 15:20:45 +0000 | [diff] [blame] | 84 | testing "uniq -u and -d produce no output" "uniq -d -u" "" "" \ |
Rob Landley | 1e51925 | 2005-09-14 14:36:40 +0000 | [diff] [blame] | 85 | "one\ntwo\ntwo\nthree\nthree\nthree\n" |
Rob Landley | 14efdc5 | 2005-09-07 04:18:36 +0000 | [diff] [blame] | 86 | |
| 87 | exit $FAILCOUNT |