1 # This program is free software: you can redistribute it and/or modify
2 # it under the terms of the GNU General Public License as published by
3 # the Free Software Foundation, either version 3 of the License, or
4 # (at your option) any later version.
6 # This program is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # GNU General Public License for more details.
11 # You should have received a copy of the GNU General Public License
12 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # test the shell globbing
20 : # if needed, change me to echo expect "$@"
23 # First, a test that bash-2.01.1 fails
24 ${THIS_SH} ./glob1.sub
25 ${THIS_SH} ./glob2.sub
26 ${THIS_SH} ./glob3.sub
27 ${THIS_SH} ./glob4.sub
28 ${THIS_SH} ./glob5.sub
29 ${THIS_SH} ./glob6.sub
30 ${THIS_SH} ./glob7.sub
31 ${THIS_SH} ./glob8.sub
32 ${THIS_SH} ./glob9.sub
33 ${THIS_SH} ./glob10.sub
35 MYDIR=$PWD # save where we are
37 TESTDIR=$TMPDIR/glob-test-$$
39 builtin cd $TESTDIR || { echo $0: cannot cd to $TESTDIR >&2 ; exit 1; }
42 touch a b c d abc abd abe bb bcd ca cb dd de Beware
45 # see if `regular' globbing works right
46 expect '<a> <abc> <abd> <abe> <X*>'
49 expect '<a> <abc> <abd> <abe>'
52 # see if null glob expansion works
55 expect '<a> <abc> <abd> <abe>'
60 # see if the failglob option works
63 touch tmp/l1 tmp/l2 tmp/l3
64 builtin echo tmp/l[12] tmp/*4 tmp/*3
66 builtin echo tmp/l[12] tmp/*4 tmp/*3
70 # see if the code that expands directories only works
74 # Test quoted and unquoted globbing characters
84 expect '<c> <ca> <cb> <a*> <*q*>'
99 # Pattern from Larry Wall's Configure that caused bash to blow up
100 expect '</^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\1/>'
101 recho "/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*"'$'"/\1/"
103 # Make sure character classes work properly
105 expect '<abc> <abd> <abe> <bb> <cb>'
108 expect '<abd> <abe> <bb> <bcd> <bdir> <ca> <cb> <dd> <de>'
119 expect '<Beware> <d> <dd> <de>'
122 # Make sure that filenames with embedded globbing characters are handled
143 *.\*) echo not there ;;
147 # examples from the Posix.2 spec (d11.2, p. 243)
162 a"b"c) echo 'match 1' ;;
163 *) echo 'BAD match 1' ;;
168 a*c) echo 'match 2' ;;
169 *) echo 'BAD match 2' ;;
174 "a?c") echo 'bad 1' ;;
180 a\*c) echo 'bad 2' ;;
186 a\[b]c) echo 'bad 3' ;;
196 # This is very odd, but sh and ksh seem to agree
199 a["\b"]c) echo 'ok 5' ;;
205 touch man/man1/bash.1
206 expect '<man/man1/bash.1>'
208 expect '<man/man1/bash.1>'
209 recho $(echo */man*/bash.*)
210 expect '<man/man1/bash.1>'
211 recho "$(echo */man*/bash.*)"
213 # tests with multiple `*'s
219 a*****?c) echo ok 2;;
223 ?*****??) echo ok 3;;
231 *****??c) echo ok 5;;
235 ?*****?c) echo ok 6;;
239 ?***?****c) echo ok 7;;
243 ?***?****?) echo ok 8;;
247 ?***?****) echo ok 9;;
251 *******c) echo ok 10;;
255 *******?) echo ok 11;;
259 a*cd**?**??k) echo ok 20;;
263 a**?**cd**?**??k) echo ok 21;;
267 a**?**cd**?**??k***) echo ok 22;;
271 a**?**cd**?**??***k) echo ok 23;;
275 a**?**cd**?**??***k**) echo ok 24;;
279 a****c**?**??*****) echo ok 25;;
283 [-abc]) echo ok 26 ;;
287 [abc-]) echo ok 27 ;;
306 # a `[' without a closing `]' is just another character to match, in the
307 # bash implementation
316 # a right bracket shall lose its special meaning and represent itself in
317 # a bracket expression if it occurs first in the list. -- POSIX.2 2.8.3.2
326 # a backslash should just escape the next character in this context
328 [a-\z]) echo ok 36 ;;
331 # this was a bug in all versions up to bash-2.04-release
333 [/\\]*) echo ok 37 ;;
336 # none of these should output anything
339 ??**********?****?) echo bad 1;;
343 ??**********?****c) echo bad 2;;
347 ?************c****?****) echo bad 3;;
355 a*****c*?**) echo bad 5;;
359 a********???*******) echo bad 6;;
370 # let's start testing the case-insensitive globbing code
379 # make sure set -f works right
384 # test out the GLOBIGNORE code
385 GLOBIGNORE='.*:*c:*e:?'
388 GLOBIGNORE='.*:*b:*d:?'
391 # see if GLOBIGNORE can substitute for `set -f'
396 expect '<man/man1/bash.1>'
399 # make sure null values for GLOBIGNORE have no effect
401 expect '<man/man1/bash.1>'
404 # this is for the benefit of pure coverage, so it writes the pcv file
405 # in the right place, and for gprof