source: drbl_ui/backup/test_busybox/busybox-1.7.2/testsuite/uniq.tests @ 195

Last change on this file since 195 was 20, checked in by chris, 17 years ago
File size: 2.3 KB
RevLine 
[20]1#!/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
7# AUDIT: Full SUSv3 coverage (except internationalization).
8
9. testing.sh
10
11# 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
17testing "uniq (exit with error)" "uniq nonexistent 2> /dev/null || echo yes" \
18  "yes\n" "" ""
19testing "uniq (exit success)" "uniq /dev/null && echo yes" "yes\n" "" ""
20
21# Test various data sources and destinations
22
23testing "uniq (default to stdin)" "uniq" "one\ntwo\nthree\n" "" \
24  "one\ntwo\ntwo\nthree\nthree\nthree\n"
25testing "uniq - (specify stdin)" "uniq -" "one\ntwo\nthree\n" "" \
26  "one\ntwo\ntwo\nthree\nthree\nthree\n"
27testing "uniq input (specify file)" "uniq input" "one\ntwo\nthree\n" \
28  "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
29
30testing "uniq input outfile (two files)" "uniq input actual > /dev/null" \
31  "one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
32testing "uniq (stdin) outfile" "uniq - actual" \
33  "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.
35testing "uniq input - (specify stdout)" "uniq input -" \
36  "one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
37
38
39#-f skip fields
40#-s skip chars
41#-c occurrences
42#-d dups only
43#-u
44
45# Test various command line options
46
47# Leading whitespace is a minor technical violation of the spec,
48# but since gnu does it...
49testing "uniq -c (occurrence count)" "uniq -c | sed 's/^[ \t]*//'" \
50  "1 one\n2 two\n3 three\n" "" \
51  "one\ntwo\ntwo\nthree\nthree\nthree\n"
52testing "uniq -d (dups only) " "uniq -d" "two\nthree\n" "" \
53  "one\ntwo\ntwo\nthree\nthree\nthree\n"
54
55testing "uniq -f -s (skip fields and chars)" "uniq -f2 -s 3" \
56"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.
67testing "uniq -u and -d produce no output" "uniq -d -u" "" "" \
68  "one\ntwo\ntwo\nthree\nthree\nthree\n"
69
70exit $FAILCOUNT
Note: See TracBrowser for help on using the repository browser.