summaryrefslogtreecommitdiff
path: root/testsuite/uniq.tests
blob: 8961d669ca7792123a760debea388745ae1a9619 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/sh

# SUSv3 compliant uniq tests.
# Copyright 2005 by Rob Landley <rob@landley.net>
# Licensed under GPL v2, see file LICENSE for details.

# AUDIT: Full SUSv3 coverage (except internationalization).

. testing.sh

# 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

testing "uniq (exit with error)" "uniq nonexistent 2> /dev/null || echo yes" \
	"yes\n" "" ""
testing "uniq (exit success)" "uniq /dev/null && echo yes" "yes\n" "" ""

# Test various data sources and destinations

testing "uniq (default to stdin)" "uniq" "one\ntwo\nthree\n" "" \
	"one\ntwo\ntwo\nthree\nthree\nthree\n"
testing "uniq - (specify stdin)" "uniq -" "one\ntwo\nthree\n" "" \
	"one\ntwo\ntwo\nthree\nthree\nthree\n"
testing "uniq input (specify file)" "uniq input" "one\ntwo\nthree\n" \
	"one\ntwo\ntwo\nthree\nthree\nthree\n" ""

testing "uniq input outfile (two files)" "uniq input actual > /dev/null" \
	"one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
testing "uniq (stdin) outfile" "uniq - actual" \
	"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.
testing "uniq input - (specify stdout)" "uniq input -" \
	"one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" ""


#-f skip fields
#-s skip chars
#-c occurrences
#-d dups only
#-u
#-w max chars

# Test various command line options

# Leading whitespace is a minor technical violation of the spec,
# but since gnu does it...
testing "uniq -c (occurrence count)" "uniq -c | sed 's/^[ \t]*//'" \
	"1 one\n2 two\n3 three\n" "" \
	"one\ntwo\ntwo\nthree\nthree\nthree\n"
testing "uniq -d (dups only) " "uniq -d" "two\nthree\n" "" \
	"one\ntwo\ntwo\nthree\nthree\nthree\n"

testing "uniq -f -s (skip fields and chars)" "uniq -f2 -s 3" \
"cc	dd	ee8
aa	bb	cc9
" "" \
"cc	dd	ee8
bb	cc	dd8
aa	bb	cc9
"
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
"

# -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.
testing "uniq -u and -d produce no output" "uniq -d -u" "" "" \
	"one\ntwo\ntwo\nthree\nthree\nthree\n"

exit $FAILCOUNT