blob: 27d9561e1427be25616c9c15906462eaa7f777b6 [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>
5# Licensed under GPL v2, see file LICENSE for details.
6
Rob Landley1e519252005-09-14 14:36:40 +00007# AUDIT: Full SUSv3 coverage (except internationalization).
Rob Landley14efdc52005-09-07 04:18:36 +00008
9if [ ${#COMMAND} -eq 0 ]; then COMMAND=uniq; fi
10. testing.sh
11
Bernhard Reutner-Fischerb47a74f2005-09-23 15:44:46 +000012# Depends on uniq
13_BB_CONFIG_DEP=uniq
14
Rob Landley1e519252005-09-14 14:36:40 +000015# testing "test name" "options" "expected result" "file input" "stdin"
16# file input will be file called "input"
17# test can create a file "actual" instead of writing to stdout
18
19# Test exit status
20
21testing "uniq (exit with error)" "nonexistent 2> /dev/null || echo yes" \
22 "yes\n" "" ""
23testing "uniq (exit success)" "/dev/null && echo yes" "yes\n" "" ""
24
25# Test various data sources and destinations
26
Rob Landley14efdc52005-09-07 04:18:36 +000027testing "uniq (default to stdin)" "" "one\ntwo\nthree\n" "" \
28 "one\ntwo\ntwo\nthree\nthree\nthree\n"
29testing "uniq - (specify stdin)" "-" "one\ntwo\nthree\n" "" \
30 "one\ntwo\ntwo\nthree\nthree\nthree\n"
31testing "uniq input (specify file)" "input" "one\ntwo\nthree\n" \
32 "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
Rob Landley1e519252005-09-14 14:36:40 +000033
Rob Landley14efdc52005-09-07 04:18:36 +000034testing "uniq input outfile (two files)" "input actual > /dev/null" \
35 "one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
Rob Landley1e519252005-09-14 14:36:40 +000036testing "uniq (stdin) outfile" "- actual" \
37 "one\ntwo\nthree\n" "" "one\ntwo\ntwo\nthree\nthree\nthree\n"
38# Note: SUSv3 doesn't seem to require support for "-" output, but we do anyway.
39testing "uniq input - (specify stdout)" "input -" \
40 "one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
Rob Landley14efdc52005-09-07 04:18:36 +000041
Rob Landley1e519252005-09-14 14:36:40 +000042
43#-f skip fields
44#-s skip chars
45#-c occurrences
46#-d dups only
47#-u
48
49# Test various command line options
50
51# Leading whitespace is a minor technical violation of the spec,
52# but since gnu does it...
53testing "uniq -c (occurrence count)" "-c | sed 's/^[ \t]*//'" \
54 "1 one\n2 two\n3 three\n" "" \
Rob Landley14efdc52005-09-07 04:18:36 +000055 "one\ntwo\ntwo\nthree\nthree\nthree\n"
Rob Landley1e519252005-09-14 14:36:40 +000056testing "uniq -d (dups only) " "-d" "two\nthree\n" "" \
Rob Landley14efdc52005-09-07 04:18:36 +000057 "one\ntwo\ntwo\nthree\nthree\nthree\n"
Rob Landley1e519252005-09-14 14:36:40 +000058
59testing "uniq -f -s (skip fields and chars)" "-f2 -s 3" \
60"cc dd ee8
61aa bb cc9
62" "" \
63"cc dd ee8
64bb cc dd8
65aa bb cc9
66"
67
68# -d is "Suppress the writing fo lines that are not repeated in the input."
69# -u is "Suppress the writing of lines that are repeated in the input."
70# Therefore, together this means they should produce no output.
71testing "uniq -u and -d produce no output" "-d -u" "" "" \
72 "one\ntwo\ntwo\nthree\nthree\nthree\n"
Rob Landley14efdc52005-09-07 04:18:36 +000073
74exit $FAILCOUNT