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

Last change on this file since 195 was 20, checked in by chris, 17 years ago
File size: 3.2 KB
RevLine 
[20]1#!/bin/sh
2
3# grep tests.
4# Copyright 2005 by Rob Landley <rob@landley.net>
5# Licensed under GPL v2, see file LICENSE for details.
6
7# AUDIT:
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 "grep (exit with error)" "grep nonexistent 2> /dev/null ; echo \$?" \
18  "1\n" "" ""
19testing "grep (exit success)" "grep grep $0 > /dev/null 2>&1 ; echo \$?" "0\n" \
20  "" ""
21# Test various data sources and destinations
22
23testing "grep (default to stdin)" "grep two" "two\n" "" \
24  "one\ntwo\nthree\nthree\nthree\n"
25testing "grep - (specify stdin)" "grep two -" "two\n" "" \
26  "one\ntwo\nthree\nthree\nthree\n"
27testing "grep input (specify file)" "grep two input" "two\n" \
28  "one\ntwo\nthree\nthree\nthree\n" ""
29
30testing "grep (no newline at EOL)" "grep bug" "bug" "bug" ""
31
32# Note that this assumes actual is empty.
33testing "grep input actual (two files)" "grep two input actual 2> /dev/null" \
34  "input:two\n" "one\ntwo\nthree\nthree\nthree\n" ""
35
36testing "grep - infile (specify stdin and file)" "grep two - input" \
37  "(standard input):two\ninput:two\n" "one\ntwo\nthree\n" \
38  "one\ntwo\ntoo\nthree\nthree\n"
39
40# Check if we see the correct return value if both stdin and non-existing file
41# are given.
42testing "grep - nofile (specify stdin and nonexisting file)" \
43  "grep two - nonexistent 2> /dev/null ; echo \$?" \
44  "(standard input):two\n(standard input):two\n2\n" \
45  "" "one\ntwo\ntwo\nthree\nthree\nthree\n"
46testing "grep -q - nofile (specify stdin and nonexisting file, no match)" \
47  "grep -q nomatch - nonexistent 2> /dev/null ; echo \$?" \
48  "2\n" "" "one\ntwo\ntwo\nthree\nthree\nthree\n"
49# SUSv3: If the -q option is specified, the exit status shall be zero
50#        if an input line is selected, even if an error was detected.
51testing "grep -q - nofile (specify stdin and nonexisting file, match)" \
52  "grep -q two - nonexistent ; echo \$?" \
53  "0\n" "" "one\ntwo\ntwo\nthree\nthree\nthree\n"
54
55# Test various command line options
56# -s no error messages
57testing "grep -s nofile (nonexisting file, no match)" \
58  "grep -s nomatch nonexistent ; echo \$?" "2\n" "" ""
59testing "grep -s nofile - (stdin and nonexisting file, match)" \
60  "grep -s domatch nonexistent - ; echo \$?" \
61  "(standard input):domatch\n2\n" "" "nomatch\ndomatch\nend\n"
62
63# This doesn't match GNU behaviour (Binary file input matches)
64# acts like GNU grep -a
65testing "grep handles binary files" "grep foo input" "foo\n" "\0foo\n\n" ""
66# This doesn't match GNU behaviour (Binary file (standard input) matches)
67# acts like GNU grep -a
68testing "grep handles binary stdin" "grep foo" "foo\n" "" "\0foo\n\n"
69
70testing "grep matches NUL" "grep . input > /dev/null 2>&1 ; echo \$?" \
71  "0\n" "\0\n" ""
72
73# -e regex
74testing "grep handles multiple regexps" "grep -e one -e two input ; echo \$?" \
75  "one\ntwo\n0\n" "one\ntwo\n" ""
76
77optional FEATURE_GREP_EGREP_ALIAS
78testing "grep -E supports extended regexps" "grep -E fo+" "foo\n" "" \
79  "b\ar\nfoo\nbaz"
80testing "grep is also egrep" "egrep foo" "foo\n" "" "foo\nbar\n"
81testing "egrep is not case insensitive" \
82  "egrep foo ; [ \$? -ne 0 ] && echo yes" "yes\n" "" "FOO\n"
83
84exit $FAILCOUNT
Note: See TracBrowser for help on using the repository browser.