blob: 49d4bed9c396adcd40976f33d693114c887fc571 [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
Rob Landley14efdc52005-09-07 04:18:36 +00009. testing.sh
10
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
Rob Landley1e519252005-09-14 14:36:40 +000044
45# Test various command line options
46
47# Leading whitespace is a minor technical violation of the spec,
48# but since gnu does it...
Rob Landley4bb1b042006-03-16 15:20:45 +000049testing "uniq -c (occurrence count)" "uniq -c | sed 's/^[ \t]*//'" \
Rob Landley1e519252005-09-14 14:36:40 +000050 "1 one\n2 two\n3 three\n" "" \
Rob Landley14efdc52005-09-07 04:18:36 +000051 "one\ntwo\ntwo\nthree\nthree\nthree\n"
Rob Landley4bb1b042006-03-16 15:20:45 +000052testing "uniq -d (dups only) " "uniq -d" "two\nthree\n" "" \
Rob Landley14efdc52005-09-07 04:18:36 +000053 "one\ntwo\ntwo\nthree\nthree\nthree\n"
Rob Landley1e519252005-09-14 14:36:40 +000054
Rob Landley4bb1b042006-03-16 15:20:45 +000055testing "uniq -f -s (skip fields and chars)" "uniq -f2 -s 3" \
Rob Landley1e519252005-09-14 14:36:40 +000056"cc dd ee8
57aa bb cc9
58" "" \
59"cc dd ee8
60bb cc dd8
61aa bb cc9
62"
63
64# -d is "Suppress the writing fo lines that are not repeated in the input."
65# -u is "Suppress the writing of lines that are repeated in the input."
66# Therefore, together this means they should produce no output.
Rob Landley4bb1b042006-03-16 15:20:45 +000067testing "uniq -u and -d produce no output" "uniq -d -u" "" "" \
Rob Landley1e519252005-09-14 14:36:40 +000068 "one\ntwo\ntwo\nthree\nthree\nthree\n"
Rob Landley14efdc52005-09-07 04:18:36 +000069
70exit $FAILCOUNT