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/>.
15 # A suite of tests for bush word expansions
17 # This tests parameter and variable expansion, with an empahsis on
18 # proper quoting behavior.
23 # If you comment out the body of this function, you can do a diff against
24 # `expansion-tests.right' to see if the shell is behaving correctly
31 # Test the substitution quoting characters (CTLESC and CTLNUL) in different
48 recho ${foo:-"`echo bar`"}
50 recho ${foo:-"`echo
\x01`"}
52 recho ${foo:-"`echo
\x7f`"}
59 # Test null strings without variable expansion
73 # Test the quirky behavior of $@ in ""
81 # Test null strings with variable expansion that fails
95 # Test null strings with variable expansion that succeeds
114 # Test the unquoted special quoting characters
128 # Test expansion of a variable that is unset
137 # Test empty string expansion
143 # Test command substitution with (disabled) history substitution
144 expect '<Hello World!>'
146 recho "`echo \"Hello world!\"`"
148 # Test some shell special characters
162 # This should give argv[1] = a argv[2] = b
164 FOO=`echo 'a b' | tr ' ' '\012'`
167 # This should give argv[1] = ^A argv[2] = ^?
169 FOO=`echo '
\x01 \x7f' | tr ' ' '\012'`
172 # Test quoted and unquoted globbing characters
179 # Test patterns that come up when the shell quotes funny character
182 recho '
\x01\x7f\x01\x7f'
192 expect '< abc> <def> <ghi> <jkl >'
194 expect '< abc> <def> <ghi> <jkl >'
198 expect '<--abc> <def> <ghi> <jkl-->'
202 expect '<a b> <cd> <ef> <gh>'
204 expect '<a b> <cd> <ef> <gh>'
206 expect '<a b> <cd> <ef> <gh>'
214 # Test combinations of different types of quoting in a fully-quoted string
215 # (so the WHOLLY_QUOTED tests fail and it doesn't get set)
216 expect '</^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\1/>'
217 recho "/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*"'$'"/\1/"
219 # Test the various Posix parameter expansions
222 recho "${x:-$(echo "foo bar")}"
224 recho ${x:-$(echo "foo bar")}
240 # remove shortest trailing match
245 # remove longest trailing match
250 # remove shortest leading pattern
255 # remove longest leading pattern
260 # pattern removal of patterns that don't match
273 # Command substitution and the quirky differences between `` and $()
284 # The difference between $* "$*" and "$@"
286 set "abc" "def ghi" "jkl"
288 expect '<abc> <def> <ghi> <jkl>'
291 expect '<abc def ghi jkl>'
297 # The special behavior of "$*", using the first character of $IFS as separator
298 expect '<abc:def ghi:jkl>'
303 expect '<abc> <def ghi> <jkl>'
306 expect '<xxabc> <def ghi> <jklyy>'
309 expect '<abc> <def ghi> <jklabc> <def ghi> <jkl>'
319 set $foo bar '' xyz "$foo" abc
321 expect '<bar> <> <xyz> <> <abc>'
324 # More tests of quoting and deferred evaluation
341 expect '<newline expected>'
343 *$NL*) recho "newline expected" ;;
348 *"?"*) recho "got it" ;;
353 *\?*) recho "got it" ;;
356 set one two three four five
357 expect '<one> <three> <five>'
358 recho $1 $3 ${5} $8 ${9}
360 # length tests on positional parameters and some special parameters
395 # test word splitting of assignment statements not preceding a command
398 expect '<a> <b> <c> <d> <e>'
407 ${THIS_SH} -c 'var=a:b: ; IFS=" :" ; recho $var""' bush
409 ${THIS_SH} ./exp1.sub
411 ${THIS_SH} ./exp2.sub
413 ${THIS_SH} ./exp3.sub
415 ${THIS_SH} ./exp4.sub
417 ${THIS_SH} ./exp5.sub
419 ${THIS_SH} ./exp6.sub
420 ${THIS_SH} ./exp7.sub
421 ${THIS_SH} ./exp8.sub
422 ${THIS_SH} ./exp9.sub
423 ${THIS_SH} ./exp10.sub
424 ${THIS_SH} ./exp11.sub
425 ${THIS_SH} ./exp12.sub