xref: /freebsd/tools/regression/usr.bin/env/regress-env.rgdata (revision d8a0fe102c0cfdfcd5b818f850eff09d8536c9bc)
1#-
2# Copyright (c) 2005  - Garance Alistair Drosehn <gad@FreeBSD.org>.
3# All rights reserved.
4#
5#  Redistribution and use in source and binary forms, with or without
6#  modification, are permitted provided that the following conditions
7#  are met:
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.
13#
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
24#  SUCH DAMAGE.
25#
26# $FreeBSD$
27#
28
29testpgm=/usr/bin/env
30gblenv=PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
31gblenv=TESTVAR=Global-TV-Value
32gblenv=OUTSIDEVAR=OutsideValue
33
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.
36[test]
37   sb_args:/bin/sh
38   setenv:TESTVAR=a1a
39   script:/bin/echo A-${TESTVAR}-Z
40   stdout:A-a1a-Z
41[run]
42[test]
43   sb_args:-S /bin/sh
44   script:/bin/echo A-${TESTVAR}-Z
45   stdout:A-Global-TV-Value-Z
46[run]
47
48[test]
49   sb_args:-S TESTVAR=bb22bb /bin/sh
50   script:/bin/echo A-${TESTVAR}-Z
51   stdout:A-bb22bb-Z
52[run]
53[test]
54   sb_args:-S\_TESTVAR=ab22ab\_/bin/sh
55   script:/bin/echo A-${TESTVAR}-Z
56   stdout:A-ab22ab-Z
57[run]
58[test]
59   sb_args:-S\_TESTVAR="abc\_33\_abc"\_/bin/sh
60   script:/bin/echo A-${TESTVAR}-Z
61   stdout:A-abc 33 abc-Z
62[run]
63
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...
67[test]
68   sb_args:-S sh
69   setenv:PATH=/usr/sbin
70   script:/bin/echo A-${PATH}-Z
71   $?:127
72   stderr:[%-testpgm.basename-%]: sh: No such file or directory
73[run]
74[test]
75   sb_args:-S -P/bin sh
76   setenv:PATH=/usr/sbin
77   script:/bin/echo A-${PATH}-Z
78   stdout:A-/usr/sbin-Z
79[run]
80[test]
81   sb_args:-S -P/sbin:/usr/sbin sh
82   script:/bin/echo A-${PATH}-Z
83   $?:127
84   stderr:[%-testpgm.basename-%]: sh: No such file or directory
85[run]
86
87#  Hmm.  I wonder if -P should always set an 'ENV_PATH' variable?
88[test]
89   sb_args:-S -P/bin:/usr/bin:${PATH} ENV_PATH=/bin:/usr/bin:${PATH} sh
90   setenv:PATH=/usr/sbin
91   script:/bin/echo A-${PATH}-Z
92   script:/bin/echo B-${ENV_PATH}-Y
93   stdout:A-/usr/sbin-Z
94   stdout:B-/bin:/usr/bin:/usr/sbin-Y
95[run]
96
97#   Show that the comment-characters are working, both for where they are
98#   recognized and where they are ignored.
99[test]
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
104[run]
105[test]
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
110[run]
111[test]
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
116[run]
117[test]
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
122[run]
123
124#   Test various aspects of quoted strings
125[test]
126   sb_args:-STESTVAR="abc'def" /bin/sh
127   script:/bin/echo A-${TESTVAR}-Z
128   stdout:A-abc'def-Z
129[run]
130[test]
131   sb_args:-STESTVAR='abc"def' /bin/sh
132   script:/bin/echo A-${TESTVAR}-Z
133   stdout:A-abc"def-Z
134[run]
135[test]
136   sb_args:-STESTVAR='ab\'cd\'ef' /bin/sh
137   script:/bin/echo A-${TESTVAR}-Z
138   stdout:A-ab'cd'ef-Z
139[run]
140[test]
141   sb_args:-STESTVAR='abc\"def\'ghi' /bin/sh
142   script:/bin/echo A-${TESTVAR}-Z
143   stdout:A-abc\"def'ghi-Z
144[run]
145[test]
146   sb_args:-STESTVAR='abc''def''ghi' /bin/sh
147   script:/bin/echo A-${TESTVAR}-Z
148   stdout:A-abcdefghi-Z
149[run]
150[test]
151   sb_args:-STESTVAR='abc\ndef\nghi' /bin/sh
152   script:/bin/echo "A-${TESTVAR}-Z"
153   stdout:A-abc\ndef\nghi-Z
154[run]
155[test]
156   sb_args:-STESTVAR="abc\ndef\nghi" /bin/sh
157   script:/bin/echo "A-${TESTVAR}-Z"
158   stdout:A-abc
159   stdout:def
160   stdout:ghi-Z
161[run]
162[test]
163   sb_args:-STESTVAR=""\_OTHERVAR=""\_/bin/sh
164   script:/bin/echo A-${TESTVAR}-M-${OTHERVAR}-Z
165   stdout:A--M--Z
166[run]
167[test]
168   sb_args:-STESTVAR=no-term-"-dq... /bin/sh
169   script:/bin/echo "A-${TESTVAR}-Z"
170   $?:1
171   stderr:[%-testpgm.basename-%]: No terminating quote for string: TESTVAR=no-term-"-dq... /bin/sh
172[run]
173[test]
174   sb_args:-STESTVAR=no-term-'-sq... /bin/sh
175   script:/bin/echo "A-${TESTVAR}-Z"
176   $?:1
177   stderr:[%-testpgm.basename-%]: No terminating quote for string: TESTVAR=no-term-'-sq... /bin/sh
178[run]
179
180# Some tests of variable-substitution.
181[test]
182   sb_args:-S TESTVAR=${TEST7} /bin/sh
183   setenv:TEST7=a23456a
184   script:/bin/echo "A-${TESTVAR}-Z"
185   stdout:A-a23456a-Z
186[run]
187[test]
188   sb_args:-S TESTVAR=${TEST8} /bin/sh
189   setenv:TEST8=b234567b
190   script:/bin/echo "A-${TESTVAR}-Z"
191   stdout:A-b234567b-Z
192[run]
193[test]
194   sb_args:-S TESTVAR=${TEST9} /bin/sh
195   setenv:TEST9=c2345678c
196   script:/bin/echo "A-${TESTVAR}-Z"
197   stdout:A-c2345678c-Z
198[run]
199[test]
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
206[run]
207[test]
208   sb_args:-S TESTVAR=$* /bin/sh
209   script:/bin/echo "A-${TESTVAR}-Z"
210   $?:1
211   stderr:[%-testpgm.basename-%]: Only ${VARNAME} expansion is supported, error at: $* /bin/sh
212[run]
213[test]
214   sb_args:-S TESTVAR=/usr/bin:$PATH /bin/sh
215   script:/bin/echo "A-${TESTVAR}-Z"
216   $?:1
217   stderr:[%-testpgm.basename-%]: Only ${VARNAME} expansion is supported, error at: $PATH /bin/sh
218[run]
219
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...
225[test]
226   symlink:/bin/echo /tmp/envtest=echo
227   sb_args:-S/tmp/envtest=echo false
228   $?:1
229[run]
230
231# Show interactions between -i (clear environment), and ${VAR} substitution,
232# and that -i will clear the environment at the right point in processing...
233[test]
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/PWD, so we use grep to get rid of those)
239   script:unset -v IFS PS1 PS2 PS4 PPID
240   script:set | grep -Ev '^(OPTIND|PWD)=' | sort
241   stdout:=== set ===
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
247[run]
248
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:
252[test]
253   sb_args:-Secho Testv:${TESTV} Scriptname:
254   setenv:TESTV=ab/ba
255   stdout:Testv:ab/ba Scriptname: [%-script.pathname-%]
256[run]
257[test]
258   sb_args:-Secho testV: ${TESTV} scriptname:
259   setenv:TESTV=cd/dc
260   stdout:testV: cd/dc scriptname: [%-script.pathname-%]
261[run]
262
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'.
268[test]
269   sb_args:-S/bin/sh [%-script.pathname-%] userDQ: "" SQ: '' scriptname:
270   setenv:TNADA=
271   script:printf "list_args.sh with \$# = $#\n"
272   script:# Process all parameters.
273   script:N=0
274   script:while test $# != 0 ; do
275   script:    N=$(($N+1))
276   script:    printf "....\$$N = [%3d] '$1'\n" ${#1}
277   script:    shift
278   script:done
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'
286[run]
287[test]
288   sb_args:-S/bin/sh [%-script.pathname-%] userB "${TNADA}" scriptname:
289   setenv:TNADA=
290   script:printf "list_args.sh with \$# = $#\n"
291   script:# Process all parameters.
292   script:N=0
293   script:while test $# != 0 ; do
294   script:    N=$(($N+1))
295   script:    printf "....\$$N = [%3d] '$1'\n" ${#1}
296   script:    shift
297   script:done
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'
303[run]
304[test]
305   sb_args:-S/bin/sh [%-script.pathname-%] userA ${TNADA} scriptname:
306   setenv:TNADA=
307   script:printf "list_args.sh with \$# = $#\n"
308   script:# Process all parameters.
309   script:N=0
310   script:while test $# != 0 ; do
311   script:    N=$(($N+1))
312   script:    printf "....\$$N = [%3d] '$1'\n" ${#1}
313   script:    shift
314   script:done
315   stdout:list_args.sh with $# = 3
316   stdout:....$1 = [  5] 'userA'
317   stdout:....$2 = [ 11] 'scriptname:'
318   stdout:....$3 = [ 16] '[%-script.pathname-%]'
319[run]
320[test]
321   sb_args:-S/bin/sh [%-script.pathname-%] ${A} ${NB} ${C} ${ND} ${NE} ${F} S:
322   setenv:A=A_ThisisAlongstring_A1
323   setenv:NB=
324   setenv:C=C_ThisisAlongstring_C1
325   setenv:ND=
326   setenv:NE=
327   setenv:F=F_ThisisAlongstring_F1
328   script:printf "list_args.sh with \$# = $#\n"
329   script:# Process all parameters.
330   script:N=0
331   script:while test $# != 0 ; do
332   script:    N=$(($N+1))
333   script:    printf "....\$$N = [%3d] '$1'\n" ${#1}
334   script:    shift
335   script:done
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'
342[run]
343[test]
344   sb_args:-S/bin/sh [%-script.pathname-%] ${A} ${NB} "${NB}" ${NB} ${C} "${ND}" ${NE} ${F} S:
345   setenv:A=A_ThisisAlongstring_A1
346   setenv:NB=
347   setenv:C=C_ThisisAlongstring_C1
348   setenv:ND=
349   setenv:NE=
350   setenv:F=F_ThisisAlongstring_F1
351   script:printf "list_args.sh with \$# = $#\n"
352   script:# Process all parameters.
353   script:N=0
354   script:while test $# != 0 ; do
355   script:    N=$(($N+1))
356   script:    printf "....\$$N = [%3d] '$1'\n" ${#1}
357   script:    shift
358   script:done
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'
367[run]
368
369[test]
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-%]
376[run]
377[test]
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-%]
384[run]
385
386[test]
387   sb_args:sh
388   script:[%-testpgm.pathname-%] -S '\c' >/dev/null
389[run]
390[test]
391   sb_args:sh
392   script:[%-testpgm.pathname-%] -S'\c' >/dev/null
393[run]
394[test]
395   sb_args:sh
396   script:[%-testpgm.pathname-%] -u foo -S '\c' >/dev/null
397[run]
398[test]
399   sb_args:sh
400   script:[%-testpgm.pathname-%] -u foo -S'\c' >/dev/null
401[run]
402[test]
403   sb_args:sh
404   script:[%-testpgm.pathname-%] -S '-u bar \c' >/dev/null
405[run]
406[test]
407   sb_args:sh
408   script:[%-testpgm.pathname-%] -S'-u bar \c' >/dev/null
409[run]
410[test]
411   sb_args:sh
412   script:[%-testpgm.pathname-%] -u foo -S '-u bar \c' >/dev/null
413[run]
414[test]
415   sb_args:sh
416   script:[%-testpgm.pathname-%] -u foo -S'-u bar \c' >/dev/null
417[run]
418