blob: 83bf382cd2291f6924f3d542c9462db26371778d [file] [log] [blame]
Rob Landley14efdc52005-09-07 04:18:36 +00001#!/bin/sh
2
3# SUSv3 compliant uniq tests.
4# Copyright 2005 by Rob Landley <rob@landley.net>
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02005# Licensed under GPLv2, see file LICENSE in this source tree.
Rob Landley14efdc52005-09-07 04:18:36 +00006
Rob Landley1e519252005-09-14 14:36:40 +00007# AUDIT: Full SUSv3 coverage (except internationalization).
Rob Landley14efdc52005-09-07 04:18:36 +00008
Mike Frysingercaa79402009-11-04 18:41:22 -05009. ./testing.sh
Rob Landley14efdc52005-09-07 04:18:36 +000010
Rob Landley1e519252005-09-14 14:36:40 +000011# 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 Landley4bb1b042006-03-16 15:20:45 +000017testing "uniq (exit with error)" "uniq nonexistent 2> /dev/null || echo yes" \
Rob Landley1e519252005-09-14 14:36:40 +000018 "yes\n" "" ""
Rob Landley4bb1b042006-03-16 15:20:45 +000019testing "uniq (exit success)" "uniq /dev/null && echo yes" "yes\n" "" ""
Rob Landley1e519252005-09-14 14:36:40 +000020
21# Test various data sources and destinations
22
Rob Landley4bb1b042006-03-16 15:20:45 +000023testing "uniq (default to stdin)" "uniq" "one\ntwo\nthree\n" "" \
Rob Landley14efdc52005-09-07 04:18:36 +000024 "one\ntwo\ntwo\nthree\nthree\nthree\n"
Rob Landley4bb1b042006-03-16 15:20:45 +000025testing "uniq - (specify stdin)" "uniq -" "one\ntwo\nthree\n" "" \
Rob Landley14efdc52005-09-07 04:18:36 +000026 "one\ntwo\ntwo\nthree\nthree\nthree\n"
Rob Landley4bb1b042006-03-16 15:20:45 +000027testing "uniq input (specify file)" "uniq input" "one\ntwo\nthree\n" \
Rob Landley14efdc52005-09-07 04:18:36 +000028 "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
Rob Landley1e519252005-09-14 14:36:40 +000029
Rob Landley4bb1b042006-03-16 15:20:45 +000030testing "uniq input outfile (two files)" "uniq input actual > /dev/null" \
Rob Landley14efdc52005-09-07 04:18:36 +000031 "one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
Rob Landley4bb1b042006-03-16 15:20:45 +000032testing "uniq (stdin) outfile" "uniq - actual" \
Rob Landley1e519252005-09-14 14:36:40 +000033 "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 Landley4bb1b042006-03-16 15:20:45 +000035testing "uniq input - (specify stdout)" "uniq input -" \
Rob Landley1e519252005-09-14 14:36:40 +000036 "one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
Rob Landley14efdc52005-09-07 04:18:36 +000037
Rob Landley1e519252005-09-14 14:36:40 +000038
39#-f skip fields
40#-s skip chars
41#-c occurrences
42#-d dups only
Denis Vlasenko9213a9e2006-09-17 16:28:10 +000043#-u
Denis Vlasenko96b99b82008-05-03 07:21:27 +000044#-w max chars
Rob Landley1e519252005-09-14 14:36:40 +000045
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 Landley4bb1b042006-03-16 15:20:45 +000050testing "uniq -c (occurrence count)" "uniq -c | sed 's/^[ \t]*//'" \
Rob Landley1e519252005-09-14 14:36:40 +000051 "1 one\n2 two\n3 three\n" "" \
Rob Landley14efdc52005-09-07 04:18:36 +000052 "one\ntwo\ntwo\nthree\nthree\nthree\n"
Denys Vlasenkoe4148962009-07-18 17:26:25 +020053testing "uniq -d (dups only)" "uniq -d" "two\nthree\n" "" \
Rob Landley14efdc52005-09-07 04:18:36 +000054 "one\ntwo\ntwo\nthree\nthree\nthree\n"
Rob Landley1e519252005-09-14 14:36:40 +000055
Rob Landley4bb1b042006-03-16 15:20:45 +000056testing "uniq -f -s (skip fields and chars)" "uniq -f2 -s 3" \
Rob Landley1e519252005-09-14 14:36:40 +000057"cc dd ee8
58aa bb cc9
59" "" \
60"cc dd ee8
61bb cc dd8
62aa bb cc9
63"
Denis Vlasenko96b99b82008-05-03 07:21:27 +000064testing "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"
Rob Landley1e519252005-09-14 14:36:40 +000080
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 Landley4bb1b042006-03-16 15:20:45 +000084testing "uniq -u and -d produce no output" "uniq -d -u" "" "" \
Rob Landley1e519252005-09-14 14:36:40 +000085 "one\ntwo\ntwo\nthree\nthree\nthree\n"
Rob Landley14efdc52005-09-07 04:18:36 +000086
87exit $FAILCOUNT