1#!/bin/sh 2 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. 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 17testing "uniq (exit with error)" "uniq nonexistent 2> /dev/null || echo yes" \ 18 "yes\n" "" "" 19testing "uniq (exit success)" "uniq /dev/null && echo yes" "yes\n" "" "" 20 21# Test various data sources and destinations 22 23testing "uniq (default to stdin)" "uniq" "one\ntwo\nthree\n" "" \ 24 "one\ntwo\ntwo\nthree\nthree\nthree\n" 25testing "uniq - (specify stdin)" "uniq -" "one\ntwo\nthree\n" "" \ 26 "one\ntwo\ntwo\nthree\nthree\nthree\n" 27testing "uniq input (specify file)" "uniq input" "one\ntwo\nthree\n" \ 28 "one\ntwo\ntwo\nthree\nthree\nthree\n" "" 29 30testing "uniq input outfile (two files)" "uniq input actual > /dev/null" \ 31 "one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" "" 32testing "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. 35testing "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#-w max chars 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... 50testing "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" 53testing "uniq -d (dups only)" "uniq -d" "two\nthree\n" "" \ 54 "one\ntwo\ntwo\nthree\nthree\nthree\n" 55 56testing "uniq -f -s (skip fields and chars)" "uniq -f2 -s 3" \ 57"cc dd ee8 58aa bb cc9 59" "" \ 60"cc dd ee8 61bb cc dd8 62aa bb cc9 63" 64testing "uniq -w (compare max characters)" "uniq -w 2" \ 65"cc1 66" "" \ 67"cc1 68cc2 69cc3 70" 71 72testing "uniq -s -w (skip fields and compare max chars)" \ 73"uniq -s 2 -w 2" \ 74"aaccaa 75" "" \ 76"aaccaa 77aaccbb 78bbccaa 79" 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. 84testing "uniq -u and -d produce no output" "uniq -d -u" "" "" \ 85 "one\ntwo\ntwo\nthree\nthree\nthree\n" 86 87exit $FAILCOUNT 88