summaryrefslogtreecommitdiff
path: root/regress/bin/ksh/obsd-regress.t
blob: a2121e82a08a642c026ed11677e09d16c3d5a983 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
#	$OpenBSD: obsd-regress.t,v 1.13 2021/03/05 15:24:37 zhuk Exp $

#
# ksh regression tests from OpenBSD
#

name: eval-1
description:
	Tests for ${name#pat} vs. "${name#pat}" expansion
stdin:
	a=
	for n in ${a#*=}; do echo ${n}; done
	for n in "${a#*=}"; do echo ${n}; done
expected-stdout:
	
---

name: eval-2
description:
	Tests for ${name##pat} vs. "${name##pat}" expansion
stdin:
	a=
	for n in ${a##*=}; do echo ${n}; done
	for n in "${a##*=}"; do echo ${n}; done
expected-stdout:
	
---

name: eval-3
description:
	Tests for ${name%=pat} vs. "${name%=pat}" expansion
stdin:
	a=
	for n in ${a%=*}; do echo ${n}; done
	for n in "${a%=*}"; do echo ${n}; done
expected-stdout:
	
---

name: eval-4
description:
	Tests for ${name%%=pat} vs. "${name%%=pat}" expansion
stdin:
	a=
	for n in ${a%%=*}; do echo ${n}; done
	for n in "${a%%=*}"; do echo ${n}; done
expected-stdout:
	
---

name: eval-5
description:
	Tests for expansion including multiple read-only variables
stdin:
	set -- script .sh
	echo ${1%$2}
	set -- foobar barbaz baz
	echo ${1%${2%$3}}
	set -- aa bb cc
	echo ${*:+$*}
expected-stdout:
	script
	foo
	aa bb cc
---

name: and-list-error-1
description:
	Test exit status of rightmost element in 2 element && list in -e mode
stdin:
	true && false
	echo "should not print"
arguments: !-e!
expected-exit: e != 0
---

name: and-list-error-2
description:
	Test exit status of rightmost element in 3 element && list in -e mode
stdin:
	true && true && false
	echo "should not print"
arguments: !-e!
expected-exit: e != 0
---

name: or-list-error-1
description:
	Test exit status of || list in -e mode
stdin:
	false || false
	echo "should not print"
arguments: !-e!
expected-exit: e != 0
---

name: or-list-error-2
description:
	Test exit status of || list in -e mode
stdin:
	eval false || true
	echo "should print"
expected-stdout:
	should print
arguments: !-e!
---

name: var-functions
description:
	Calling
	
		FOO=bar f
	
	where f is a ksh style function, should not set FOO in the current env.
	If f is a bourne style function, FOO should be set. Furthermore,
	the function should receive a correct value of FOO. Additionally,
	setting FOO in the function itself should not change the value in
	global environment.
	
	Inspired by PR 2450.
stdin:
	function k {
		if [ x$FOO != xbar ]; then
			echo 1
			return 1
		fi
		x=$(env | grep FOO)
		if [ "x$x" != "xFOO=bar" ]; then
			echo 2
			return 1;
		fi
		FOO=foo
		return 0
	}
	b () {
		if [ x$FOO != xbar ]; then
			echo 3
			return 1
		fi
		x=$(env | grep FOO)
		if [ "x$x" != "xFOO=bar" ]; then
			echo 4
			return 1;
		fi
		FOO=foo
		return 0
	}
	FOO=bar k
	if [ $? != 0 ]; then
		exit 1
	fi
	if [ x$FOO != x ]; then
		exit 1
	fi
	FOO=bar b
	if [ $? != 0 ]; then
		exit 1
	fi
	if [ x$FOO != xbar ]; then
		exit 1
	fi
	FOO=barbar
	FOO=bar k
	if [ $? != 0 ]; then
		exit 1
	fi
	if [ x$FOO != xbarbar ]; then
		exit 1
	fi
	FOO=bar b
	if [ $? != 0 ]; then
		exit 1
	fi
	if [ x$FOO != xbar ]; then
		exit 1
	fi
---

name: longline-crash
description:
	This used to cause a core dump
stdin:
	ulimit -c 0
	deplibs="-lz -lpng /usr/local/lib/libjpeg.la -ltiff -lm -lX11 -lXext /usr/local/lib/libiconv.la -L/usr/local/lib -L/usr/ports/devel/gettext/w-gettext-0.10.40/gettext-0.10.40/intl/.libs /usr/local/lib/libintl.la /usr/local/lib/libglib.la /usr/local/lib/libgmodule.la -lintl -lm -lX11 -lXext -L/usr/X11R6/lib -lglib -lgmodule -L/usr/local/lib /usr/local/lib/libgdk.la -lintl -lm -lX11 -lXext -L/usr/X11R6/lib -lglib -lgmodule -L/usr/local/lib /usr/local/lib/libgtk.la -ltiff -ljpeg -lz -lpng -lm -lX11 -lXext -lintl -lglib -lgmodule -lgdk -lgtk -L/usr/X11R6/lib -lglib -lgmodule -L/usr/local/lib /usr/local/lib/libgdk_pixbuf.la -lz -lpng /usr/local/lib/libiconv.la -L/usr/local/lib -L/usr/ports/devel/gettext/w-gettext-0.10.40/gettext-0.10.40/intl/.libs /usr/local/lib/libintl.la /usr/local/lib/libglib.la -lm -lm /usr/local/lib/libaudiofile.la -lm -lm -laudiofile -L/usr/local/lib /usr/local/lib/libesd.la -lm -lz -L/usr/local/lib /usr/local/lib/libgnomesupport.la -lm -lz -lm -lglib -L/usr/local/lib /usr/local/lib/libgnome.la -lX11 -lXext /usr/local/lib/libiconv.la -L/usr/local/lib -L/usr/ports/devel/gettext/w-gettext-0.10.40/gettext-0.10.40/intl/.libs /usr/local/lib/libintl.la /usr/local/lib/libgmodule.la -lintl -lm -lX11 -lXext -L/usr/X11R6/lib -lglib -lgmodule -L/usr/local/lib /usr/local/lib/libgdk.la -lintl -lm -lX11 -lXext -L/usr/X11R6/lib -lglib -lgmodule -L/usr/local/lib /usr/local/lib/libgtk.la -lICE -lSM -lz -lpng /usr/local/lib/libungif.la /usr/local/lib/libjpeg.la -ltiff -lm -lz -lpng /usr/local/lib/libungif.la -lz /usr/local/lib/libjpeg.la -ltiff -L/usr/local/lib -L/usr/X11R6/lib /usr/local/lib/libgdk_imlib.la -lm -L/usr/local/lib /usr/local/lib/libart_lgpl.la -lm -lz -lm -lX11 -lXext -lintl -lglib -lgmodule -lgdk -lgtk -lICE -lSM -lm -lX11 -lXext -lintl -lglib -lgmodule -lgdk -lgtk -L/usr/X11R6/lib -lm -lz -lpng -lungif -lz -ljpeg -ltiff -ljpeg -lgdk_imlib -lglib -lm -laudiofile -lm -laudiofile -lesd -L/usr/local/lib /usr/local/lib/libgnomeui.la -lz -lz /usr/local/lib/libxml.la -lz -lz -lz /usr/local/lib/libxml.la -lm -lX11 -lXext /usr/local/lib/libiconv.la -L/usr/ports/devel/gettext/w-gettext-0.10.40/gettext-0.10.40/intl/.libs /usr/local/lib/libintl.la /usr/local/lib/libglib.la /usr/local/lib/libgmodule.la -lintl -lglib -lgmodule /usr/local/lib/libgdk.la /usr/local/lib/libgtk.la -L/usr/X11R6/lib -L/usr/local/lib /usr/local/lib/libglade.la -lz -lz -lz /usr/local/lib/libxml.la /usr/local/lib/libglib.la -lm -lm /usr/local/lib/libaudiofile.la -lm -lm -laudiofile /usr/local/lib/libesd.la -lm -lz /usr/local/lib/libgnomesupport.la -lm -lz -lm -lglib /usr/local/lib/libgnome.la -lX11 -lXext /usr/local/lib/libiconv.la -L/usr/ports/devel/gettext/w-gettext-0.10.40/gettext-0.10.40/intl/.libs /usr/local/lib/libintl.la /usr/local/lib/libgmodule.la -lintl -lm -lX11 -lXext -lglib -lgmodule /usr/local/lib/libgdk.la -lintl -lm -lX11 -lXext -lglib -lgmodule /usr/local/lib/libgtk.la -lICE -lSM -lz -lpng /usr/local/lib/libungif.la /usr/local/lib/libjpeg.la -ltiff -lm -lz -lz /usr/local/lib/libgdk_imlib.la /usr/local/lib/libart_lgpl.la -lm -lz -lm -lX11 -lXext -lintl -lglib -lgmodule -lgdk -lgtk -lm -lX11 -lXext -lintl -lglib -lgmodule -lgdk -lgtk -lm -lz -lungif -lz -ljpeg -ljpeg -lgdk_imlib -lglib -lm -laudiofile -lm -laudiofile -lesd /usr/local/lib/libgnomeui.la -L/usr/X11R6/lib -L/usr/local/lib /usr/local/lib/libglade-gnome.la /usr/local/lib/libglib.la -lm -lm /usr/local/lib/libaudiofile.la -lm -lm -laudiofile -L/usr/local/lib /usr/local/lib/libesd.la -lm -lz -L/usr/local/lib /usr/local/lib/libgnomesupport.la -lm -lz -lm -lglib -L/usr/local/lib /usr/local/lib/libgnome.la -lX11 -lXext /usr/local/lib/libiconv.la -L/usr/local/lib -L/usr/ports/devel/gettext/w-gettext-0.10.40/gettext-0.10.40/intl/.libs /usr/local/lib/libintl.la /usr/local/lib/libgmodule.la -lintl -lm -lX11 -lXext -L/usr/X11R6/lib -lglib -lgmodule -L/usr/local/lib /usr/local/lib/libgdk.la -lintl -lm -lX11 -lXext -L/usr/X11R6/lib -lglib -lgmodule -L/usr/local/lib /usr/local/lib/libgtk.la -lICE -lSM -lz -lpng /usr/local/lib/libungif.la /usr/local/lib/libjpeg.la -ltiff -lm -lz -lpng /usr/local/lib/libungif.la -lz /usr/local/lib/libjpeg.la -ltiff -L/usr/local/lib -L/usr/X11R6/lib /usr/local/lib/libgdk_imlib.la -lm -L/usr/local/lib /usr/local/lib/libart_lgpl.la -lm -lz -lm -lX11 -lXext -lintl -lglib -lgmodule -lgdk -lgtk -lICE -lSM -lm -lX11 -lXext -lintl -lglib -lgmodule -lgdk -lgtk -L/usr/X11R6/lib -lm -lz -lpng -lungif -lz -ljpeg -ltiff -ljpeg -lgdk_imlib -lglib -lm -laudiofile -lm -laudiofile -lesd -L/usr/local/lib /usr/local/lib/libgnomeui.la -L/usr/X11R6/lib -L/usr/local/lib"
	specialdeplibs="-lgnomeui -lart_lgpl -lgdk_imlib -ltiff -ljpeg -lungif -lpng -lz -lSM -lICE -lgtk -lgdk -lgmodule -lintl -lXext -lX11 -lgnome -lgnomesupport -lesd -laudiofile -lm -lglib"
	for deplib in $deplibs; do
	    case $deplib in
		-L*) 
		    new_libs="$deplib $new_libs" 
		    ;;
		*)
		    case " $specialdeplibs " in
			*" $deplib "*) 
			    new_libs="$deplib $new_libs";;
		    esac
		    ;;
	    esac
	done
---

name: seterror-1
description:
	The -e flag should be ignored on unsuccessful commands before && inside an
	if statement.
stdin:
	if true; then false && false; fi
	true
arguments: !-e!
expected-exit: e == 0
---

name: seterror-2
description:
	The -e flag should be ignored on unsuccessful commands before && inside a
	nested if statement.
stdin:
	if true; then if true; then false && false; fi; fi
	true
arguments: !-e!
expected-exit: e == 0
---

name: seterror-3
description:
	The -e flag should be ignored when executing a compound list
	followed by an elif statement.
stdin:
	if true; then :; elif true; then false && false; fi
arguments: !-e!
expected-exit: e == 0
---

name: seterror-4
description:
	Inside a for statement, the -e flag should be ignored on successful commands
	before ||, or unsuccessful commands before &&.
stdin:
	for i in 1 2 3
	do
		false && false
		true || false
	done
arguments: !-e!
expected-exit: e == 0
---

name: seterror-5
description:
	The -e flag should be ignored when executing a pipeline
	beginning with '!'
stdin:
	! true | false
	true
arguments: !-e!
expected-exit: e == 0
---

name: seterror-6
description:
	When trapping ERR and EXIT, both traps should run in -e mode
	when an error occurs.
stdin:
	trap 'echo EXIT' EXIT
	trap 'echo ERR' ERR
	set -e
	false
	echo DONE
	exit 0
arguments: !-e!
expected-exit: e != 0
expected-stdout:
	ERR
	EXIT
---

name: seterror-7
description:
	The -e flag within a command substitution should be honored
stdin:
	echo $( set -e; false; echo foo )
arguments: !-e!
expected-stdout:
	
---

name: seterror-8
description:
	The -e flag within an if statement should terminate && chains on
	failure in rightmost command.
stdin:
	if true; then true && false; fi
	true
arguments: !-e!
expected-exit: e != 0
---

name: seterror-9
description:
	The -e flag within a for statement should terminate && or || chains on
	failure in rightmost command.
stdin:
	for f in 0; do true && false; done
	true
arguments: !-e!
expected-exit: e != 0
---

name: seterror-10
description:
	The -e flag within a while statement should terminate && or || chains on
	failure in rightmost command.
stdin:
	while true; do true && false; done
	true
arguments: !-e!
expected-exit: e != 0
---

name: seterror-11
description:
	Putting it all together for -e mode, test an && chain behaving in different
	ways in different iterations of a for loop.
# file x is absent; xx is present
file-setup: file 644 "xx"
# file y is absent
arguments: !-e!
# first iteration of for loop errors at first branch of &&
#   execution should continue in spite of -e mode
# second iteration of for loop errors at second branch of &&
#   -e mode should trigger exit
stdin:
	for f in x xx
	do
		test -f $f && test -f y  # final statement in loop
	done
	echo "should not print"
expected-exit: e != 0
---

name: seterror-12
description:
	Putting it all together for -e mode, test an && chain behaving in different
	ways in different iterations of a while loop.
# file x is absent; xx is present
file-setup: file 644 "x"
# file y is absent
arguments: !-e!
# first iteration of for loop errors at first branch of &&
#   execution should continue in spite of -e mode
# second iteration of for loop errors at second branch of &&
#   -e mode should trigger exit
stdin:
	x=''
	y=''
	while [ "$x" != xxx ]
	do
		x=x$x
		y=y$y
		test -f $x && test -f y  # final statement in loop
	done
	echo "should not print"
expected-exit: e != 0
---

name: seterror-13
description:
	Putting it all together for -e mode, test an && chain behaving in different
	ways in different iterations of a until loop.
# file x is absent; xx is present
file-setup: file 644 "x"
# files y and yy are both absent
arguments: !-e!
# first iteration of for loop errors at first branch of &&
#   execution should continue in spite of -e mode
# second iteration of for loop errors at second branch of &&
#   -e mode should trigger exit
stdin:
	x=''
	y=''
	until [ "$x" == xxx ]
	do
		x=x$x
		y=y$y
		test -f $x && test -f $y  # final statement in loop
	done
	echo "should not print"
expected-exit: e != 0
---

name: input-comsub
description:
	A command substitution using input redirection should exit with
	failure if the input file does not exist.
stdin:
	var=$(< non-existent)
expected-exit: e != 0
expected-stderr-pattern: /non-existent/

---
name: empty-for-list
description:
	A for list which expands to zero items should not execute the body.
stdin:
	set foo bar baz ; for out in ; do echo $out ; done

---

name: command-pvV-posix-priorities
description:
	For POSIX compatibility, command -v should find aliases and reserved
	words, and command -p[vV] should find aliases, reserved words, and
	builtins over external commands.
stdin:
	PATH=$(command -p getconf PATH) || PATH=/bin:/usr/bin
	alias foo="bar baz"
	bar() { :; }
	for word in 'if' 'foo' 'bar' 'set' 'true' 'ls'; do
		command -v "$word"
		command -pv "$word"
		command -V "$word"
		command -pV "$word"
	done
expected-stdout-pattern:
	/^if
	if
	if is a reserved word
	if is a reserved word
	alias foo='bar baz'
	alias foo='bar baz'
	foo is an alias for 'bar baz'
	foo is an alias for 'bar baz'
	bar
	bar
	bar is a function
	bar is a function
	set
	set
	set is a special shell builtin
	set is a special shell builtin
	true
	true
	true is a shell builtin
	true is a shell builtin
	.*\/ls.*
	.*\/ls.*
	ls is a tracked alias for .*\/ls.*
	ls is .*\/ls.*$/
---

name: whence-preserve-tradition
description:
	POSIX 'command' and ksh88/pdksh-specific 'whence' are handled by the
	same c_whence() function.  This regression test is to ensure that
	the POSIX compatibility changes for 'command' (see previous test) do
	not affect traditional 'whence' behaviour.
stdin:
	PATH=$(command -p getconf PATH) || PATH=/bin:/usr/bin
	alias foo="bar baz"
	bar() { :; }
	for word in 'if' 'foo' 'bar' 'set' 'true' 'ls'; do
		whence "$word"
		whence -p "$word"
		whence -v "$word"
		whence -pv "$word"
	done
expected-stdout-pattern:
	/^if
	if is a reserved word
	if not found
	'bar baz'
	foo is an alias for 'bar baz'
	foo not found
	bar
	bar is a function
	bar not found
	set
	set is a special shell builtin
	set not found
	true
	.*\/true.*
	true is a shell builtin
	true is a tracked alias for .*\/true.*
	.*\/ls.*
	.*\/ls.*
	ls is a tracked alias for .*\/ls.*
	ls is a tracked alias for .*\/ls.*$/
---

name: shellopt-u-1
description:
	Check that "$@" and "$*" are exempt from 'set -u' (nounset)
stdin:
	set -u
	: "$@$*$1"
expected-exit: e == 1
expected-stderr-pattern:
	/: 1: parameter not set$/
---

name: pwd
description:
	PWD and OLDPWD must be exported
stdin:
	d=$(printenv PWD)
	: ${d:?"PWD not exported"}
	cd .
	d=$(printenv OLDPWD)
	: ${d:?"OLDPWD not exported"}
---

name: kill-SIGNAME
description:
	support kill -s SIGNAME syntax
stdin:
	kill -s SIGINFO $$
---

name: pipeline-pipefail-1
description:
	check pipeline return status
stdin:
	set -o pipefail
	true | true
---

name: pipeline-pipefail-2
description:
	check pipeline return status
stdin:
	set -o pipefail
	false | true
expected-exit: e == 1
---

name: pipeline-pipefail-3
description:
	check pipeline return status
stdin:
	set -o pipefail
	true | false
expected-exit: e == 1
---

name: pipeline-pipefail-4
description:
	check pipeline return status
stdin:
	set -o pipefail
	! false | true
---

name: pipeline-pipefail-errexit-1
description:
	check pipeline return status
stdin:
	set -e
	false | true
	echo "ok"
expected-stdout: ok
---

name: pipeline-pipefail-errexit-2
description:
	check pipeline return status
stdin:
	set -e
	set -o pipefail
	false | true
	echo "should not print"
expected-exit: e == 1
expected-stdout:
---

name: pipeline-pipefail-errexit-3
description:
	check pipeline return status
stdin:
	set -e
	set -o pipefail
	false | true || echo "ok"
expected-stdout: ok
---

name: pipeline-pipefail-check-time-1
description:
	check pipeline return status
stdin:
	false | true &
	p=$!
	set -o pipefail
	wait $p
---

name: pipeline-pipefail-check-time-2
description:
	check pipeline return status
stdin:
	set -o pipefail
	false | true &
	p=$!
	set +o pipefail
	wait $p
expected-exit: e == 1
---

name: overwrite-ro-array
description:
	do not allow to override first element of a read-only array
	via the non-array access.
stdin:
	arr[0]=foo
	readonly arr
	arr=bar
expected-exit: e == 1
expected-stderr-pattern:
	/: arr: is read only$/
---