2005-09-07 09:48:36 +05:30
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# SUSv3 compliant uniq tests.
|
|
|
|
# Copyright 2005 by Rob Landley <rob@landley.net>
|
|
|
|
# Licensed under GPL v2, see file LICENSE for details.
|
|
|
|
|
2005-09-14 20:06:40 +05:30
|
|
|
# AUDIT: Full SUSv3 coverage (except internationalization).
|
2005-09-07 09:48:36 +05:30
|
|
|
|
|
|
|
. testing.sh
|
|
|
|
|
2005-09-14 20:06:40 +05:30
|
|
|
# testing "test name" "options" "expected result" "file input" "stdin"
|
|
|
|
# file input will be file called "input"
|
|
|
|
# test can create a file "actual" instead of writing to stdout
|
|
|
|
|
|
|
|
# Test exit status
|
|
|
|
|
2006-03-16 20:50:45 +05:30
|
|
|
testing "uniq (exit with error)" "uniq nonexistent 2> /dev/null || echo yes" \
|
2005-09-14 20:06:40 +05:30
|
|
|
"yes\n" "" ""
|
2006-03-16 20:50:45 +05:30
|
|
|
testing "uniq (exit success)" "uniq /dev/null && echo yes" "yes\n" "" ""
|
2005-09-14 20:06:40 +05:30
|
|
|
|
|
|
|
# Test various data sources and destinations
|
|
|
|
|
2006-03-16 20:50:45 +05:30
|
|
|
testing "uniq (default to stdin)" "uniq" "one\ntwo\nthree\n" "" \
|
2005-09-07 09:48:36 +05:30
|
|
|
"one\ntwo\ntwo\nthree\nthree\nthree\n"
|
2006-03-16 20:50:45 +05:30
|
|
|
testing "uniq - (specify stdin)" "uniq -" "one\ntwo\nthree\n" "" \
|
2005-09-07 09:48:36 +05:30
|
|
|
"one\ntwo\ntwo\nthree\nthree\nthree\n"
|
2006-03-16 20:50:45 +05:30
|
|
|
testing "uniq input (specify file)" "uniq input" "one\ntwo\nthree\n" \
|
2005-09-07 09:48:36 +05:30
|
|
|
"one\ntwo\ntwo\nthree\nthree\nthree\n" ""
|
2005-09-14 20:06:40 +05:30
|
|
|
|
2006-03-16 20:50:45 +05:30
|
|
|
testing "uniq input outfile (two files)" "uniq input actual > /dev/null" \
|
2005-09-07 09:48:36 +05:30
|
|
|
"one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
|
2006-03-16 20:50:45 +05:30
|
|
|
testing "uniq (stdin) outfile" "uniq - actual" \
|
2005-09-14 20:06:40 +05:30
|
|
|
"one\ntwo\nthree\n" "" "one\ntwo\ntwo\nthree\nthree\nthree\n"
|
|
|
|
# Note: SUSv3 doesn't seem to require support for "-" output, but we do anyway.
|
2006-03-16 20:50:45 +05:30
|
|
|
testing "uniq input - (specify stdout)" "uniq input -" \
|
2005-09-14 20:06:40 +05:30
|
|
|
"one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
|
2005-09-07 09:48:36 +05:30
|
|
|
|
2005-09-14 20:06:40 +05:30
|
|
|
|
|
|
|
#-f skip fields
|
|
|
|
#-s skip chars
|
|
|
|
#-c occurrences
|
|
|
|
#-d dups only
|
2006-09-17 21:58:10 +05:30
|
|
|
#-u
|
2008-05-03 12:51:27 +05:30
|
|
|
#-w max chars
|
2005-09-14 20:06:40 +05:30
|
|
|
|
|
|
|
# Test various command line options
|
|
|
|
|
|
|
|
# Leading whitespace is a minor technical violation of the spec,
|
|
|
|
# but since gnu does it...
|
2006-03-16 20:50:45 +05:30
|
|
|
testing "uniq -c (occurrence count)" "uniq -c | sed 's/^[ \t]*//'" \
|
2005-09-14 20:06:40 +05:30
|
|
|
"1 one\n2 two\n3 three\n" "" \
|
|
|
|
"one\ntwo\ntwo\nthree\nthree\nthree\n"
|
2006-03-16 20:50:45 +05:30
|
|
|
testing "uniq -d (dups only) " "uniq -d" "two\nthree\n" "" \
|
2005-09-07 09:48:36 +05:30
|
|
|
"one\ntwo\ntwo\nthree\nthree\nthree\n"
|
2005-09-14 20:06:40 +05:30
|
|
|
|
2006-03-16 20:50:45 +05:30
|
|
|
testing "uniq -f -s (skip fields and chars)" "uniq -f2 -s 3" \
|
2005-09-14 20:06:40 +05:30
|
|
|
"cc dd ee8
|
|
|
|
aa bb cc9
|
|
|
|
" "" \
|
|
|
|
"cc dd ee8
|
|
|
|
bb cc dd8
|
|
|
|
aa bb cc9
|
|
|
|
"
|
2008-05-03 12:51:27 +05:30
|
|
|
testing "uniq -w (compare max characters)" "uniq -w 2" \
|
|
|
|
"cc1
|
|
|
|
" "" \
|
|
|
|
"cc1
|
|
|
|
cc2
|
|
|
|
cc3
|
|
|
|
"
|
|
|
|
|
|
|
|
testing "uniq -s -w (skip fields and compare max chars)" \
|
|
|
|
"uniq -s 2 -w 2" \
|
|
|
|
"aaccaa
|
|
|
|
" "" \
|
|
|
|
"aaccaa
|
|
|
|
aaccbb
|
|
|
|
bbccaa
|
|
|
|
"
|
2005-09-14 20:06:40 +05:30
|
|
|
|
|
|
|
# -d is "Suppress the writing fo lines that are not repeated in the input."
|
|
|
|
# -u is "Suppress the writing of lines that are repeated in the input."
|
|
|
|
# Therefore, together this means they should produce no output.
|
2006-03-16 20:50:45 +05:30
|
|
|
testing "uniq -u and -d produce no output" "uniq -d -u" "" "" \
|
2005-09-07 09:48:36 +05:30
|
|
|
"one\ntwo\ntwo\nthree\nthree\nthree\n"
|
|
|
|
|
|
|
|
exit $FAILCOUNT
|