VirtualBox

source: kBuild/vendor/grep/2.12/tests/foad1@ 3627

Last change on this file since 3627 was 2595, checked in by bird, 13 years ago

gnu grep version 2.12 (grep-2.12.tar.xz, md5sum=8d2f0346d08b13c18afb81f0e8aa1e2f)

File size: 9.0 KB
Line 
1#! /bin/sh
2# Test various combinations of command-line options.
3#
4# Copyright (C) 2001, 2006, 2009-2012 Free Software Foundation, Inc.
5#
6# Copying and distribution of this file, with or without modification,
7# are permitted in any medium without royalty provided the copyright
8# notice and this notice are preserved.
9#
10# This set of tests was started by Julian Foad.
11
12. "${srcdir=.}/init.sh"; path_prepend_ ../src
13
14failures=0
15
16# grep_test INPUT EXPECTED_OUTPUT PATTERN_AND_OPTIONS...
17# Run "grep" with the given INPUT, pattern and options, and check that
18# the output is EXPECTED_OUTPUT. If not, print a message and set 'failures'.
19# "/" represents a newline within INPUT and EXPECTED_OUTPUT.
20grep_test ()
21{
22 INPUT="$1"
23 EXPECT="$2"
24 shift 2
25 OUTPUT=$(printf %s "$INPUT" | tr "/" "\n" | grep "$@" | tr "\n" "/")
26 if test "$OUTPUT" != "$EXPECT" || test "$VERBOSE" = "yes"; then
27 echo "Testing: grep $@"
28 test "$LC_ALL" != C && test "$LC_ALL" != "" && echo " LC_ALL: \"$LC_ALL\""
29 echo " input: \"$INPUT\""
30 echo " output: \"$OUTPUT\""
31 fi
32 if test "$OUTPUT" != "$EXPECT"; then
33 echo " expect: \"$EXPECT\""
34 echo "FAIL"
35 failures=1
36 fi
37}
38
39
40# Test "--only-matching" ("-o") option
41
42# "-o" with "-i" should output an exact copy of the matching input text.
43grep_test "WordA/wordB/WORDC/" "Word/word/WORD/" "word" -o -i
44grep_test "WordA/wordB/WORDC/" "Word/word/WORD/" "Word" -o -i
45grep_test "WordA/wordB/WORDC/" "Word/word/WORD/" "WORD" -o -i
46
47# Should display the line number (-n), octet offset (-b), or file name
48# (-H) of every match, not just of the first match on each input line.
49# Check it both with and without -i because of the separate code paths.
50# Also check what it does when lines of context are specified.
51grep_test "wA wB/wC/" "1:wA/1:wB/2:wC/" "w." -o -n
52grep_test "wA wB/wC/" "1:wA/1:wB/2:wC/" "w." -o -n -i
53grep_test "wA wB/wC/" "1:wA/1:wB/2:wC/" "w." -o -n -3 2>/dev/null
54grep_test "XwA YwB/ZwC/" "1:wA/5:wB/9:wC/" "w." -o -b
55grep_test "XwA YwB/ZwC/" "1:wA/5:wB/9:wC/" "w." -o -b -i
56grep_test "XwA YwB/ZwC/" "1:wA/5:wB/9:wC/" "w." -o -b -3 2>/dev/null
57grep_test "XwA YwB/ZwC/" "1:w/5:w/9:w/" "w" -F -o -b
58grep_test "XwA YwB/ZwC/" "1:w/5:w/9:w/" "w" -F -o -b -i
59grep_test "XwA YwB/ZwC/" "1:w/5:w/9:w/" "w" -F -o -b -3 2>/dev/null
60grep_test "wA wB/" "(standard input):wA/(standard input):wB/" "w." -o -H
61grep_test "wA wB/" "(standard input):wA/(standard input):wB/" "w." -o -H -i
62grep_test "wA wB/" "(standard input):wA/(standard input):wB/" "w." -o -H -3 2>/dev/null
63
64# Combination of -h and -H
65grep_test "wA wB/" "wA wB/" "w."
66grep_test "wA wB/" "wA wB/" "w." -h
67grep_test "wA wB/" "wA wB/" "w." -H -h
68grep_test "wA wB/" "(standard input):wA wB/" "w." -H
69grep_test "wA wB/" "(standard input):wA wB/" "w." -h -H
70
71# End of a previous match should not match a "start of ..." expression.
72grep_test "word_word/" "word_/" "^word_*" -o
73grep_test "wordword/" "word/" "\<word" -o
74
75
76# Test "--color" option
77
78CB="[01;31m[K"
79CE="[m[K"
80
81# "--color" with "-i" should output an exact copy of the matching input text.
82grep_test "WordA/wordb/WORDC/" "${CB}Word${CE}A/${CB}word${CE}b/${CB}WORD${CE}C/" "word" --color=always -i
83grep_test "WordA/wordb/WORDC/" "${CB}Word${CE}A/${CB}word${CE}b/${CB}WORD${CE}C/" "Word" --color=always -i
84grep_test "WordA/wordb/WORDC/" "${CB}Word${CE}A/${CB}word${CE}b/${CB}WORD${CE}C/" "WORD" --color=always -i
85
86# End of a previous match should not match a "start of ..." expression.
87grep_test "word_word/" "${CB}word_${CE}word/" "^word_*" --color=always
88grep_test "wordword/" "${CB}word${CE}word/" "\<word" --color=always
89
90
91# Test combination of "-m" with "-A" and anchors.
92# Based on a report from Pavol Gono.
93grep_test "4/40/" "4/40/" "^4$" -m1 -A99
94grep_test "4/04/" "4/04/" "^4$" -m1 -A99
95grep_test "4/444/" "4/444/" "^4$" -m1 -A99
96grep_test "4/40/" "4/" "^4" -m1 -A99
97grep_test "4/04/" "4/04/" "^4" -m1 -A99
98grep_test "4/444/" "4/" "^4" -m1 -A99
99grep_test "4/40/" "4/40/" "4$" -m1 -A99
100grep_test "4/04/" "4/" "4$" -m1 -A99
101grep_test "4/444/" "4/" "4$" -m1 -A99
102
103
104# Test for "-F -w" bugs. Thanks to Gordon Lack for these two.
105grep_test "A/CX/B/C/" "A/B/C/" -wF -e A -e B -e C
106grep_test "LIN7C 55327/" "" -wF -e 5327 -e 5532
107
108# Test for non-empty matches following empty ones.
109grep_test 'xyz/' 'y/' -o 'y*'
110grep_test 'xyz/' "x${CB}y${CE}z/" --color=always 'y*'
111
112# Test for increasing/decreasing-length word matches,
113# for independence from pattern order within the pattern list,
114# and for preferring the longest match at a given position.
115x0='a bb ccc dddd/'
116x1='dddd ccc bb a/'
117x2='bcd abcd abc bc bcd abc/'
118x3='bc abcd bc/'
119y0="a ${CB}bb${CE} ${CB}ccc${CE} dddd/"
120y1="dddd ${CB}ccc${CE} ${CB}bb${CE} a/"
121y2="bcd abcd abc ${CB}bc${CE} bcd abc/"
122y3="${CB}bc${CE} abcd ${CB}bc${CE}/"
123grep_test "$x0" "$y0" -E --color=always -e bb -e cc -e ccc
124grep_test "$x0" "$y0" -F --color=always -e bb -e cc -e ccc
125grep_test "$x0" "$y0" -E --color=always -e bb -e ccc -e cc
126grep_test "$x0" "$y0" -F --color=always -e bb -e ccc -e cc
127grep_test "$x0" "$y0" -E -w --color=always -e bb -e ccc
128grep_test "$x0" "$y0" -F -w --color=always -e bb -e ccc
129grep_test "$x0" "$y0" -E -w --color=always -e ccc -e bb
130grep_test "$x0" "$y0" -F -w --color=always -e ccc -e bb
131grep_test "$x1" "$y1" -E -w --color=always -e bb -e ccc
132grep_test "$x1" "$y1" -F -w --color=always -e bb -e ccc
133grep_test "$x1" "$y1" -E -w --color=always -e ccc -e bb
134grep_test "$x1" "$y1" -F -w --color=always -e ccc -e bb
135grep_test "$x2" "$y2" -E -w --color=always bc
136grep_test "$x2" "$y2" -F -w --color=always bc
137grep_test "$x3" "$y3" -E -w --color=always bc
138grep_test "$x3" "$y3" -F -w --color=always bc
139
140# Skip the rest of the tests - known to fail. TAA.
141Exit $failures
142
143# The rest of this file is meant to be executed under this locale.
144LC_ALL=cs_CZ.UTF-8; export LC_ALL
145# If the UTF-8 locale doesn't work, skip these tests silently.
146locale -k LC_CTYPE 2>/dev/null | grep -q "charmap.*UTF-8" || Exit $failures
147
148# Test character class erroneously matching a '[' character.
149grep_test "[/" "" "[[:alpha:]]" -E
150
151for mode in F G E; do
152 # Hint: pipe the output of these tests in
153 # "| LESS= LESSCHARSET=ascii less".
154 # LETTER N WITH TILDE is U+00F1 and U+00D1.
155 # LETTER Y WITH DIAERESIS is U+00FF and U+0178.
156 grep_test 'añÿb/AÑŸB/' 'ñÿ/ÑŸ/' 'ñÿ' -o -i -$mode
157 grep_test 'añÿb/AÑŸB/' 'ñÿ/ÑŸ/' 'ÑŸ' -o -i -$mode
158 grep_test 'añÿb/AÑŸB/' "a${CB}ñÿ${CE}b/A${CB}ÑŸ${CE}B/" 'ñÿ' --color=always -i -$mode
159 grep_test 'añÿb/AÑŸB/' "a${CB}ñÿ${CE}b/A${CB}ÑŸ${CE}B/" 'ÑŸ' --color=always -i -$mode
160
161 # POSIX (about -i): ... each character in the string is matched
162 # against the pattern, not only the character, but also its case
163 # counterpart (if any), shall be matched.
164 # The following were chosen because of their trickiness due to the
165 # differing UTF-8 octet length of their counterpart and to the
166 # non-reflexivity of their mapping.
167 # Beware of homographs! Look carefully at the actual octets.
168
169 # lc(U+0130 LATIN CAPITAL LETTER I WITH DOT ABOVE) = U+0069 LATIN SMALL LETTER I
170 grep_test 'aİb/' "a${CB}İ${CE}b/" 'i' --color=always -i -$mode
171 grep_test 'aib/' '' 'İ' --color=always -i -$mode
172 grep_test 'aİb/' '' 'I' --color=always -i -$mode
173 # uc(U+0131 LATIN SMALL LETTER DOTLESS I) = U+0049 LATIN CAPITAL LETTER I
174 grep_test 'aıb/' "a${CB}ı${CE}b/" 'I' --color=always -i -$mode
175 grep_test 'aIb/' '' 'ı' --color=always -i -$mode
176 grep_test 'aıb/' '' 'i' --color=always -i -$mode
177 # uc(U+017F LATIN SMALL LETTER LONG S) = U+0053 LATIN CAPITAL LETTER S
178 grep_test 'aſb/' "a${CB}ſ${CE}b/" 'S' --color=always -i -$mode
179 grep_test 'aSb/' '' 'ſ' --color=always -i -$mode
180 grep_test 'aſb/' '' 's' --color=always -i -$mode
181 # uc(U+1FBE GREEK PROSGEGRAMMENI) = U+0399 GREEK CAPITAL LETTER IOTA
182 grep_test 'aιb/' "a${CB}ι${CE}b/" 'Ι' --color=always -i -$mode
183 grep_test 'aΙb/' '' 'ι' --color=always -i -$mode
184 grep_test 'aιb/' '' 'ι' --color=always -i -$mode
185 # lc(U+2126 OHM SIGN) = U+03C9 GREEK SMALL LETTER OMEGA
186 grep_test 'aΩb/' "a${CB}Ω${CE}b/" 'ω' --color=always -i -$mode
187 grep_test 'aωb/' '' 'Ω' --color=always -i -$mode
188 grep_test 'aΩb/' '' 'Ω' --color=always -i -$mode
189 # lc(U+212A KELVIN SIGN) = U+006B LATIN SMALL LETTER K
190 grep_test 'aKb/' "a${CB}K${CE}b/" 'k' --color=always -i -$mode
191 grep_test 'akb/' '' 'K' --color=always -i -$mode
192 grep_test 'aKb/' '' 'K' --color=always -i -$mode
193 # lc(U+212B ANGSTROM SIGN) = U+00E5 LATIN SMALL LETTER A WITH RING ABOVE
194 grep_test 'aÅb/' "a${CB}Å${CE}b/" 'å' --color=always -i -$mode
195 grep_test 'aåb/' '' 'Å' --color=always -i -$mode
196 grep_test 'aÅb/' '' 'Å' --color=always -i -$mode
197done
198
199
200# Any tests inserted right here will be performed under an UTF-8 locale.
201# Insert them before LC_ALL is set above to avoid this.
202# Leave this comment last.
203
204Exit $failures
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette