2 # Copyright (c) 2005 - Garance Alistair Drosehn <gad@FreeBSD.org>.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
14 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 gblenv=PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
31 gblenv=TESTVAR=Global-TV-Value
32 gblenv=OUTSIDEVAR=OutsideValue
34 # These first two tests are testing how well the regression-script itself is
35 # handling environment-variables, as much as testing the `env' program.
39 script:/bin/echo A-${TESTVAR}-Z
44 script:/bin/echo A-${TESTVAR}-Z
45 stdout:A-Global-TV-Value-Z
49 sb_args:-S TESTVAR=bb22bb /bin/sh
50 script:/bin/echo A-${TESTVAR}-Z
54 sb_args:-S\_TESTVAR=ab22ab\_/bin/sh
55 script:/bin/echo A-${TESTVAR}-Z
59 sb_args:-S\_TESTVAR="abc\_33\_abc"\_/bin/sh
60 script:/bin/echo A-${TESTVAR}-Z
64 # First we see that 'sh' can not be found in /usr/sbin, and then
65 # we show that it can be found without changing PATH by using -P
66 # And then show that it can be NOT found by using -P...
70 script:/bin/echo A-${PATH}-Z
72 stderr:[%-testpgm.basename-%]: sh: No such file or directory
77 script:/bin/echo A-${PATH}-Z
81 sb_args:-S -P/sbin:/usr/sbin sh
82 script:/bin/echo A-${PATH}-Z
84 stderr:[%-testpgm.basename-%]: sh: No such file or directory
87 # Hmm. I wonder if -P should always set an 'ENV_PATH' variable?
89 sb_args:-S -P/bin:/usr/bin:${PATH} ENV_PATH=/bin:/usr/bin:${PATH} sh
91 script:/bin/echo A-${PATH}-Z
92 script:/bin/echo B-${ENV_PATH}-Y
94 stdout:B-/bin:/usr/bin:/usr/sbin-Y
97 # Show that the comment-characters are working, both for where they are
98 # recognized and where they are ignored.
100 sb_args:-STESTVAR="abc44abc" /bin/sh # This is some arbitrary text
101 user_args:us11er us22er
102 script:/bin/echo A-${TESTVAR}-Z B-$1-Y
103 stdout:A-abc44abc-Z B-us11er-Y
106 sb_args:-STESTVAR="abc55abc" /bin/sh \c This is some arbitrary text
107 user_args:us11er us22er
108 script:/bin/echo A-${TESTVAR}-Z B-$1-Y
109 stdout:A-abc55abc-Z B-us11er-Y
112 sb_args:-STESTVAR=abc#44#abc /bin/sh
113 user_args:us11er us22er
114 script:/bin/echo A-${TESTVAR}-Z B-$1-Y
115 stdout:A-abc#44#abc-Z B-us11er-Y
118 sb_args:-STESTVAR='abc\c55\cabc' /bin/sh
119 user_args:us11er us22er
120 script:/bin/echo A-${TESTVAR}-Z B-$1-Y
121 stdout:A-abc\c55\cabc-Z B-us11er-Y
124 # Test various aspects of quoted strings
126 sb_args:-STESTVAR="abc'def" /bin/sh
127 script:/bin/echo A-${TESTVAR}-Z
131 sb_args:-STESTVAR='abc"def' /bin/sh
132 script:/bin/echo A-${TESTVAR}-Z
136 sb_args:-STESTVAR='ab\'cd\'ef' /bin/sh
137 script:/bin/echo A-${TESTVAR}-Z
141 sb_args:-STESTVAR='abc\"def\'ghi' /bin/sh
142 script:/bin/echo A-${TESTVAR}-Z
143 stdout:A-abc\"def'ghi-Z
146 sb_args:-STESTVAR='abc''def''ghi' /bin/sh
147 script:/bin/echo A-${TESTVAR}-Z
151 sb_args:-STESTVAR='abc\ndef\nghi' /bin/sh
152 script:/bin/echo "A-${TESTVAR}-Z"
153 stdout:A-abc\ndef\nghi-Z
156 sb_args:-STESTVAR="abc\ndef\nghi" /bin/sh
157 script:/bin/echo "A-${TESTVAR}-Z"
163 sb_args:-STESTVAR=""\_OTHERVAR=""\_/bin/sh
164 script:/bin/echo A-${TESTVAR}-M-${OTHERVAR}-Z
168 sb_args:-STESTVAR=no-term-"-dq... /bin/sh
169 script:/bin/echo "A-${TESTVAR}-Z"
171 stderr:[%-testpgm.basename-%]: No terminating quote for string: TESTVAR=no-term-"-dq... /bin/sh
174 sb_args:-STESTVAR=no-term-'-sq... /bin/sh
175 script:/bin/echo "A-${TESTVAR}-Z"
177 stderr:[%-testpgm.basename-%]: No terminating quote for string: TESTVAR=no-term-'-sq... /bin/sh
180 # Some tests of variable-substitution.
182 sb_args:-S TESTVAR=${TEST7} /bin/sh
184 script:/bin/echo "A-${TESTVAR}-Z"
188 sb_args:-S TESTVAR=${TEST8} /bin/sh
189 setenv:TEST8=b234567b
190 script:/bin/echo "A-${TESTVAR}-Z"
194 sb_args:-S TESTVAR=${TEST9} /bin/sh
195 setenv:TEST9=c2345678c
196 script:/bin/echo "A-${TESTVAR}-Z"
200 sb_args:-S TESTVAR=${TEST8}+${TEST9}+${TEST10} /bin/sh
201 setenv:TEST8=a234567z
202 setenv:TEST9=a2345678z
203 setenv:TEST10=a23456789z
204 script:/bin/echo "A-${TESTVAR}-Z"
205 stdout:A-a234567z+a2345678z+a23456789z-Z
208 sb_args:-S TESTVAR=$* /bin/sh
209 script:/bin/echo "A-${TESTVAR}-Z"
211 stderr:[%-testpgm.basename-%]: Only ${VARNAME} expansion is supported, error at: $* /bin/sh
214 sb_args:-S TESTVAR=/usr/bin:$PATH /bin/sh
215 script:/bin/echo "A-${TESTVAR}-Z"
217 stderr:[%-testpgm.basename-%]: Only ${VARNAME} expansion is supported, error at: $PATH /bin/sh
220 # For a short time `env' was changed to recognize 'something=value' as a
221 # valid utility name if 'something' begins with a '/'. However, that was
222 # a bad idea, since variable-names with a '/' -- while rare -- are still
223 # more blessed by standards than a filename with an '=' in it. So, this
224 # test goes back to expecting an error...
226 symlink:/bin/echo /tmp/envtest=echo
227 sb_args:-S/tmp/envtest=echo false
231 # Show interactions between -i (clear environment), and ${VAR} substitution,
232 # and that -i will clear the environment at the right point in processing...
234 sb_args:-iS PATH=/bin:/usr/bin:/Not WASPATH=${PATH} WASOUT=${OUTSIDEVAR} TESTVAR=SbValue WASTEST=${TESTVAR} /bin/sh
235 script:/bin/echo "=== set ==="
236 script:# drop some environment variables that 'sh' itself sets, and
237 script:# then have 'set' print out all remaining environment variables.
238 script:# (can't unset OPTIND, so we use grep to get rid of that)
239 script:unset -v IFS PS1 PS2 PPID
240 script:set | grep -v '^OPTIND=' | sort
242 stdout:PATH=/bin:/usr/bin:/Not
243 stdout:TESTVAR=SbValue
244 stdout:WASOUT=OutsideValue
245 stdout:WASPATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
246 stdout:WASTEST=Global-TV-Value
249 # Had a bug with ${VAR} expansion if the character before the $ was
250 # one of the argument-separator characters. So the first of the
251 # following worked, but the second one failed:
253 sb_args:-Secho Testv:${TESTV} Scriptname:
255 stdout:Testv:ab/ba Scriptname: [%-script.pathname-%]
258 sb_args:-Secho testV: ${TESTV} scriptname:
260 stdout:testV: cd/dc scriptname: [%-script.pathname-%]
263 # A "nothing variable" inside a quoted string should produce a zero-length
264 # argument, but if it's outside of quotes then it should result in, well,
265 # nothing. Note the tricks we play with [%-script.pathname-%] so that we
266 # can supply parameters *to* the script, even though the kernel is always
267 # going to stick the script name on as ARG[2] when invoking `env'.
269 sb_args:-S/bin/sh [%-script.pathname-%] userDQ: "" SQ: '' scriptname:
271 script:printf "list_args.sh with \$# = $#\n"
272 script:# Process all parameters.
274 script:while test $# != 0 ; do
276 script: printf "....\$$N = [%3d] '$1'\n" ${#1}
279 stdout:list_args.sh with $# = 6
280 stdout:....$1 = [ 7] 'userDQ:'
281 stdout:....$2 = [ 0] ''
282 stdout:....$3 = [ 3] 'SQ:'
283 stdout:....$4 = [ 0] ''
284 stdout:....$5 = [ 11] 'scriptname:'
285 stdout:....$6 = [ 16] '/tmp/env-regress'
288 sb_args:-S/bin/sh [%-script.pathname-%] userB "${TNADA}" scriptname:
290 script:printf "list_args.sh with \$# = $#\n"
291 script:# Process all parameters.
293 script:while test $# != 0 ; do
295 script: printf "....\$$N = [%3d] '$1'\n" ${#1}
298 stdout:list_args.sh with $# = 4
299 stdout:....$1 = [ 5] 'userB'
300 stdout:....$2 = [ 0] ''
301 stdout:....$3 = [ 11] 'scriptname:'
302 stdout:....$4 = [ 16] '/tmp/env-regress'
305 sb_args:-S/bin/sh [%-script.pathname-%] userA ${TNADA} scriptname:
307 script:printf "list_args.sh with \$# = $#\n"
308 script:# Process all parameters.
310 script:while test $# != 0 ; do
312 script: printf "....\$$N = [%3d] '$1'\n" ${#1}
315 stdout:list_args.sh with $# = 3
316 stdout:....$1 = [ 5] 'userA'
317 stdout:....$2 = [ 11] 'scriptname:'
318 stdout:....$3 = [ 16] '[%-script.pathname-%]'
321 sb_args:-S/bin/sh [%-script.pathname-%] ${A} ${NB} ${C} ${ND} ${NE} ${F} S:
322 setenv:A=A_ThisisAlongstring_A1
324 setenv:C=C_ThisisAlongstring_C1
327 setenv:F=F_ThisisAlongstring_F1
328 script:printf "list_args.sh with \$# = $#\n"
329 script:# Process all parameters.
331 script:while test $# != 0 ; do
333 script: printf "....\$$N = [%3d] '$1'\n" ${#1}
336 stdout:list_args.sh with $# = 5
337 stdout:....$1 = [ 22] 'A_ThisisAlongstring_A1'
338 stdout:....$2 = [ 22] 'C_ThisisAlongstring_C1'
339 stdout:....$3 = [ 22] 'F_ThisisAlongstring_F1'
340 stdout:....$4 = [ 2] 'S:'
341 stdout:....$5 = [ 16] '/tmp/env-regress'
344 sb_args:-S/bin/sh [%-script.pathname-%] ${A} ${NB} "${NB}" ${NB} ${C} "${ND}" ${NE} ${F} S:
345 setenv:A=A_ThisisAlongstring_A1
347 setenv:C=C_ThisisAlongstring_C1
350 setenv:F=F_ThisisAlongstring_F1
351 script:printf "list_args.sh with \$# = $#\n"
352 script:# Process all parameters.
354 script:while test $# != 0 ; do
356 script: printf "....\$$N = [%3d] '$1'\n" ${#1}
359 stdout:list_args.sh with $# = 7
360 stdout:....$1 = [ 22] 'A_ThisisAlongstring_A1'
361 stdout:....$2 = [ 0] ''
362 stdout:....$3 = [ 22] 'C_ThisisAlongstring_C1'
363 stdout:....$4 = [ 0] ''
364 stdout:....$5 = [ 22] 'F_ThisisAlongstring_F1'
365 stdout:....$6 = [ 2] 'S:'
366 stdout:....$7 = [ 16] '/tmp/env-regress'
370 sb_args:-S/bin/echo ${A} ${B} ${C} ${D} ScriptName:
371 setenv:A=A_ThisisAlongstring_A1
372 setenv:B=B_ThisisAlongstring_B1
373 setenv:C=C_ThisisAlongstring_C1
374 setenv:D=D_ThisisAlongstring_D1
375 stdout:A_ThisisAlongstring_A1 B_ThisisAlongstring_B1 C_ThisisAlongstring_C1 D_ThisisAlongstring_D1 ScriptName: [%-script.pathname-%]
378 sb_args:-S/bin/echo ${A} "${B}" ${C} "${D}" ScriptName:
379 setenv:A=A_ThisisAlongstring_A1
380 setenv:B=B_ThisisAlongstring_B1
381 setenv:C=C_ThisisAlongstring_C1
382 setenv:D=D_ThisisAlongstring_D1
383 stdout:A_ThisisAlongstring_A1 B_ThisisAlongstring_B1 C_ThisisAlongstring_C1 D_ThisisAlongstring_D1 ScriptName: [%-script.pathname-%]