2 # A suite of tests for bash word expansions
4 # This tests parameter and variable expansion, with an empahsis on
5 # proper quoting behavior.
10 # If you comment out the body of this function, you can do a diff against
11 # `expansion-tests.right' to see if the shell is behaving correctly
18 # Test the substitution quoting characters (CTLESC and CTLNUL) in different
34 # Test null strings without variable expansion
48 # Test the quirky behavior of $@ in ""
56 # Test null strings with variable expansion that fails
70 # Test null strings with variable expansion that succeeds
89 # Test the unquoted special quoting characters
103 # Test expansion of a variable that is unset
112 # Test empty string expansion
118 # Test command substitution with (disabled) history substitution
119 expect '<Hello World!>'
121 recho "`echo \"Hello world!\"`"
123 # Test some shell special characters
137 # This should give argv[1] = a argv[2] = b
139 FOO=`echo 'a b' | tr ' ' '\012'`
142 # This should give argv[1] = ^A argv[2] = ^B
144 FOO=`echo '
\ 1 \ 2' | tr ' ' '\012'`
147 # Test quoted and unquoted globbing characters
154 # Test patterns that come up when the shell quotes funny character
167 expect '< abc> <def> <ghi> <jkl >'
169 expect '< abc> <def> <ghi> <jkl >'
173 expect '<--abc> <def> <ghi> <jkl-->'
177 expect '<a b> <cd> <ef> <gh>'
179 expect '<a b> <cd> <ef> <gh>'
181 expect '<a b> <cd> <ef> <gh>'
189 # Test combinations of different types of quoting in a fully-quoted string
190 # (so the WHOLLY_QUOTED tests fail and it doesn't get set)
191 expect '</^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\1/>'
192 recho "/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*"'$'"/\1/"
194 # Test the various Posix parameter expansions
197 recho "${x:-$(echo "foo bar")}"
199 recho ${x:-$(echo "foo bar")}
215 # remove shortest trailing match
220 # remove longest trailing match
225 # remove shortest leading pattern
230 # remove longest leading pattern
235 # pattern removal of patterns that don't match
248 # Command substitution and the quirky differences between `` and $()
259 # The difference between $* "$*" and "$@"
261 set "abc" "def ghi" "jkl"
263 expect '<abc> <def> <ghi> <jkl>'
266 expect '<abc def ghi jkl>'
272 # The special behavior of "$*", using the first character of $IFS as separator
273 expect '<abc:def ghi:jkl>'
278 expect '<abc> <def ghi> <jkl>'
281 expect '<xxabc> <def ghi> <jklyy>'
284 expect '<abc> <def ghi> <jklabc> <def ghi> <jkl>'
294 set $foo bar '' xyz "$foo" abc
296 expect '<bar> <> <xyz> <> <abc>'
299 # More tests of quoting and deferred evaluation
316 expect '<newline expected>'
318 *$NL*) recho "newline expected" ;;
323 *"?"*) recho "got it" ;;
328 *\?*) recho "got it" ;;
331 set one two three four five
332 expect '<one> <three> <five>'
333 recho $1 $3 ${5} $8 ${9}
335 # length tests on positional parameters and some special parameters
370 # test word splitting of assignment statements not preceding a command
373 expect '<a> <b> <c> <d> <e>'