blob: d5df4cba849759656d3f056a2c19726550be24b4 [file] [log] [blame]
Elliott Hughes47086262019-03-26 12:34:31 -07001# $MirOS: src/bin/mksh/check.t,v 1.812 2019/03/01 16:17:29 tg Exp $
Elliott Hughes50012062015-03-10 22:22:24 -07002# -*- mode: sh -*-
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003#-
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00004# Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
Elliott Hughes47086262019-03-26 12:34:31 -07005# 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018,
6# 2019
Elliott Hughesfc0307d2016-02-02 15:26:47 -08007# mirabilos <m@mirbsd.org>
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008#
9# Provided that these terms and disclaimer and all copyright notices
10# are retained or reproduced in an accompanying document, permission
11# is granted to deal in this work without restriction, including un‐
12# limited rights to use, publicly perform, distribute, sell, modify,
13# merge, give away, or sublicence.
14#
15# This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
16# the utmost extent permitted by applicable law, neither express nor
17# implied; without malicious intent or gross negligence. In no event
18# may a licensor, author or contributor be held liable for indirect,
19# direct, other damage, loss, or other issues arising in any way out
20# of dealing in the work, even if advised of the possibility of such
21# damage or existence of a defect, except proven that it results out
22# of said person’s immediate fault when using the work as intended.
23#-
24# You may also want to test IFS with the script at
25# http://www.research.att.com/~gsf/public/ifs.sh
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000026#
27# More testsuites at:
Elliott Hughes50012062015-03-10 22:22:24 -070028# http://svnweb.freebsd.org/base/head/bin/test/tests/legacy_test.sh?view=co&content-type=text%2Fplain
29#
30# Integrated testsuites from:
Elliott Hughes77740fc2016-08-12 15:06:53 -070031# (2013/12/02 20:39:44) http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070032
33expected-stdout:
Elliott Hughes47086262019-03-26 12:34:31 -070034 @(#)MIRBSD KSH R57 2019/03/01
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070035description:
Elliott Hughes23925bb2017-09-22 16:04:20 -070036 Check base version of full shell
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070037stdin:
Elliott Hughes23925bb2017-09-22 16:04:20 -070038 echo ${KSH_VERSION%%' +'*}
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070039name: KSH_VERSION
Elliott Hughes23925bb2017-09-22 16:04:20 -070040category: !shell:legacy-yes
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000041---
42expected-stdout:
Elliott Hughes47086262019-03-26 12:34:31 -070043 @(#)LEGACY KSH R57 2019/03/01
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000044description:
Elliott Hughes23925bb2017-09-22 16:04:20 -070045 Check base version of legacy shell
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000046stdin:
Elliott Hughes23925bb2017-09-22 16:04:20 -070047 echo ${KSH_VERSION%%' +'*}
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000048name: KSH_VERSION-legacy
Elliott Hughes23925bb2017-09-22 16:04:20 -070049category: !shell:legacy-no
Elliott Hughesa3c3f962017-04-12 16:52:30 -070050---
Elliott Hughes23925bb2017-09-22 16:04:20 -070051name: KSH_VERSION-ascii
Elliott Hughesa3c3f962017-04-12 16:52:30 -070052description:
Elliott Hughes23925bb2017-09-22 16:04:20 -070053 Check that the shell version tag does not include EBCDIC
54category: !shell:ebcdic-yes
Elliott Hughesa3c3f962017-04-12 16:52:30 -070055stdin:
Elliott Hughes23925bb2017-09-22 16:04:20 -070056 for x in $KSH_VERSION; do
57 [[ $x = '+EBCDIC' ]] && exit 1
58 done
59 exit 0
60---
61name: KSH_VERSION-ebcdic
62description:
63 Check that the shell version tag includes EBCDIC
64category: !shell:ebcdic-no
65stdin:
66 for x in $KSH_VERSION; do
67 [[ $x = '+EBCDIC' ]] && exit 0
68 done
69 exit 1
70---
71name: KSH_VERSION-binmode
72description:
73 Check that the shell version tag does not include TEXTMODE
74category: !shell:textmode-yes
75stdin:
76 for x in $KSH_VERSION; do
77 [[ $x = '+TEXTMODE' ]] && exit 1
78 done
79 exit 0
80---
Elliott Hughesa3c3f962017-04-12 16:52:30 -070081name: KSH_VERSION-textmode
Elliott Hughesa3c3f962017-04-12 16:52:30 -070082description:
Elliott Hughes23925bb2017-09-22 16:04:20 -070083 Check that the shell version tag includes TEXTMODE
84category: !shell:textmode-no
Elliott Hughesa3c3f962017-04-12 16:52:30 -070085stdin:
Elliott Hughes23925bb2017-09-22 16:04:20 -070086 for x in $KSH_VERSION; do
87 [[ $x = '+TEXTMODE' ]] && exit 0
88 done
89 exit 1
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070090---
91name: selftest-1
92description:
93 Regression test self-testing
94stdin:
95 echo ${foo:-baz}
96expected-stdout:
97 baz
98---
99name: selftest-2
100description:
101 Regression test self-testing
102env-setup: !foo=bar!
103stdin:
104 echo ${foo:-baz}
105expected-stdout:
106 bar
107---
108name: selftest-3
109description:
110 Regression test self-testing
111env-setup: !ENV=fnord!
112stdin:
113 echo "<$ENV>"
114expected-stdout:
115 <fnord>
116---
Elliott Hughes737fdce2014-08-07 12:59:26 -0700117name: selftest-exec
118description:
119 Ensure that the test run directory (default /tmp but can be changed
120 with check.pl flag -T or test.sh $TMPDIR) is not mounted noexec, as
121 we execute scripts from the scratch directory during several tests.
122stdin:
123 print '#!'"$__progname"'\necho tf' >lq
124 chmod +x lq
125 ./lq
126expected-stdout:
127 tf
128---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700129name: selftest-env
130description:
131 Just output the environment variables set (always fails)
132category: disabled
133stdin:
134 set
135---
Geremy Condra03ebf062011-10-12 18:17:24 -0700136name: selftest-direct-builtin-call
137description:
138 Check that direct builtin calls work
139stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000140 ln -s "$__progname" cat || cp "$__progname" cat
141 ln -s "$__progname" echo || cp "$__progname" echo
Geremy Condra03ebf062011-10-12 18:17:24 -0700142 ./echo -c 'echo foo' | ./cat -u
143expected-stdout:
144 -c echo foo
145---
Elliott Hughesa3c3f962017-04-12 16:52:30 -0700146name: selftest-pathsep-unix
147description:
148 Check that $PATHSEP is set correctly.
149category: !os:os2
150stdin:
151 PATHSEP=.; export PATHSEP
152 "$__progname" -c 'print -r -- $PATHSEP'
153expected-stdout:
154 :
155---
156name: selftest-pathsep-dospath
157description:
158 Check that $PATHSEP is set correctly.
159category: os:os2
160stdin:
161 PATHSEP=.; export PATHSEP
162 "$__progname" -c 'print -r -- $PATHSEP'
163expected-stdout:
164 ;
165---
Elliott Hughes47086262019-03-26 12:34:31 -0700166name: selftest-tty-absent
167description:
168 Check that a controlling tty is not present as regress:no-ctty was used
169 (if this test fails for you DO NOT PASS regress:no-ctty and fix every
170 other test that fails: why u use it if u haz ctty?)
171category: regress:no-ctty
172env-setup: !ENV=./envf!
173file-setup: file 644 "envf"
174 PS1=X
175arguments: !-i!
176stdin:
177 echo ok
178expected-stdout:
179 ok
180expected-stderr-pattern:
181 /mksh: warning: won't have full job control\nXX/
182---
183name: selftest-tty-present
184description:
185 Check that a controlling tty is present as regress:no-ctty was not used
186need-ctty: yes
187env-setup: !ENV=./envf!
188file-setup: file 644 "envf"
189 PS1=X
190arguments: !-i!
191stdin:
192 echo ok
193expected-stdout:
194 ok
195expected-stderr: !
196 XX
197---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700198name: alias-1
199description:
200 Check that recursion is detected/avoided in aliases.
201stdin:
202 alias fooBar=fooBar
203 fooBar
204 exit 0
205expected-stderr-pattern:
206 /fooBar.*not found.*/
207---
208name: alias-2
209description:
210 Check that recursion is detected/avoided in aliases.
211stdin:
212 alias fooBar=barFoo
213 alias barFoo=fooBar
214 fooBar
215 barFoo
216 exit 0
217expected-stderr-pattern:
218 /fooBar.*not found.*\n.*barFoo.*not found/
219---
220name: alias-3
221description:
222 Check that recursion is detected/avoided in aliases.
223stdin:
224 alias Echo='echo '
225 alias fooBar=barFoo
226 alias barFoo=fooBar
227 Echo fooBar
228 unalias barFoo
229 Echo fooBar
230expected-stdout:
231 fooBar
232 barFoo
233---
234name: alias-4
235description:
236 Check that alias expansion isn't done on keywords (in keyword
237 postitions).
238stdin:
239 alias Echo='echo '
240 alias while=While
241 while false; do echo hi ; done
242 Echo while
243expected-stdout:
244 While
245---
246name: alias-5
247description:
248 Check that alias expansion done after alias with trailing space.
249stdin:
250 alias Echo='echo '
251 alias foo='bar stuff '
252 alias bar='Bar1 Bar2 '
253 alias stuff='Stuff'
254 alias blah='Blah'
255 Echo foo blah
256expected-stdout:
257 Bar1 Bar2 Stuff Blah
258---
259name: alias-6
260description:
261 Check that alias expansion done after alias with trailing space.
262stdin:
263 alias Echo='echo '
264 alias foo='bar bar'
265 alias bar='Bar '
266 alias blah=Blah
267 Echo foo blah
268expected-stdout:
269 Bar Bar Blah
270---
271name: alias-7
272description:
273 Check that alias expansion done after alias with trailing space
274 after a keyword.
275stdin:
276 alias X='case '
277 alias Y=Z
Elliott Hughes77740fc2016-08-12 15:06:53 -0700278 X Y in 'Y') echo is y ;; Z) echo is z ;; esac
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700279expected-stdout:
280 is z
281---
282name: alias-8
283description:
284 Check that newlines in an alias don't cause the command to be lost.
285stdin:
286 alias foo='
287
288
289 echo hi
290
291
292
293 echo there
294
295
296 '
297 foo
298expected-stdout:
299 hi
300 there
301---
302name: alias-9
303description:
304 Check that recursion is detected/avoided in aliases.
305 This check fails for slow machines or Cygwin, raise
306 the time-limit clause (e.g. to 7) if this occurs.
307time-limit: 3
308stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000309 print '#!'"$__progname"'\necho tf' >lq
310 chmod +x lq
Elliott Hughes96b43632015-07-17 11:39:41 -0700311 PATH=$PWD$PATHSEP$PATH
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000312 alias lq=lq
313 lq
314 echo = now
315 i=`lq`
316 print -r -- $i
317 echo = out
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700318 exit 0
319expected-stdout:
320 tf
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000321 = now
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700322 tf
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000323 = out
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700324---
325name: alias-10
326description:
327 Check that recursion is detected/avoided in aliases.
328 Regression, introduced during an old bugfix.
329stdin:
330 alias foo='print hello '
331 alias bar='foo world'
332 echo $(bar)
333expected-stdout:
334 hello world
335---
Elliott Hughesb27ce952015-04-21 13:39:18 -0700336name: alias-11
337description:
338 Check that special argument handling still applies with escaped aliases
339stdin:
Elliott Hughesa3c3f962017-04-12 16:52:30 -0700340 alias local1='\typeset'
341 alias local2='\\builtin typeset'
342 function fooa {
343 local1 x=$1 y=z
Elliott Hughesb27ce952015-04-21 13:39:18 -0700344 print -r -- "$x,$y"
345 }
Elliott Hughesa3c3f962017-04-12 16:52:30 -0700346 function foob {
347 local2 x=$1 y=z
348 print -r -- "$x,$y"
349 }
350 x=1 y=2; fooa 'bar - baz'
351 x=1 y=2; foob 'bar - baz'
Elliott Hughesb27ce952015-04-21 13:39:18 -0700352expected-stdout:
353 bar - baz,z
Elliott Hughesa3c3f962017-04-12 16:52:30 -0700354 bar - baz,z
355---
356name: alias-12
357description:
358 Something weird from Martijn Dekker
359stdin:
360 alias echo=print
361 x() { echo a; (echo b); x=$(echo c); }
362 typeset -f x
363 alias OPEN='{' CLOSE='};'
364 { OPEN echo hi1; CLOSE }
365 var=`{ OPEN echo hi2; CLOSE }` && echo "$var"
366 var=$({ OPEN echo hi3; CLOSE }) && echo "$var"
367expected-stdout:
368 x() {
369 \print a
370 ( \print b )
371 x=$(\print c )
372 }
373 hi1
374 hi2
375 hi3
Elliott Hughesb27ce952015-04-21 13:39:18 -0700376---
Elliott Hughesfc0307d2016-02-02 15:26:47 -0800377name: arith-compound
378description:
379 Check that arithmetic expressions are compound constructs
380stdin:
381 { ! (( 0$(cat >&2) )) <<<1; } <<<2
382expected-stderr:
383 1
384---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700385name: arith-lazy-1
386description:
387 Check that only one side of ternary operator is evaluated
388stdin:
389 x=i+=2
390 y=j+=2
391 typeset -i i=1 j=1
392 echo $((1 ? 20 : (x+=2)))
393 echo $i,$x
394 echo $((0 ? (y+=2) : 30))
395 echo $j,$y
396expected-stdout:
397 20
398 1,i+=2
399 30
400 1,j+=2
401---
402name: arith-lazy-2
403description:
404 Check that assignments not done on non-evaluated side of ternary
405 operator
406stdin:
407 x=i+=2
408 y=j+=2
409 typeset -i i=1 j=1
410 echo $((1 ? 20 : (x+=2)))
411 echo $i,$x
412 echo $((0 ? (y+=2) : 30))
413 echo $i,$y
414expected-stdout:
415 20
416 1,i+=2
417 30
418 1,j+=2
419---
420name: arith-lazy-3
421description:
422 Check that assignments not done on non-evaluated side of ternary
423 operator and this construct is parsed correctly (Debian #445651)
424stdin:
425 x=4
426 y=$((0 ? x=1 : 2))
427 echo = $x $y =
428expected-stdout:
429 = 4 2 =
430---
Thorsten Glaser811a5752013-07-25 14:24:45 +0000431name: arith-lazy-4
432description:
433 Check that preun/postun not done on non-evaluated side of ternary
434 operator
435stdin:
436 (( m = n = 0, 1 ? n++ : m++ ? 2 : 3 ))
437 echo "($n, $m)"
438 m=0; echo $(( 0 ? ++m : 2 )); echo $m
439 m=0; echo $(( 0 ? m++ : 2 )); echo $m
440expected-stdout:
441 (1, 0)
442 2
443 0
444 2
445 0
446---
Elliott Hughes966dd552016-12-08 15:56:04 -0800447name: arith-lazy-5-arr-n
448description: Check lazy evaluation with side effects
449stdin:
450 a=0; echo "$((0&&b[a++],a))"
451expected-stdout:
452 0
453---
454name: arith-lazy-5-arr-p
455description: Check lazy evaluation with side effects
456stdin:
457 a=0; echo "$((0&&(b[a++]),a))"
458expected-stdout:
459 0
460---
461name: arith-lazy-5-str-n
462description: Check lazy evaluation with side effects
463stdin:
464 a=0 b=a++; ((0&&b)); echo $a
465expected-stdout:
466 0
467---
468name: arith-lazy-5-str-p
469description: Check lazy evaluation with side effects
470stdin:
471 a=0 b=a++; ((0&&(b))); echo $a
472expected-stdout:
473 0
474---
475name: arith-lazy-5-tern-l-n
476description: Check lazy evaluation with side effects
477stdin:
478 a=0; echo "$((0?b[a++]:999,a))"
479expected-stdout:
480 0
481---
482name: arith-lazy-5-tern-l-p
483description: Check lazy evaluation with side effects
484stdin:
485 a=0; echo "$((0?(b[a++]):999,a))"
486expected-stdout:
487 0
488---
489name: arith-lazy-5-tern-r-n
490description: Check lazy evaluation with side effects
491stdin:
492 a=0; echo "$((1?999:b[a++],a))"
493expected-stdout:
494 0
495---
496name: arith-lazy-5-tern-r-p
497description: Check lazy evaluation with side effects
498stdin:
499 a=0; echo "$((1?999:(b[a++]),a))"
500expected-stdout:
501 0
502---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700503name: arith-ternary-prec-1
504description:
505 Check precedence of ternary operator vs assignment
506stdin:
507 typeset -i x=2
508 y=$((1 ? 20 : x+=2))
509expected-exit: e != 0
510expected-stderr-pattern:
511 /.*:.*1 \? 20 : x\+=2.*lvalue.*\n$/
512---
513name: arith-ternary-prec-2
514description:
515 Check precedence of ternary operator vs assignment
516stdin:
517 typeset -i x=2
518 echo $((0 ? x+=2 : 20))
519expected-stdout:
520 20
521---
Elliott Hughes77740fc2016-08-12 15:06:53 -0700522name: arith-prec-1
523description:
524 Prove arithmetic expressions with embedded parameter
525 substitutions cannot be parsed ahead of time
526stdin:
527 a='3 + 4'
528 print 1 $((2 * a)) .
529 print 2 $((2 * $a)) .
530expected-stdout:
531 1 14 .
532 2 10 .
533---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700534name: arith-div-assoc-1
535description:
536 Check associativity of division operator
537stdin:
538 echo $((20 / 2 / 2))
539expected-stdout:
540 5
541---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000542name: arith-div-byzero
543description:
544 Check division by zero errors out
545stdin:
546 x=$(echo $((1 / 0)))
547 echo =$?:$x.
548expected-stdout:
549 =1:.
550expected-stderr-pattern:
551 /.*divisor/
552---
553name: arith-div-intmin-by-minusone
554description:
555 Check division overflow wraps around silently
556category: int:32
557stdin:
558 echo signed:$((-2147483648 / -1))r$((-2147483648 % -1)).
559 echo unsigned:$((# -2147483648 / -1))r$((# -2147483648 % -1)).
560expected-stdout:
561 signed:-2147483648r0.
562 unsigned:0r2147483648.
563---
564name: arith-div-intmin-by-minusone-64
565description:
566 Check division overflow wraps around silently
567category: int:64
568stdin:
569 echo signed:$((-9223372036854775808 / -1))r$((-9223372036854775808 % -1)).
570 echo unsigned:$((# -9223372036854775808 / -1))r$((# -9223372036854775808 % -1)).
571expected-stdout:
572 signed:-9223372036854775808r0.
573 unsigned:0r9223372036854775808.
574---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700575name: arith-assop-assoc-1
576description:
577 Check associativity of assignment-operator operator
578stdin:
579 typeset -i i=1 j=2 k=3
580 echo $((i += j += k))
581 echo $i,$j,$k
582expected-stdout:
583 6
584 6,5,3
585---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000586name: arith-mandatory
587description:
Thorsten Glaser811a5752013-07-25 14:24:45 +0000588 Passing of this test is *mandatory* for a valid mksh executable!
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000589category: shell:legacy-no
590stdin:
591 typeset -i sari=0
592 typeset -Ui uari=0
593 typeset -i x=0
Thorsten Glaser811a5752013-07-25 14:24:45 +0000594 print -r -- $((x++)):$sari=$uari. #0
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000595 let --sari --uari
Thorsten Glaser811a5752013-07-25 14:24:45 +0000596 print -r -- $((x++)):$sari=$uari. #1
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000597 sari=2147483647 uari=2147483647
Thorsten Glaser811a5752013-07-25 14:24:45 +0000598 print -r -- $((x++)):$sari=$uari. #2
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000599 let ++sari ++uari
Thorsten Glaser811a5752013-07-25 14:24:45 +0000600 print -r -- $((x++)):$sari=$uari. #3
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000601 let --sari --uari
602 let 'sari *= 2' 'uari *= 2'
603 let ++sari ++uari
Thorsten Glaser811a5752013-07-25 14:24:45 +0000604 print -r -- $((x++)):$sari=$uari. #4
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000605 let ++sari ++uari
Thorsten Glaser811a5752013-07-25 14:24:45 +0000606 print -r -- $((x++)):$sari=$uari. #5
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000607 sari=-2147483648 uari=-2147483648
Thorsten Glaser811a5752013-07-25 14:24:45 +0000608 print -r -- $((x++)):$sari=$uari. #6
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000609 let --sari --uari
Thorsten Glaser811a5752013-07-25 14:24:45 +0000610 print -r -- $((x++)):$sari=$uari. #7
611 (( sari = -5 >> 1 ))
612 ((# uari = -5 >> 1 ))
613 print -r -- $((x++)):$sari=$uari. #8
614 (( sari = -2 ))
615 ((# uari = sari ))
616 print -r -- $((x++)):$sari=$uari. #9
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000617expected-stdout:
618 0:0=0.
619 1:-1=4294967295.
620 2:2147483647=2147483647.
621 3:-2147483648=2147483648.
622 4:-1=4294967295.
623 5:0=0.
624 6:-2147483648=2147483648.
625 7:2147483647=2147483647.
Thorsten Glaser811a5752013-07-25 14:24:45 +0000626 8:-3=2147483645.
627 9:-2=4294967294.
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000628---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700629name: arith-unsigned-1
630description:
631 Check if unsigned arithmetics work
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000632category: int:32
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700633stdin:
634 # signed vs unsigned
635 echo x1 $((-1)) $((#-1))
636 # calculating
637 typeset -i vs
638 typeset -Ui vu
639 vs=4123456789; vu=4123456789
640 echo x2 $vs $vu
641 (( vs %= 2147483647 ))
642 (( vu %= 2147483647 ))
643 echo x3 $vs $vu
644 vs=4123456789; vu=4123456789
645 (( # vs %= 2147483647 ))
646 (( # vu %= 2147483647 ))
647 echo x4 $vs $vu
648 # make sure the calculation does not change unsigned flag
649 vs=4123456789; vu=4123456789
650 echo x5 $vs $vu
651 # short form
652 echo x6 $((# vs % 2147483647)) $((# vu % 2147483647))
653 # array refs
654 set -A va
655 va[1975973142]=right
656 va[4123456789]=wrong
657 echo x7 ${va[#4123456789%2147483647]}
Elliott Hughesfc0307d2016-02-02 15:26:47 -0800658 # make sure multiple calculations don't interfere with each other
659 let '# mca = -4 % -2' ' mcb = -4 % -2'
660 echo x8 $mca $mcb
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700661expected-stdout:
662 x1 -1 4294967295
663 x2 -171510507 4123456789
664 x3 -171510507 4123456789
665 x4 1975973142 1975973142
666 x5 -171510507 4123456789
667 x6 1975973142 1975973142
668 x7 right
Elliott Hughesfc0307d2016-02-02 15:26:47 -0800669 x8 -4 0
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700670---
671name: arith-limit32-1
672description:
673 Check if arithmetics are 32 bit
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000674category: int:32
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700675stdin:
676 # signed vs unsigned
677 echo x1 $((-1)) $((#-1))
678 # calculating
679 typeset -i vs
680 typeset -Ui vu
681 vs=2147483647; vu=2147483647
682 echo x2 $vs $vu
683 let vs++ vu++
684 echo x3 $vs $vu
685 vs=4294967295; vu=4294967295
686 echo x4 $vs $vu
687 let vs++ vu++
688 echo x5 $vs $vu
689 let vs++ vu++
690 echo x6 $vs $vu
691expected-stdout:
692 x1 -1 4294967295
693 x2 2147483647 2147483647
694 x3 -2147483648 2147483648
695 x4 -1 4294967295
696 x5 0 0
697 x6 1 1
698---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000699name: arith-limit64-1
700description:
701 Check if arithmetics are 64 bit
702category: int:64
703stdin:
704 # signed vs unsigned
705 echo x1 $((-1)) $((#-1))
706 # calculating
707 typeset -i vs
708 typeset -Ui vu
709 vs=9223372036854775807; vu=9223372036854775807
710 echo x2 $vs $vu
711 let vs++ vu++
712 echo x3 $vs $vu
713 vs=18446744073709551615; vu=18446744073709551615
714 echo x4 $vs $vu
715 let vs++ vu++
716 echo x5 $vs $vu
717 let vs++ vu++
718 echo x6 $vs $vu
719expected-stdout:
720 x1 -1 18446744073709551615
721 x2 9223372036854775807 9223372036854775807
722 x3 -9223372036854775808 9223372036854775808
723 x4 -1 18446744073709551615
724 x5 0 0
725 x6 1 1
726---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700727name: bksl-nl-ign-1
728description:
Geremy Condra03ebf062011-10-12 18:17:24 -0700729 Check that \newline is not collapsed after #
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700730stdin:
731 echo hi #there \
732 echo folks
733expected-stdout:
734 hi
735 folks
736---
737name: bksl-nl-ign-2
738description:
Geremy Condra03ebf062011-10-12 18:17:24 -0700739 Check that \newline is not collapsed inside single quotes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700740stdin:
741 echo 'hi \
742 there'
743 echo folks
744expected-stdout:
745 hi \
746 there
747 folks
748---
749name: bksl-nl-ign-3
750description:
Geremy Condra03ebf062011-10-12 18:17:24 -0700751 Check that \newline is not collapsed inside single quotes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700752stdin:
753 cat << \EOF
754 hi \
755 there
756 EOF
757expected-stdout:
758 hi \
759 there
760---
761name: bksl-nl-ign-4
762description:
763 Check interaction of aliases, single quotes and here-documents
764 with backslash-newline
765 (don't know what POSIX has to say about this)
766stdin:
767 a=2
768 alias x='echo hi
769 cat << "EOF"
770 foo\
771 bar
772 some'
773 x
774 more\
775 stuff$a
776 EOF
777expected-stdout:
778 hi
779 foo\
780 bar
781 some
782 more\
783 stuff$a
784---
785name: bksl-nl-ign-5
786description:
787 Check what happens with backslash at end of input
788 (the old Bourne shell trashes them; so do we)
789stdin: !
790 echo `echo foo\\`bar
791 echo hi\
792expected-stdout:
793 foobar
794 hi
795---
796#
797# Places \newline should be collapsed
798#
799name: bksl-nl-1
800description:
Geremy Condra03ebf062011-10-12 18:17:24 -0700801 Check that \newline is collapsed before, in the middle of, and
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700802 after words
803stdin:
804 \
805 echo hi\
806 There, \
807 folks
808expected-stdout:
809 hiThere, folks
810---
811name: bksl-nl-2
812description:
Geremy Condra03ebf062011-10-12 18:17:24 -0700813 Check that \newline is collapsed in $ sequences
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700814 (ksh93 fails this)
815stdin:
816 a=12
817 ab=19
818 echo $\
819 a
820 echo $a\
821 b
822 echo $\
823 {a}
824 echo ${a\
825 b}
826 echo ${ab\
827 }
828expected-stdout:
829 12
830 19
831 12
832 19
833 19
834---
835name: bksl-nl-3
836description:
Geremy Condra03ebf062011-10-12 18:17:24 -0700837 Check that \newline is collapsed in $(..) and `...` sequences
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700838 (ksh93 fails this)
839stdin:
840 echo $\
841 (echo foobar1)
842 echo $(\
843 echo foobar2)
844 echo $(echo foo\
845 bar3)
846 echo $(echo foobar4\
847 )
848 echo `
849 echo stuff1`
850 echo `echo st\
851 uff2`
852expected-stdout:
853 foobar1
854 foobar2
855 foobar3
856 foobar4
857 stuff1
858 stuff2
859---
860name: bksl-nl-4
861description:
Geremy Condra03ebf062011-10-12 18:17:24 -0700862 Check that \newline is collapsed in $((..)) sequences
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700863 (ksh93 fails this)
864stdin:
865 echo $\
866 ((1+2))
867 echo $(\
868 (1+2+3))
869 echo $((\
870 1+2+3+4))
871 echo $((1+\
872 2+3+4+5))
873 echo $((1+2+3+4+5+6)\
874 )
875expected-stdout:
876 3
877 6
878 10
879 15
880 21
881---
882name: bksl-nl-5
883description:
Geremy Condra03ebf062011-10-12 18:17:24 -0700884 Check that \newline is collapsed in double quoted strings
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700885stdin:
886 echo "\
887 hi"
888 echo "foo\
889 bar"
890 echo "folks\
891 "
892expected-stdout:
893 hi
894 foobar
895 folks
896---
897name: bksl-nl-6
898description:
Geremy Condra03ebf062011-10-12 18:17:24 -0700899 Check that \newline is collapsed in here document delimiters
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700900 (ksh93 fails second part of this)
901stdin:
902 a=12
903 cat << EO\
904 F
905 a=$a
906 foo\
907 bar
908 EOF
909 cat << E_O_F
910 foo
911 E_O_\
912 F
913 echo done
914expected-stdout:
915 a=12
916 foobar
917 foo
918 done
919---
920name: bksl-nl-7
921description:
Geremy Condra03ebf062011-10-12 18:17:24 -0700922 Check that \newline is collapsed in double-quoted here-document
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700923 delimiter.
924stdin:
925 a=12
926 cat << "EO\
927 F"
928 a=$a
929 foo\
930 bar
931 EOF
932 echo done
933expected-stdout:
934 a=$a
935 foo\
936 bar
937 done
938---
939name: bksl-nl-8
940description:
Geremy Condra03ebf062011-10-12 18:17:24 -0700941 Check that \newline is collapsed in various 2+ character tokens
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700942 delimiter.
943 (ksh93 fails this)
944stdin:
945 echo hi &\
946 & echo there
947 echo foo |\
948 | echo bar
949 cat <\
950 < EOF
951 stuff
952 EOF
953 cat <\
954 <\
955 - EOF
956 more stuff
957 EOF
958 cat <<\
959 EOF
960 abcdef
961 EOF
962 echo hi >\
963 > /dev/null
964 echo $?
965 i=1
966 case $i in
967 (\
968 x|\
969 1\
970 ) echo hi;\
971 ;
972 (*) echo oops
973 esac
974expected-stdout:
975 hi
976 there
977 foo
978 stuff
979 more stuff
980 abcdef
981 0
982 hi
983---
984name: bksl-nl-9
985description:
986 Check that \ at the end of an alias is collapsed when followed
987 by a newline
988 (don't know what POSIX has to say about this)
989stdin:
990 alias x='echo hi\'
991 x
992 echo there
993expected-stdout:
994 hiecho there
995---
996name: bksl-nl-10
997description:
998 Check that \newline in a keyword is collapsed
999stdin:
1000 i\
1001 f true; then\
1002 echo pass; el\
1003 se echo fail; fi
1004expected-stdout:
1005 pass
1006---
1007#
1008# Places \newline should be collapsed (ksh extensions)
1009#
1010name: bksl-nl-ksh-1
1011description:
1012 Check that \newline is collapsed in extended globbing
1013 (ksh93 fails this)
1014stdin:
1015 xxx=foo
1016 case $xxx in
1017 (f*\
1018 (\
1019 o\
1020 )\
1021 ) echo ok ;;
1022 *) echo bad
1023 esac
1024expected-stdout:
1025 ok
1026---
1027name: bksl-nl-ksh-2
1028description:
1029 Check that \newline is collapsed in ((...)) expressions
1030 (ksh93 fails this)
1031stdin:
1032 i=1
1033 (\
1034 (\
1035 i=i+2\
1036 )\
1037 )
1038 echo $i
1039expected-stdout:
1040 3
1041---
1042name: break-1
1043description:
1044 See if break breaks out of loops
1045stdin:
1046 for i in a b c; do echo $i; break; echo bad-$i; done
1047 echo end-1
1048 for i in a b c; do echo $i; break 1; echo bad-$i; done
1049 echo end-2
1050 for i in a b c; do
1051 for j in x y z; do
1052 echo $i:$j
1053 break
1054 echo bad-$i
1055 done
1056 echo end-$i
1057 done
1058 echo end-3
Elliott Hughesa3c3f962017-04-12 16:52:30 -07001059 for i in a b c; do echo $i; eval break; echo bad-$i; done
1060 echo end-4
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001061expected-stdout:
1062 a
1063 end-1
1064 a
1065 end-2
1066 a:x
1067 end-a
1068 b:x
1069 end-b
1070 c:x
1071 end-c
1072 end-3
Elliott Hughesa3c3f962017-04-12 16:52:30 -07001073 a
1074 end-4
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001075---
1076name: break-2
1077description:
1078 See if break breaks out of nested loops
1079stdin:
1080 for i in a b c; do
1081 for j in x y z; do
1082 echo $i:$j
1083 break 2
1084 echo bad-$i
1085 done
1086 echo end-$i
1087 done
1088 echo end
1089expected-stdout:
1090 a:x
1091 end
1092---
1093name: break-3
1094description:
1095 What if break used outside of any loops
1096 (ksh88,ksh93 don't print error messages here)
1097stdin:
1098 break
1099expected-stderr-pattern:
1100 /.*break.*/
1101---
1102name: break-4
1103description:
1104 What if break N used when only N-1 loops
1105 (ksh88,ksh93 don't print error messages here)
1106stdin:
1107 for i in a b c; do echo $i; break 2; echo bad-$i; done
1108 echo end
1109expected-stdout:
1110 a
1111 end
1112expected-stderr-pattern:
1113 /.*break.*/
1114---
1115name: break-5
1116description:
1117 Error if break argument isn't a number
1118stdin:
1119 for i in a b c; do echo $i; break abc; echo more-$i; done
1120 echo end
1121expected-stdout:
1122 a
1123expected-exit: e != 0
1124expected-stderr-pattern:
1125 /.*break.*/
1126---
1127name: continue-1
1128description:
1129 See if continue continues loops
1130stdin:
1131 for i in a b c; do echo $i; continue; echo bad-$i ; done
1132 echo end-1
1133 for i in a b c; do echo $i; continue 1; echo bad-$i; done
1134 echo end-2
1135 for i in a b c; do
1136 for j in x y z; do
1137 echo $i:$j
1138 continue
1139 echo bad-$i-$j
1140 done
1141 echo end-$i
1142 done
1143 echo end-3
Elliott Hughesa3c3f962017-04-12 16:52:30 -07001144 for i in a b c; do echo $i; eval continue; echo bad-$i ; done
1145 echo end-4
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001146expected-stdout:
1147 a
1148 b
1149 c
1150 end-1
1151 a
1152 b
1153 c
1154 end-2
1155 a:x
1156 a:y
1157 a:z
1158 end-a
1159 b:x
1160 b:y
1161 b:z
1162 end-b
1163 c:x
1164 c:y
1165 c:z
1166 end-c
1167 end-3
Elliott Hughesa3c3f962017-04-12 16:52:30 -07001168 a
1169 b
1170 c
1171 end-4
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001172---
1173name: continue-2
1174description:
1175 See if continue breaks out of nested loops
1176stdin:
1177 for i in a b c; do
1178 for j in x y z; do
1179 echo $i:$j
1180 continue 2
1181 echo bad-$i-$j
1182 done
1183 echo end-$i
1184 done
1185 echo end
1186expected-stdout:
1187 a:x
1188 b:x
1189 c:x
1190 end
1191---
1192name: continue-3
1193description:
1194 What if continue used outside of any loops
1195 (ksh88,ksh93 don't print error messages here)
1196stdin:
1197 continue
1198expected-stderr-pattern:
1199 /.*continue.*/
1200---
1201name: continue-4
1202description:
1203 What if continue N used when only N-1 loops
1204 (ksh88,ksh93 don't print error messages here)
1205stdin:
1206 for i in a b c; do echo $i; continue 2; echo bad-$i; done
1207 echo end
1208expected-stdout:
1209 a
1210 b
1211 c
1212 end
1213expected-stderr-pattern:
1214 /.*continue.*/
1215---
1216name: continue-5
1217description:
1218 Error if continue argument isn't a number
1219stdin:
1220 for i in a b c; do echo $i; continue abc; echo more-$i; done
1221 echo end
1222expected-stdout:
1223 a
1224expected-exit: e != 0
1225expected-stderr-pattern:
1226 /.*continue.*/
1227---
1228name: cd-history
1229description:
1230 Test someone's CD history package (uses arrays)
1231stdin:
1232 # go to known place before doing anything
1233 cd /
1234
1235 alias cd=_cd
1236 function _cd
1237 {
1238 typeset -i cdlen i
1239 typeset t
1240
1241 if [ $# -eq 0 ]
1242 then
1243 set -- $HOME
1244 fi
1245
1246 if [ "$CDHISTFILE" -a -r "$CDHISTFILE" ] # if directory history exists
1247 then
1248 typeset CDHIST
1249 i=-1
1250 while read -r t # read directory history file
1251 do
1252 CDHIST[i=i+1]=$t
1253 done <$CDHISTFILE
1254 fi
1255
1256 if [ "${CDHIST[0]}" != "$PWD" -a "$PWD" != "" ]
1257 then
1258 _cdins # insert $PWD into cd history
1259 fi
1260
1261 cdlen=${#CDHIST[*]} # number of elements in history
1262
1263 case "$@" in
1264 -) # cd to new dir
1265 if [ "$OLDPWD" = "" ] && ((cdlen>1))
1266 then
1267 'print' ${CDHIST[1]}
1268 'cd' ${CDHIST[1]}
1269 _pwd
1270 else
1271 'cd' $@
1272 _pwd
1273 fi
1274 ;;
1275 -l) # print directory list
1276 typeset -R3 num
1277 ((i=cdlen))
1278 while (((i=i-1)>=0))
1279 do
1280 num=$i
1281 'print' "$num ${CDHIST[i]}"
1282 done
1283 return
1284 ;;
1285 -[0-9]|-[0-9][0-9]) # cd to dir in list
1286 if (((i=${1#-})<cdlen))
1287 then
1288 'print' ${CDHIST[i]}
1289 'cd' ${CDHIST[i]}
1290 _pwd
1291 else
1292 'cd' $@
1293 _pwd
1294 fi
1295 ;;
1296 -*) # cd to matched dir in list
1297 t=${1#-}
1298 i=1
1299 while ((i<cdlen))
1300 do
1301 case ${CDHIST[i]} in
1302 *$t*)
1303 'print' ${CDHIST[i]}
1304 'cd' ${CDHIST[i]}
1305 _pwd
1306 break
1307 ;;
1308 esac
1309 ((i=i+1))
1310 done
1311 if ((i>=cdlen))
1312 then
1313 'cd' $@
1314 _pwd
1315 fi
1316 ;;
1317 *) # cd to new dir
1318 'cd' $@
1319 _pwd
1320 ;;
1321 esac
1322
1323 _cdins # insert $PWD into cd history
1324
1325 if [ "$CDHISTFILE" ]
1326 then
1327 cdlen=${#CDHIST[*]} # number of elements in history
1328
1329 i=0
1330 while ((i<cdlen))
1331 do
1332 'print' -r ${CDHIST[i]} # update directory history
1333 ((i=i+1))
1334 done >$CDHISTFILE
1335 fi
1336 }
1337
1338 function _cdins # insert $PWD into cd history
1339 { # meant to be called only by _cd
1340 typeset -i i
1341
1342 ((i=0))
1343 while ((i<${#CDHIST[*]})) # see if dir is already in list
1344 do
1345 if [ "${CDHIST[$i]}" = "$PWD" ]
1346 then
1347 break
1348 fi
1349 ((i=i+1))
1350 done
1351
1352 if ((i>22)) # limit max size of list
1353 then
1354 i=22
1355 fi
1356
1357 while (((i=i-1)>=0)) # bump old dirs in list
1358 do
1359 CDHIST[i+1]=${CDHIST[i]}
1360 done
1361
1362 CDHIST[0]=$PWD # insert new directory in list
1363 }
1364
1365
1366 function _pwd
1367 {
1368 if [ -n "$ECD" ]
1369 then
1370 pwd 1>&6
1371 fi
1372 }
1373 # Start of test
1374 cd /tmp
1375 cd /bin
1376 cd /etc
1377 cd -
1378 cd -2
1379 cd -l
1380expected-stdout:
1381 /bin
1382 /tmp
1383 3 /
1384 2 /etc
1385 1 /bin
1386 0 /tmp
1387---
Geremy Condra03ebf062011-10-12 18:17:24 -07001388name: cd-pe
1389description:
1390 Check package for cd -Pe
1391need-pass: no
Elliott Hughes23925bb2017-09-22 16:04:20 -07001392# the mv command fails on Cygwin and z/OS
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001393# Hurd aborts the testsuite (permission denied)
1394# QNX does not find subdir to cd into
Elliott Hughes96b43632015-07-17 11:39:41 -07001395category: !os:cygwin,!os:gnu,!os:msys,!os:nto,!os:os390,!nosymlink
Geremy Condra03ebf062011-10-12 18:17:24 -07001396file-setup: file 644 "x"
1397 mkdir noread noread/target noread/target/subdir
1398 ln -s noread link
1399 chmod 311 noread
1400 cd -P$1 .
1401 echo 0=$?
1402 bwd=$PWD
1403 cd -P$1 link/target
1404 echo 1=$?,${PWD#$bwd/}
1405 epwd=$($TSHELL -c pwd 2>/dev/null)
1406 # This unexpectedly succeeds on GNU/Linux and MidnightBSD
1407 #echo pwd=$?,$epwd
1408 # expect: pwd=1,
1409 mv ../../noread ../../renamed
1410 cd -P$1 subdir
1411 echo 2=$?,${PWD#$bwd/}
1412 cd $bwd
Elliott Hughes23925bb2017-09-22 16:04:20 -07001413 chmod 755 noread renamed 2>/dev/null
Geremy Condra03ebf062011-10-12 18:17:24 -07001414 rm -rf noread link renamed
1415stdin:
1416 export TSHELL="$__progname"
1417 "$__progname" x
1418 echo "now with -e:"
1419 "$__progname" x e
1420expected-stdout:
1421 0=0
1422 1=0,noread/target
1423 2=0,noread/target/subdir
1424 now with -e:
1425 0=0
1426 1=0,noread/target
1427 2=1,noread/target/subdir
1428---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001429name: env-prompt
1430description:
1431 Check that prompt not printed when processing ENV
1432env-setup: !ENV=./foo!
1433file-setup: file 644 "foo"
1434 XXX=_
1435 PS1=X
1436 false && echo hmmm
Geremy Condra03ebf062011-10-12 18:17:24 -07001437need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001438arguments: !-i!
1439stdin:
1440 echo hi${XXX}there
1441expected-stdout:
1442 hi_there
1443expected-stderr: !
1444 XX
1445---
1446name: expand-ugly
1447description:
1448 Check that weird ${foo+bar} constructs are parsed correctly
1449stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001450 print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
1451 print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "<$x> "; done' >pfs
1452 chmod +x pfn pfs
1453 (echo 1 ${IFS+'}'z}) 2>/dev/null || echo failed in 1
1454 (echo 2 "${IFS+'}'z}") 2>/dev/null || echo failed in 2
1455 (echo 3 "foo ${IFS+'bar} baz") 2>/dev/null || echo failed in 3
1456 (echo -n '4 '; ./pfn "foo ${IFS+"b c"} baz") 2>/dev/null || echo failed in 4
1457 (echo -n '5 '; ./pfn "foo ${IFS+b c} baz") 2>/dev/null || echo failed in 5
1458 (echo 6 ${IFS+"}"z}) 2>/dev/null || echo failed in 6
1459 (echo 7 "${IFS+"}"z}") 2>/dev/null || echo failed in 7
1460 (echo 8 "${IFS+\"}\"z}") 2>/dev/null || echo failed in 8
1461 (echo 9 "${IFS+\"\}\"z}") 2>/dev/null || echo failed in 9
1462 (echo 10 foo ${IFS+'bar} baz'}) 2>/dev/null || echo failed in 10
1463 (echo 11 "$(echo "${IFS+'}'z}")") 2>/dev/null || echo failed in 11
1464 (echo 12 "$(echo ${IFS+'}'z})") 2>/dev/null || echo failed in 12
1465 (echo 13 ${IFS+\}z}) 2>/dev/null || echo failed in 13
1466 (echo 14 "${IFS+\}z}") 2>/dev/null || echo failed in 14
1467 u=x; (echo -n '15 '; ./pfs "foo ${IFS+a"b$u{ {"{{\}b} c ${IFS+d{}} bar" ${IFS-e{}} baz; echo .) 2>/dev/null || echo failed in 15
1468 l=t; (echo 16 ${IFS+h`echo -n i ${IFS+$l}h`ere}) 2>/dev/null || echo failed in 16
1469 l=t; (echo 17 ${IFS+h$(echo -n i ${IFS+$l}h)ere}) 2>/dev/null || echo failed in 17
1470 l=t; (echo 18 "${IFS+h`echo -n i ${IFS+$l}h`ere}") 2>/dev/null || echo failed in 18
1471 l=t; (echo 19 "${IFS+h$(echo -n i ${IFS+$l}h)ere}") 2>/dev/null || echo failed in 19
1472 l=t; (echo 20 ${IFS+h`echo -n i "${IFS+$l}"h`ere}) 2>/dev/null || echo failed in 20
1473 l=t; (echo 21 ${IFS+h$(echo -n i "${IFS+$l}"h)ere}) 2>/dev/null || echo failed in 21
1474 l=t; (echo 22 "${IFS+h`echo -n i "${IFS+$l}"h`ere}") 2>/dev/null || echo failed in 22
1475 l=t; (echo 23 "${IFS+h$(echo -n i "${IFS+$l}"h)ere}") 2>/dev/null || echo failed in 23
1476 key=value; (echo -n '24 '; ./pfn "${IFS+'$key'}") 2>/dev/null || echo failed in 24
1477 key=value; (echo -n '25 '; ./pfn "${IFS+"'$key'"}") 2>/dev/null || echo failed in 25 # ksh93: “'$key'”
1478 key=value; (echo -n '26 '; ./pfn ${IFS+'$key'}) 2>/dev/null || echo failed in 26
1479 key=value; (echo -n '27 '; ./pfn ${IFS+"'$key'"}) 2>/dev/null || echo failed in 27
1480 (echo -n '28 '; ./pfn "${IFS+"'"x ~ x'}'x"'}"x}" #') 2>/dev/null || echo failed in 28
1481 u=x; (echo -n '29 '; ./pfs foo ${IFS+a"b$u{ {"{ {\}b} c ${IFS+d{}} bar ${IFS-e{}} baz; echo .) 2>/dev/null || echo failed in 29
1482 (echo -n '30 '; ./pfs ${IFS+foo 'b\
1483 ar' baz}; echo .) 2>/dev/null || (echo failed in 30; echo failed in 31)
1484 (echo -n '32 '; ./pfs ${IFS+foo "b\
1485 ar" baz}; echo .) 2>/dev/null || echo failed in 32
1486 (echo -n '33 '; ./pfs "${IFS+foo 'b\
1487 ar' baz}"; echo .) 2>/dev/null || echo failed in 33
1488 (echo -n '34 '; ./pfs "${IFS+foo "b\
1489 ar" baz}"; echo .) 2>/dev/null || echo failed in 34
1490 (echo -n '35 '; ./pfs ${v=a\ b} x ${v=c\ d}; echo .) 2>/dev/null || echo failed in 35
1491 (echo -n '36 '; ./pfs "${v=a\ b}" x "${v=c\ d}"; echo .) 2>/dev/null || echo failed in 36
1492 (echo -n '37 '; ./pfs ${v-a\ b} x ${v-c\ d}; echo .) 2>/dev/null || echo failed in 37
1493 (echo 38 ${IFS+x'a'y} / "${IFS+x'a'y}" .) 2>/dev/null || echo failed in 38
1494 foo="x'a'y"; (echo 39 ${foo%*'a'*} / "${foo%*'a'*}" .) 2>/dev/null || echo failed in 39
1495 foo="a b c"; (echo -n '40 '; ./pfs "${foo#a}"; echo .) 2>/dev/null || echo failed in 40
Elliott Hughes77740fc2016-08-12 15:06:53 -07001496 (foo() { return 100; }; foo; echo 41 ${#+${#:+${#?}}\ \}\}\}}) 2>/dev/null || echo failed in 41
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001497expected-stdout:
1498 1 }z
1499 2 ''z}
1500 3 foo 'bar baz
1501 4 foo b c baz
1502 5 foo b c baz
1503 6 }z
1504 7 }z
1505 8 ""z}
1506 9 "}"z
1507 10 foo bar} baz
1508 11 ''z}
1509 12 }z
1510 13 }z
1511 14 }z
1512 15 <foo abx{ {{{}b c d{} bar> <}> <baz> .
1513 16 hi there
1514 17 hi there
1515 18 hi there
1516 19 hi there
1517 20 hi there
1518 21 hi there
1519 22 hi there
1520 23 hi there
1521 24 'value'
1522 25 'value'
1523 26 $key
1524 27 'value'
1525 28 'x ~ x''x}"x}" #
1526 29 <foo> <abx{ {{> <{}b> <c> <d{}> <bar> <}> <baz> .
1527 30 <foo> <b\
1528 ar> <baz> .
1529 32 <foo> <bar> <baz> .
1530 33 <foo 'bar' baz> .
1531 34 <foo bar baz> .
1532 35 <a> <b> <x> <a> <b> .
1533 36 <a\ b> <x> <a\ b> .
1534 37 <a b> <x> <c d> .
1535 38 xay / x'a'y .
1536 39 x' / x' .
1537 40 < b c> .
Elliott Hughes77740fc2016-08-12 15:06:53 -07001538 41 3 }}}
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001539---
1540name: expand-unglob-dblq
1541description:
1542 Check that regular "${foo+bar}" constructs are parsed correctly
1543stdin:
1544 u=x
1545 tl_norm() {
1546 v=$2
1547 test x"$v" = x"-" && unset v
1548 (echo "$1 plus norm foo ${v+'bar'} baz")
1549 (echo "$1 dash norm foo ${v-'bar'} baz")
1550 (echo "$1 eqal norm foo ${v='bar'} baz")
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001551 (echo "$1 qstn norm foo ${v?'bar'} baz") 2>/dev/null || \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001552 echo "$1 qstn norm -> error"
1553 (echo "$1 PLUS norm foo ${v:+'bar'} baz")
1554 (echo "$1 DASH norm foo ${v:-'bar'} baz")
1555 (echo "$1 EQAL norm foo ${v:='bar'} baz")
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001556 (echo "$1 QSTN norm foo ${v:?'bar'} baz") 2>/dev/null || \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001557 echo "$1 QSTN norm -> error"
1558 }
1559 tl_paren() {
1560 v=$2
1561 test x"$v" = x"-" && unset v
1562 (echo "$1 plus parn foo ${v+(bar)} baz")
1563 (echo "$1 dash parn foo ${v-(bar)} baz")
1564 (echo "$1 eqal parn foo ${v=(bar)} baz")
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001565 (echo "$1 qstn parn foo ${v?(bar)} baz") 2>/dev/null || \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001566 echo "$1 qstn parn -> error"
1567 (echo "$1 PLUS parn foo ${v:+(bar)} baz")
1568 (echo "$1 DASH parn foo ${v:-(bar)} baz")
1569 (echo "$1 EQAL parn foo ${v:=(bar)} baz")
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001570 (echo "$1 QSTN parn foo ${v:?(bar)} baz") 2>/dev/null || \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001571 echo "$1 QSTN parn -> error"
1572 }
1573 tl_brace() {
1574 v=$2
1575 test x"$v" = x"-" && unset v
1576 (echo "$1 plus brac foo ${v+a$u{{{\}b} c ${v+d{}} baz")
1577 (echo "$1 dash brac foo ${v-a$u{{{\}b} c ${v-d{}} baz")
1578 (echo "$1 eqal brac foo ${v=a$u{{{\}b} c ${v=d{}} baz")
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001579 (echo "$1 qstn brac foo ${v?a$u{{{\}b} c ${v?d{}} baz") 2>/dev/null || \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001580 echo "$1 qstn brac -> error"
1581 (echo "$1 PLUS brac foo ${v:+a$u{{{\}b} c ${v:+d{}} baz")
1582 (echo "$1 DASH brac foo ${v:-a$u{{{\}b} c ${v:-d{}} baz")
1583 (echo "$1 EQAL brac foo ${v:=a$u{{{\}b} c ${v:=d{}} baz")
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001584 (echo "$1 QSTN brac foo ${v:?a$u{{{\}b} c ${v:?d{}} baz") 2>/dev/null || \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001585 echo "$1 QSTN brac -> error"
1586 }
Elliott Hughes77740fc2016-08-12 15:06:53 -07001587 : '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}'
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001588 tl_norm 1 -
1589 tl_norm 2 ''
1590 tl_norm 3 x
1591 tl_paren 4 -
1592 tl_paren 5 ''
1593 tl_paren 6 x
1594 tl_brace 7 -
1595 tl_brace 8 ''
1596 tl_brace 9 x
1597expected-stdout:
1598 1 plus norm foo baz
1599 1 dash norm foo 'bar' baz
1600 1 eqal norm foo 'bar' baz
1601 1 qstn norm -> error
1602 1 PLUS norm foo baz
1603 1 DASH norm foo 'bar' baz
1604 1 EQAL norm foo 'bar' baz
1605 1 QSTN norm -> error
1606 2 plus norm foo 'bar' baz
1607 2 dash norm foo baz
1608 2 eqal norm foo baz
1609 2 qstn norm foo baz
1610 2 PLUS norm foo baz
1611 2 DASH norm foo 'bar' baz
1612 2 EQAL norm foo 'bar' baz
1613 2 QSTN norm -> error
1614 3 plus norm foo 'bar' baz
1615 3 dash norm foo x baz
1616 3 eqal norm foo x baz
1617 3 qstn norm foo x baz
1618 3 PLUS norm foo 'bar' baz
1619 3 DASH norm foo x baz
1620 3 EQAL norm foo x baz
1621 3 QSTN norm foo x baz
1622 4 plus parn foo baz
1623 4 dash parn foo (bar) baz
1624 4 eqal parn foo (bar) baz
1625 4 qstn parn -> error
1626 4 PLUS parn foo baz
1627 4 DASH parn foo (bar) baz
1628 4 EQAL parn foo (bar) baz
1629 4 QSTN parn -> error
1630 5 plus parn foo (bar) baz
1631 5 dash parn foo baz
1632 5 eqal parn foo baz
1633 5 qstn parn foo baz
1634 5 PLUS parn foo baz
1635 5 DASH parn foo (bar) baz
1636 5 EQAL parn foo (bar) baz
1637 5 QSTN parn -> error
1638 6 plus parn foo (bar) baz
1639 6 dash parn foo x baz
1640 6 eqal parn foo x baz
1641 6 qstn parn foo x baz
1642 6 PLUS parn foo (bar) baz
1643 6 DASH parn foo x baz
1644 6 EQAL parn foo x baz
1645 6 QSTN parn foo x baz
1646 7 plus brac foo c } baz
1647 7 dash brac foo ax{{{}b c d{} baz
1648 7 eqal brac foo ax{{{}b c ax{{{}b} baz
1649 7 qstn brac -> error
1650 7 PLUS brac foo c } baz
1651 7 DASH brac foo ax{{{}b c d{} baz
1652 7 EQAL brac foo ax{{{}b c ax{{{}b} baz
1653 7 QSTN brac -> error
1654 8 plus brac foo ax{{{}b c d{} baz
1655 8 dash brac foo c } baz
1656 8 eqal brac foo c } baz
1657 8 qstn brac foo c } baz
1658 8 PLUS brac foo c } baz
1659 8 DASH brac foo ax{{{}b c d{} baz
1660 8 EQAL brac foo ax{{{}b c ax{{{}b} baz
1661 8 QSTN brac -> error
1662 9 plus brac foo ax{{{}b c d{} baz
1663 9 dash brac foo x c x} baz
1664 9 eqal brac foo x c x} baz
1665 9 qstn brac foo x c x} baz
1666 9 PLUS brac foo ax{{{}b c d{} baz
1667 9 DASH brac foo x c x} baz
1668 9 EQAL brac foo x c x} baz
1669 9 QSTN brac foo x c x} baz
1670---
1671name: expand-unglob-unq
1672description:
1673 Check that regular ${foo+bar} constructs are parsed correctly
1674stdin:
1675 u=x
1676 tl_norm() {
1677 v=$2
1678 test x"$v" = x"-" && unset v
1679 (echo $1 plus norm foo ${v+'bar'} baz)
1680 (echo $1 dash norm foo ${v-'bar'} baz)
1681 (echo $1 eqal norm foo ${v='bar'} baz)
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001682 (echo $1 qstn norm foo ${v?'bar'} baz) 2>/dev/null || \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001683 echo "$1 qstn norm -> error"
1684 (echo $1 PLUS norm foo ${v:+'bar'} baz)
1685 (echo $1 DASH norm foo ${v:-'bar'} baz)
1686 (echo $1 EQAL norm foo ${v:='bar'} baz)
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001687 (echo $1 QSTN norm foo ${v:?'bar'} baz) 2>/dev/null || \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001688 echo "$1 QSTN norm -> error"
1689 }
1690 tl_paren() {
1691 v=$2
1692 test x"$v" = x"-" && unset v
1693 (echo $1 plus parn foo ${v+\(bar')'} baz)
1694 (echo $1 dash parn foo ${v-\(bar')'} baz)
1695 (echo $1 eqal parn foo ${v=\(bar')'} baz)
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001696 (echo $1 qstn parn foo ${v?\(bar')'} baz) 2>/dev/null || \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001697 echo "$1 qstn parn -> error"
1698 (echo $1 PLUS parn foo ${v:+\(bar')'} baz)
1699 (echo $1 DASH parn foo ${v:-\(bar')'} baz)
1700 (echo $1 EQAL parn foo ${v:=\(bar')'} baz)
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001701 (echo $1 QSTN parn foo ${v:?\(bar')'} baz) 2>/dev/null || \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001702 echo "$1 QSTN parn -> error"
1703 }
1704 tl_brace() {
1705 v=$2
1706 test x"$v" = x"-" && unset v
1707 (echo $1 plus brac foo ${v+a$u{{{\}b} c ${v+d{}} baz)
1708 (echo $1 dash brac foo ${v-a$u{{{\}b} c ${v-d{}} baz)
1709 (echo $1 eqal brac foo ${v=a$u{{{\}b} c ${v=d{}} baz)
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001710 (echo $1 qstn brac foo ${v?a$u{{{\}b} c ${v?d{}} baz) 2>/dev/null || \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001711 echo "$1 qstn brac -> error"
1712 (echo $1 PLUS brac foo ${v:+a$u{{{\}b} c ${v:+d{}} baz)
1713 (echo $1 DASH brac foo ${v:-a$u{{{\}b} c ${v:-d{}} baz)
1714 (echo $1 EQAL brac foo ${v:=a$u{{{\}b} c ${v:=d{}} baz)
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001715 (echo $1 QSTN brac foo ${v:?a$u{{{\}b} c ${v:?d{}} baz) 2>/dev/null || \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001716 echo "$1 QSTN brac -> error"
1717 }
Elliott Hughes77740fc2016-08-12 15:06:53 -07001718 : '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}'
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001719 tl_norm 1 -
1720 tl_norm 2 ''
1721 tl_norm 3 x
1722 tl_paren 4 -
1723 tl_paren 5 ''
1724 tl_paren 6 x
1725 tl_brace 7 -
1726 tl_brace 8 ''
1727 tl_brace 9 x
1728expected-stdout:
1729 1 plus norm foo baz
1730 1 dash norm foo bar baz
1731 1 eqal norm foo bar baz
1732 1 qstn norm -> error
1733 1 PLUS norm foo baz
1734 1 DASH norm foo bar baz
1735 1 EQAL norm foo bar baz
1736 1 QSTN norm -> error
1737 2 plus norm foo bar baz
1738 2 dash norm foo baz
1739 2 eqal norm foo baz
1740 2 qstn norm foo baz
1741 2 PLUS norm foo baz
1742 2 DASH norm foo bar baz
1743 2 EQAL norm foo bar baz
1744 2 QSTN norm -> error
1745 3 plus norm foo bar baz
1746 3 dash norm foo x baz
1747 3 eqal norm foo x baz
1748 3 qstn norm foo x baz
1749 3 PLUS norm foo bar baz
1750 3 DASH norm foo x baz
1751 3 EQAL norm foo x baz
1752 3 QSTN norm foo x baz
1753 4 plus parn foo baz
1754 4 dash parn foo (bar) baz
1755 4 eqal parn foo (bar) baz
1756 4 qstn parn -> error
1757 4 PLUS parn foo baz
1758 4 DASH parn foo (bar) baz
1759 4 EQAL parn foo (bar) baz
1760 4 QSTN parn -> error
1761 5 plus parn foo (bar) baz
1762 5 dash parn foo baz
1763 5 eqal parn foo baz
1764 5 qstn parn foo baz
1765 5 PLUS parn foo baz
1766 5 DASH parn foo (bar) baz
1767 5 EQAL parn foo (bar) baz
1768 5 QSTN parn -> error
1769 6 plus parn foo (bar) baz
1770 6 dash parn foo x baz
1771 6 eqal parn foo x baz
1772 6 qstn parn foo x baz
1773 6 PLUS parn foo (bar) baz
1774 6 DASH parn foo x baz
1775 6 EQAL parn foo x baz
1776 6 QSTN parn foo x baz
1777 7 plus brac foo c } baz
1778 7 dash brac foo ax{{{}b c d{} baz
1779 7 eqal brac foo ax{{{}b c ax{{{}b} baz
1780 7 qstn brac -> error
1781 7 PLUS brac foo c } baz
1782 7 DASH brac foo ax{{{}b c d{} baz
1783 7 EQAL brac foo ax{{{}b c ax{{{}b} baz
1784 7 QSTN brac -> error
1785 8 plus brac foo ax{{{}b c d{} baz
1786 8 dash brac foo c } baz
1787 8 eqal brac foo c } baz
1788 8 qstn brac foo c } baz
1789 8 PLUS brac foo c } baz
1790 8 DASH brac foo ax{{{}b c d{} baz
1791 8 EQAL brac foo ax{{{}b c ax{{{}b} baz
1792 8 QSTN brac -> error
1793 9 plus brac foo ax{{{}b c d{} baz
1794 9 dash brac foo x c x} baz
1795 9 eqal brac foo x c x} baz
1796 9 qstn brac foo x c x} baz
1797 9 PLUS brac foo ax{{{}b c d{} baz
1798 9 DASH brac foo x c x} baz
1799 9 EQAL brac foo x c x} baz
1800 9 QSTN brac foo x c x} baz
1801---
Geremy Condra03ebf062011-10-12 18:17:24 -07001802name: expand-threecolons-dblq
1803description:
1804 Check for a particular thing that used to segfault
1805stdin:
1806 TEST=1234
1807 echo "${TEST:1:2:3}"
1808 echo $? but still living
1809expected-stderr-pattern:
1810 /bad substitution/
1811expected-exit: 1
1812---
1813name: expand-threecolons-unq
1814description:
1815 Check for a particular thing that used to not error out
1816stdin:
1817 TEST=1234
1818 echo ${TEST:1:2:3}
1819 echo $? but still living
1820expected-stderr-pattern:
1821 /bad substitution/
1822expected-exit: 1
1823---
1824name: expand-weird-1
1825description:
Elliott Hughes77740fc2016-08-12 15:06:53 -07001826 Check corner cases of trim expansion vs. $# vs. ${#var} vs. ${var?}
Geremy Condra03ebf062011-10-12 18:17:24 -07001827stdin:
1828 set 1 2 3 4 5 6 7 8 9 10 11
1829 echo ${#} # value of $#
1830 echo ${##} # length of $#
1831 echo ${##1} # $# trimmed 1
1832 set 1 2 3 4 5 6 7 8 9 10 11 12
1833 echo ${##1}
Geremy Condra03ebf062011-10-12 18:17:24 -07001834 (exit 0)
1835 echo $? = ${#?} .
1836 (exit 111)
1837 echo $? = ${#?} .
1838expected-stdout:
Elliott Hughes77740fc2016-08-12 15:06:53 -07001839 11
1840 2
1841 1
1842 2
Geremy Condra03ebf062011-10-12 18:17:24 -07001843 0 = 1 .
1844 111 = 3 .
1845---
Elliott Hughes77740fc2016-08-12 15:06:53 -07001846name: expand-weird-2
1847description:
1848 Check more substitution and extension corner cases
1849stdin:
1850 :& set -C; pid=$$; sub=$!; flg=$-; set -- i; exec 3>x.tmp
1851 #echo "D: !=$! #=$# \$=$$ -=$- ?=$?"
1852 echo >&3 3 = s^${!-word} , ${#-word} , p^${$-word} , f^${--word} , ${?-word} .
1853 echo >&3 4 = ${!+word} , ${#+word} , ${$+word} , ${-+word} , ${?+word} .
1854 echo >&3 5 = s^${!=word} , ${#=word} , p^${$=word} , f^${-=word} , ${?=word} .
1855 echo >&3 6 = s^${!?word} , ${#?word} , p^${$?word} , f^${-?word} , ${??word} .
1856 echo >&3 7 = sl^${#!} , ${##} , pl^${#$} , fl^${#-} , ${#?} .
1857 echo >&3 8 = sw^${%!} , ${%#} , pw^${%$} , fw^${%-} , ${%?} .
1858 echo >&3 9 = ${!!} , s^${!#} , ${!$} , s^${!-} , s^${!?} .
1859 echo >&3 10 = s^${!#pattern} , ${##pattern} , p^${$#pattern} , f^${-#pattern} , ${?#pattern} .
1860 echo >&3 11 = s^${!%pattern} , ${#%pattern} , p^${$%pattern} , f^${-%pattern} , ${?%pattern} .
1861 echo >&3 12 = $# : ${##} , ${##1} .
1862 set --
1863 echo >&3 14 = $# : ${##} , ${##1} .
1864 set -- 1 2 3 4 5
1865 echo >&3 16 = $# : ${##} , ${##1} .
1866 set -- 1 2 3 4 5 6 7 8 9 a b c d e
1867 echo >&3 18 = $# : ${##} , ${##1} .
1868 exec 3>&-
1869 <x.tmp sed \
1870 -e "s/ pl^${#pid} / PID /g" -e "s/ sl^${#sub} / SUB /g" -e "s/ fl^${#flg} / FLG /g" \
1871 -e "s/ pw^${%pid} / PID /g" -e "s/ sw^${%sub} / SUB /g" -e "s/ fw^${%flg} / FLG /g" \
1872 -e "s/ p^$pid / PID /g" -e "s/ s^$sub / SUB /g" -e "s/ f^$flg / FLG /g"
1873expected-stdout:
1874 3 = SUB , 1 , PID , FLG , 0 .
1875 4 = word , word , word , word , word .
1876 5 = SUB , 1 , PID , FLG , 0 .
1877 6 = SUB , 1 , PID , FLG , 0 .
1878 7 = SUB , 1 , PID , FLG , 1 .
1879 8 = SUB , 1 , PID , FLG , 1 .
1880 9 = ! , SUB , $ , SUB , SUB .
1881 10 = SUB , 1 , PID , FLG , 0 .
1882 11 = SUB , 1 , PID , FLG , 0 .
1883 12 = 1 : 1 , .
1884 14 = 0 : 1 , 0 .
1885 16 = 5 : 1 , 5 .
1886 18 = 14 : 2 , 4 .
1887---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001888name: expand-weird-3
1889description:
1890 Check that trimming works with positional parameters (Debian #48453)
1891stdin:
1892 A=9999-02
1893 B=9999
1894 echo 1=${A#$B?}.
1895 set -- $A $B
1896 echo 2=${1#$2?}.
1897expected-stdout:
1898 1=02.
1899 2=02.
1900---
Elliott Hughesfc0307d2016-02-02 15:26:47 -08001901name: expand-weird-4
1902description:
1903 Check that tilde expansion is enabled in ${x#~}
1904 and cases that are modelled after it (${x/~/~})
1905stdin:
1906 HOME=/etc
1907 a="~/x"
1908 echo "<${a#~}> <${a#\~}> <${b:-~}> <${b:-\~}> <${c:=~}><$c> <${a/~}> <${a/x/~}> <${a/x/\~}>"
1909expected-stdout:
1910 <~/x> </x> <~> <\~> <~><~> <~/x> <~//etc> <~/~>
1911---
Elliott Hughes77740fc2016-08-12 15:06:53 -07001912name: expand-bang-1
1913description:
1914 Check corner case of ${!?} with ! being var vs. op
1915stdin:
1916 echo ${!?}
1917expected-exit: 1
1918expected-stderr-pattern: /not set/
1919---
1920name: expand-bang-2
1921description:
1922 Check corner case of ${!var} vs. ${var op} with var=!
1923stdin:
1924 echo 1 $! .
1925 echo 2 ${!#} .
1926 echo 3 ${!#[0-9]} .
1927 echo 4 ${!-foo} .
1928 # get an at least three-digit bg pid
1929 while :; do
1930 :&
1931 x=$!
1932 if [[ $x != +([0-9]) ]]; then
1933 echo >&2 "cannot test, pid '$x' not numeric"
1934 echo >&2 report this with as many details as possible
1935 exit 1
1936 fi
1937 [[ $x = [0-9][0-9][0-9]* ]] && break
1938 done
1939 y=${x#?}
1940 t=$!; [[ $t = $x ]]; echo 5 $? .
1941 t=${!#}; [[ $t = $x ]]; echo 6 $? .
1942 t=${!#[0-9]}; [[ $t = $y ]]; echo 7 $? .
1943 t=${!-foo}; [[ $t = $x ]]; echo 8 $? .
1944 t=${!?bar}; [[ $t = $x ]]; echo 9 $? .
1945expected-stdout:
1946 1 .
1947 2 .
1948 3 .
1949 4 foo .
1950 5 0 .
1951 6 0 .
1952 7 0 .
1953 8 0 .
1954 9 0 .
1955---
Elliott Hughes737fdce2014-08-07 12:59:26 -07001956name: expand-number-1
1957description:
1958 Check that positional arguments do not overflow
1959stdin:
1960 echo "1 ${12345678901234567890} ."
1961expected-stdout:
1962 1 .
1963---
Elliott Hughes77740fc2016-08-12 15:06:53 -07001964name: expand-slashes-1
1965description:
1966 Check that side effects in substring replacement are handled correctly
1967stdin:
1968 foo=n1n1n1n2n3
1969 i=2
1970 n=1
1971 echo 1 ${foo//n$((n++))/[$((++i))]} .
1972 echo 2 $n , $i .
1973expected-stdout:
1974 1 [3][3][3]n2n3 .
1975 2 2 , 3 .
1976---
1977name: expand-slashes-2
1978description:
1979 Check that side effects in substring replacement are handled correctly
1980stdin:
1981 foo=n1n1n1n2n3
1982 i=2
1983 n=1
1984 echo 1 ${foo@/n$((n++))/[$((++i))]} .
1985 echo 2 $n , $i .
1986expected-stdout:
1987 1 [3]n1n1[4][5] .
1988 2 5 , 5 .
1989---
1990name: expand-slashes-3
1991description:
1992 Check that we can access the replaced string
1993stdin:
1994 foo=n1n1n1n2n3
1995 echo 1 ${foo@/n[12]/[$KSH_MATCH]} .
1996expected-stdout:
1997 1 [n1][n1][n1][n2]n3 .
1998---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001999name: eglob-bad-1
2000description:
2001 Check that globbing isn't done when glob has syntax error
Elliott Hughes23925bb2017-09-22 16:04:20 -07002002category: !os:cygwin,!os:msys,!os:os2
2003file-setup: file 644 "@(a[b|)c]foo"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002004stdin:
Elliott Hughes23925bb2017-09-22 16:04:20 -07002005 echo @(a[b|)c]*
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002006expected-stdout:
Elliott Hughes23925bb2017-09-22 16:04:20 -07002007 @(a[b|)c]*
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002008---
2009name: eglob-bad-2
2010description:
2011 Check that globbing isn't done when glob has syntax error
2012 (AT&T ksh fails this test)
2013file-setup: file 644 "abcx"
2014file-setup: file 644 "abcz"
2015file-setup: file 644 "bbc"
2016stdin:
2017 echo [a*(]*)z
2018expected-stdout:
2019 [a*(]*)z
2020---
2021name: eglob-infinite-plus
2022description:
2023 Check that shell doesn't go into infinite loop expanding +(...)
2024 expressions.
2025file-setup: file 644 "abc"
2026time-limit: 3
2027stdin:
2028 echo +()c
2029 echo +()x
2030 echo +(*)c
2031 echo +(*)x
2032expected-stdout:
2033 +()c
2034 +()x
2035 abc
2036 +(*)x
2037---
2038name: eglob-subst-1
2039description:
2040 Check that eglobbing isn't done on substitution results
2041file-setup: file 644 "abc"
2042stdin:
2043 x='@(*)'
2044 echo $x
2045expected-stdout:
2046 @(*)
2047---
2048name: eglob-nomatch-1
2049description:
2050 Check that the pattern doesn't match
2051stdin:
2052 echo 1: no-file+(a|b)stuff
2053 echo 2: no-file+(a*(c)|b)stuff
2054 echo 3: no-file+((((c)))|b)stuff
2055expected-stdout:
2056 1: no-file+(a|b)stuff
2057 2: no-file+(a*(c)|b)stuff
2058 3: no-file+((((c)))|b)stuff
2059---
2060name: eglob-match-1
2061description:
2062 Check that the pattern matches correctly
2063file-setup: file 644 "abd"
2064file-setup: file 644 "acd"
2065file-setup: file 644 "abac"
2066stdin:
2067 echo 1: a+(b|c)d
2068 echo 2: a!(@(b|B))d
2069 echo 3: *(a(b|c)) # (...|...) can be used within X(..)
2070 echo 4: a[b*(foo|bar)]d # patterns not special inside [...]
2071expected-stdout:
2072 1: abd acd
2073 2: acd
2074 3: abac
2075 4: abd
2076---
2077name: eglob-case-1
2078description:
2079 Simple negation tests
2080stdin:
2081 case foo in !(foo|bar)) echo yes;; *) echo no;; esac
2082 case bar in !(foo|bar)) echo yes;; *) echo no;; esac
2083expected-stdout:
2084 no
2085 no
2086---
2087name: eglob-case-2
2088description:
2089 Simple kleene tests
2090stdin:
2091 case foo in *(a|b[)) echo yes;; *) echo no;; esac
2092 case foo in *(a|b[)|f*) echo yes;; *) echo no;; esac
2093 case '*(a|b[)' in *(a|b[)) echo yes;; *) echo no;; esac
Elliott Hughes23925bb2017-09-22 16:04:20 -07002094 case 'aab[b[ab[a' in *(a|b[)) echo yes;; *) echo no;; esac
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002095expected-stdout:
2096 no
2097 yes
Elliott Hughes23925bb2017-09-22 16:04:20 -07002098 no
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002099 yes
2100---
2101name: eglob-trim-1
2102description:
2103 Eglobbing in trim expressions...
2104 (AT&T ksh fails this - docs say # matches shortest string, ## matches
2105 longest...)
2106stdin:
2107 x=abcdef
2108 echo 1: ${x#a|abc}
2109 echo 2: ${x##a|abc}
2110 echo 3: ${x%def|f}
2111 echo 4: ${x%%f|def}
2112expected-stdout:
2113 1: bcdef
2114 2: def
2115 3: abcde
2116 4: abc
2117---
2118name: eglob-trim-2
2119description:
2120 Check eglobbing works in trims...
2121stdin:
2122 x=abcdef
2123 echo 1: ${x#*(a|b)cd}
2124 echo 2: "${x#*(a|b)cd}"
2125 echo 3: ${x#"*(a|b)cd"}
2126 echo 4: ${x#a(b|c)}
2127expected-stdout:
2128 1: ef
2129 2: ef
2130 3: abcdef
2131 4: cdef
2132---
Geremy Condra03ebf062011-10-12 18:17:24 -07002133name: eglob-trim-3
2134description:
2135 Check eglobbing works in trims, for Korn Shell
2136 Ensure eglobbing does not work for reduced-feature /bin/sh
2137stdin:
2138 set +o sh
2139 x=foobar
2140 y=foobaz
2141 z=fooba\?
2142 echo "<${x%bar|baz},${y%bar|baz},${z%\?}>"
2143 echo "<${x%ba(r|z)},${y%ba(r|z)}>"
2144 set -o sh
2145 echo "<${x%bar|baz},${y%bar|baz},${z%\?}>"
2146 z='foo(bar'
2147 echo "<${z%(*}>"
2148expected-stdout:
2149 <foo,foo,fooba>
2150 <foo,foo>
2151 <foobar,foobaz,fooba>
2152 <foo>
2153---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002154name: eglob-substrpl-1
2155description:
2156 Check eglobbing works in substs... and they work at all
2157stdin:
2158 [[ -n $BASH_VERSION ]] && shopt -s extglob
2159 x=1222321_ab/cde_b/c_1221
2160 y=xyz
Elliott Hughes77740fc2016-08-12 15:06:53 -07002161 echo 1: ${x/2} . ${x/}
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002162 echo 2: ${x//2}
2163 echo 3: ${x/+(2)}
2164 echo 4: ${x//+(2)}
2165 echo 5: ${x/2/4}
2166 echo 6: ${x//2/4}
2167 echo 7: ${x/+(2)/4}
2168 echo 8: ${x//+(2)/4}
2169 echo 9: ${x/b/c/e/f}
2170 echo 10: ${x/b\/c/e/f}
2171 echo 11: ${x/b\/c/e\/f}
2172 echo 12: ${x/b\/c/e\\/f}
2173 echo 13: ${x/b\\/c/e\\/f}
2174 echo 14: ${x//b/c/e/f}
2175 echo 15: ${x//b\/c/e/f}
2176 echo 16: ${x//b\/c/e\/f}
2177 echo 17: ${x//b\/c/e\\/f}
2178 echo 18: ${x//b\\/c/e\\/f}
2179 echo 19: ${x/b\/*\/c/x}
2180 echo 20: ${x/\//.}
2181 echo 21: ${x//\//.}
2182 echo 22: ${x///.}
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002183 echo 23: ${x/#1/9}
2184 echo 24: ${x//#1/9}
2185 echo 25: ${x/%1/9}
2186 echo 26: ${x//%1/9}
2187 echo 27: ${x//\%1/9}
2188 echo 28: ${x//\\%1/9}
2189 echo 29: ${x//\a/9}
2190 echo 30: ${x//\\a/9}
2191 echo 31: ${x/2/$y}
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002192expected-stdout:
Elliott Hughes77740fc2016-08-12 15:06:53 -07002193 1: 122321_ab/cde_b/c_1221 . 1222321_ab/cde_b/c_1221
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002194 2: 131_ab/cde_b/c_11
2195 3: 1321_ab/cde_b/c_1221
2196 4: 131_ab/cde_b/c_11
2197 5: 1422321_ab/cde_b/c_1221
2198 6: 1444341_ab/cde_b/c_1441
2199 7: 14321_ab/cde_b/c_1221
2200 8: 14341_ab/cde_b/c_141
2201 9: 1222321_ac/e/f/cde_b/c_1221
2202 10: 1222321_ae/fde_b/c_1221
2203 11: 1222321_ae/fde_b/c_1221
2204 12: 1222321_ae\/fde_b/c_1221
2205 13: 1222321_ab/cde_b/c_1221
2206 14: 1222321_ac/e/f/cde_c/e/f/c_1221
2207 15: 1222321_ae/fde_e/f_1221
2208 16: 1222321_ae/fde_e/f_1221
2209 17: 1222321_ae\/fde_e\/f_1221
2210 18: 1222321_ab/cde_b/c_1221
2211 19: 1222321_ax_1221
2212 20: 1222321_ab.cde_b/c_1221
2213 21: 1222321_ab.cde_b.c_1221
2214 22: 1222321_ab/cde_b/c_1221
2215 23: 9222321_ab/cde_b/c_1221
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002216 24: 1222321_ab/cde_b/c_1221
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002217 25: 1222321_ab/cde_b/c_1229
2218 26: 1222321_ab/cde_b/c_1221
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002219 27: 1222321_ab/cde_b/c_1221
2220 28: 1222321_ab/cde_b/c_1221
2221 29: 1222321_9b/cde_b/c_1221
2222 30: 1222321_ab/cde_b/c_1221
2223 31: 1xyz22321_ab/cde_b/c_1221
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002224---
2225name: eglob-substrpl-2
2226description:
2227 Check anchored substring replacement works, corner cases
2228stdin:
2229 foo=123
2230 echo 1: ${foo/#/x}
2231 echo 2: ${foo/%/x}
2232 echo 3: ${foo/#/}
2233 echo 4: ${foo/#}
2234 echo 5: ${foo/%/}
2235 echo 6: ${foo/%}
2236expected-stdout:
2237 1: x123
2238 2: 123x
2239 3: 123
2240 4: 123
2241 5: 123
2242 6: 123
2243---
2244name: eglob-substrpl-3a
2245description:
2246 Check substring replacement works with variables and slashes, too
2247stdin:
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002248 HOME=/etc
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002249 pfx=/home/user
2250 wd=/home/user/tmp
2251 echo "${wd/#$pfx/~}"
2252 echo "${wd/#\$pfx/~}"
2253 echo "${wd/#"$pfx"/~}"
2254 echo "${wd/#'$pfx'/~}"
2255 echo "${wd/#"\$pfx"/~}"
2256 echo "${wd/#'\$pfx'/~}"
2257expected-stdout:
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002258 /etc/tmp
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002259 /home/user/tmp
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002260 /etc/tmp
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002261 /home/user/tmp
2262 /home/user/tmp
2263 /home/user/tmp
2264---
2265name: eglob-substrpl-3b
2266description:
2267 More of this, bash fails it (bash4 passes)
2268stdin:
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002269 HOME=/etc
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002270 pfx=/home/user
2271 wd=/home/user/tmp
2272 echo "${wd/#$(echo /home/user)/~}"
2273 echo "${wd/#"$(echo /home/user)"/~}"
2274 echo "${wd/#'$(echo /home/user)'/~}"
2275expected-stdout:
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002276 /etc/tmp
2277 /etc/tmp
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002278 /home/user/tmp
2279---
2280name: eglob-substrpl-3c
2281description:
2282 Even more weird cases
2283stdin:
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002284 HOME=/etc
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002285 pfx=/home/user
2286 wd='$pfx/tmp'
2287 echo 1: ${wd/#$pfx/~}
2288 echo 2: ${wd/#\$pfx/~}
2289 echo 3: ${wd/#"$pfx"/~}
2290 echo 4: ${wd/#'$pfx'/~}
2291 echo 5: ${wd/#"\$pfx"/~}
2292 echo 6: ${wd/#'\$pfx'/~}
2293 ts='a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)'
2294 tp=a/b
2295 tr=c/d
2296 [[ -n $BASH_VERSION ]] && shopt -s extglob
2297 echo 7: ${ts/a\/b/$tr}
2298 echo 8: ${ts/a\/b/\$tr}
2299 echo 9: ${ts/$tp/$tr}
2300 echo 10: ${ts/\$tp/$tr}
2301 echo 11: ${ts/\\$tp/$tr}
2302 echo 12: ${ts/$tp/c/d}
2303 echo 13: ${ts/$tp/c\/d}
2304 echo 14: ${ts/$tp/c\\/d}
2305 echo 15: ${ts/+(a\/b)/$tr}
2306 echo 16: ${ts/+(a\/b)/\$tr}
2307 echo 17: ${ts/+($tp)/$tr}
2308 echo 18: ${ts/+($tp)/c/d}
2309 echo 19: ${ts/+($tp)/c\/d}
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002310 echo 20: ${ts//a\/b/$tr}
2311 echo 21: ${ts//a\/b/\$tr}
2312 echo 22: ${ts//$tp/$tr}
2313 echo 23: ${ts//$tp/c/d}
2314 echo 24: ${ts//$tp/c\/d}
2315 echo 25: ${ts//+(a\/b)/$tr}
2316 echo 26: ${ts//+(a\/b)/\$tr}
2317 echo 27: ${ts//+($tp)/$tr}
2318 echo 28: ${ts//+($tp)/c/d}
2319 echo 29: ${ts//+($tp)/c\/d}
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002320 tp="+($tp)"
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002321 echo 30: ${ts/$tp/$tr}
2322 echo 31: ${ts//$tp/$tr}
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002323expected-stdout:
2324 1: $pfx/tmp
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002325 2: /etc/tmp
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002326 3: $pfx/tmp
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002327 4: /etc/tmp
2328 5: /etc/tmp
2329 6: $pfx/tmp
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002330 7: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2331 8: $tra/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2332 9: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2333 10: a/ba/bc/d$tp_a/b$tp_*(a/b)_*($tp)
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002334 11: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002335 12: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2336 13: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2337 14: c\/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2338 15: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2339 16: $tr$tp$tp_a/b$tp_*(a/b)_*($tp)
2340 17: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2341 18: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2342 19: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002343 20: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2344 21: $tr$tr$tp$tp_$tr$tp_*($tr)_*($tp)
2345 22: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2346 23: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2347 24: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2348 25: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2349 26: $tr$tp$tp_$tr$tp_*($tr)_*($tp)
2350 27: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2351 28: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2352 29: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2353 30: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2354 31: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002355# This is what GNU bash does:
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002356# 30: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2357# 31: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002358---
2359name: eglob-utf8-1
2360description:
2361 UTF-8 mode differences for eglobbing
Elliott Hughes23925bb2017-09-22 16:04:20 -07002362category: !shell:ebcdic-yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002363stdin:
2364 s=blöd
2365 set +U
2366 print 1: ${s%???} .
2367 print 2: ${s/b???d/x} .
2368 set -U
2369 print 3: ${s%???} .
2370 print 4: ${s/b??d/x} .
2371 x=nö
2372 print 5: ${x%?} ${x%%?} .
2373 x=äh
2374 print 6: ${x#?} ${x##?} .
2375 x=‚
2376 print 7: ${x%?} ${x%%?} .
2377 x=mä€
2378 print 8: ${x%?} ${x%%?} .
2379 x=何
2380 print 9: ${x%?} ${x%%?} .
2381expected-stdout:
2382 1: bl .
2383 2: x .
2384 3: b .
2385 4: x .
2386 5: n n .
2387 6: h h .
2388 7:   .
2389 8: mä mä .
2390 9: .
2391---
2392name: glob-bad-1
2393description:
Elliott Hughes23925bb2017-09-22 16:04:20 -07002394 Check that [ matches itself if it's not a valid bracket expr
2395 but does not prevent globbing, while backslash-escaping does
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002396file-setup: dir 755 "[x"
2397file-setup: file 644 "[x/foo"
2398stdin:
2399 echo [*
2400 echo *[x
2401 echo [x/*
Elliott Hughes23925bb2017-09-22 16:04:20 -07002402 :>'ab[x'
2403 :>'a[a-z][x'
2404 echo a[a-z][*
2405 echo a[a-z]*
2406 echo a[a\-z]*
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002407expected-stdout:
Elliott Hughes23925bb2017-09-22 16:04:20 -07002408 [x
2409 [x
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002410 [x/foo
Elliott Hughes23925bb2017-09-22 16:04:20 -07002411 ab[x
2412 ab[x
2413 a[a-z]*
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002414---
2415name: glob-bad-2
2416description:
2417 Check that symbolic links aren't stat()'d
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00002418# breaks on Dell UNIX 4.0 R2.2 (SVR4) where unlink also fails
Elliott Hughes96b43632015-07-17 11:39:41 -07002419# breaks on FreeMiNT (cannot unlink dangling symlinks)
2420# breaks on MSYS, OS/2 (do not support symlinks)
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00002421category: !os:mint,!os:msys,!os:svr4.0,!nosymlink
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002422file-setup: dir 755 "dir"
2423file-setup: symlink 644 "dir/abc"
2424 non-existent-file
2425stdin:
2426 echo d*/*
2427 echo d*/abc
2428expected-stdout:
2429 dir/abc
2430 dir/abc
2431---
Elliott Hughes23925bb2017-09-22 16:04:20 -07002432name: glob-bad-3
2433description:
2434 Check that the slash is parsed before the glob
2435stdin:
2436 mkdir a 'a[b'
2437 (cd 'a[b'; echo ok >'c]d')
2438 echo nok >abd
2439 echo fail >a/d
2440 cat a[b/c]d
2441expected-stdout:
2442 ok
2443---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002444name: glob-range-1
2445description:
2446 Test range matching
2447file-setup: file 644 ".bc"
2448file-setup: file 644 "abc"
2449file-setup: file 644 "bbc"
2450file-setup: file 644 "cbc"
2451file-setup: file 644 "-bc"
Elliott Hughes23925bb2017-09-22 16:04:20 -07002452file-setup: file 644 "!bc"
2453file-setup: file 644 "^bc"
2454file-setup: file 644 "+bc"
2455file-setup: file 644 ",bc"
2456file-setup: file 644 "0bc"
2457file-setup: file 644 "1bc"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002458stdin:
2459 echo [ab-]*
2460 echo [-ab]*
2461 echo [!-ab]*
2462 echo [!ab]*
2463 echo []ab]*
Elliott Hughes737fdce2014-08-07 12:59:26 -07002464 echo [^ab]*
Elliott Hughes23925bb2017-09-22 16:04:20 -07002465 echo [+--]*
2466 echo [--1]*
2467
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002468expected-stdout:
2469 -bc abc bbc
2470 -bc abc bbc
Elliott Hughes23925bb2017-09-22 16:04:20 -07002471 !bc +bc ,bc 0bc 1bc ^bc cbc
2472 !bc +bc ,bc -bc 0bc 1bc ^bc cbc
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002473 abc bbc
Elliott Hughes737fdce2014-08-07 12:59:26 -07002474 ^bc abc bbc
Elliott Hughes23925bb2017-09-22 16:04:20 -07002475 +bc ,bc -bc
2476 -bc 0bc 1bc
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002477---
2478name: glob-range-2
2479description:
2480 Test range matching
2481 (AT&T ksh fails this; POSIX says invalid)
2482file-setup: file 644 "abc"
2483stdin:
2484 echo [a--]*
2485expected-stdout:
2486 [a--]*
2487---
2488name: glob-range-3
2489description:
2490 Check that globbing matches the right things...
Elliott Hughes47086262019-03-26 12:34:31 -07002491# breaks on Mac OSX (HFS+ non-standard UTF-8 canonical decomposition)
Geremy Condra03ebf062011-10-12 18:17:24 -07002492# breaks on Cygwin 1.7 (files are now UTF-16 or something)
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00002493# breaks on QNX 6.4.1 (says RT)
Elliott Hughes23925bb2017-09-22 16:04:20 -07002494category: !os:cygwin,!os:darwin,!os:msys,!os:nto,!os:os2,!os:os390
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00002495need-pass: no
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002496file-setup: file 644 "aÂc"
2497stdin:
2498 echo a[Á-Ú]*
2499expected-stdout:
2500 aÂc
2501---
2502name: glob-range-4
2503description:
2504 Results unspecified according to POSIX
2505file-setup: file 644 ".bc"
2506stdin:
2507 echo [a.]*
2508expected-stdout:
2509 [a.]*
2510---
2511name: glob-range-5
2512description:
2513 Results unspecified according to POSIX
2514 (AT&T ksh treats this like [a-cc-e]*)
2515file-setup: file 644 "abc"
2516file-setup: file 644 "bbc"
2517file-setup: file 644 "cbc"
2518file-setup: file 644 "dbc"
2519file-setup: file 644 "ebc"
2520file-setup: file 644 "-bc"
Elliott Hughes23925bb2017-09-22 16:04:20 -07002521file-setup: file 644 "@bc"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002522stdin:
2523 echo [a-c-e]*
Elliott Hughes23925bb2017-09-22 16:04:20 -07002524 echo [a--@]*
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002525expected-stdout:
2526 -bc abc bbc cbc ebc
Elliott Hughes23925bb2017-09-22 16:04:20 -07002527 @bc
2528---
2529name: glob-word-1
2530description:
2531 Check BSD word boundary matches
2532stdin:
2533 t() { [[ $1 = *[[:\<:]]bar[[:\>:]]* ]]; echo =$?; }
2534 t 'foo bar baz'
2535 t 'foobar baz'
2536 t 'foo barbaz'
2537 t 'bar'
2538 t '_bar'
2539 t 'bar_'
2540expected-stdout:
2541 =0
2542 =1
2543 =1
2544 =0
2545 =1
2546 =1
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002547---
Elliott Hughes737fdce2014-08-07 12:59:26 -07002548name: glob-trim-1
2549description:
2550 Check against a regression from fixing IFS-subst-2
2551stdin:
2552 x='#foo'
2553 print -r "before='$x'"
2554 x=${x%%#*}
2555 print -r "after ='$x'"
2556expected-stdout:
2557 before='#foo'
2558 after =''
2559---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002560name: heredoc-1
2561description:
2562 Check ordering/content of redundent here documents.
2563stdin:
2564 cat << EOF1 << EOF2
2565 hi
2566 EOF1
2567 there
2568 EOF2
2569expected-stdout:
2570 there
2571---
2572name: heredoc-2
2573description:
2574 Check quoted here-doc is protected.
2575stdin:
2576 a=foo
2577 cat << 'EOF'
2578 hi\
2579 there$a
2580 stuff
2581 EO\
2582 F
2583 EOF
2584expected-stdout:
2585 hi\
2586 there$a
2587 stuff
2588 EO\
2589 F
2590---
2591name: heredoc-3
2592description:
2593 Check that newline isn't needed after heredoc-delimiter marker.
2594stdin: !
2595 cat << EOF
2596 hi
2597 there
2598 EOF
2599expected-stdout:
2600 hi
2601 there
2602---
Elliott Hughes77740fc2016-08-12 15:06:53 -07002603name: heredoc-4a
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002604description:
2605 Check that an error occurs if the heredoc-delimiter is missing.
2606stdin: !
2607 cat << EOF
2608 hi
2609 there
2610expected-exit: e > 0
2611expected-stderr-pattern: /.*/
2612---
Elliott Hughes77740fc2016-08-12 15:06:53 -07002613name: heredoc-4an
2614description:
2615 Check that an error occurs if the heredoc-delimiter is missing.
2616arguments: !-n!
2617stdin: !
2618 cat << EOF
2619 hi
2620 there
2621expected-exit: e > 0
2622expected-stderr-pattern: /.*/
2623---
2624name: heredoc-4b
2625description:
2626 Check that an error occurs if the heredoc is missing.
2627stdin: !
2628 cat << EOF
2629expected-exit: e > 0
2630expected-stderr-pattern: /.*/
2631---
2632name: heredoc-4bn
2633description:
2634 Check that an error occurs if the heredoc is missing.
2635arguments: !-n!
2636stdin: !
2637 cat << EOF
2638expected-exit: e > 0
2639expected-stderr-pattern: /.*/
2640---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002641name: heredoc-5
2642description:
2643 Check that backslash quotes a $, ` and \ and kills a \newline
2644stdin:
2645 a=BAD
2646 b=ok
2647 cat << EOF
2648 h\${a}i
2649 h\\${b}i
2650 th\`echo not-run\`ere
2651 th\\`echo is-run`ere
2652 fol\\ks
2653 more\\
2654 last \
2655 line
2656 EOF
2657expected-stdout:
2658 h${a}i
2659 h\oki
2660 th`echo not-run`ere
2661 th\is-runere
2662 fol\ks
2663 more\
2664 last line
2665---
2666name: heredoc-6
2667description:
2668 Check that \newline in initial here-delim word doesn't imply
2669 a quoted here-doc.
2670stdin:
2671 a=i
2672 cat << EO\
2673 F
2674 h$a
2675 there
2676 EOF
2677expected-stdout:
2678 hi
2679 there
2680---
2681name: heredoc-7
2682description:
2683 Check that double quoted $ expressions in here delimiters are
2684 not expanded and match the delimiter.
2685 POSIX says only quote removal is applied to the delimiter.
2686stdin:
2687 a=b
2688 cat << "E$a"
2689 hi
2690 h$a
2691 hb
2692 E$a
2693 echo done
2694expected-stdout:
2695 hi
2696 h$a
2697 hb
2698 done
2699---
2700name: heredoc-8
2701description:
2702 Check that double quoted escaped $ expressions in here
2703 delimiters are not expanded and match the delimiter.
2704 POSIX says only quote removal is applied to the delimiter
2705 (\ counts as a quote).
2706stdin:
2707 a=b
2708 cat << "E\$a"
2709 hi
2710 h$a
2711 h\$a
2712 hb
2713 h\b
2714 E$a
2715 echo done
2716expected-stdout:
2717 hi
2718 h$a
2719 h\$a
2720 hb
2721 h\b
2722 done
2723---
2724name: heredoc-9a
2725description:
2726 Check that here strings work.
2727stdin:
2728 bar="bar
2729 baz"
2730 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<foo
2731 "$__progname" -c "tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<foo"
2732 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"$bar"
2733 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<'$bar'
2734 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<\$bar
2735 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<-foo
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00002736 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"$(echo "foo bar")"
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002737 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"A $(echo "foo bar") B"
2738 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<\$b\$b$bar
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002739expected-stdout:
2740 sbb
2741 sbb
2742 one
2743 onm
2744 $one
2745 $one
2746 -sbb
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00002747 sbb one
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002748 A sbb one B
2749 $o$oone
2750 onm
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002751---
2752name: heredoc-9b
2753description:
2754 Check that a corner case of here strings works like bash
2755stdin:
2756 fnord=42
2757 bar="bar
2758 \$fnord baz"
2759 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<$bar
2760expected-stdout:
2761 one $sabeq onm
2762category: bash
2763---
2764name: heredoc-9c
2765description:
2766 Check that a corner case of here strings works like ksh93, zsh
2767stdin:
2768 fnord=42
2769 bar="bar
2770 \$fnord baz"
2771 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<$bar
2772expected-stdout:
2773 one
2774 $sabeq onm
2775---
2776name: heredoc-9d
2777description:
2778 Check another corner case of here strings
2779stdin:
2780 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<< bar
2781expected-stdout:
2782 one
2783---
Geremy Condra03ebf062011-10-12 18:17:24 -07002784name: heredoc-9e
2785description:
2786 Check here string related regression with multiple iops
2787stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00002788 echo $(tr r z <<<'bar' 2>/dev/null)
Geremy Condra03ebf062011-10-12 18:17:24 -07002789expected-stdout:
2790 baz
2791---
Elliott Hughes50012062015-03-10 22:22:24 -07002792name: heredoc-9f
2793description:
2794 Check long here strings
2795stdin:
2796 cat <<< "$( : )aa"
2797expected-stdout:
2798 aa
2799---
Geremy Condra03ebf062011-10-12 18:17:24 -07002800name: heredoc-10
2801description:
2802 Check direct here document assignment
Elliott Hughes23925bb2017-09-22 16:04:20 -07002803category: !shell:ebcdic-yes
Geremy Condra03ebf062011-10-12 18:17:24 -07002804stdin:
2805 x=u
2806 va=<<EOF
2807 =a $x \x40=
2808 EOF
2809 vb=<<'EOF'
2810 =b $x \x40=
2811 EOF
2812 function foo {
2813 vc=<<-EOF
2814 =c $x \x40=
2815 EOF
2816 }
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00002817 fnd=$(typeset -f foo)
2818 print -r -- "$fnd"
2819 function foo {
2820 echo blub
2821 }
2822 foo
2823 eval "$fnd"
Geremy Condra03ebf062011-10-12 18:17:24 -07002824 foo
2825 # rather nonsensical, but…
2826 vd=<<<"=d $x \x40="
2827 ve=<<<'=e $x \x40='
2828 vf=<<<$'=f $x \x40='
2829 # now check
2830 print -r -- "| va={$va} vb={$vb} vc={$vc} vd={$vd} ve={$ve} vf={$vf} |"
Elliott Hughes50012062015-03-10 22:22:24 -07002831 # check append
2832 v=<<-EOF
2833 vapp1
2834 EOF
2835 v+=<<-EOF
2836 vapp2
2837 EOF
2838 print -r -- "| ${v//$'\n'/^} |"
Geremy Condra03ebf062011-10-12 18:17:24 -07002839expected-stdout:
2840 function foo {
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002841 vc=<<-EOF
Geremy Condra03ebf062011-10-12 18:17:24 -07002842 =c $x \x40=
2843 EOF
2844
2845 }
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00002846 blub
Geremy Condra03ebf062011-10-12 18:17:24 -07002847 | va={=a u \x40=
2848 } vb={=b $x \x40=
2849 } vc={=c u \x40=
2850 } vd={=d u \x40=
2851 } ve={=e $x \x40=
2852 } vf={=f $x @=
2853 } |
Elliott Hughes50012062015-03-10 22:22:24 -07002854 | vapp1^vapp2^ |
Geremy Condra03ebf062011-10-12 18:17:24 -07002855---
Elliott Hughes23925bb2017-09-22 16:04:20 -07002856name: heredoc-10-ebcdic
2857description:
2858 Check direct here document assignment
2859category: !shell:ebcdic-no
2860stdin:
2861 x=u
2862 va=<<EOF
2863 =a $x \x7C=
2864 EOF
2865 vb=<<'EOF'
2866 =b $x \x7C=
2867 EOF
2868 function foo {
2869 vc=<<-EOF
2870 =c $x \x7C=
2871 EOF
2872 }
2873 fnd=$(typeset -f foo)
2874 print -r -- "$fnd"
2875 function foo {
2876 echo blub
2877 }
2878 foo
2879 eval "$fnd"
2880 foo
2881 # rather nonsensical, but…
2882 vd=<<<"=d $x \x7C="
2883 ve=<<<'=e $x \x7C='
2884 vf=<<<$'=f $x \x7C='
2885 # now check
2886 print -r -- "| va={$va} vb={$vb} vc={$vc} vd={$vd} ve={$ve} vf={$vf} |"
2887 # check append
2888 v=<<-EOF
2889 vapp1
2890 EOF
2891 v+=<<-EOF
2892 vapp2
2893 EOF
2894 print -r -- "| ${v//$'\n'/^} |"
2895expected-stdout:
2896 function foo {
2897 vc=<<-EOF
2898 =c $x \x7C=
2899 EOF
2900
2901 }
2902 blub
2903 | va={=a u \x7C=
2904 } vb={=b $x \x7C=
2905 } vc={=c u \x7C=
2906 } vd={=d u \x7C=
2907 } ve={=e $x \x7C=
2908 } vf={=f $x @=
2909 } |
2910 | vapp1^vapp2^ |
2911---
Geremy Condra03ebf062011-10-12 18:17:24 -07002912name: heredoc-11
2913description:
2914 Check here documents with no or empty delimiter
2915stdin:
2916 x=u
2917 va=<<
2918 =a $x \x40=
2919 <<
2920 vb=<<''
2921 =b $x \x40=
2922
2923 function foo {
2924 vc=<<-
2925 =c $x \x40=
2926 <<
2927 vd=<<-''
2928 =d $x \x40=
2929
2930 }
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00002931 fnd=$(typeset -f foo)
2932 print -r -- "$fnd"
2933 function foo {
2934 echo blub
2935 }
2936 foo
2937 eval "$fnd"
Geremy Condra03ebf062011-10-12 18:17:24 -07002938 foo
2939 print -r -- "| va={$va} vb={$vb} vc={$vc} vd={$vd} |"
Elliott Hughes77740fc2016-08-12 15:06:53 -07002940 x=y
2941 foo
2942 typeset -f foo
2943 print -r -- "| vc={$vc} vd={$vd} |"
Elliott Hughes50012062015-03-10 22:22:24 -07002944 # check append
2945 v=<<-
2946 vapp1
2947 <<
2948 v+=<<-''
2949 vapp2
2950
2951 print -r -- "| ${v//$'\n'/^} |"
Geremy Condra03ebf062011-10-12 18:17:24 -07002952expected-stdout:
2953 function foo {
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002954 vc=<<-
Geremy Condra03ebf062011-10-12 18:17:24 -07002955 =c $x \x40=
2956 <<
2957
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002958 vd=<<-""
Geremy Condra03ebf062011-10-12 18:17:24 -07002959 =d $x \x40=
2960
2961
2962 }
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00002963 blub
Geremy Condra03ebf062011-10-12 18:17:24 -07002964 | va={=a u \x40=
2965 } vb={=b $x \x40=
2966 } vc={=c u \x40=
2967 } vd={=d $x \x40=
2968 } |
Elliott Hughes77740fc2016-08-12 15:06:53 -07002969 function foo {
2970 vc=<<-
2971 =c $x \x40=
2972 <<
2973
2974 vd=<<-""
2975 =d $x \x40=
2976
2977
2978 }
2979 | vc={=c y \x40=
2980 } vd={=d $x \x40=
2981 } |
Elliott Hughes50012062015-03-10 22:22:24 -07002982 | vapp1^vapp2^ |
2983---
2984name: heredoc-12
2985description:
2986 Check here documents can use $* and $@; note shells vary:
2987 • pdksh 5.2.14 acts the same
2988 • dash has 1 and 2 the same but 3 lacks the space
2989 • ksh93, bash4 differ in 2 by using space ipv colon
2990stdin:
2991 set -- a b
2992 nl='
2993 '
2994 IFS=" $nl"; n=1
2995 cat <<EOF
2996 $n foo $* foo
2997 $n bar "$*" bar
2998 $n baz $@ baz
2999 $n bla "$@" bla
3000 EOF
3001 IFS=":"; n=2
3002 cat <<EOF
3003 $n foo $* foo
3004 $n bar "$*" bar
3005 $n baz $@ baz
3006 $n bla "$@" bla
3007 EOF
3008 IFS=; n=3
3009 cat <<EOF
3010 $n foo $* foo
3011 $n bar "$*" bar
3012 $n baz $@ baz
3013 $n bla "$@" bla
3014 EOF
3015expected-stdout:
3016 1 foo a b foo
3017 1 bar "a b" bar
3018 1 baz a b baz
3019 1 bla "a b" bla
3020 2 foo a:b foo
3021 2 bar "a:b" bar
3022 2 baz a:b baz
3023 2 bla "a:b" bla
3024 3 foo a b foo
3025 3 bar "a b" bar
3026 3 baz a b baz
3027 3 bla "a b" bla
Geremy Condra03ebf062011-10-12 18:17:24 -07003028---
Elliott Hughesfc0307d2016-02-02 15:26:47 -08003029name: heredoc-14
3030description:
3031 Check that using multiple here documents works
3032stdin:
3033 foo() {
3034 echo "got $(cat) on stdin"
3035 echo "got $(cat <&4) on fd#4"
3036 echo "got $(cat <&5) on fd#5"
3037 }
3038 bar() {
3039 foo 4<<-a <<-b 5<<-c
3040 four
3041 a
3042 zero
3043 b
3044 five
3045 c
3046 }
3047 x=$(typeset -f bar)
3048 eval "$x"
3049 y=$(typeset -f bar)
3050 [[ $x = "$y" ]]; echo $?
3051 typeset -f bar
3052 bar
3053expected-stdout:
3054 0
3055 bar() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -07003056 \foo 4<<-a <<-b 5<<-c
Elliott Hughesfc0307d2016-02-02 15:26:47 -08003057 four
3058 a
3059 zero
3060 b
3061 five
3062 c
3063
3064 }
3065 got zero on stdin
3066 got four on fd#4
3067 got five on fd#5
3068---
Elliott Hughes47086262019-03-26 12:34:31 -07003069name: heredoc-15
3070description:
3071 Check high-bit7 separators work
3072stdin:
3073 u=ä
3074 tr a-z A-Z <<-…
3075 m${u}h
3076 …
3077 echo ok
3078expected-stdout:
3079 MäH
3080 ok
3081---
Geremy Condra03ebf062011-10-12 18:17:24 -07003082name: heredoc-comsub-1
3083description:
3084 Tests for here documents in COMSUB, taken from Austin ML
3085stdin:
3086 text=$(cat <<EOF
3087 here is the text
3088 EOF)
3089 echo = $text =
3090expected-stdout:
3091 = here is the text =
3092---
3093name: heredoc-comsub-2
3094description:
3095 Tests for here documents in COMSUB, taken from Austin ML
3096stdin:
3097 unbalanced=$(cat <<EOF
3098 this paren ) is a problem
3099 EOF)
3100 echo = $unbalanced =
3101expected-stdout:
3102 = this paren ) is a problem =
3103---
3104name: heredoc-comsub-3
3105description:
3106 Tests for here documents in COMSUB, taken from Austin ML
3107stdin:
3108 balanced=$(cat <<EOF
3109 these parens ( ) are not a problem
3110 EOF)
3111 echo = $balanced =
3112expected-stdout:
3113 = these parens ( ) are not a problem =
3114---
3115name: heredoc-comsub-4
3116description:
3117 Tests for here documents in COMSUB, taken from Austin ML
3118stdin:
3119 balanced=$(cat <<EOF
3120 these parens \( ) are a problem
3121 EOF)
3122 echo = $balanced =
3123expected-stdout:
3124 = these parens \( ) are a problem =
3125---
Elliott Hughes77740fc2016-08-12 15:06:53 -07003126name: heredoc-comsub-5
3127description:
3128 Check heredoc and COMSUB mixture in input
3129stdin:
3130 prefix() { sed -e "s/^/$1:/"; }
3131 XXX() { echo x-en; }
3132 YYY() { echo y-es; }
3133
3134 prefix A <<XXX && echo "$(prefix B <<XXX
3135 echo line 1
3136 XXX
3137 echo line 2)" && prefix C <<YYY
3138 echo line 3
3139 XXX
3140 echo line 4)"
3141 echo line 5
3142 YYY
3143 XXX
3144expected-stdout:
3145 A:echo line 3
3146 B:echo line 1
3147 line 2
3148 C:echo line 4)"
3149 C:echo line 5
3150 x-en
3151---
3152name: heredoc-comsub-6
3153description:
3154 Check here documents and here strings can be used
3155 without a specific command, like $(<…) (extension)
3156stdin:
3157 foo=bar
3158 x=$(<<<EO${foo}F)
3159 echo "3<$x>"
3160 y=$(<<-EOF
3161 hi!
3162
3163 $foo) is not a problem
3164
3165
3166 EOF)
3167 echo "7<$y>"
3168expected-stdout:
3169 3<EObarF>
3170 7<hi!
3171
3172 bar) is not a problem>
3173---
Geremy Condra03ebf062011-10-12 18:17:24 -07003174name: heredoc-subshell-1
3175description:
3176 Tests for here documents in subshells, taken from Austin ML
3177stdin:
3178 (cat <<EOF
3179 some text
3180 EOF)
3181 echo end
3182expected-stdout:
3183 some text
3184 end
3185---
3186name: heredoc-subshell-2
3187description:
3188 Tests for here documents in subshells, taken from Austin ML
3189stdin:
3190 (cat <<EOF
3191 some text
3192 EOF
3193 )
3194 echo end
3195expected-stdout:
3196 some text
3197 end
3198---
3199name: heredoc-subshell-3
3200description:
3201 Tests for here documents in subshells, taken from Austin ML
3202stdin:
3203 (cat <<EOF; )
3204 some text
3205 EOF
3206 echo end
3207expected-stdout:
3208 some text
3209 end
3210---
3211name: heredoc-weird-1
3212description:
3213 Tests for here documents, taken from Austin ML
3214 Documents current state in mksh, *NOT* necessarily correct!
3215stdin:
3216 cat <<END
3217 hello
3218 END\
3219 END
3220 END
3221 echo end
3222expected-stdout:
3223 hello
3224 ENDEND
3225 end
3226---
3227name: heredoc-weird-2
3228description:
3229 Tests for here documents, taken from Austin ML
3230stdin:
3231 cat <<' END '
3232 hello
3233 END
3234 echo end
3235expected-stdout:
3236 hello
3237 end
3238---
3239name: heredoc-weird-4
3240description:
3241 Tests for here documents, taken from Austin ML
3242 Documents current state in mksh, *NOT* necessarily correct!
3243stdin:
3244 cat <<END
3245 hello\
3246 END
3247 END
3248 echo end
3249expected-stdout:
3250 helloEND
3251 end
3252---
3253name: heredoc-weird-5
3254description:
3255 Tests for here documents, taken from Austin ML
3256 Documents current state in mksh, *NOT* necessarily correct!
3257stdin:
3258 cat <<END
3259 hello
3260 \END
3261 END
3262 echo end
3263expected-stdout:
3264 hello
3265 \END
3266 end
3267---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003268name: heredoc-tmpfile-1
3269description:
3270 Check that heredoc temp files aren't removed too soon or too late.
3271 Heredoc in simple command.
3272stdin:
3273 TMPDIR=$PWD
3274 eval '
3275 cat <<- EOF
3276 hi
3277 EOF
3278 for i in a b ; do
3279 cat <<- EOF
3280 more
3281 EOF
3282 done
3283 ' &
3284 sleep 1
3285 echo Left overs: *
3286expected-stdout:
3287 hi
3288 more
3289 more
3290 Left overs: *
3291---
3292name: heredoc-tmpfile-2
3293description:
3294 Check that heredoc temp files aren't removed too soon or too late.
3295 Heredoc in function, multiple calls to function.
3296stdin:
3297 TMPDIR=$PWD
3298 eval '
3299 foo() {
3300 cat <<- EOF
3301 hi
3302 EOF
3303 }
3304 foo
3305 foo
3306 ' &
3307 sleep 1
3308 echo Left overs: *
3309expected-stdout:
3310 hi
3311 hi
3312 Left overs: *
3313---
3314name: heredoc-tmpfile-3
3315description:
3316 Check that heredoc temp files aren't removed too soon or too late.
3317 Heredoc in function in loop, multiple calls to function.
3318stdin:
3319 TMPDIR=$PWD
3320 eval '
3321 foo() {
3322 cat <<- EOF
3323 hi
3324 EOF
3325 }
3326 for i in a b; do
3327 foo
3328 foo() {
3329 cat <<- EOF
3330 folks $i
3331 EOF
3332 }
3333 done
3334 foo
3335 ' &
3336 sleep 1
3337 echo Left overs: *
3338expected-stdout:
3339 hi
3340 folks b
3341 folks b
3342 Left overs: *
3343---
3344name: heredoc-tmpfile-4
3345description:
3346 Check that heredoc temp files aren't removed too soon or too late.
3347 Backgrounded simple command with here doc
3348stdin:
3349 TMPDIR=$PWD
3350 eval '
3351 cat <<- EOF &
3352 hi
3353 EOF
3354 ' &
3355 sleep 1
3356 echo Left overs: *
3357expected-stdout:
3358 hi
3359 Left overs: *
3360---
3361name: heredoc-tmpfile-5
3362description:
3363 Check that heredoc temp files aren't removed too soon or too late.
3364 Backgrounded subshell command with here doc
3365stdin:
3366 TMPDIR=$PWD
3367 eval '
3368 (
3369 sleep 1 # so parent exits
3370 echo A
3371 cat <<- EOF
3372 hi
3373 EOF
3374 echo B
3375 ) &
3376 ' &
Elliott Hughesdd4abe02018-02-05 15:55:19 -08003377 sleep 5
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003378 echo Left overs: *
3379expected-stdout:
3380 A
3381 hi
3382 B
3383 Left overs: *
3384---
3385name: heredoc-tmpfile-6
3386description:
3387 Check that heredoc temp files aren't removed too soon or too late.
3388 Heredoc in pipeline.
3389stdin:
3390 TMPDIR=$PWD
3391 eval '
3392 cat <<- EOF | sed "s/hi/HI/"
3393 hi
3394 EOF
3395 ' &
3396 sleep 1
3397 echo Left overs: *
3398expected-stdout:
3399 HI
3400 Left overs: *
3401---
3402name: heredoc-tmpfile-7
3403description:
3404 Check that heredoc temp files aren't removed too soon or too late.
3405 Heredoc in backgrounded pipeline.
3406stdin:
3407 TMPDIR=$PWD
3408 eval '
3409 cat <<- EOF | sed 's/hi/HI/' &
3410 hi
3411 EOF
3412 ' &
3413 sleep 1
3414 echo Left overs: *
3415expected-stdout:
3416 HI
3417 Left overs: *
3418---
3419name: heredoc-tmpfile-8
3420description:
3421 Check that heredoc temp files aren't removed too soon or too
3422 late. Heredoc in function, backgrounded call to function.
3423 This check can fail on slow machines (<100 MHz), or Cygwin,
3424 that's normal.
Geremy Condra03ebf062011-10-12 18:17:24 -07003425need-pass: no
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003426stdin:
3427 TMPDIR=$PWD
3428 # Background eval so main shell doesn't do parsing
3429 eval '
3430 foo() {
3431 cat <<- EOF
3432 hi
3433 EOF
3434 }
3435 foo
3436 # sleep so eval can die
3437 (sleep 1; foo) &
3438 (sleep 1; foo) &
3439 foo
3440 ' &
Elliott Hughesdd4abe02018-02-05 15:55:19 -08003441 sleep 5
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003442 echo Left overs: *
3443expected-stdout:
3444 hi
3445 hi
3446 hi
3447 hi
3448 Left overs: *
3449---
Thorsten Glaser811a5752013-07-25 14:24:45 +00003450name: heredoc-quoting-unsubst
3451description:
3452 Check for correct handling of quoted characters in
3453 here documents without substitution (marker is quoted).
3454stdin:
3455 foo=bar
3456 cat <<-'EOF'
3457 x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
3458 EOF
3459expected-stdout:
3460 x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
3461---
3462name: heredoc-quoting-subst
3463description:
3464 Check for correct handling of quoted characters in
3465 here documents with substitution (marker is not quoted).
3466stdin:
3467 foo=bar
3468 cat <<-EOF
3469 x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
3470 EOF
3471expected-stdout:
3472 x " \" \ \ $ $ baz `echo baz` bar $foo x
3473---
3474name: single-quotes-in-braces
3475description:
3476 Check that single quotes inside unquoted {} are treated as quotes
3477stdin:
3478 foo=1
3479 echo ${foo:+'blah $foo'}
3480expected-stdout:
3481 blah $foo
3482---
3483name: single-quotes-in-quoted-braces
3484description:
3485 Check that single quotes inside quoted {} are treated as
3486 normal char
3487stdin:
3488 foo=1
3489 echo "${foo:+'blah $foo'}"
3490expected-stdout:
3491 'blah 1'
3492---
3493name: single-quotes-in-braces-nested
3494description:
3495 Check that single quotes inside unquoted {} are treated as quotes,
3496 even if that's inside a double-quoted command expansion
3497stdin:
3498 foo=1
3499 echo "$( echo ${foo:+'blah $foo'})"
3500expected-stdout:
3501 blah $foo
3502---
3503name: single-quotes-in-brace-pattern
3504description:
3505 Check that single quotes inside {} pattern are treated as quotes
3506stdin:
3507 foo=1234
3508 echo ${foo%'2'*} "${foo%'2'*}" ${foo%2'*'} "${foo%2'*'}"
3509expected-stdout:
3510 1 1 1234 1234
3511---
3512name: single-quotes-in-heredoc-braces
3513description:
3514 Check that single quotes inside {} in heredoc are treated
3515 as normal char
3516stdin:
3517 foo=1
3518 cat <<EOM
3519 ${foo:+'blah $foo'}
3520 EOM
3521expected-stdout:
3522 'blah 1'
3523---
3524name: single-quotes-in-nested-braces
3525description:
3526 Check that single quotes inside nested unquoted {} are
3527 treated as quotes
3528stdin:
3529 foo=1
3530 echo ${foo:+${foo:+'blah $foo'}}
3531expected-stdout:
3532 blah $foo
3533---
3534name: single-quotes-in-nested-quoted-braces
3535description:
3536 Check that single quotes inside nested quoted {} are treated
3537 as normal char
3538stdin:
3539 foo=1
3540 echo "${foo:+${foo:+'blah $foo'}}"
3541expected-stdout:
3542 'blah 1'
3543---
3544name: single-quotes-in-nested-braces-nested
3545description:
3546 Check that single quotes inside nested unquoted {} are treated
3547 as quotes, even if that's inside a double-quoted command expansion
3548stdin:
3549 foo=1
3550 echo "$( echo ${foo:+${foo:+'blah $foo'}})"
3551expected-stdout:
3552 blah $foo
3553---
3554name: single-quotes-in-nested-brace-pattern
3555description:
3556 Check that single quotes inside nested {} pattern are treated as quotes
3557stdin:
3558 foo=1234
3559 echo ${foo:+${foo%'2'*}} "${foo:+${foo%'2'*}}" ${foo:+${foo%2'*'}} "${foo:+${foo%2'*'}}"
3560expected-stdout:
3561 1 1 1234 1234
3562---
3563name: single-quotes-in-heredoc-nested-braces
3564description:
3565 Check that single quotes inside nested {} in heredoc are treated
3566 as normal char
3567stdin:
3568 foo=1
3569 cat <<EOM
3570 ${foo:+${foo:+'blah $foo'}}
3571 EOM
3572expected-stdout:
3573 'blah 1'
3574---
Elliott Hughes47086262019-03-26 12:34:31 -07003575name: single-quotes-in-heredoc-trim
3576description:
3577 In some cases, single quotes inside {} in heredoc are not normal
3578stdin:
3579 x=notOK
3580 cat <<EOF
3581 1: ${x#not} ${x:+${x#not}}
3582 2: ${x#\n\o\t} ${x:+${x#\n\o\t}}
3583 3: ${x#"not"} ${x:+${x#"not"}}
3584 4: ${x#'not'} ${x:+${x#'not'}}
3585 5: ${x#$'not'} ${x:+${x#$'not'}}
3586 EOF
3587expected-stdout:
3588 1: OK OK
3589 2: OK OK
3590 3: OK OK
3591 4: OK OK
3592 5: OK OK
3593---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003594name: history-basic
3595description:
3596 See if we can test history at all
Geremy Condra03ebf062011-10-12 18:17:24 -07003597need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003598arguments: !-i!
3599env-setup: !ENV=./Env!HISTFILE=hist.file!
3600file-setup: file 644 "Env"
3601 PS1=X
3602stdin:
3603 echo hi
3604 fc -l
3605expected-stdout:
3606 hi
3607 1 echo hi
3608expected-stderr-pattern:
3609 /^X*$/
3610---
3611name: history-dups
3612description:
3613 Verify duplicates and spaces are not entered
Geremy Condra03ebf062011-10-12 18:17:24 -07003614need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003615arguments: !-i!
3616env-setup: !ENV=./Env!HISTFILE=hist.file!
3617file-setup: file 644 "Env"
3618 PS1=X
3619stdin:
3620 echo hi
3621 echo yo
3622 echo hi
3623 fc -l
3624expected-stdout:
3625 hi
3626 yo
3627 hi
3628 1 echo hi
3629expected-stderr-pattern:
3630 /^X*$/
3631---
3632name: history-unlink
3633description:
3634 Check if broken HISTFILEs do not cause trouble
Geremy Condra03ebf062011-10-12 18:17:24 -07003635need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003636arguments: !-i!
3637env-setup: !ENV=./Env!HISTFILE=foo/hist.file!
3638file-setup: file 644 "Env"
3639 PS1=X
3640file-setup: dir 755 "foo"
3641file-setup: file 644 "foo/hist.file"
3642 sometext
3643time-limit: 5
3644perl-setup: chmod(0555, "foo");
3645stdin:
3646 echo hi
3647 fc -l
3648 chmod 0755 foo
3649expected-stdout:
3650 hi
3651 1 echo hi
3652expected-stderr-pattern:
Geremy Condra03ebf062011-10-12 18:17:24 -07003653 /(.*can't unlink HISTFILE.*\n)?X*$/
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003654---
Elliott Hughes77740fc2016-08-12 15:06:53 -07003655name: history-multiline
3656description:
3657 Check correct multiline history, Debian #783978
3658need-ctty: yes
3659arguments: !-i!
3660env-setup: !ENV=./Env!
3661file-setup: file 644 "Env"
3662 PS1=X
3663 PS2=Y
3664stdin:
3665 for i in A B C
3666 do
3667 print $i
3668 print $i
3669 done
3670 fc -l
3671expected-stdout:
3672 A
3673 A
3674 B
3675 B
3676 C
3677 C
3678 1 for i in A B C
3679 do
3680 print $i
3681 print $i
3682 done
3683expected-stderr-pattern:
3684 /^XYYYYXX$/
3685---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003686name: history-e-minus-1
3687description:
3688 Check if more recent command is executed
Geremy Condra03ebf062011-10-12 18:17:24 -07003689need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003690arguments: !-i!
3691env-setup: !ENV=./Env!HISTFILE=hist.file!
3692file-setup: file 644 "Env"
3693 PS1=X
3694stdin:
3695 echo hi
3696 echo there
3697 fc -e -
3698expected-stdout:
3699 hi
3700 there
3701 there
3702expected-stderr-pattern:
3703 /^X*echo there\nX*$/
3704---
3705name: history-e-minus-2
3706description:
3707 Check that repeated command is printed before command
3708 is re-executed.
Geremy Condra03ebf062011-10-12 18:17:24 -07003709need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003710arguments: !-i!
3711env-setup: !ENV=./Env!HISTFILE=hist.file!
3712file-setup: file 644 "Env"
3713 PS1=X
3714stdin:
3715 exec 2>&1
3716 echo hi
3717 echo there
3718 fc -e -
3719expected-stdout-pattern:
3720 /X*hi\nX*there\nX*echo there\nthere\nX*/
3721expected-stderr-pattern:
3722 /^X*$/
3723---
3724name: history-e-minus-3
3725description:
3726 fc -e - fails when there is no history
3727 (ksh93 has a bug that causes this to fail)
3728 (ksh88 loops on this)
Geremy Condra03ebf062011-10-12 18:17:24 -07003729need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003730arguments: !-i!
3731env-setup: !ENV=./Env!HISTFILE=hist.file!
3732file-setup: file 644 "Env"
3733 PS1=X
3734stdin:
3735 fc -e -
3736 echo ok
3737expected-stdout:
3738 ok
3739expected-stderr-pattern:
3740 /^X*.*:.*history.*\nX*$/
3741---
3742name: history-e-minus-4
3743description:
3744 Check if "fc -e -" command output goes to stdout.
Geremy Condra03ebf062011-10-12 18:17:24 -07003745need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003746arguments: !-i!
3747env-setup: !ENV=./Env!HISTFILE=hist.file!
3748file-setup: file 644 "Env"
3749 PS1=X
3750stdin:
3751 echo abc
3752 fc -e - | (read x; echo "A $x")
3753 echo ok
3754expected-stdout:
3755 abc
3756 A abc
3757 ok
3758expected-stderr-pattern:
3759 /^X*echo abc\nX*/
3760---
3761name: history-e-minus-5
3762description:
3763 fc is replaced in history by new command.
Geremy Condra03ebf062011-10-12 18:17:24 -07003764need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003765arguments: !-i!
3766env-setup: !ENV=./Env!HISTFILE=hist.file!
3767file-setup: file 644 "Env"
3768 PS1=X
3769stdin:
3770 echo abc def
3771 echo ghi jkl
3772 :
3773 fc -e - echo
3774 fc -l 2 5
3775expected-stdout:
3776 abc def
3777 ghi jkl
3778 ghi jkl
3779 2 echo ghi jkl
3780 3 :
3781 4 echo ghi jkl
3782 5 fc -l 2 5
3783expected-stderr-pattern:
3784 /^X*echo ghi jkl\nX*$/
3785---
3786name: history-list-1
3787description:
3788 List lists correct range
3789 (ksh88 fails 'cause it lists the fc command)
Geremy Condra03ebf062011-10-12 18:17:24 -07003790need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003791arguments: !-i!
3792env-setup: !ENV=./Env!HISTFILE=hist.file!
3793file-setup: file 644 "Env"
3794 PS1=X
3795stdin:
3796 echo line 1
3797 echo line 2
3798 echo line 3
3799 fc -l -- -2
3800expected-stdout:
3801 line 1
3802 line 2
3803 line 3
3804 2 echo line 2
3805 3 echo line 3
3806expected-stderr-pattern:
3807 /^X*$/
3808---
3809name: history-list-2
3810description:
3811 Lists oldest history if given pre-historic number
3812 (ksh93 has a bug that causes this to fail)
3813 (ksh88 fails 'cause it lists the fc command)
Geremy Condra03ebf062011-10-12 18:17:24 -07003814need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003815arguments: !-i!
3816env-setup: !ENV=./Env!HISTFILE=hist.file!
3817file-setup: file 644 "Env"
3818 PS1=X
3819stdin:
3820 echo line 1
3821 echo line 2
3822 echo line 3
3823 fc -l -- -40
3824expected-stdout:
3825 line 1
3826 line 2
3827 line 3
3828 1 echo line 1
3829 2 echo line 2
3830 3 echo line 3
3831expected-stderr-pattern:
3832 /^X*$/
3833---
3834name: history-list-3
3835description:
3836 Can give number 'options' to fc
Geremy Condra03ebf062011-10-12 18:17:24 -07003837need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003838arguments: !-i!
3839env-setup: !ENV=./Env!HISTFILE=hist.file!
3840file-setup: file 644 "Env"
3841 PS1=X
3842stdin:
3843 echo line 1
3844 echo line 2
3845 echo line 3
3846 echo line 4
3847 fc -l -3 -2
3848expected-stdout:
3849 line 1
3850 line 2
3851 line 3
3852 line 4
3853 2 echo line 2
3854 3 echo line 3
3855expected-stderr-pattern:
3856 /^X*$/
3857---
3858name: history-list-4
3859description:
3860 -1 refers to previous command
Geremy Condra03ebf062011-10-12 18:17:24 -07003861need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003862arguments: !-i!
3863env-setup: !ENV=./Env!HISTFILE=hist.file!
3864file-setup: file 644 "Env"
3865 PS1=X
3866stdin:
3867 echo line 1
3868 echo line 2
3869 echo line 3
3870 echo line 4
3871 fc -l -1 -1
3872expected-stdout:
3873 line 1
3874 line 2
3875 line 3
3876 line 4
3877 4 echo line 4
3878expected-stderr-pattern:
3879 /^X*$/
3880---
3881name: history-list-5
3882description:
3883 List command stays in history
Geremy Condra03ebf062011-10-12 18:17:24 -07003884need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003885arguments: !-i!
3886env-setup: !ENV=./Env!HISTFILE=hist.file!
3887file-setup: file 644 "Env"
3888 PS1=X
3889stdin:
3890 echo line 1
3891 echo line 2
3892 echo line 3
3893 echo line 4
3894 fc -l -1 -1
3895 fc -l -2 -1
3896expected-stdout:
3897 line 1
3898 line 2
3899 line 3
3900 line 4
3901 4 echo line 4
3902 4 echo line 4
3903 5 fc -l -1 -1
3904expected-stderr-pattern:
3905 /^X*$/
3906---
3907name: history-list-6
3908description:
3909 HISTSIZE limits about of history kept.
3910 (ksh88 fails 'cause it lists the fc command)
Geremy Condra03ebf062011-10-12 18:17:24 -07003911need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003912arguments: !-i!
3913env-setup: !ENV=./Env!HISTFILE=hist.file!HISTSIZE=3!
3914file-setup: file 644 "Env"
3915 PS1=X
3916stdin:
3917 echo line 1
3918 echo line 2
3919 echo line 3
3920 echo line 4
3921 echo line 5
3922 fc -l
3923expected-stdout:
3924 line 1
3925 line 2
3926 line 3
3927 line 4
3928 line 5
3929 4 echo line 4
3930 5 echo line 5
3931expected-stderr-pattern:
3932 /^X*$/
3933---
3934name: history-list-7
3935description:
3936 fc allows too old/new errors in range specification
Geremy Condra03ebf062011-10-12 18:17:24 -07003937need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003938arguments: !-i!
3939env-setup: !ENV=./Env!HISTFILE=hist.file!HISTSIZE=3!
3940file-setup: file 644 "Env"
3941 PS1=X
3942stdin:
3943 echo line 1
3944 echo line 2
3945 echo line 3
3946 echo line 4
3947 echo line 5
3948 fc -l 1 30
3949expected-stdout:
3950 line 1
3951 line 2
3952 line 3
3953 line 4
3954 line 5
3955 4 echo line 4
3956 5 echo line 5
3957 6 fc -l 1 30
3958expected-stderr-pattern:
3959 /^X*$/
3960---
3961name: history-list-r-1
3962description:
3963 test -r flag in history
Geremy Condra03ebf062011-10-12 18:17:24 -07003964need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003965arguments: !-i!
3966env-setup: !ENV=./Env!HISTFILE=hist.file!
3967file-setup: file 644 "Env"
3968 PS1=X
3969stdin:
3970 echo line 1
3971 echo line 2
3972 echo line 3
3973 echo line 4
3974 echo line 5
3975 fc -l -r 2 4
3976expected-stdout:
3977 line 1
3978 line 2
3979 line 3
3980 line 4
3981 line 5
3982 4 echo line 4
3983 3 echo line 3
3984 2 echo line 2
3985expected-stderr-pattern:
3986 /^X*$/
3987---
3988name: history-list-r-2
3989description:
3990 If first is newer than last, -r is implied.
Geremy Condra03ebf062011-10-12 18:17:24 -07003991need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003992arguments: !-i!
3993env-setup: !ENV=./Env!HISTFILE=hist.file!
3994file-setup: file 644 "Env"
3995 PS1=X
3996stdin:
3997 echo line 1
3998 echo line 2
3999 echo line 3
4000 echo line 4
4001 echo line 5
4002 fc -l 4 2
4003expected-stdout:
4004 line 1
4005 line 2
4006 line 3
4007 line 4
4008 line 5
4009 4 echo line 4
4010 3 echo line 3
4011 2 echo line 2
4012expected-stderr-pattern:
4013 /^X*$/
4014---
4015name: history-list-r-3
4016description:
4017 If first is newer than last, -r is cancelled.
Geremy Condra03ebf062011-10-12 18:17:24 -07004018need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004019arguments: !-i!
4020env-setup: !ENV=./Env!HISTFILE=hist.file!
4021file-setup: file 644 "Env"
4022 PS1=X
4023stdin:
4024 echo line 1
4025 echo line 2
4026 echo line 3
4027 echo line 4
4028 echo line 5
4029 fc -l -r 4 2
4030expected-stdout:
4031 line 1
4032 line 2
4033 line 3
4034 line 4
4035 line 5
4036 2 echo line 2
4037 3 echo line 3
4038 4 echo line 4
4039expected-stderr-pattern:
4040 /^X*$/
4041---
4042name: history-subst-1
4043description:
4044 Basic substitution
Geremy Condra03ebf062011-10-12 18:17:24 -07004045need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004046arguments: !-i!
4047env-setup: !ENV=./Env!HISTFILE=hist.file!
4048file-setup: file 644 "Env"
4049 PS1=X
4050stdin:
4051 echo abc def
4052 echo ghi jkl
4053 fc -e - abc=AB 'echo a'
4054expected-stdout:
4055 abc def
4056 ghi jkl
4057 AB def
4058expected-stderr-pattern:
4059 /^X*echo AB def\nX*$/
4060---
4061name: history-subst-2
4062description:
4063 Does subst find previous command?
Geremy Condra03ebf062011-10-12 18:17:24 -07004064need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004065arguments: !-i!
4066env-setup: !ENV=./Env!HISTFILE=hist.file!
4067file-setup: file 644 "Env"
4068 PS1=X
4069stdin:
4070 echo abc def
4071 echo ghi jkl
4072 fc -e - jkl=XYZQRT 'echo g'
4073expected-stdout:
4074 abc def
4075 ghi jkl
4076 ghi XYZQRT
4077expected-stderr-pattern:
4078 /^X*echo ghi XYZQRT\nX*$/
4079---
4080name: history-subst-3
4081description:
4082 Does subst find previous command when no arguments given
Geremy Condra03ebf062011-10-12 18:17:24 -07004083need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004084arguments: !-i!
4085env-setup: !ENV=./Env!HISTFILE=hist.file!
4086file-setup: file 644 "Env"
4087 PS1=X
4088stdin:
4089 echo abc def
4090 echo ghi jkl
4091 fc -e - jkl=XYZQRT
4092expected-stdout:
4093 abc def
4094 ghi jkl
4095 ghi XYZQRT
4096expected-stderr-pattern:
4097 /^X*echo ghi XYZQRT\nX*$/
4098---
4099name: history-subst-4
4100description:
4101 Global substitutions work
4102 (ksh88 and ksh93 do not have -g option)
Geremy Condra03ebf062011-10-12 18:17:24 -07004103need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004104arguments: !-i!
4105env-setup: !ENV=./Env!HISTFILE=hist.file!
4106file-setup: file 644 "Env"
4107 PS1=X
4108stdin:
4109 echo abc def asjj sadjhasdjh asdjhasd
4110 fc -e - -g a=FooBAR
4111expected-stdout:
4112 abc def asjj sadjhasdjh asdjhasd
4113 FooBARbc def FooBARsjj sFooBARdjhFooBARsdjh FooBARsdjhFooBARsd
4114expected-stderr-pattern:
4115 /^X*echo FooBARbc def FooBARsjj sFooBARdjhFooBARsdjh FooBARsdjhFooBARsd\nX*$/
4116---
4117name: history-subst-5
4118description:
4119 Make sure searches don't find current (fc) command
4120 (ksh88/ksh93 don't have the ? prefix thing so they fail this test)
Geremy Condra03ebf062011-10-12 18:17:24 -07004121need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004122arguments: !-i!
4123env-setup: !ENV=./Env!HISTFILE=hist.file!
4124file-setup: file 644 "Env"
4125 PS1=X
4126stdin:
4127 echo abc def
4128 echo ghi jkl
4129 fc -e - abc=AB \?abc
4130expected-stdout:
4131 abc def
4132 ghi jkl
4133 AB def
4134expected-stderr-pattern:
4135 /^X*echo AB def\nX*$/
4136---
4137name: history-ed-1-old
4138description:
4139 Basic (ed) editing works (assumes you have generic ed editor
4140 that prints no prompts). This is for oldish ed(1) which write
4141 the character count to stdout.
4142category: stdout-ed
Geremy Condra03ebf062011-10-12 18:17:24 -07004143need-ctty: yes
4144need-pass: no
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004145arguments: !-i!
4146env-setup: !ENV=./Env!HISTFILE=hist.file!
4147file-setup: file 644 "Env"
4148 PS1=X
4149stdin:
4150 echo abc def
4151 fc echo
4152 s/abc/FOOBAR/
4153 w
4154 q
4155expected-stdout:
4156 abc def
4157 13
4158 16
4159 FOOBAR def
4160expected-stderr-pattern:
4161 /^X*echo FOOBAR def\nX*$/
4162---
4163name: history-ed-2-old
4164description:
4165 Correct command is edited when number given
4166category: stdout-ed
Geremy Condra03ebf062011-10-12 18:17:24 -07004167need-ctty: yes
4168need-pass: no
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004169arguments: !-i!
4170env-setup: !ENV=./Env!HISTFILE=hist.file!
4171file-setup: file 644 "Env"
4172 PS1=X
4173stdin:
4174 echo line 1
4175 echo line 2 is here
4176 echo line 3
4177 echo line 4
4178 fc 2
4179 s/is here/is changed/
4180 w
4181 q
4182expected-stdout:
4183 line 1
4184 line 2 is here
4185 line 3
4186 line 4
4187 20
4188 23
4189 line 2 is changed
4190expected-stderr-pattern:
4191 /^X*echo line 2 is changed\nX*$/
4192---
4193name: history-ed-3-old
4194description:
4195 Newly created multi line commands show up as single command
4196 in history.
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004197 (ksh88 fails 'cause it lists the fc command)
4198category: stdout-ed
Geremy Condra03ebf062011-10-12 18:17:24 -07004199need-ctty: yes
4200need-pass: no
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004201arguments: !-i!
4202env-setup: !ENV=./Env!HISTFILE=hist.file!
4203file-setup: file 644 "Env"
4204 PS1=X
4205stdin:
4206 echo abc def
4207 fc echo
4208 s/abc/FOOBAR/
4209 $a
4210 echo a new line
4211 .
4212 w
4213 q
4214 fc -l
4215expected-stdout:
4216 abc def
4217 13
4218 32
4219 FOOBAR def
4220 a new line
4221 1 echo abc def
4222 2 echo FOOBAR def
Elliott Hughes96b43632015-07-17 11:39:41 -07004223 echo a new line
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004224expected-stderr-pattern:
4225 /^X*echo FOOBAR def\necho a new line\nX*$/
4226---
4227name: history-ed-1
4228description:
4229 Basic (ed) editing works (assumes you have generic ed editor
4230 that prints no prompts). This is for newish ed(1) and stderr.
4231category: !no-stderr-ed
Geremy Condra03ebf062011-10-12 18:17:24 -07004232need-ctty: yes
4233need-pass: no
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004234arguments: !-i!
4235env-setup: !ENV=./Env!HISTFILE=hist.file!
4236file-setup: file 644 "Env"
4237 PS1=X
4238stdin:
4239 echo abc def
4240 fc echo
4241 s/abc/FOOBAR/
4242 w
4243 q
4244expected-stdout:
4245 abc def
4246 FOOBAR def
4247expected-stderr-pattern:
4248 /^X*13\n16\necho FOOBAR def\nX*$/
4249---
4250name: history-ed-2
4251description:
4252 Correct command is edited when number given
4253category: !no-stderr-ed
Geremy Condra03ebf062011-10-12 18:17:24 -07004254need-ctty: yes
4255need-pass: no
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004256arguments: !-i!
4257env-setup: !ENV=./Env!HISTFILE=hist.file!
4258file-setup: file 644 "Env"
4259 PS1=X
4260stdin:
4261 echo line 1
4262 echo line 2 is here
4263 echo line 3
4264 echo line 4
4265 fc 2
4266 s/is here/is changed/
4267 w
4268 q
4269expected-stdout:
4270 line 1
4271 line 2 is here
4272 line 3
4273 line 4
4274 line 2 is changed
4275expected-stderr-pattern:
4276 /^X*20\n23\necho line 2 is changed\nX*$/
4277---
4278name: history-ed-3
4279description:
4280 Newly created multi line commands show up as single command
4281 in history.
4282category: !no-stderr-ed
Geremy Condra03ebf062011-10-12 18:17:24 -07004283need-ctty: yes
4284need-pass: no
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004285arguments: !-i!
4286env-setup: !ENV=./Env!HISTFILE=hist.file!
4287file-setup: file 644 "Env"
4288 PS1=X
4289stdin:
4290 echo abc def
4291 fc echo
4292 s/abc/FOOBAR/
4293 $a
4294 echo a new line
4295 .
4296 w
4297 q
4298 fc -l
4299expected-stdout:
4300 abc def
4301 FOOBAR def
4302 a new line
4303 1 echo abc def
4304 2 echo FOOBAR def
Elliott Hughes96b43632015-07-17 11:39:41 -07004305 echo a new line
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004306expected-stderr-pattern:
4307 /^X*13\n32\necho FOOBAR def\necho a new line\nX*$/
4308---
4309name: IFS-space-1
4310description:
4311 Simple test, default IFS
4312stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004313 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004314 set -- A B C
4315 showargs 1 $*
4316 showargs 2 "$*"
4317 showargs 3 $@
4318 showargs 4 "$@"
4319expected-stdout:
Elliott Hughes50012062015-03-10 22:22:24 -07004320 <1> <A> <B> <C> .
4321 <2> <A B C> .
4322 <3> <A> <B> <C> .
4323 <4> <A> <B> <C> .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004324---
4325name: IFS-colon-1
4326description:
4327 Simple test, IFS=:
4328stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004329 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004330 IFS=:
4331 set -- A B C
4332 showargs 1 $*
4333 showargs 2 "$*"
4334 showargs 3 $@
4335 showargs 4 "$@"
4336expected-stdout:
Elliott Hughes50012062015-03-10 22:22:24 -07004337 <1> <A> <B> <C> .
4338 <2> <A:B:C> .
4339 <3> <A> <B> <C> .
4340 <4> <A> <B> <C> .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004341---
4342name: IFS-null-1
4343description:
4344 Simple test, IFS=""
4345stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004346 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004347 IFS=""
4348 set -- A B C
4349 showargs 1 $*
4350 showargs 2 "$*"
4351 showargs 3 $@
4352 showargs 4 "$@"
4353expected-stdout:
Elliott Hughes50012062015-03-10 22:22:24 -07004354 <1> <A> <B> <C> .
4355 <2> <ABC> .
4356 <3> <A> <B> <C> .
4357 <4> <A> <B> <C> .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004358---
4359name: IFS-space-colon-1
4360description:
4361 Simple test, IFS=<white-space>:
4362stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004363 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004364 IFS="$IFS:"
4365 set --
4366 showargs 1 $*
4367 showargs 2 "$*"
4368 showargs 3 $@
4369 showargs 4 "$@"
4370 showargs 5 : "$@"
4371expected-stdout:
Elliott Hughes50012062015-03-10 22:22:24 -07004372 <1> .
4373 <2> <> .
4374 <3> .
4375 <4> .
4376 <5> <:> .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004377---
4378name: IFS-space-colon-2
4379description:
4380 Simple test, IFS=<white-space>:
4381 AT&T ksh fails this, POSIX says the test is correct.
4382stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004383 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004384 IFS="$IFS:"
4385 set --
4386 showargs :"$@"
4387expected-stdout:
Elliott Hughes50012062015-03-10 22:22:24 -07004388 <:> .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004389---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004390name: IFS-space-colon-4
4391description:
4392 Simple test, IFS=<white-space>:
4393stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004394 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004395 IFS="$IFS:"
4396 set --
4397 showargs "$@$@"
4398expected-stdout:
Elliott Hughes50012062015-03-10 22:22:24 -07004399 .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004400---
4401name: IFS-space-colon-5
4402description:
4403 Simple test, IFS=<white-space>:
4404 Don't know what POSIX thinks of this. AT&T ksh does not do this.
4405stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004406 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004407 IFS="$IFS:"
4408 set --
4409 showargs "${@:-}"
4410expected-stdout:
Elliott Hughes50012062015-03-10 22:22:24 -07004411 <> .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004412---
4413name: IFS-subst-1
4414description:
4415 Simple test, IFS=<white-space>:
4416stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004417 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004418 IFS="$IFS:"
4419 x=":b: :"
4420 echo -n '1:'; for i in $x ; do echo -n " [$i]" ; done ; echo
4421 echo -n '2:'; for i in :b:: ; do echo -n " [$i]" ; done ; echo
4422 showargs 3 $x
4423 showargs 4 :b::
4424 x="a:b:"
4425 echo -n '5:'; for i in $x ; do echo -n " [$i]" ; done ; echo
4426 showargs 6 $x
4427 x="a::c"
4428 echo -n '7:'; for i in $x ; do echo -n " [$i]" ; done ; echo
4429 showargs 8 $x
4430 echo -n '9:'; for i in ${FOO-`echo -n h:i`th:ere} ; do echo -n " [$i]" ; done ; echo
4431 showargs 10 ${FOO-`echo -n h:i`th:ere}
4432 showargs 11 "${FOO-`echo -n h:i`th:ere}"
4433 x=" A : B::D"
4434 echo -n '12:'; for i in $x ; do echo -n " [$i]" ; done ; echo
4435 showargs 13 $x
4436expected-stdout:
4437 1: [] [b] []
4438 2: [:b::]
Elliott Hughes50012062015-03-10 22:22:24 -07004439 <3> <> <b> <> .
4440 <4> <:b::> .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004441 5: [a] [b]
Elliott Hughes50012062015-03-10 22:22:24 -07004442 <6> <a> <b> .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004443 7: [a] [] [c]
Elliott Hughes50012062015-03-10 22:22:24 -07004444 <8> <a> <> <c> .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004445 9: [h] [ith] [ere]
Elliott Hughes50012062015-03-10 22:22:24 -07004446 <10> <h> <ith> <ere> .
4447 <11> <h:ith:ere> .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004448 12: [A] [B] [] [D]
Elliott Hughes50012062015-03-10 22:22:24 -07004449 <13> <A> <B> <> <D> .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004450---
Elliott Hughes737fdce2014-08-07 12:59:26 -07004451name: IFS-subst-2
4452description:
4453 Check leading whitespace after trim does not make a field
4454stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004455 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
Elliott Hughes737fdce2014-08-07 12:59:26 -07004456 x="X 1 2"
4457 showargs 1 shift ${x#X}
4458expected-stdout:
Elliott Hughes50012062015-03-10 22:22:24 -07004459 <1> <shift> <1> <2> .
Elliott Hughes737fdce2014-08-07 12:59:26 -07004460---
Elliott Hughes50012062015-03-10 22:22:24 -07004461name: IFS-subst-3-arr
Elliott Hughes56b517d2014-10-06 11:30:44 -07004462description:
4463 Check leading IFS non-whitespace after trim does make a field
Elliott Hughesf7f79562014-10-07 15:04:14 -07004464 but leading IFS whitespace does not, nor empty replacements
Elliott Hughes56b517d2014-10-06 11:30:44 -07004465stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004466 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
Elliott Hughesf7f79562014-10-07 15:04:14 -07004467 showargs 0 ${-+}
Elliott Hughes56b517d2014-10-06 11:30:44 -07004468 IFS=:
4469 showargs 1 ${-+:foo:bar}
Elliott Hughesf7f79562014-10-07 15:04:14 -07004470 IFS=' '
4471 showargs 2 ${-+ foo bar}
Elliott Hughes56b517d2014-10-06 11:30:44 -07004472expected-stdout:
Elliott Hughes50012062015-03-10 22:22:24 -07004473 <0> .
4474 <1> <> <foo> <bar> .
4475 <2> <foo> <bar> .
4476---
4477name: IFS-subst-3-ass
4478description:
4479 Check non-field semantics
4480stdin:
4481 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4482 showargs 0 x=${-+}
4483 IFS=:
4484 showargs 1 x=${-+:foo:bar}
4485 IFS=' '
4486 showargs 2 x=${-+ foo bar}
4487expected-stdout:
4488 <0> <x=> .
4489 <1> <x=> <foo> <bar> .
4490 <2> <x=> <foo> <bar> .
4491---
4492name: IFS-subst-3-lcl
4493description:
4494 Check non-field semantics, smaller corner case (LP#1381965)
4495stdin:
4496 set -x
4497 local regex=${2:-}
4498 exit 1
4499expected-exit: e != 0
4500expected-stderr-pattern:
4501 /regex=/
Elliott Hughes56b517d2014-10-06 11:30:44 -07004502---
4503name: IFS-subst-4-1
4504description:
4505 reported by mikeserv
4506stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004507 pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
Elliott Hughes56b517d2014-10-06 11:30:44 -07004508 a='space divded argument
4509 here'
4510 IFS=\ ; set -- $a
4511 IFS= ; q="$*" ; nq=$*
Elliott Hughes50012062015-03-10 22:22:24 -07004512 pfn "$*" $* "$q" "$nq"
Elliott Hughes56b517d2014-10-06 11:30:44 -07004513 [ "$q" = "$nq" ] && echo =true || echo =false
4514expected-stdout:
4515 <spacedivdedargument
4516 here>
4517 <space>
4518 <divded>
4519 <argument
4520 here>
4521 <spacedivdedargument
4522 here>
4523 <spacedivdedargument
4524 here>
4525 =true
4526---
4527name: IFS-subst-4-2
4528description:
4529 extended testsuite based on problem by mikeserv
4530stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004531 pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
Elliott Hughes56b517d2014-10-06 11:30:44 -07004532 a='space divded argument
4533 here'
4534 IFS=\ ; set -- $a
4535 IFS= ; q="$@" ; nq=$@
Elliott Hughes50012062015-03-10 22:22:24 -07004536 pfn "$*" $* "$q" "$nq"
Elliott Hughes56b517d2014-10-06 11:30:44 -07004537 [ "$q" = "$nq" ] && echo =true || echo =false
4538expected-stdout:
4539 <spacedivdedargument
4540 here>
4541 <space>
4542 <divded>
4543 <argument
4544 here>
4545 <space divded argument
4546 here>
4547 <space divded argument
4548 here>
4549 =true
4550---
4551name: IFS-subst-4-3
4552description:
4553 extended testsuite based on problem by mikeserv
4554stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004555 pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
Elliott Hughes56b517d2014-10-06 11:30:44 -07004556 a='space divded argument
4557 here'
4558 IFS=\ ; set -- $a; IFS=
4559 qs="$*"
4560 nqs=$*
4561 qk="$@"
4562 nqk=$@
Elliott Hughes50012062015-03-10 22:22:24 -07004563 print -nr -- '= qs '; pfn "$qs"
4564 print -nr -- '=nqs '; pfn "$nqs"
4565 print -nr -- '= qk '; pfn "$qk"
4566 print -nr -- '=nqk '; pfn "$nqk"
4567 print -nr -- '~ qs '; pfn "$*"
4568 print -nr -- '~nqs '; pfn $*
4569 print -nr -- '~ qk '; pfn "$@"
4570 print -nr -- '~nqk '; pfn $@
Elliott Hughes56b517d2014-10-06 11:30:44 -07004571expected-stdout:
4572 = qs <spacedivdedargument
4573 here>
4574 =nqs <spacedivdedargument
4575 here>
4576 = qk <space divded argument
4577 here>
4578 =nqk <space divded argument
4579 here>
4580 ~ qs <spacedivdedargument
4581 here>
4582 ~nqs <space>
4583 <divded>
4584 <argument
4585 here>
4586 ~ qk <space>
4587 <divded>
4588 <argument
4589 here>
4590 ~nqk <space>
4591 <divded>
4592 <argument
4593 here>
4594---
4595name: IFS-subst-4-4
4596description:
4597 extended testsuite based on problem by mikeserv
4598stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004599 pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
Elliott Hughes56b517d2014-10-06 11:30:44 -07004600 a='space divded argument
4601 here'
4602 IFS=\ ; set -- $a; IFS=
4603 qs="$*"
Elliott Hughes50012062015-03-10 22:22:24 -07004604 print -nr -- '= qs '; pfn "$qs"
4605 print -nr -- '~ qs '; pfn "$*"
Elliott Hughes56b517d2014-10-06 11:30:44 -07004606 nqs=$*
Elliott Hughes50012062015-03-10 22:22:24 -07004607 print -nr -- '=nqs '; pfn "$nqs"
4608 print -nr -- '~nqs '; pfn $*
Elliott Hughes56b517d2014-10-06 11:30:44 -07004609 qk="$@"
Elliott Hughes50012062015-03-10 22:22:24 -07004610 print -nr -- '= qk '; pfn "$qk"
4611 print -nr -- '~ qk '; pfn "$@"
Elliott Hughes56b517d2014-10-06 11:30:44 -07004612 nqk=$@
Elliott Hughes50012062015-03-10 22:22:24 -07004613 print -nr -- '=nqk '; pfn "$nqk"
4614 print -nr -- '~nqk '; pfn $@
Elliott Hughes56b517d2014-10-06 11:30:44 -07004615expected-stdout:
4616 = qs <spacedivdedargument
4617 here>
4618 ~ qs <spacedivdedargument
4619 here>
4620 =nqs <spacedivdedargument
4621 here>
4622 ~nqs <space>
4623 <divded>
4624 <argument
4625 here>
4626 = qk <space divded argument
4627 here>
4628 ~ qk <space>
4629 <divded>
4630 <argument
4631 here>
4632 =nqk <space divded argument
4633 here>
4634 ~nqk <space>
4635 <divded>
4636 <argument
4637 here>
4638---
4639name: IFS-subst-4-4p
4640description:
4641 extended testsuite based on problem by mikeserv
4642stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004643 pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
Elliott Hughes56b517d2014-10-06 11:30:44 -07004644 a='space divded argument
4645 here'
4646 IFS=\ ; set -- $a; IFS=
4647 unset v
4648 qs=${v:-"$*"}
Elliott Hughes50012062015-03-10 22:22:24 -07004649 print -nr -- '= qs '; pfn "$qs"
4650 print -nr -- '~ qs '; pfn ${v:-"$*"}
Elliott Hughes56b517d2014-10-06 11:30:44 -07004651 nqs=${v:-$*}
Elliott Hughes50012062015-03-10 22:22:24 -07004652 print -nr -- '=nqs '; pfn "$nqs"
4653 print -nr -- '~nqs '; pfn ${v:-$*}
Elliott Hughes56b517d2014-10-06 11:30:44 -07004654 qk=${v:-"$@"}
Elliott Hughes50012062015-03-10 22:22:24 -07004655 print -nr -- '= qk '; pfn "$qk"
4656 print -nr -- '~ qk '; pfn ${v:-"$@"}
Elliott Hughes56b517d2014-10-06 11:30:44 -07004657 nqk=${v:-$@}
Elliott Hughes50012062015-03-10 22:22:24 -07004658 print -nr -- '=nqk '; pfn "$nqk"
4659 print -nr -- '~nqk '; pfn ${v:-$@}
Elliott Hughes56b517d2014-10-06 11:30:44 -07004660expected-stdout:
4661 = qs <spacedivdedargument
4662 here>
4663 ~ qs <spacedivdedargument
4664 here>
4665 =nqs <spacedivdedargument
4666 here>
4667 ~nqs <space>
4668 <divded>
4669 <argument
4670 here>
4671 = qk <space divded argument
4672 here>
4673 ~ qk <space>
4674 <divded>
4675 <argument
4676 here>
4677 =nqk <space divded argument
4678 here>
4679 ~nqk <space>
4680 <divded>
4681 <argument
4682 here>
4683---
4684name: IFS-subst-4-5
4685description:
4686 extended testsuite based on problem by mikeserv
4687stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004688 pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
Elliott Hughes56b517d2014-10-06 11:30:44 -07004689 a='space divded argument
4690 here'
4691 IFS=\ ; set -- $a; IFS=,
4692 qs="$*"
Elliott Hughes50012062015-03-10 22:22:24 -07004693 print -nr -- '= qs '; pfn "$qs"
4694 print -nr -- '~ qs '; pfn "$*"
Elliott Hughes56b517d2014-10-06 11:30:44 -07004695 nqs=$*
Elliott Hughes50012062015-03-10 22:22:24 -07004696 print -nr -- '=nqs '; pfn "$nqs"
4697 print -nr -- '~nqs '; pfn $*
Elliott Hughes56b517d2014-10-06 11:30:44 -07004698 qk="$@"
Elliott Hughes50012062015-03-10 22:22:24 -07004699 print -nr -- '= qk '; pfn "$qk"
4700 print -nr -- '~ qk '; pfn "$@"
Elliott Hughes56b517d2014-10-06 11:30:44 -07004701 nqk=$@
Elliott Hughes50012062015-03-10 22:22:24 -07004702 print -nr -- '=nqk '; pfn "$nqk"
4703 print -nr -- '~nqk '; pfn $@
Elliott Hughes56b517d2014-10-06 11:30:44 -07004704expected-stdout:
4705 = qs <space,divded,argument
4706 here>
4707 ~ qs <space,divded,argument
4708 here>
4709 =nqs <space,divded,argument
4710 here>
4711 ~nqs <space>
4712 <divded>
4713 <argument
4714 here>
4715 = qk <space divded argument
4716 here>
4717 ~ qk <space>
4718 <divded>
4719 <argument
4720 here>
4721 =nqk <space divded argument
4722 here>
4723 ~nqk <space>
4724 <divded>
4725 <argument
4726 here>
4727---
4728name: IFS-subst-4-5p
4729description:
4730 extended testsuite based on problem by mikeserv
4731stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004732 pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
Elliott Hughes56b517d2014-10-06 11:30:44 -07004733 a='space divded argument
4734 here'
4735 IFS=\ ; set -- $a; IFS=,
4736 unset v
4737 qs=${v:-"$*"}
Elliott Hughes50012062015-03-10 22:22:24 -07004738 print -nr -- '= qs '; pfn "$qs"
4739 print -nr -- '~ qs '; pfn ${v:-"$*"}
Elliott Hughes56b517d2014-10-06 11:30:44 -07004740 nqs=${v:-$*}
Elliott Hughes50012062015-03-10 22:22:24 -07004741 print -nr -- '=nqs '; pfn "$nqs"
4742 print -nr -- '~nqs '; pfn ${v:-$*}
Elliott Hughes56b517d2014-10-06 11:30:44 -07004743 qk=${v:-"$@"}
Elliott Hughes50012062015-03-10 22:22:24 -07004744 print -nr -- '= qk '; pfn "$qk"
4745 print -nr -- '~ qk '; pfn ${v:-"$@"}
Elliott Hughes56b517d2014-10-06 11:30:44 -07004746 nqk=${v:-$@}
Elliott Hughes50012062015-03-10 22:22:24 -07004747 print -nr -- '=nqk '; pfn "$nqk"
4748 print -nr -- '~nqk '; pfn ${v:-$@}
Elliott Hughes56b517d2014-10-06 11:30:44 -07004749expected-stdout:
4750 = qs <space,divded,argument
4751 here>
4752 ~ qs <space,divded,argument
4753 here>
4754 =nqs <space,divded,argument
4755 here>
4756 ~nqs <space>
4757 <divded>
4758 <argument
4759 here>
4760 = qk <space divded argument
4761 here>
4762 ~ qk <space>
4763 <divded>
4764 <argument
4765 here>
4766 =nqk <space divded argument
4767 here>
4768 ~nqk <space>
4769 <divded>
4770 <argument
4771 here>
4772---
4773name: IFS-subst-5
4774description:
4775 extended testsuite based on IFS-subst-3
4776 differs slightly from ksh93:
4777 - omit trailing field in a3zna, a7ina (unquoted $@ expansion)
4778 - has extra middle fields in b5ins, b7ina (IFS_NWS unquoted expansion)
4779 differs slightly from bash:
4780 - omit leading field in a5ins, a7ina (IFS_NWS unquoted expansion)
4781 differs slightly from zsh:
4782 - differs in assignment, not expansion; probably zsh bug
4783 - has extra middle fields in b5ins, b7ina (IFS_NWS unquoted expansion)
4784 'emulate sh' zsh has extra fields in
4785 - a5ins (IFS_NWS unquoted $*)
4786 - b5ins, matching mksh’s
Elliott Hughes50012062015-03-10 22:22:24 -07004787 !!WARNING!! more to come: http://austingroupbugs.net/view.php?id=888
Elliott Hughes56b517d2014-10-06 11:30:44 -07004788stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004789 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4790 IFS=; set -- "" 2 ""; pfb $*; x=$*; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004791 echo '=a1zns'
Elliott Hughes50012062015-03-10 22:22:24 -07004792 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4793 IFS=; set -- "" 2 ""; pfb "$*"; x="$*"; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004794 echo '=a2zqs'
Elliott Hughes50012062015-03-10 22:22:24 -07004795 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4796 IFS=; set -- "" 2 ""; pfb $@; x=$@; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004797 echo '=a3zna'
Elliott Hughes50012062015-03-10 22:22:24 -07004798 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4799 IFS=; set -- "" 2 ""; pfb "$@"; x="$@"; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004800 echo '=a4zqa'
Elliott Hughes50012062015-03-10 22:22:24 -07004801 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4802 IFS=,; set -- "" 2 ""; pfb $*; x=$*; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004803 echo '=a5ins'
Elliott Hughes50012062015-03-10 22:22:24 -07004804 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4805 IFS=,; set -- "" 2 ""; pfb "$*"; x="$*"; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004806 echo '=a6iqs'
Elliott Hughes50012062015-03-10 22:22:24 -07004807 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4808 IFS=,; set -- "" 2 ""; pfb $@; x=$@; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004809 echo '=a7ina'
Elliott Hughes50012062015-03-10 22:22:24 -07004810 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4811 IFS=,; set -- "" 2 ""; pfb "$@"; x="$@"; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004812 echo '=a8iqa'
Elliott Hughes50012062015-03-10 22:22:24 -07004813 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4814 IFS=; set -- A B "" "" C; pfb $*; x=$*; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004815 echo '=b1zns'
Elliott Hughes50012062015-03-10 22:22:24 -07004816 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4817 IFS=; set -- A B "" "" C; pfb "$*"; x="$*"; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004818 echo '=b2zqs'
Elliott Hughes50012062015-03-10 22:22:24 -07004819 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4820 IFS=; set -- A B "" "" C; pfb $@; x=$@; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004821 echo '=b3zna'
Elliott Hughes50012062015-03-10 22:22:24 -07004822 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4823 IFS=; set -- A B "" "" C; pfb "$@"; x="$@"; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004824 echo '=b4zqa'
Elliott Hughes50012062015-03-10 22:22:24 -07004825 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4826 IFS=,; set -- A B "" "" C; pfb $*; x=$*; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004827 echo '=b5ins'
Elliott Hughes50012062015-03-10 22:22:24 -07004828 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4829 IFS=,; set -- A B "" "" C; pfb "$*"; x="$*"; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004830 echo '=b6iqs'
Elliott Hughes50012062015-03-10 22:22:24 -07004831 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4832 IFS=,; set -- A B "" "" C; pfb $@; x=$@; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004833 echo '=b7ina'
Elliott Hughes50012062015-03-10 22:22:24 -07004834 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4835 IFS=,; set -- A B "" "" C; pfb "$@"; x="$@"; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004836 echo '=b8iqa'
4837expected-stdout:
4838 [2]
4839 <2>
4840 =a1zns
4841 [2]
4842 <2>
4843 =a2zqs
4844 [2]
4845 < 2 >
4846 =a3zna
4847 []
4848 [2]
4849 []
4850 < 2 >
4851 =a4zqa
4852 [2]
4853 <,2,>
4854 =a5ins
4855 [,2,]
4856 <,2,>
4857 =a6iqs
4858 [2]
4859 < 2 >
4860 =a7ina
4861 []
4862 [2]
4863 []
4864 < 2 >
4865 =a8iqa
4866 [A]
4867 [B]
4868 [C]
4869 <ABC>
4870 =b1zns
4871 [ABC]
4872 <ABC>
4873 =b2zqs
4874 [A]
4875 [B]
4876 [C]
4877 <A B C>
4878 =b3zna
4879 [A]
4880 [B]
4881 []
4882 []
4883 [C]
4884 <A B C>
4885 =b4zqa
4886 [A]
4887 [B]
4888 []
4889 []
4890 [C]
4891 <A,B,,,C>
4892 =b5ins
4893 [A,B,,,C]
4894 <A,B,,,C>
4895 =b6iqs
4896 [A]
4897 [B]
4898 []
4899 []
4900 [C]
4901 <A B C>
4902 =b7ina
4903 [A]
4904 [B]
4905 []
4906 []
4907 [C]
4908 <A B C>
4909 =b8iqa
4910---
Elliott Hughes50012062015-03-10 22:22:24 -07004911name: IFS-subst-6
4912description:
4913 Regression wrt. vector expansion in trim
4914stdin:
4915 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4916 IFS=
4917 x=abc
4918 set -- a b
4919 showargs ${x#$*}
4920expected-stdout:
4921 <c> .
4922---
4923name: IFS-subst-7
4924description:
4925 ksh93 bug wrt. vector expansion in trim
4926stdin:
4927 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4928 IFS="*"
4929 a=abcd
4930 set -- '' c
4931 showargs "$*" ${a##"$*"}
4932expected-stdout:
4933 <*c> <abcd> .
4934---
4935name: IFS-subst-8
4936description:
4937 http://austingroupbugs.net/view.php?id=221
4938stdin:
4939 n() { echo "$#"; }; n "${foo-$@}"
4940expected-stdout:
4941 1
4942---
4943name: IFS-subst-9
4944description:
4945 Scalar context for $*/$@ in [[ and case
4946stdin:
4947 "$__progname" -c 'IFS=; set a b; [[ $* = "$1$2" ]]; echo 1 $?' sh a b
4948 "$__progname" -c 'IFS=; [[ $* = ab ]]; echo 2 "$?"' sh a b
4949 "$__progname" -c 'IFS=; [[ "$*" = ab ]]; echo 3 "$?"' sh a b
4950 "$__progname" -c 'IFS=; [[ $* = a ]]; echo 4 "$?"' sh a b
4951 "$__progname" -c 'IFS=; [[ "$*" = a ]]; echo 5 "$?"' sh a b
4952 "$__progname" -c 'IFS=; [[ "$@" = a ]]; echo 6 "$?"' sh a b
4953 "$__progname" -c 'IFS=; case "$@" in a) echo 7 a;; ab) echo 7 b;; a\ b) echo 7 ok;; esac' sh a b
4954 "$__progname" -c 'IFS=; case $* in a) echo 8 a;; ab) echo 8 ok;; esac' sh a b
4955 "$__progname" -c 'pfsp() { for s_arg in "$@"; do print -nr -- "<$s_arg> "; done; print .; }; IFS=; star=$* at="$@"; pfsp 9 "$star" "$at"' sh a b
4956expected-stdout:
4957 1 0
4958 2 0
4959 3 0
4960 4 1
4961 5 1
4962 6 1
4963 7 ok
4964 8 ok
4965 <9> <ab> <a b> .
4966---
Elliott Hughesa3c3f962017-04-12 16:52:30 -07004967name: IFS-subst-10
4968description:
4969 Scalar context in ${var=$subst}
4970stdin:
4971 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4972 set -- one "two three" four
4973 unset -v var
4974 save_IFS=$IFS
4975 IFS=
4976 set -- ${var=$*}
4977 IFS=$save_IFS
4978 echo "var=$var"
4979 showargs "$@"
4980expected-stdout:
4981 var=onetwo threefour
4982 <onetwo threefour> .
4983---
Elliott Hughes737fdce2014-08-07 12:59:26 -07004984name: IFS-arith-1
4985description:
4986 http://austingroupbugs.net/view.php?id=832
4987stdin:
4988 ${ZSH_VERSION+false} || emulate sh
4989 ${BASH_VERSION+set -o posix}
Elliott Hughes50012062015-03-10 22:22:24 -07004990 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
Elliott Hughes737fdce2014-08-07 12:59:26 -07004991 IFS=0
4992 showargs $((1230456))
4993expected-stdout:
4994 <123> <456> .
4995---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004996name: integer-base-err-1
4997description:
4998 Can't have 0 base (causes shell to exit)
4999expected-exit: e != 0
5000stdin:
5001 typeset -i i
5002 i=3
5003 i=0#4
5004 echo $i
5005expected-stderr-pattern:
5006 /^.*:.*0#4.*\n$/
5007---
5008name: integer-base-err-2
5009description:
5010 Can't have multiple bases in a 'constant' (causes shell to exit)
5011 (ksh88 fails this test)
5012expected-exit: e != 0
5013stdin:
5014 typeset -i i
5015 i=3
5016 i=2#110#11
5017 echo $i
5018expected-stderr-pattern:
5019 /^.*:.*2#110#11.*\n$/
5020---
5021name: integer-base-err-3
5022description:
5023 Syntax errors in expressions and effects on bases
5024 (interactive so errors don't cause exits)
5025 (ksh88 fails this test - shell exits, even with -i)
Geremy Condra03ebf062011-10-12 18:17:24 -07005026need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07005027arguments: !-i!
5028stdin:
5029 PS1= # minimise prompt hassles
5030 typeset -i4 a=10
5031 typeset -i a=2+
5032 echo $a
5033 typeset -i4 a=10
5034 typeset -i2 a=2+
5035 echo $a
5036expected-stderr-pattern:
5037 /^([#\$] )?.*:.*2+.*\n.*:.*2+.*\n$/
5038expected-stdout:
5039 4#22
5040 4#22
5041---
5042name: integer-base-err-4
5043description:
5044 Are invalid digits (according to base) errors?
5045 (ksh93 fails this test)
5046expected-exit: e != 0
5047stdin:
5048 typeset -i i;
5049 i=3#4
5050expected-stderr-pattern:
5051 /^([#\$] )?.*:.*3#4.*\n$/
5052---
5053name: integer-base-1
5054description:
5055 Missing number after base is treated as 0.
5056stdin:
5057 typeset -i i
5058 i=3
5059 i=2#
5060 echo $i
5061expected-stdout:
5062 0
5063---
5064name: integer-base-2
5065description:
5066 Check 'stickyness' of base in various situations
5067stdin:
5068 typeset -i i=8
5069 echo $i
5070 echo ---------- A
5071 typeset -i4 j=8
5072 echo $j
5073 echo ---------- B
5074 typeset -i k=8
5075 typeset -i4 k=8
5076 echo $k
5077 echo ---------- C
5078 typeset -i4 l
5079 l=3#10
5080 echo $l
5081 echo ---------- D
5082 typeset -i m
5083 m=3#10
5084 echo $m
5085 echo ---------- E
5086 n=2#11
5087 typeset -i n
5088 echo $n
5089 n=10
5090 echo $n
5091 echo ---------- F
5092 typeset -i8 o=12
5093 typeset -i4 o
5094 echo $o
5095 echo ---------- G
5096 typeset -i p
5097 let p=8#12
5098 echo $p
5099expected-stdout:
5100 8
5101 ---------- A
5102 4#20
5103 ---------- B
5104 4#20
5105 ---------- C
5106 4#3
5107 ---------- D
5108 3#10
5109 ---------- E
5110 2#11
5111 2#1010
5112 ---------- F
5113 4#30
5114 ---------- G
5115 8#12
5116---
5117name: integer-base-3
5118description:
5119 More base parsing (hmm doesn't test much..)
5120stdin:
5121 typeset -i aa
5122 aa=1+12#10+2
5123 echo $aa
5124 typeset -i bb
5125 bb=1+$aa
5126 echo $bb
5127 typeset -i bb
5128 bb=$aa
5129 echo $bb
5130 typeset -i cc
5131 cc=$aa
5132 echo $cc
5133expected-stdout:
5134 15
5135 16
5136 15
5137 15
5138---
5139name: integer-base-4
5140description:
5141 Check that things not declared as integers are not made integers,
5142 also, check if base is not reset by -i with no arguments.
5143 (ksh93 fails - prints 10#20 - go figure)
5144stdin:
5145 xx=20
5146 let xx=10
5147 typeset -i | grep '^xx='
5148 typeset -i4 a=10
5149 typeset -i a=20
5150 echo $a
5151expected-stdout:
5152 4#110
5153---
5154name: integer-base-5
5155description:
5156 More base stuff
5157stdin:
5158 typeset -i4 a=3#10
5159 echo $a
5160 echo --
5161 typeset -i j=3
5162 j='~3'
5163 echo $j
5164 echo --
5165 typeset -i k=1
5166 x[k=k+1]=3
5167 echo $k
5168 echo --
5169 typeset -i l
5170 for l in 1 2+3 4; do echo $l; done
5171expected-stdout:
5172 4#3
5173 --
5174 -4
5175 --
5176 2
5177 --
5178 1
5179 5
5180 4
5181---
5182name: integer-base-6
5183description:
5184 Even more base stuff
5185 (ksh93 fails this test - prints 0)
5186stdin:
5187 typeset -i7 i
5188 i=
5189 echo $i
5190expected-stdout:
5191 7#0
5192---
5193name: integer-base-7
5194description:
5195 Check that non-integer parameters don't get bases assigned
5196stdin:
5197 echo $(( zz = 8#100 ))
5198 echo $zz
5199expected-stdout:
5200 64
5201 64
5202---
Elliott Hughes96b43632015-07-17 11:39:41 -07005203name: integer-base-8
5204description:
5205 Check that base-36 works (full span)
5206stdin:
5207 echo 1:$((36#109AZ)).
5208 typeset -i36 x=1691675
5209 echo 2:$x.
5210 typeset -Uui36 x
5211 echo 3:$x.
5212expected-stdout:
5213 1:1691675.
5214 2:36#109az.
5215 3:36#109AZ.
5216---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005217name: integer-base-check-flat
5218description:
Thorsten Glaser811a5752013-07-25 14:24:45 +00005219 Check behaviour does not match POSuX (except if set -o posix),
5220 because a not type-safe scripting language has *no* business
Elliott Hughes966dd552016-12-08 15:56:04 -08005221 interpreting the string "010" as octal number eight (dangerous).
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005222stdin:
Thorsten Glaser811a5752013-07-25 14:24:45 +00005223 echo 1 "$("$__progname" -c 'echo :$((10))/$((010)),$((0x10)):')" .
5224 echo 2 "$("$__progname" -o posix -c 'echo :$((10))/$((010)),$((0x10)):')" .
5225 echo 3 "$("$__progname" -o sh -c 'echo :$((10))/$((010)),$((0x10)):')" .
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005226expected-stdout:
Thorsten Glaser811a5752013-07-25 14:24:45 +00005227 1 :10/10,16: .
5228 2 :10/8,16: .
5229 3 :10/10,16: .
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005230---
Elliott Hughes23925bb2017-09-22 16:04:20 -07005231name: integer-base-check-numeric-from-1
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005232description:
Elliott Hughes23925bb2017-09-22 16:04:20 -07005233 Check behaviour for base one
5234category: !shell:ebcdic-yes
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005235stdin:
5236 echo 1:$((1#1))0.
Elliott Hughes23925bb2017-09-22 16:04:20 -07005237expected-stdout:
5238 1:490.
5239---
5240name: integer-base-check-numeric-from-1-ebcdic
5241description:
5242 Check behaviour for base one
5243category: !shell:ebcdic-no
5244stdin:
5245 echo 1:$((1#1))0.
5246expected-stdout:
5247 1:2410.
5248---
5249name: integer-base-check-numeric-from-2
5250description:
5251 Check behaviour for base two to 36, and that 37 degrades to 10
5252stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005253 i=1
Elliott Hughes96b43632015-07-17 11:39:41 -07005254 while (( ++i <= 37 )); do
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005255 eval 'echo '$i':$(('$i'#10)).'
5256 done
5257 echo 37:$($__progname -c 'echo $((37#10))').$?:
5258expected-stdout:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005259 2:2.
5260 3:3.
5261 4:4.
5262 5:5.
5263 6:6.
5264 7:7.
5265 8:8.
5266 9:9.
5267 10:10.
5268 11:11.
5269 12:12.
5270 13:13.
5271 14:14.
5272 15:15.
5273 16:16.
5274 17:17.
5275 18:18.
5276 19:19.
5277 20:20.
5278 21:21.
5279 22:22.
5280 23:23.
5281 24:24.
5282 25:25.
5283 26:26.
5284 27:27.
5285 28:28.
5286 29:29.
5287 30:30.
5288 31:31.
5289 32:32.
5290 33:33.
5291 34:34.
5292 35:35.
5293 36:36.
Elliott Hughes96b43632015-07-17 11:39:41 -07005294 37:10.
5295 37:10.0:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005296---
Elliott Hughes23925bb2017-09-22 16:04:20 -07005297name: integer-base-check-numeric-to-1
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005298description:
Elliott Hughes23925bb2017-09-22 16:04:20 -07005299 Check behaviour for base one
5300category: !shell:ebcdic-yes
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005301stdin:
Elliott Hughes23925bb2017-09-22 16:04:20 -07005302 i=1
5303 typeset -Uui$i x=0x40
5304 eval "typeset -i10 y=$x"
5305 print $i:$x.$y.
5306expected-stdout:
5307 1:1#@.64.
5308---
5309name: integer-base-check-numeric-to-1-ebcdic
5310description:
5311 Check behaviour for base one
5312category: !shell:ebcdic-no
5313stdin:
5314 i=1
5315 typeset -Uui$i x=0x7C
5316 eval "typeset -i10 y=$x"
5317 print $i:$x.$y.
5318expected-stdout:
5319 1:1#@.124.
5320---
5321name: integer-base-check-numeric-to-2
5322description:
5323 Check behaviour for base two to 36, and that 37 degrades to 10
5324stdin:
5325 i=1
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005326 while (( ++i <= 37 )); do
5327 typeset -Uui$i x=0x40
5328 eval "typeset -i10 y=$x"
5329 print $i:$x.$y.
5330 done
5331expected-stdout:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005332 2:2#1000000.64.
5333 3:3#2101.64.
5334 4:4#1000.64.
5335 5:5#224.64.
5336 6:6#144.64.
5337 7:7#121.64.
5338 8:8#100.64.
5339 9:9#71.64.
5340 10:64.64.
5341 11:11#59.64.
5342 12:12#54.64.
5343 13:13#4C.64.
5344 14:14#48.64.
5345 15:15#44.64.
5346 16:16#40.64.
5347 17:17#3D.64.
5348 18:18#3A.64.
5349 19:19#37.64.
5350 20:20#34.64.
5351 21:21#31.64.
5352 22:22#2K.64.
5353 23:23#2I.64.
5354 24:24#2G.64.
5355 25:25#2E.64.
5356 26:26#2C.64.
5357 27:27#2A.64.
5358 28:28#28.64.
5359 29:29#26.64.
5360 30:30#24.64.
5361 31:31#22.64.
5362 32:32#20.64.
5363 33:33#1V.64.
5364 34:34#1U.64.
5365 35:35#1T.64.
5366 36:36#1S.64.
Elliott Hughes96b43632015-07-17 11:39:41 -07005367 37:64.64.
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005368---
5369name: integer-arithmetic-span
5370description:
5371 Check wraparound and size that is defined in mksh
5372category: int:32
5373stdin:
5374 echo s:$((2147483647+1)).$(((2147483647*2)+1)).$(((2147483647*2)+2)).
5375 echo u:$((#2147483647+1)).$((#(2147483647*2)+1)).$((#(2147483647*2)+2)).
5376expected-stdout:
5377 s:-2147483648.-1.0.
5378 u:2147483648.4294967295.0.
5379---
5380name: integer-arithmetic-span-64
5381description:
5382 Check wraparound and size that is defined in mksh
5383category: int:64
5384stdin:
5385 echo s:$((9223372036854775807+1)).$(((9223372036854775807*2)+1)).$(((9223372036854775807*2)+2)).
5386 echo u:$((#9223372036854775807+1)).$((#(9223372036854775807*2)+1)).$((#(9223372036854775807*2)+2)).
5387expected-stdout:
5388 s:-9223372036854775808.-1.0.
5389 u:9223372036854775808.18446744073709551615.0.
5390---
Thorsten Glaser811a5752013-07-25 14:24:45 +00005391name: integer-size-FAIL-to-detect
5392description:
5393 Notify the user that their ints are not 32 or 64 bit
5394category: int:u
5395stdin:
5396 :
5397---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07005398name: lineno-stdin
5399description:
5400 See if $LINENO is updated and can be modified.
5401stdin:
5402 echo A $LINENO
5403 echo B $LINENO
5404 LINENO=20
5405 echo C $LINENO
5406expected-stdout:
5407 A 1
5408 B 2
5409 C 20
5410---
5411name: lineno-inc
5412description:
5413 See if $LINENO is set for .'d files.
5414file-setup: file 644 "dotfile"
5415 echo dot A $LINENO
5416 echo dot B $LINENO
5417 LINENO=20
5418 echo dot C $LINENO
5419stdin:
5420 echo A $LINENO
5421 echo B $LINENO
5422 . ./dotfile
5423expected-stdout:
5424 A 1
5425 B 2
5426 dot A 1
5427 dot B 2
5428 dot C 20
5429---
5430name: lineno-func
5431description:
5432 See if $LINENO is set for commands in a function.
5433stdin:
5434 echo A $LINENO
5435 echo B $LINENO
5436 bar() {
5437 echo func A $LINENO
5438 echo func B $LINENO
5439 }
5440 bar
5441 echo C $LINENO
5442expected-stdout:
5443 A 1
5444 B 2
5445 func A 4
5446 func B 5
5447 C 8
5448---
5449name: lineno-unset
5450description:
5451 See if unsetting LINENO makes it non-magic.
5452file-setup: file 644 "dotfile"
5453 echo dot A $LINENO
5454 echo dot B $LINENO
5455stdin:
5456 unset LINENO
5457 echo A $LINENO
5458 echo B $LINENO
5459 bar() {
5460 echo func A $LINENO
5461 echo func B $LINENO
5462 }
5463 bar
5464 . ./dotfile
5465 echo C $LINENO
5466expected-stdout:
5467 A
5468 B
5469 func A
5470 func B
5471 dot A
5472 dot B
5473 C
5474---
5475name: lineno-unset-use
5476description:
5477 See if unsetting LINENO makes it non-magic even
5478 when it is re-used.
5479file-setup: file 644 "dotfile"
5480 echo dot A $LINENO
5481 echo dot B $LINENO
5482stdin:
5483 unset LINENO
5484 LINENO=3
5485 echo A $LINENO
5486 echo B $LINENO
5487 bar() {
5488 echo func A $LINENO
5489 echo func B $LINENO
5490 }
5491 bar
5492 . ./dotfile
5493 echo C $LINENO
5494expected-stdout:
5495 A 3
5496 B 3
5497 func A 3
5498 func B 3
5499 dot A 3
5500 dot B 3
5501 C 3
5502---
5503name: lineno-trap
5504description:
5505 Check if LINENO is tracked in traps
5506stdin:
5507 fail() {
5508 echo "line <$1>"
5509 exit 1
5510 }
5511 trap 'fail $LINENO' INT ERR
5512 false
5513expected-stdout:
5514 line <6>
5515expected-exit: 1
5516---
Elliott Hughesa3c3f962017-04-12 16:52:30 -07005517name: lineno-eval-alias
5518description:
5519 Check if LINENO is trapped in eval and aliases
5520stdin:
5521 ${ZSH_VERSION+false} || emulate sh; echo $LINENO
5522 echo $LINENO
5523 eval ' echo $LINENO
5524 echo $LINENO
5525 echo $LINENO'
5526 echo $LINENO
5527expected-stdout:
5528 1
5529 2
5530 3
5531 3
5532 3
5533 6
5534---
Geremy Condra03ebf062011-10-12 18:17:24 -07005535name: unknown-trap
5536description:
5537 Ensure unknown traps are not a syntax error
5538stdin:
5539 (
5540 trap "echo trap 1 executed" UNKNOWNSIGNAL || echo "foo"
5541 echo =1
5542 trap "echo trap 2 executed" UNKNOWNSIGNAL EXIT 999999 FNORD
5543 echo = $?
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005544 ) 2>&1 | sed "s^${__progname%.exe}\.*e*x*e*: <stdin>\[[0-9]*]PROG"
Geremy Condra03ebf062011-10-12 18:17:24 -07005545expected-stdout:
5546 PROG: trap: bad signal 'UNKNOWNSIGNAL'
5547 foo
5548 =1
5549 PROG: trap: bad signal 'UNKNOWNSIGNAL'
5550 PROG: trap: bad signal '999999'
5551 PROG: trap: bad signal 'FNORD'
Elliott Hughes96b43632015-07-17 11:39:41 -07005552 = 1
Geremy Condra03ebf062011-10-12 18:17:24 -07005553 trap 2 executed
5554---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07005555name: read-IFS-1
5556description:
5557 Simple test, default IFS
5558stdin:
5559 echo "A B " > IN
5560 unset x y z
5561 read x y z < IN
5562 echo 1: "x[$x] y[$y] z[$z]"
5563 echo 1a: ${z-z not set}
5564 read x < IN
5565 echo 2: "x[$x]"
5566expected-stdout:
5567 1: x[A] y[B] z[]
5568 1a:
5569 2: x[A B]
5570---
Elliott Hughesb27ce952015-04-21 13:39:18 -07005571name: read-IFS-2
5572description:
5573 Complex tests, IFS either colon (IFS-NWS) or backslash (tricky)
5574stdin:
5575 n=0
5576 showargs() { print -nr "$1"; shift; for s_arg in "$@"; do print -nr -- " [$s_arg]"; done; print; }
5577 (IFS=\\ a=\<\\\>; showargs 3 $a)
5578 (IFS=: b=\<:\>; showargs 4 $b)
5579 print -r '<\>' | (IFS=\\ read f g; showargs 5 "$f" "$g")
5580 print -r '<\\>' | (IFS=\\ read f g; showargs 6 "$f" "$g")
5581 print '<\\\n>' | (IFS=\\ read f g; showargs 7 "$f" "$g")
5582 print -r '<\>' | (IFS=\\ read f; showargs 8 "$f")
5583 print -r '<\\>' | (IFS=\\ read f; showargs 9 "$f")
5584 print '<\\\n>' | (IFS=\\ read f; showargs 10 "$f")
5585 print -r '<\>' | (IFS=\\ read -r f g; showargs 11 "$f" "$g")
5586 print -r '<\\>' | (IFS=\\ read -r f g; showargs 12 "$f" "$g")
5587 print '<\\\n>' | (IFS=\\ read -r f g; showargs 13 "$f" "$g")
5588 print -r '<\>' | (IFS=\\ read -r f; showargs 14 "$f")
5589 print -r '<\\>' | (IFS=\\ read -r f; showargs 15 "$f")
5590 print '<\\\n>' | (IFS=\\ read -r f; showargs 16 "$f")
5591 print -r '<:>' | (IFS=: read f g; showargs 17 "$f" "$g")
5592 print -r '<::>' | (IFS=: read f g; showargs 18 "$f" "$g")
5593 print '<:\n>' | (IFS=: read f g; showargs 19 "$f" "$g")
5594 print -r '<:>' | (IFS=: read f; showargs 20 "$f")
5595 print -r '<::>' | (IFS=: read f; showargs 21 "$f")
5596 print '<:\n>' | (IFS=: read f; showargs 22 "$f")
5597 print -r '<:>' | (IFS=: read -r f g; showargs 23 "$f" "$g")
5598 print -r '<::>' | (IFS=: read -r f g; showargs 24 "$f" "$g")
5599 print '<:\n>' | (IFS=: read -r f g; showargs 25 "$f" "$g")
5600 print -r '<:>' | (IFS=: read -r f; showargs 26 "$f")
5601 print -r '<::>' | (IFS=: read -r f; showargs 27 "$f")
5602 print '<:\n>' | (IFS=: read -r f; showargs 28 "$f")
5603expected-stdout:
5604 3 [<] [>]
5605 4 [<] [>]
5606 5 [<] [>]
5607 6 [<] [>]
5608 7 [<>] []
5609 8 [<>]
5610 9 [<\>]
5611 10 [<>]
5612 11 [<] [>]
5613 12 [<] [\>]
5614 13 [<] []
5615 14 [<\>]
5616 15 [<\\>]
5617 16 [<]
5618 17 [<] [>]
5619 18 [<] [:>]
5620 19 [<] []
5621 20 [<:>]
5622 21 [<::>]
5623 22 [<]
5624 23 [<] [>]
5625 24 [<] [:>]
5626 25 [<] []
5627 26 [<:>]
5628 27 [<::>]
5629 28 [<]
5630---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07005631name: read-ksh-1
5632description:
5633 If no var specified, REPLY is used
5634stdin:
5635 echo "abc" > IN
5636 read < IN
5637 echo "[$REPLY]";
5638expected-stdout:
5639 [abc]
5640---
Geremy Condra03ebf062011-10-12 18:17:24 -07005641name: read-regress-1
5642description:
5643 Check a regression of read
5644file-setup: file 644 "foo"
5645 foo bar
5646 baz
5647 blah
5648stdin:
5649 while read a b c; do
5650 read d
5651 break
5652 done <foo
5653 echo "<$a|$b|$c><$d>"
5654expected-stdout:
5655 <foo|bar|><baz>
5656---
5657name: read-delim-1
5658description:
5659 Check read with delimiters
5660stdin:
5661 emit() {
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005662 print -n 'foo bar\tbaz\nblah \0blub\tblech\nmyok meck \0'
Geremy Condra03ebf062011-10-12 18:17:24 -07005663 }
5664 emit | while IFS= read -d "" foo; do print -r -- "<$foo>"; done
5665 emit | while read -d "" foo; do print -r -- "<$foo>"; done
5666 emit | while read -d "eh?" foo; do print -r -- "<$foo>"; done
5667expected-stdout:
5668 <foo bar baz
5669 blah >
5670 <blub blech
5671 myok meck >
5672 <foo bar baz
5673 blah>
5674 <blub blech
5675 myok meck>
5676 <foo bar baz
5677 blah blub bl>
5678 <ch
5679 myok m>
5680---
5681name: read-ext-1
5682description:
5683 Check read with number of bytes specified, and -A
5684stdin:
5685 print 'foo\nbar' >x1
5686 print -n x >x2
5687 print 'foo\\ bar baz' >x3
5688 x1a=u; read x1a <x1
5689 x1b=u; read -N-1 x1b <x1
5690 x2a=u; read x2a <x2; r2a=$?
5691 x2b=u; read -N2 x2c <x2; r2b=$?
5692 x2c=u; read -n2 x2c <x2; r2c=$?
5693 x3a=u; read -A x3a <x3
5694 print -r "x1a=<$x1a>"
5695 print -r "x1b=<$x1b>"
5696 print -r "x2a=$r2a<$x2a>"
5697 print -r "x2b=$r2b<$x2b>"
5698 print -r "x2c=$r2c<$x2c>"
5699 print -r "x3a=<${x3a[0]}|${x3a[1]}|${x3a[2]}>"
5700expected-stdout:
5701 x1a=<foo>
5702 x1b=<foo
5703 bar>
5704 x2a=1<x>
5705 x2b=1<u>
5706 x2c=0<x>
5707 x3a=<foo bar|baz|>
5708---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07005709name: regression-1
5710description:
5711 Lex array code had problems with this.
5712stdin:
5713 echo foo[
5714 n=bar
5715 echo "hi[ $n ]=1"
5716expected-stdout:
5717 foo[
5718 hi[ bar ]=1
5719---
5720name: regression-2
5721description:
5722 When PATH is set before running a command, the new path is
5723 not used in doing the path search
5724 $ echo echo hi > /tmp/q ; chmod a+rx /tmp/q
5725 $ PATH=/tmp q
5726 q: not found
5727 $
5728 in comexec() the two lines
5729 while (*vp != NULL)
5730 (void) typeset(*vp++, xxx, 0);
5731 need to be moved out of the switch to before findcom() is
5732 called - I don't know what this will break.
5733stdin:
Elliott Hughes96b43632015-07-17 11:39:41 -07005734 : "${PWD:-`pwd 2> /dev/null`}"
Elliott Hughesfc0307d2016-02-02 15:26:47 -08005735 : "${PWD:?"PWD not set - cannot do test"}"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07005736 mkdir Y
5737 cat > Y/xxxscript << EOF
5738 #!/bin/sh
5739 # Need to restore path so echo can be found (some shells don't have
5740 # it as a built-in)
5741 PATH=\$OLDPATH
5742 echo hi
5743 exit 0
5744 EOF
5745 chmod a+rx Y/xxxscript
5746 export OLDPATH="$PATH"
5747 PATH=$PWD/Y xxxscript
5748 exit $?
5749expected-stdout:
5750 hi
5751---
5752name: regression-6
5753description:
5754 Parsing of $(..) expressions is non-optimal. It is
5755 impossible to have any parentheses inside the expression.
5756 I.e.,
5757 $ ksh -c 'echo $(echo \( )'
5758 no closing quote
5759 $ ksh -c 'echo $(echo "(" )'
5760 no closing quote
5761 $
5762 The solution is to hack the parsing clode in lex.c, the
5763 question is how to hack it: should any parentheses be
5764 escaped by a backslash, or should recursive parsing be done
5765 (so quotes could also be used to hide hem). The former is
5766 easier, the later better...
5767stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005768 echo $(echo \( )
5769 echo $(echo "(" )
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07005770expected-stdout:
5771 (
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005772 (
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07005773---
5774name: regression-9
5775description:
5776 Continue in a for loop does not work right:
5777 for i in a b c ; do
5778 if [ $i = b ] ; then
5779 continue
5780 fi
5781 echo $i
5782 done
5783 Prints a forever...
5784stdin:
5785 first=yes
5786 for i in a b c ; do
5787 if [ $i = b ] ; then
5788 if [ $first = no ] ; then
5789 echo 'continue in for loop broken'
5790 break # hope break isn't broken too :-)
5791 fi
5792 first=no
5793 continue
5794 fi
5795 done
5796 echo bye
5797expected-stdout:
5798 bye
5799---
5800name: regression-10
5801description:
5802 The following:
5803 set -- `false`
5804 echo $?
5805 should print 0 according to POSIX (dash, bash, ksh93, posh)
5806 but not 0 according to the getopt(1) manual page, ksh88, and
5807 Bourne sh (such as /bin/sh on Solaris).
Thorsten Glaser811a5752013-07-25 14:24:45 +00005808 We honour POSIX except when -o sh is set.
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005809category: shell:legacy-no
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07005810stdin:
5811 showf() {
5812 [[ -o posix ]]; FPOSIX=$((1-$?))
5813 [[ -o sh ]]; FSH=$((1-$?))
5814 echo -n "FPOSIX=$FPOSIX FSH=$FSH "
5815 }
5816 set +o posix +o sh
5817 showf
5818 set -- `false`
5819 echo rv=$?
5820 set -o sh
5821 showf
5822 set -- `false`
5823 echo rv=$?
5824 set -o posix
5825 showf
5826 set -- `false`
5827 echo rv=$?
Thorsten Glaser811a5752013-07-25 14:24:45 +00005828 set -o posix -o sh
5829 showf
5830 set -- `false`
5831 echo rv=$?
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07005832expected-stdout:
5833 FPOSIX=0 FSH=0 rv=0
5834 FPOSIX=0 FSH=1 rv=1
5835 FPOSIX=1 FSH=0 rv=0
Thorsten Glaser811a5752013-07-25 14:24:45 +00005836 FPOSIX=1 FSH=1 rv=0
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07005837---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005838name: regression-10-legacy
5839description:
5840 The following:
5841 set -- `false`
5842 echo $?
5843 should print 0 according to POSIX (dash, bash, ksh93, posh)
5844 but not 0 according to the getopt(1) manual page, ksh88, and
5845 Bourne sh (such as /bin/sh on Solaris).
5846category: shell:legacy-yes
5847stdin:
5848 showf() {
5849 [[ -o posix ]]; FPOSIX=$((1-$?))
5850 [[ -o sh ]]; FSH=$((1-$?))
5851 echo -n "FPOSIX=$FPOSIX FSH=$FSH "
5852 }
5853 set +o posix +o sh
5854 showf
5855 set -- `false`
5856 echo rv=$?
5857 set -o sh
5858 showf
5859 set -- `false`
5860 echo rv=$?
5861 set -o posix
5862 showf
5863 set -- `false`
5864 echo rv=$?
Thorsten Glaser811a5752013-07-25 14:24:45 +00005865 set -o posix -o sh
5866 showf
5867 set -- `false`
5868 echo rv=$?
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005869expected-stdout:
5870 FPOSIX=0 FSH=0 rv=1
5871 FPOSIX=0 FSH=1 rv=1
Thorsten Glaser811a5752013-07-25 14:24:45 +00005872 FPOSIX=1 FSH=0 rv=0
5873 FPOSIX=1 FSH=1 rv=0
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005874---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07005875name: regression-11
5876description:
5877 The following:
5878 x=/foo/bar/blah
5879 echo ${x##*/}
5880 should echo blah but on some machines echos /foo/bar/blah.
5881stdin:
5882 x=/foo/bar/blah
5883 echo ${x##*/}
5884expected-stdout:
5885 blah
5886---
5887name: regression-12
5888description:
5889 Both of the following echos produce the same output under sh/ksh.att:
5890 #!/bin/sh
5891 x="foo bar"
5892 echo "`echo \"$x\"`"
5893 echo "`echo "$x"`"
5894 pdksh produces different output for the former (foo instead of foo\tbar)
5895stdin:
5896 x="foo bar"
5897 echo "`echo \"$x\"`"
5898 echo "`echo "$x"`"
5899expected-stdout:
5900 foo bar
5901 foo bar
5902---
5903name: regression-13
5904description:
5905 The following command hangs forever:
5906 $ (: ; cat /etc/termcap) | sleep 2
5907 This is because the shell forks a shell to run the (..) command
5908 and this shell has the pipe open. When the sleep dies, the cat
5909 doesn't get a SIGPIPE 'cause a process (ie, the second shell)
5910 still has the pipe open.
5911
5912 NOTE: this test provokes a bizarre bug in ksh93 (shell starts reading
5913 commands from /etc/termcap..)
5914time-limit: 10
5915stdin:
5916 echo A line of text that will be duplicated quite a number of times.> t1
5917 cat t1 t1 t1 t1 t1 t1 t1 t1 t1 t1 t1 t1 t1 t1 t1 t1 > t2
5918 cat t2 t2 t2 t2 t2 t2 t2 t2 t2 t2 t2 t2 t2 t2 t2 t2 > t1
5919 cat t1 t1 t1 t1 > t2
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005920 (: ; cat t2 2>/dev/null) | sleep 1
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07005921---
5922name: regression-14
5923description:
5924 The command
5925 $ (foobar) 2> /dev/null
5926 generates no output under /bin/sh, but pdksh produces the error
5927 foobar: not found
5928 Also, the command
5929 $ foobar 2> /dev/null
5930 generates an error under /bin/sh and pdksh, but AT&T ksh88 produces
5931 no error (redirected to /dev/null).
5932stdin:
5933 (you/should/not/see/this/error/1) 2> /dev/null
5934 you/should/not/see/this/error/2 2> /dev/null
5935 true
5936---
5937name: regression-15
5938description:
5939 The command
5940 $ whence foobar
5941 generates a blank line under pdksh and sets the exit status to 0.
5942 AT&T ksh88 generates no output and sets the exit status to 1. Also,
5943 the command
5944 $ whence foobar cat
5945 generates no output under AT&T ksh88 (pdksh generates a blank line
5946 and /bin/cat).
5947stdin:
5948 whence does/not/exist > /dev/null
5949 echo 1: $?
5950 echo 2: $(whence does/not/exist | wc -l)
5951 echo 3: $(whence does/not/exist cat | wc -l)
5952expected-stdout:
5953 1: 1
5954 2: 0
5955 3: 0
5956---
5957name: regression-16
5958description:
5959 ${var%%expr} seems to be broken in many places. On the mips
5960 the commands
5961 $ read line < /etc/passwd
5962 $ echo $line
5963 root:0:1:...
5964 $ echo ${line%%:*}
5965 root
5966 $ echo $line
5967 root
5968 $
5969 change the value of line. On sun4s & pas, the echo ${line%%:*} doesn't
5970 work. Haven't checked elsewhere...
5971script:
5972 read x
5973 y=$x
5974 echo ${x%%:*}
5975 echo $x
5976stdin:
5977 root:asdjhasdasjhs:0:1:Root:/:/bin/sh
5978expected-stdout:
5979 root
5980 root:asdjhasdasjhs:0:1:Root:/:/bin/sh
5981---
5982name: regression-17
5983description:
5984 The command
5985 . /foo/bar
5986 should set the exit status to non-zero (sh and AT&T ksh88 do).
5987 XXX doting a non existent file is a fatal error for a script
5988stdin:
5989 . does/not/exist
5990expected-exit: e != 0
5991expected-stderr-pattern: /.?/
5992---
5993name: regression-19
5994description:
5995 Both of the following echos should produce the same thing, but don't:
5996 $ x=foo/bar
5997 $ echo ${x%/*}
5998 foo
5999 $ echo "${x%/*}"
6000 foo/bar
6001stdin:
6002 x=foo/bar
6003 echo "${x%/*}"
6004expected-stdout:
6005 foo
6006---
6007name: regression-21
6008description:
6009 backslash does not work as expected in case labels:
6010 $ x='-x'
6011 $ case $x in
6012 -\?) echo hi
6013 esac
6014 hi
6015 $ x='-?'
6016 $ case $x in
6017 -\\?) echo hi
6018 esac
6019 hi
6020 $
6021stdin:
6022 case -x in
6023 -\?) echo fail
6024 esac
6025---
6026name: regression-22
6027description:
6028 Quoting backquotes inside backquotes doesn't work:
6029 $ echo `echo hi \`echo there\` folks`
6030 asks for more info. sh and AT&T ksh88 both echo
6031 hi there folks
6032stdin:
6033 echo `echo hi \`echo there\` folks`
6034expected-stdout:
6035 hi there folks
6036---
6037name: regression-23
6038description:
6039 )) is not treated `correctly':
6040 $ (echo hi ; (echo there ; echo folks))
6041 missing ((
6042 $
6043 instead of (as sh and ksh.att)
6044 $ (echo hi ; (echo there ; echo folks))
6045 hi
6046 there
6047 folks
6048 $
6049stdin:
6050 ( : ; ( : ; echo hi))
6051expected-stdout:
6052 hi
6053---
6054name: regression-25
6055description:
6056 Check reading stdin in a while loop. The read should only read
6057 a single line, not a whole stdio buffer; the cat should get
6058 the rest.
6059stdin:
6060 (echo a; echo b) | while read x ; do
6061 echo $x
6062 cat > /dev/null
6063 done
6064expected-stdout:
6065 a
6066---
6067name: regression-26
6068description:
6069 Check reading stdin in a while loop. The read should read both
6070 lines, not just the first.
6071script:
6072 a=
6073 while [ "$a" != xxx ] ; do
6074 last=$x
6075 read x
6076 cat /dev/null | sed 's/x/y/'
6077 a=x$a
6078 done
6079 echo $last
6080stdin:
6081 a
6082 b
6083expected-stdout:
6084 b
6085---
6086name: regression-27
6087description:
6088 The command
6089 . /does/not/exist
6090 should cause a script to exit.
6091stdin:
6092 . does/not/exist
6093 echo hi
6094expected-exit: e != 0
6095expected-stderr-pattern: /does\/not\/exist/
6096---
6097name: regression-28
6098description:
6099 variable assignements not detected well
6100stdin:
6101 a.x=1 echo hi
6102expected-exit: e != 0
6103expected-stderr-pattern: /a\.x=1/
6104---
6105name: regression-29
6106description:
6107 alias expansion different from AT&T ksh88
6108stdin:
6109 alias a='for ' b='i in'
6110 a b hi ; do echo $i ; done
6111expected-stdout:
6112 hi
6113---
6114name: regression-30
6115description:
6116 strange characters allowed inside ${...}
6117stdin:
6118 echo ${a{b}}
6119expected-exit: e != 0
6120expected-stderr-pattern: /.?/
6121---
6122name: regression-31
6123description:
6124 Does read handle partial lines correctly
6125script:
6126 a= ret=
6127 while [ "$a" != xxx ] ; do
6128 read x y z
6129 ret=$?
6130 a=x$a
6131 done
6132 echo "[$x]"
6133 echo $ret
6134stdin: !
6135 a A aA
6136 b B Bb
6137 c
6138expected-stdout:
6139 [c]
6140 1
6141---
6142name: regression-32
6143description:
6144 Does read set variables to null at eof?
6145script:
6146 a=
6147 while [ "$a" != xxx ] ; do
6148 read x y z
6149 a=x$a
6150 done
6151 echo 1: ${x-x not set} ${y-y not set} ${z-z not set}
6152 echo 2: ${x:+x not null} ${y:+y not null} ${z:+z not null}
6153stdin:
6154 a A Aa
6155 b B Bb
6156expected-stdout:
6157 1:
6158 2:
6159---
6160name: regression-33
6161description:
6162 Does umask print a leading 0 when umask is 3 digits?
6163stdin:
Geremy Condra03ebf062011-10-12 18:17:24 -07006164 # on MiNT, the first umask call seems to fail
6165 umask 022
6166 # now, the test proper
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006167 umask 222
6168 umask
6169expected-stdout:
6170 0222
6171---
6172name: regression-35
6173description:
6174 Tempory files used for here-docs in functions get trashed after
6175 the function is parsed (before it is executed)
6176stdin:
6177 f1() {
6178 cat <<- EOF
6179 F1
6180 EOF
6181 f2() {
6182 cat <<- EOF
6183 F2
6184 EOF
6185 }
6186 }
6187 f1
6188 f2
6189 unset -f f1
6190 f2
6191expected-stdout:
6192 F1
6193 F2
6194 F2
6195---
6196name: regression-36
6197description:
6198 Command substitution breaks reading in while loop
6199 (test from <sjg@void.zen.oz.au>)
6200stdin:
6201 (echo abcdef; echo; echo 123) |
6202 while read line
6203 do
6204 # the following line breaks it
6205 c=`echo $line | wc -c`
6206 echo $c
6207 done
6208expected-stdout:
6209 7
6210 1
6211 4
6212---
6213name: regression-37
6214description:
6215 Machines with broken times() (reported by <sjg@void.zen.oz.au>)
6216 time does not report correct real time
6217stdin:
6218 time sleep 1
6219expected-stderr-pattern: !/^\s*0\.0[\s\d]+real|^\s*real[\s]+0+\.0/
6220---
6221name: regression-38
6222description:
6223 set -e doesn't ignore exit codes for if/while/until/&&/||/!.
6224arguments: !-e!
6225stdin:
6226 if false; then echo hi ; fi
6227 false || true
6228 false && true
6229 while false; do echo hi; done
6230 echo ok
6231expected-stdout:
6232 ok
6233---
6234name: regression-39
6235description:
Thorsten Glaser811a5752013-07-25 14:24:45 +00006236 Only posh and oksh(2013-07) say “hi” below; FreeBSD sh,
6237 GNU bash in POSIX mode, dash, ksh93, mksh don’t. All of
6238 them exit 0. The POSIX behaviour is needed by BSD make.
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006239stdin:
Thorsten Glaser811a5752013-07-25 14:24:45 +00006240 set -e
Elliott Hughes737fdce2014-08-07 12:59:26 -07006241 echo `false; echo hi` $(<this-file-does-not-exist)
Thorsten Glaser811a5752013-07-25 14:24:45 +00006242 echo $?
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006243expected-stdout:
6244
Thorsten Glaser811a5752013-07-25 14:24:45 +00006245 0
Elliott Hughes737fdce2014-08-07 12:59:26 -07006246expected-stderr-pattern: /this-file-does-not-exist/
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006247---
6248name: regression-40
6249description:
6250 This used to cause a core dump
6251env-setup: !RANDOM=12!
6252stdin:
6253 echo hi
6254expected-stdout:
6255 hi
6256---
6257name: regression-41
6258description:
6259 foo should be set to bar (should not be empty)
6260stdin:
6261 foo=`
6262 echo bar`
6263 echo "($foo)"
6264expected-stdout:
6265 (bar)
6266---
6267name: regression-42
6268description:
6269 Can't use command line assignments to assign readonly parameters.
6270stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006271 print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
6272 'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
Elliott Hughes96b43632015-07-17 11:39:41 -07006273 done >env; chmod +x env; PATH=.$PATHSEP$PATH
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006274 foo=bar
6275 readonly foo
6276 foo=stuff env | grep '^foo'
6277expected-exit: e != 0
6278expected-stderr-pattern:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006279 /read-only/
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006280---
6281name: regression-43
6282description:
6283 Can subshells be prefixed by redirections (historical shells allow
6284 this)
6285stdin:
6286 < /dev/null (sed 's/^/X/')
6287---
6288name: regression-45
6289description:
6290 Parameter assignments with [] recognised correctly
6291stdin:
6292 FOO=*[12]
6293 BAR=abc[
6294 MORE=[abc]
6295 JUNK=a[bc
6296 echo "<$FOO>"
6297 echo "<$BAR>"
6298 echo "<$MORE>"
6299 echo "<$JUNK>"
6300expected-stdout:
6301 <*[12]>
6302 <abc[>
6303 <[abc]>
6304 <a[bc>
6305---
6306name: regression-46
6307description:
6308 Check that alias expansion works in command substitutions and
6309 at the end of file.
6310stdin:
6311 alias x='echo hi'
6312 FOO="`x` "
6313 echo "[$FOO]"
6314 x
6315expected-stdout:
6316 [hi ]
6317 hi
6318---
6319name: regression-47
6320description:
6321 Check that aliases are fully read.
6322stdin:
6323 alias x='echo hi;
6324 echo there'
6325 x
6326 echo done
6327expected-stdout:
6328 hi
6329 there
6330 done
6331---
6332name: regression-48
6333description:
6334 Check that (here doc) temp files are not left behind after an exec.
6335stdin:
6336 mkdir foo || exit 1
6337 TMPDIR=$PWD/foo "$__progname" <<- 'EOF'
6338 x() {
6339 sed 's/^/X /' << E_O_F
6340 hi
6341 there
6342 folks
6343 E_O_F
6344 echo "done ($?)"
6345 }
6346 echo=echo; [ -x /bin/echo ] && echo=/bin/echo
6347 exec $echo subtest-1 hi
6348 EOF
6349 echo subtest-1 foo/*
6350 TMPDIR=$PWD/foo "$__progname" <<- 'EOF'
6351 echo=echo; [ -x /bin/echo ] && echo=/bin/echo
6352 sed 's/^/X /' << E_O_F; exec $echo subtest-2 hi
6353 a
6354 few
6355 lines
6356 E_O_F
6357 EOF
6358 echo subtest-2 foo/*
6359expected-stdout:
6360 subtest-1 hi
6361 subtest-1 foo/*
6362 X a
6363 X few
6364 X lines
6365 subtest-2 hi
6366 subtest-2 foo/*
6367---
6368name: regression-49
6369description:
6370 Check that unset params with attributes are reported by set, those
6371 sans attributes are not.
6372stdin:
6373 unset FOO BAR
6374 echo X$FOO
6375 export BAR
6376 typeset -i BLAH
6377 set | grep FOO
6378 set | grep BAR
6379 set | grep BLAH
6380expected-stdout:
6381 X
6382 BAR
6383 BLAH
6384---
6385name: regression-50
6386description:
6387 Check that aliases do not use continuation prompt after trailing
6388 semi-colon.
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006389file-setup: file 644 "envf"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006390 PS1=Y
6391 PS2=X
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006392env-setup: !ENV=./envf!
Geremy Condra03ebf062011-10-12 18:17:24 -07006393need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006394arguments: !-i!
6395stdin:
6396 alias foo='echo hi ; '
6397 foo
6398 foo echo there
6399expected-stdout:
6400 hi
6401 hi
6402 there
6403expected-stderr: !
6404 YYYY
6405---
6406name: regression-51
6407description:
6408 Check that set allows both +o and -o options on same command line.
6409stdin:
6410 set a b c
6411 set -o noglob +o allexport
6412 echo A: $*, *
6413expected-stdout:
6414 A: a b c, *
6415---
6416name: regression-52
6417description:
6418 Check that globbing works in pipelined commands
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006419file-setup: file 644 "envf"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006420 PS1=P
6421file-setup: file 644 "abc"
6422 stuff
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006423env-setup: !ENV=./envf!
Geremy Condra03ebf062011-10-12 18:17:24 -07006424need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006425arguments: !-i!
6426stdin:
6427 sed 's/^/X /' < ab*
6428 echo mark 1
6429 sed 's/^/X /' < ab* | sed 's/^/Y /'
6430 echo mark 2
6431expected-stdout:
6432 X stuff
6433 mark 1
6434 Y X stuff
6435 mark 2
6436expected-stderr: !
6437 PPPPP
6438---
6439name: regression-53
6440description:
6441 Check that getopts works in functions
6442stdin:
6443 bfunc() {
6444 echo bfunc: enter "(args: $*; OPTIND=$OPTIND)"
6445 while getopts B oc; do
6446 case $oc in
6447 (B)
6448 echo bfunc: B option
6449 ;;
6450 (*)
6451 echo bfunc: odd option "($oc)"
6452 ;;
6453 esac
6454 done
6455 echo bfunc: leave
6456 }
6457
6458 function kfunc {
6459 echo kfunc: enter "(args: $*; OPTIND=$OPTIND)"
6460 while getopts K oc; do
6461 case $oc in
6462 (K)
6463 echo kfunc: K option
6464 ;;
6465 (*)
6466 echo bfunc: odd option "($oc)"
6467 ;;
6468 esac
6469 done
6470 echo kfunc: leave
6471 }
6472
6473 set -- -f -b -k -l
6474 echo "line 1: OPTIND=$OPTIND"
6475 getopts kbfl optc
6476 echo "line 2: ret=$?, optc=$optc, OPTIND=$OPTIND"
6477 bfunc -BBB blah
6478 echo "line 3: OPTIND=$OPTIND"
6479 getopts kbfl optc
6480 echo "line 4: ret=$?, optc=$optc, OPTIND=$OPTIND"
6481 kfunc -KKK blah
6482 echo "line 5: OPTIND=$OPTIND"
6483 getopts kbfl optc
6484 echo "line 6: ret=$?, optc=$optc, OPTIND=$OPTIND"
6485 echo
6486
6487 OPTIND=1
6488 set -- -fbkl
6489 echo "line 10: OPTIND=$OPTIND"
6490 getopts kbfl optc
6491 echo "line 20: ret=$?, optc=$optc, OPTIND=$OPTIND"
6492 bfunc -BBB blah
6493 echo "line 30: OPTIND=$OPTIND"
6494 getopts kbfl optc
6495 echo "line 40: ret=$?, optc=$optc, OPTIND=$OPTIND"
6496 kfunc -KKK blah
6497 echo "line 50: OPTIND=$OPTIND"
6498 getopts kbfl optc
6499 echo "line 60: ret=$?, optc=$optc, OPTIND=$OPTIND"
6500expected-stdout:
6501 line 1: OPTIND=1
6502 line 2: ret=0, optc=f, OPTIND=2
6503 bfunc: enter (args: -BBB blah; OPTIND=2)
6504 bfunc: B option
6505 bfunc: B option
6506 bfunc: leave
6507 line 3: OPTIND=2
6508 line 4: ret=0, optc=b, OPTIND=3
6509 kfunc: enter (args: -KKK blah; OPTIND=1)
6510 kfunc: K option
6511 kfunc: K option
6512 kfunc: K option
6513 kfunc: leave
6514 line 5: OPTIND=3
6515 line 6: ret=0, optc=k, OPTIND=4
6516
6517 line 10: OPTIND=1
6518 line 20: ret=0, optc=f, OPTIND=2
6519 bfunc: enter (args: -BBB blah; OPTIND=2)
6520 bfunc: B option
6521 bfunc: B option
6522 bfunc: leave
6523 line 30: OPTIND=2
6524 line 40: ret=1, optc=?, OPTIND=2
6525 kfunc: enter (args: -KKK blah; OPTIND=1)
6526 kfunc: K option
6527 kfunc: K option
6528 kfunc: K option
6529 kfunc: leave
6530 line 50: OPTIND=2
6531 line 60: ret=1, optc=?, OPTIND=2
6532---
6533name: regression-54
6534description:
6535 Check that ; is not required before the then in if (( ... )) then ...
6536stdin:
6537 if (( 1 )) then
6538 echo ok dparen
6539 fi
6540 if [[ -n 1 ]] then
6541 echo ok dbrackets
6542 fi
6543expected-stdout:
6544 ok dparen
6545 ok dbrackets
6546---
6547name: regression-55
6548description:
6549 Check ${foo:%bar} is allowed (ksh88 allows it...)
6550stdin:
6551 x=fooXbarXblah
6552 echo 1 ${x%X*}
6553 echo 2 ${x:%X*}
6554 echo 3 ${x%%X*}
6555 echo 4 ${x:%%X*}
6556 echo 5 ${x#*X}
6557 echo 6 ${x:#*X}
6558 echo 7 ${x##*X}
6559 echo 8 ${x:##*X}
6560expected-stdout:
6561 1 fooXbar
6562 2 fooXbar
6563 3 foo
6564 4 foo
6565 5 barXblah
6566 6 barXblah
6567 7 blah
6568 8 blah
6569---
6570name: regression-57
6571description:
6572 Check if typeset output is correct for
6573 uninitialised array elements.
6574stdin:
6575 typeset -i xxx[4]
6576 echo A
6577 typeset -i | grep xxx | sed 's/^/ /'
6578 echo B
6579 typeset | grep xxx | sed 's/^/ /'
6580
6581 xxx[1]=2+5
6582 echo M
6583 typeset -i | grep xxx | sed 's/^/ /'
6584 echo N
6585 typeset | grep xxx | sed 's/^/ /'
6586expected-stdout:
6587 A
6588 xxx
6589 B
6590 typeset -i xxx
6591 M
6592 xxx[1]=7
6593 N
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006594 set -A xxx
6595 typeset -i xxx[1]
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006596---
6597name: regression-58
6598description:
6599 Check if trap exit is ok (exit not mistaken for signal name)
6600stdin:
6601 trap 'echo hi' exit
6602 trap exit 1
6603expected-stdout:
6604 hi
6605---
6606name: regression-59
6607description:
6608 Check if ${#array[*]} is calculated correctly.
6609stdin:
6610 a[12]=hi
6611 a[8]=there
6612 echo ${#a[*]}
6613expected-stdout:
6614 2
6615---
6616name: regression-60
6617description:
6618 Check if default exit status is previous command
6619stdin:
6620 (true; exit)
6621 echo A $?
6622 (false; exit)
6623 echo B $?
6624 ( (exit 103) ; exit)
6625 echo C $?
6626expected-stdout:
6627 A 0
6628 B 1
6629 C 103
6630---
6631name: regression-61
6632description:
6633 Check if EXIT trap is executed for sub shells.
6634stdin:
6635 trap 'echo parent exit' EXIT
6636 echo start
6637 (echo A; echo A last)
6638 echo B
6639 (echo C; trap 'echo sub exit' EXIT; echo C last)
6640 echo parent last
6641expected-stdout:
6642 start
6643 A
6644 A last
6645 B
6646 C
6647 C last
6648 sub exit
6649 parent last
6650 parent exit
6651---
6652name: regression-62
6653description:
6654 Check if test -nt/-ot succeeds if second(first) file is missing.
6655stdin:
Elliott Hughesa3c3f962017-04-12 16:52:30 -07006656 :>a
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006657 test a -nt b && echo nt OK || echo nt BAD
6658 test b -ot a && echo ot OK || echo ot BAD
6659expected-stdout:
6660 nt OK
6661 ot OK
6662---
6663name: regression-63
6664description:
6665 Check if typeset, export, and readonly work
6666stdin:
6667 {
6668 echo FNORD-0
6669 FNORD_A=1
6670 FNORD_B=2
6671 FNORD_C=3
6672 FNORD_D=4
6673 FNORD_E=5
6674 FNORD_F=6
6675 FNORD_G=7
6676 FNORD_H=8
6677 integer FNORD_E FNORD_F FNORD_G FNORD_H
6678 export FNORD_C FNORD_D FNORD_G FNORD_H
6679 readonly FNORD_B FNORD_D FNORD_F FNORD_H
6680 echo FNORD-1
6681 export
6682 echo FNORD-2
6683 export -p
6684 echo FNORD-3
6685 readonly
6686 echo FNORD-4
6687 readonly -p
6688 echo FNORD-5
6689 typeset
6690 echo FNORD-6
6691 typeset -p
6692 echo FNORD-7
6693 typeset -
6694 echo FNORD-8
6695 } | fgrep FNORD
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006696 fnord=(42 23)
6697 typeset -p fnord
6698 echo FNORD-9
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006699expected-stdout:
6700 FNORD-0
6701 FNORD-1
6702 FNORD_C
6703 FNORD_D
6704 FNORD_G
6705 FNORD_H
6706 FNORD-2
6707 export FNORD_C=3
6708 export FNORD_D=4
6709 export FNORD_G=7
6710 export FNORD_H=8
6711 FNORD-3
6712 FNORD_B
6713 FNORD_D
6714 FNORD_F
6715 FNORD_H
6716 FNORD-4
6717 readonly FNORD_B=2
6718 readonly FNORD_D=4
6719 readonly FNORD_F=6
6720 readonly FNORD_H=8
6721 FNORD-5
6722 typeset FNORD_A
6723 typeset -r FNORD_B
6724 typeset -x FNORD_C
6725 typeset -x -r FNORD_D
6726 typeset -i FNORD_E
6727 typeset -i -r FNORD_F
6728 typeset -i -x FNORD_G
6729 typeset -i -x -r FNORD_H
6730 FNORD-6
6731 typeset FNORD_A=1
6732 typeset -r FNORD_B=2
6733 typeset -x FNORD_C=3
6734 typeset -x -r FNORD_D=4
6735 typeset -i FNORD_E=5
6736 typeset -i -r FNORD_F=6
6737 typeset -i -x FNORD_G=7
6738 typeset -i -x -r FNORD_H=8
6739 FNORD-7
6740 FNORD_A=1
6741 FNORD_B=2
6742 FNORD_C=3
6743 FNORD_D=4
6744 FNORD_E=5
6745 FNORD_F=6
6746 FNORD_G=7
6747 FNORD_H=8
6748 FNORD-8
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006749 set -A fnord
6750 typeset fnord[0]=42
6751 typeset fnord[1]=23
6752 FNORD-9
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006753---
6754name: regression-64
6755description:
6756 Check that we can redefine functions calling time builtin
6757stdin:
6758 t() {
6759 time >/dev/null
6760 }
6761 t 2>/dev/null
6762 t() {
6763 time
6764 }
6765---
Geremy Condra03ebf062011-10-12 18:17:24 -07006766name: regression-65
6767description:
6768 check for a regression with sleep builtin and signal mask
6769category: !nojsig
Elliott Hughesdd4abe02018-02-05 15:55:19 -08006770time-limit: 5
Geremy Condra03ebf062011-10-12 18:17:24 -07006771stdin:
6772 sleep 1
6773 echo blub |&
6774 while read -p line; do :; done
6775 echo ok
6776expected-stdout:
6777 ok
6778---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006779name: regression-66
6780description:
6781 Check that quoting is sane
6782category: !nojsig
6783stdin:
6784 ac_space=' '
6785 ac_newline='
6786 '
6787 set | grep ^ac_ |&
6788 set -A lines
6789 while IFS= read -pr line; do
6790 if [[ $line = *space* ]]; then
6791 lines[0]=$line
6792 else
6793 lines[1]=$line
6794 fi
6795 done
6796 for line in "${lines[@]}"; do
6797 print -r -- "$line"
6798 done
6799expected-stdout:
6800 ac_space=' '
6801 ac_newline=$'\n'
6802---
Elliott Hughes77740fc2016-08-12 15:06:53 -07006803name: regression-67
6804description:
6805 Check that we can both break and use source on the same line
6806stdin:
6807 for s in s; do break; done; print -s s
6808---
6809name: regression-68
6810description:
6811 Check that all common arithmetic operators work as expected
6812stdin:
6813 echo 1 $(( a = 5 )) .
6814 echo 2 $(( ++a )) , $(( a++ )) , $(( a )) .
6815 echo 3 $(( --a )) , $(( a-- )) , $(( a )) .
6816 echo 4 $(( a == 5 )) , $(( a == 6 )) .
6817 echo 5 $(( a != 5 )) , $(( a != 6 )) .
6818 echo 6 $(( a *= 3 )) .
6819 echo 7 $(( a /= 5 )) .
6820 echo 8 $(( a %= 2 )) .
6821 echo 9 $(( a += 9 )) .
6822 echo 10 $(( a -= 4 )) .
6823 echo 11 $(( a <<= 1 )) .
6824 echo 12 $(( a >>= 1 )) .
6825 echo 13 $(( a &= 4 )) .
6826 echo 14 $(( a ^= a )) .
6827 echo 15 $(( a |= 5 )) .
6828 echo 16 $(( 5 << 1 )) .
6829 echo 17 $(( 5 >> 1 )) .
6830 echo 18 $(( 5 <= 6 )) , $(( 5 <= 5 )) , $(( 5 <= 4 )) .
6831 echo 19 $(( 5 >= 6 )) , $(( 5 >= 5 )) , $(( 5 >= 4 )) .
6832 echo 20 $(( 5 < 6 )) , $(( 5 < 5 )) , $(( 5 < 4 )) .
6833 echo 21 $(( 5 > 6 )) , $(( 5 > 5 )) , $(( 5 > 4 )) .
6834 echo 22 $(( 0 && 0 )) , $(( 0 && 1 )) , $(( 1 && 0 )) , $(( 1 && 1 )) .
6835 echo 23 $(( 0 || 0 )) , $(( 0 || 1 )) , $(( 1 || 0 )) , $(( 1 || 1 )) .
6836 echo 24 $(( 5 * 3 )) .
6837 echo 25 $(( 7 / 2 )) .
6838 echo 26 $(( 5 % 5 )) , $(( 5 % 4 )) , $(( 5 % 1 )) , $(( 5 % -1 )) , $(( 5 % -2 )) .
6839 echo 27 $(( 5 + 2 )) , $(( 5 + 0 )) , $(( 5 + -2 )) .
6840 echo 28 $(( 5 - 2 )) , $(( 5 - 0 )) , $(( 5 - -2 )) .
6841 echo 29 $(( 6 & 4 )) , $(( 6 & 8 )) .
6842 echo 30 $(( 4 ^ 2 )) , $(( 4 ^ 4 )) .
6843 echo 31 $(( 4 | 2 )) , $(( 4 | 4 )) , $(( 4 | 0 )) .
6844 echo 32 $(( 0 ? 1 : 2 )) , $(( 3 ? 4 : 5 )) .
6845 echo 33 $(( 5 , 2 , 3 )) .
6846 echo 34 $(( ~0 )) , $(( ~1 )) , $(( ~~1 )) , $(( ~~2 )) .
6847 echo 35 $(( !0 )) , $(( !1 )) , $(( !!1 )) , $(( !!2 )) .
6848 echo 36 $(( (5) )) .
6849expected-stdout:
6850 1 5 .
6851 2 6 , 6 , 7 .
6852 3 6 , 6 , 5 .
6853 4 1 , 0 .
6854 5 0 , 1 .
6855 6 15 .
6856 7 3 .
6857 8 1 .
6858 9 10 .
6859 10 6 .
6860 11 12 .
6861 12 6 .
6862 13 4 .
6863 14 0 .
6864 15 5 .
6865 16 10 .
6866 17 2 .
6867 18 1 , 1 , 0 .
6868 19 0 , 1 , 1 .
6869 20 1 , 0 , 0 .
6870 21 0 , 0 , 1 .
6871 22 0 , 0 , 0 , 1 .
6872 23 0 , 1 , 1 , 1 .
6873 24 15 .
6874 25 3 .
6875 26 0 , 1 , 0 , 0 , 1 .
6876 27 7 , 5 , 3 .
6877 28 3 , 5 , 7 .
6878 29 4 , 0 .
6879 30 6 , 0 .
6880 31 6 , 4 , 4 .
6881 32 2 , 4 .
6882 33 3 .
6883 34 -1 , -2 , 1 , 2 .
6884 35 1 , 0 , 1 , 1 .
6885 36 5 .
6886---
6887name: regression-69
6888description:
6889 Check that all non-lksh arithmetic operators work as expected
6890category: shell:legacy-no
6891stdin:
6892 a=5 b=0x80000005
6893 echo 1 $(( a ^<= 1 )) , $(( b ^<= 1 )) .
6894 echo 2 $(( a ^>= 2 )) , $(( b ^>= 2 )) .
6895 echo 3 $(( 5 ^< 1 )) .
6896 echo 4 $(( 5 ^> 1 )) .
6897expected-stdout:
6898 1 10 , 11 .
6899 2 -2147483646 , -1073741822 .
6900 3 10 .
6901 4 -2147483646 .
6902---
Elliott Hughes47086262019-03-26 12:34:31 -07006903name: export-1
6904description:
6905 Check allexport works, basic
6906stdin:
6907 qa=1
6908 set -A qb 2 3
6909 set -a
6910 qc=4
6911 set -A qd 5 6
6912 export -p | grep '^export q'
6913expected-stdout:
6914 export qc=4
6915 export qd[0]=5
6916 export qd[1]=6
6917---
Geremy Condra03ebf062011-10-12 18:17:24 -07006918name: readonly-0
6919description:
6920 Ensure readonly is honoured for assignments and unset
6921stdin:
6922 "$__progname" -c 'u=x; echo $? $u .' || echo aborted, $?
6923 echo =
6924 "$__progname" -c 'readonly u; u=x; echo $? $u .' || echo aborted, $?
6925 echo =
6926 "$__progname" -c 'u=x; readonly u; unset u; echo $? $u .' || echo aborted, $?
6927expected-stdout:
6928 0 x .
6929 =
6930 aborted, 2
6931 =
6932 1 x .
6933expected-stderr-pattern:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006934 /read-only/
Geremy Condra03ebf062011-10-12 18:17:24 -07006935---
6936name: readonly-1
6937description:
6938 http://austingroupbugs.net/view.php?id=367 for export
6939stdin:
6940 "$__progname" -c 'readonly foo; export foo=a; echo $?' || echo aborted, $?
6941expected-stdout:
6942 aborted, 2
6943expected-stderr-pattern:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006944 /read-only/
Geremy Condra03ebf062011-10-12 18:17:24 -07006945---
6946name: readonly-2a
6947description:
6948 Check that getopts works as intended, for readonly-2b to be valid
6949stdin:
6950 "$__progname" -c 'set -- -a b; getopts a c; echo $? $c .; getopts a c; echo $? $c .' || echo aborted, $?
6951expected-stdout:
6952 0 a .
6953 1 ? .
6954---
6955name: readonly-2b
6956description:
6957 http://austingroupbugs.net/view.php?id=367 for getopts
6958stdin:
6959 "$__progname" -c 'readonly c; set -- -a b; getopts a c; echo $? $c .' || echo aborted, $?
6960expected-stdout:
6961 2 .
6962expected-stderr-pattern:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006963 /read-only/
Geremy Condra03ebf062011-10-12 18:17:24 -07006964---
6965name: readonly-3
6966description:
6967 http://austingroupbugs.net/view.php?id=367 for read
6968stdin:
6969 echo x | "$__progname" -c 'read s; echo $? $s .' || echo aborted, $?
6970 echo y | "$__progname" -c 'readonly s; read s; echo $? $s .' || echo aborted, $?
6971expected-stdout:
6972 0 x .
6973 2 .
6974expected-stderr-pattern:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006975 /read-only/
Geremy Condra03ebf062011-10-12 18:17:24 -07006976---
Elliott Hughes737fdce2014-08-07 12:59:26 -07006977name: readonly-4
6978description:
6979 Do not permit bypassing readonly for first array item
6980stdin:
6981 set -A arr -- foo bar
6982 readonly arr
6983 arr=baz
6984 print -r -- "${arr[@]}"
6985expected-exit: e != 0
6986expected-stderr-pattern:
6987 /read[ -]?only/
6988---
Elliott Hughes23925bb2017-09-22 16:04:20 -07006989name: readonly-5
6990description:
6991 Ensure readonly is idempotent
6992stdin:
6993 readonly x=1
6994 readonly x
6995---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006996name: syntax-1
6997description:
6998 Check that lone ampersand is a syntax error
6999stdin:
7000 &
7001expected-exit: e != 0
7002expected-stderr-pattern:
7003 /syntax error/
7004---
7005name: xxx-quoted-newline-1
7006description:
7007 Check that \<newline> works inside of ${}
7008stdin:
7009 abc=2
7010 echo ${ab\
7011 c}
7012expected-stdout:
7013 2
7014---
7015name: xxx-quoted-newline-2
7016description:
7017 Check that \<newline> works at the start of a here document
7018stdin:
7019 cat << EO\
7020 F
7021 hi
7022 EOF
7023expected-stdout:
7024 hi
7025---
7026name: xxx-quoted-newline-3
7027description:
7028 Check that \<newline> works at the end of a here document
7029stdin:
7030 cat << EOF
7031 hi
7032 EO\
7033 F
7034expected-stdout:
7035 hi
7036---
7037name: xxx-multi-assignment-cmd
7038description:
7039 Check that assignments in a command affect subsequent assignments
7040 in the same command
7041stdin:
7042 FOO=abc
7043 FOO=123 BAR=$FOO
7044 echo $BAR
7045expected-stdout:
7046 123
7047---
7048name: xxx-multi-assignment-posix-cmd
7049description:
7050 Check that the behaviour for multiple assignments with a
7051 command name matches POSIX. See:
7052 http://thread.gmane.org/gmane.comp.standards.posix.austin.general/1925
7053stdin:
7054 X=a Y=b; X=$Y Y=$X "$__progname" -c 'echo 1 $X $Y .'; echo 2 $X $Y .
7055 unset X Y Z
7056 X=a Y=${X=b} Z=$X "$__progname" -c 'echo 3 $Z .'
7057 unset X Y Z
7058 X=a Y=${X=b} Z=$X; echo 4 $Z .
7059expected-stdout:
7060 1 b a .
7061 2 a b .
7062 3 b .
7063 4 a .
7064---
7065name: xxx-multi-assignment-posix-nocmd
7066description:
7067 Check that the behaviour for multiple assignments with no
7068 command name matches POSIX (Debian #334182). See:
7069 http://thread.gmane.org/gmane.comp.standards.posix.austin.general/1925
7070stdin:
7071 X=a Y=b; X=$Y Y=$X; echo 1 $X $Y .
7072expected-stdout:
7073 1 b b .
7074---
7075name: xxx-multi-assignment-posix-subassign
7076description:
7077 Check that the behaviour for multiple assignments matches POSIX:
7078 - The assignment words shall be expanded in the current execution
7079 environment.
7080 - The assignments happen in the temporary execution environment.
7081stdin:
7082 unset X Y Z
7083 Z=a Y=${X:=b} sh -c 'echo +$X+ +$Y+ +$Z+'
7084 echo /$X/
7085 # Now for the special case:
7086 unset X Y Z
7087 X= Y=${X:=b} sh -c 'echo +$X+ +$Y+'
7088 echo /$X/
7089expected-stdout:
7090 ++ +b+ +a+
7091 /b/
7092 ++ +b+
7093 /b/
7094---
7095name: xxx-exec-environment-1
7096description:
7097 Check to see if exec sets it's environment correctly
7098stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007099 print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
7100 'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
Elliott Hughes96b43632015-07-17 11:39:41 -07007101 done >env; chmod +x env; PATH=.$PATHSEP$PATH
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007102 FOO=bar exec env
7103expected-stdout-pattern:
7104 /(^|.*\n)FOO=bar\n/
7105---
7106name: xxx-exec-environment-2
7107description:
7108 Check to make sure exec doesn't change environment if a program
7109 isn't exec-ed
7110stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007111 print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
7112 'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
Elliott Hughes96b43632015-07-17 11:39:41 -07007113 done >env; chmod +x env; PATH=.$PATHSEP$PATH
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007114 env >bar1
7115 FOO=bar exec; env >bar2
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007116 cmp -s bar1 bar2
7117---
7118name: exec-function-environment-1
7119description:
7120 Check assignments in function calls and whether they affect
7121 the current execution environment (ksh93, SUSv4)
7122stdin:
7123 f() { a=2; }; g() { b=3; echo y$c-; }; a=1 f; b=2; c=1 g
7124 echo x$a-$b- z$c-
7125expected-stdout:
7126 y1-
7127 x2-3- z1-
7128---
Elliott Hughes23925bb2017-09-22 16:04:20 -07007129name: exec-modern-korn-shell
7130description:
7131 Check that exec can execute any command that makes it
7132 through syntax and parser
7133stdin:
7134 print '#!'"$__progname"'\necho tf' >lq
7135 chmod +x lq
7136 PATH=$PWD
7137 exec 2>&1
7138 foo() { print two; }
7139 print =1
7140 (exec print one)
7141 print =2
7142 (exec foo)
7143 print =3
7144 (exec ls)
7145 print =4
7146 (exec lq)
7147expected-stdout-pattern:
Elliott Hughes47086262019-03-26 12:34:31 -07007148 /=1\none\n=2\ntwo\n=3\n.*: ls: inaccessible or not found\n=4\ntf\n/
Elliott Hughes23925bb2017-09-22 16:04:20 -07007149---
7150name: exec-ksh88
7151description:
7152 Check that exec only executes after a PATH search
7153arguments: !-o!posix!
7154stdin:
7155 print '#!'"$__progname"'\necho tf' >lq
7156 chmod +x lq
7157 PATH=$PWD
7158 exec 2>&1
7159 foo() { print two; }
7160 print =1
7161 (exec print one)
7162 print =2
7163 (exec foo)
7164 print =3
7165 (exec ls)
7166 print =4
7167 (exec lq)
7168expected-stdout-pattern:
Elliott Hughes47086262019-03-26 12:34:31 -07007169 /=1\n.*: print: inaccessible or not found\n=2\n.*: foo: inaccessible or not found\n=3\n.*: ls: inaccessible or not found\n=4\ntf\n/
Elliott Hughes23925bb2017-09-22 16:04:20 -07007170---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007171name: xxx-what-do-you-call-this-1
7172stdin:
7173 echo "${foo:-"a"}*"
7174expected-stdout:
7175 a*
7176---
7177name: xxx-prefix-strip-1
7178stdin:
7179 foo='a cdef'
7180 echo ${foo#a c}
7181expected-stdout:
7182 def
7183---
7184name: xxx-prefix-strip-2
7185stdin:
7186 set a c
7187 x='a cdef'
7188 echo ${x#$*}
7189expected-stdout:
7190 def
7191---
7192name: xxx-variable-syntax-1
7193stdin:
7194 echo ${:}
7195expected-stderr-pattern:
7196 /bad substitution/
7197expected-exit: 1
7198---
7199name: xxx-variable-syntax-2
7200stdin:
7201 set 0
7202 echo ${*:0}
7203expected-stderr-pattern:
7204 /bad substitution/
7205expected-exit: 1
7206---
7207name: xxx-variable-syntax-3
7208stdin:
7209 set -A foo 0
7210 echo ${foo[*]:0}
7211expected-stderr-pattern:
7212 /bad substitution/
7213expected-exit: 1
7214---
Elliott Hughesfc0307d2016-02-02 15:26:47 -08007215name: xxx-variable-syntax-4
7216description:
7217 Not all kinds of trims are currently impossible, check those who do
7218stdin:
7219 foo() {
7220 echo "<$*> X${*:+ }X"
7221 }
7222 foo a b
7223 foo "" c
7224 foo ""
7225 foo "" ""
7226 IFS=:
7227 foo a b
7228 foo "" c
7229 foo ""
7230 foo "" ""
7231 IFS=
7232 foo a b
7233 foo "" c
7234 foo ""
7235 foo "" ""
7236expected-stdout:
7237 <a b> X X
7238 < c> X X
7239 <> XX
7240 < > X X
7241 <a:b> X X
7242 <:c> X X
7243 <> XX
7244 <:> X X
7245 <ab> X X
7246 <c> X X
7247 <> XX
7248 <> XX
7249---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007250name: xxx-substitution-eval-order
7251description:
7252 Check order of evaluation of expressions
7253stdin:
7254 i=1 x= y=
7255 set -A A abc def GHI j G k
7256 echo ${A[x=(i+=1)]#${A[y=(i+=2)]}}
7257 echo $x $y
7258expected-stdout:
7259 HI
7260 2 4
7261---
Elliott Hughes47086262019-03-26 12:34:31 -07007262name: xxx-substitution-eval-order-2
7263description:
7264 Check some corner cases
7265stdin:
7266 unset var
7267 i=42
7268 : ${var+${q[i=777]}} required to be lazy by POSIX
7269 echo 1=$i
7270 var=meow
7271 i=42
7272 : ${var+${q[i=777]}} eval since var is now set
7273 echo 2=$i
7274 unset var
7275 i=42
7276 : ${var#${q[i=777]}} pattern is needed even if var is empty
7277 echo 3=$i
7278 var=meow
7279 i=42
7280 : ${var#${q[i=777]}}
7281 echo 4=$i
7282expected-stdout:
7283 1=42
7284 2=777
7285 3=777
7286 4=777
7287---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007288name: xxx-set-option-1
7289description:
7290 Check option parsing in set
7291stdin:
7292 set -vsA foo -- A 1 3 2
7293 echo ${foo[*]}
7294expected-stderr:
7295 echo ${foo[*]}
7296expected-stdout:
7297 1 2 3 A
7298---
7299name: xxx-exec-1
7300description:
7301 Check that exec exits for built-ins
Geremy Condra03ebf062011-10-12 18:17:24 -07007302need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007303arguments: !-i!
7304stdin:
7305 exec echo hi
7306 echo still herre
7307expected-stdout:
7308 hi
7309expected-stderr-pattern: /.*/
7310---
7311name: xxx-while-1
7312description:
7313 Check the return value of while loops
7314 XXX need to do same for for/select/until loops
7315stdin:
7316 i=x
7317 while [ $i != xxx ] ; do
7318 i=x$i
7319 if [ $i = xxx ] ; then
7320 false
7321 continue
7322 fi
7323 done
7324 echo loop1=$?
7325
7326 i=x
7327 while [ $i != xxx ] ; do
7328 i=x$i
7329 if [ $i = xxx ] ; then
7330 false
7331 break
7332 fi
7333 done
7334 echo loop2=$?
7335
7336 i=x
7337 while [ $i != xxx ] ; do
7338 i=x$i
7339 false
7340 done
7341 echo loop3=$?
7342expected-stdout:
7343 loop1=0
7344 loop2=0
7345 loop3=1
7346---
7347name: xxx-status-1
7348description:
7349 Check that blank lines don't clear $?
Geremy Condra03ebf062011-10-12 18:17:24 -07007350need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007351arguments: !-i!
7352stdin:
7353 (exit 1)
7354 echo $?
7355 (exit 1)
7356
7357 echo $?
7358 true
7359expected-stdout:
7360 1
7361 1
7362expected-stderr-pattern: /.*/
7363---
7364name: xxx-status-2
7365description:
7366 Check that $? is preserved in subshells, includes, traps.
7367stdin:
7368 (exit 1)
7369
7370 echo blank: $?
7371
7372 (exit 2)
7373 (echo subshell: $?)
7374
7375 echo 'echo include: $?' > foo
7376 (exit 3)
7377 . ./foo
7378
7379 trap 'echo trap: $?' ERR
7380 (exit 4)
7381 echo exit: $?
7382expected-stdout:
7383 blank: 1
7384 subshell: 2
7385 include: 3
7386 trap: 4
7387 exit: 4
7388---
Elliott Hughes47086262019-03-26 12:34:31 -07007389name: xxx-stat-1
7390description:
7391 Check that tests on files are consistent
7392stdin:
7393 mkdir a
7394 echo x >a/b
7395 test -e a/b; echo 1e $? .
7396 test -f a/b; echo 1f $? .
7397 chmod 0 a
7398 test -e a/b; echo 2e $? .
7399 test -f a/b; echo 2f $? .
7400 chmod 700 a
7401 test -e a/b; echo 3e $? .
7402 test -f a/b; echo 3f $? .
7403expected-stdout:
7404 1e 0 .
7405 1f 0 .
7406 2e 1 .
7407 2f 1 .
7408 3e 0 .
7409 3f 0 .
7410---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007411name: xxx-clean-chars-1
7412description:
7413 Check MAGIC character is stuffed correctly
7414stdin:
7415 echo `echo [£`
7416expected-stdout:
7417
7418---
7419name: xxx-param-subst-qmark-1
7420description:
7421 Check suppresion of error message with null string. According to
7422 POSIX, it shouldn't print the error as 'word' isn't ommitted.
Elliott Hughesfc0307d2016-02-02 15:26:47 -08007423 ksh88/93, Solaris /bin/sh and /usr/xpg4/bin/sh all print the error.
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007424stdin:
7425 unset foo
7426 x=
7427 echo x${foo?$x}
7428expected-exit: 1
Elliott Hughesfc0307d2016-02-02 15:26:47 -08007429expected-stderr-pattern: !/not set/
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007430---
Elliott Hughes77740fc2016-08-12 15:06:53 -07007431name: xxx-param-subst-qmark-namespec
7432description:
7433 Check special names are output correctly
7434stdin:
7435 doit() {
7436 "$__progname" -c "$@" >o1 2>o2
7437 rv=$?
7438 echo RETVAL: $rv
7439 sed -e "s^${__progname%.exe}\.*e*x*e*: PROG: " -e 's/^/STDOUT: /g' <o1
7440 sed -e "s^${__progname%.exe}\.*e*x*e*: PROG: " -e 's/^/STDERR: /g' <o2
7441 }
7442 doit 'echo ${1x}'
7443 doit 'echo "${1x}"'
7444 doit 'echo ${1?}'
7445 doit 'echo ${19?}'
7446 doit 'echo ${!:?}'
7447 doit -u 'echo ${*:?}' foo ""
7448expected-stdout:
7449 RETVAL: 1
7450 STDERR: PROG: ${1x}: bad substitution
7451 RETVAL: 1
7452 STDERR: PROG: ${1x}: bad substitution
7453 RETVAL: 1
7454 STDERR: PROG: 1: parameter null or not set
7455 RETVAL: 1
7456 STDERR: PROG: 19: parameter null or not set
7457 RETVAL: 1
7458 STDERR: PROG: !: parameter null or not set
7459 RETVAL: 1
7460 STDERR: foo: ${*:?}: bad substitution
7461---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007462name: xxx-param-_-1
7463# fails due to weirdness of execv stuff
7464category: !os:uwin-nt
7465description:
7466 Check c flag is set.
7467arguments: !-c!echo "[$-]"!
7468expected-stdout-pattern: /^\[.*c.*\]$/
7469---
7470name: tilde-expand-1
7471description:
7472 Check tilde expansion after equal signs
7473env-setup: !HOME=/sweet!
7474stdin:
7475 echo ${A=a=}~ b=~ c=d~ ~
Elliott Hughesfc0307d2016-02-02 15:26:47 -08007476 export e=~ f=d~
7477 command command export g=~ h=d~
7478 echo ". $e . $f ."
7479 echo ". $g . $h ."
7480 set -o posix
7481 unset A e f g h
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007482 echo ${A=a=}~ b=~ c=d~ ~
Elliott Hughesfc0307d2016-02-02 15:26:47 -08007483 export e=~ f=d~
7484 command command export g=~ h=d~
7485 echo ". $e . $f ."
7486 echo ". $g . $h ."
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007487expected-stdout:
7488 a=/sweet b=/sweet c=d~ /sweet
Elliott Hughesfc0307d2016-02-02 15:26:47 -08007489 . /sweet . d~ .
7490 . /sweet . d~ .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007491 a=~ b=~ c=d~ /sweet
Elliott Hughesfc0307d2016-02-02 15:26:47 -08007492 . /sweet . d~ .
7493 . /sweet . d~ .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007494---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007495name: tilde-expand-2
7496description:
7497 Check tilde expansion works
7498env-setup: !HOME=/sweet!
7499stdin:
Elliott Hughesa3c3f962017-04-12 16:52:30 -07007500 :>'c=a'
7501 typeset c=[ab]
7502 :>'d=a'
7503 x=typeset; $x d=[ab]
7504 echo "<$c>" "<$d>"
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007505 wd=$PWD
7506 cd /
7507 plus=$(print -r -- ~+)
7508 minus=$(print -r -- ~-)
7509 nix=$(print -r -- ~)
7510 [[ $plus = / ]]; echo one $? .
7511 [[ $minus = "$wd" ]]; echo two $? .
7512 [[ $nix = /sweet ]]; echo nix $? .
7513expected-stdout:
Elliott Hughesa3c3f962017-04-12 16:52:30 -07007514 <[ab]> <a>
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007515 one 0 .
7516 two 0 .
7517 nix 0 .
7518---
Elliott Hughesa3c3f962017-04-12 16:52:30 -07007519name: tilde-expand-3
7520description:
7521 Check mostly Austin 351 stuff
7522stdin:
7523 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
7524 set "1 b=2" "3 d=4"
7525 export a=$1 \c=$2
7526 showargs 1 "$a" "$b" "$c" "$d"
7527 unset a b c d
7528 HOME=/tmp
7529 export \a=~ b=~
7530 command export c=~
7531 builtin export d=~
7532 \\builtin export e=~
7533 showargs 2 "$a" "$b" "$c" "$d" "$e" ksh
7534 unset a b c d e
7535 set -o posix
7536 export \a=~ b=~
7537 command export c=~
7538 builtin export d=~
7539 \\builtin export e=~
7540 showargs 3 "$a" "$b" "$c" "$d" "$e" posix
7541 unset a b c d e
7542 set +o posix
7543 export a=$1
7544 showargs 4 "$a" "$b" ksh
7545 unset a b
7546 showargs 5 a=$1 ksh
7547 export \a=$1
7548 showargs 6 "$a" "$b" ksh
7549 unset a b
7550 set -o posix
7551 export a=$1
7552 showargs 7 "$a" "$b" posix
7553 unset a b
7554 showargs 8 a=$1 posix
7555 export \a=$1
7556 showargs 9 "$a" "$b" posix
7557 unset a b
7558 set +o posix
7559 command echo 10 ksh a=~
7560 command command export a=~
7561 showargs 11 "$a"
7562 unset a
7563 set -o posix
7564 command echo 12 posix a=~
7565 command command export a=~
7566 showargs 13 "$a"
7567 unset a
7568 # unspecified whether /tmp or ~
7569 var=export; command $var a=~
7570 showargs 14 "$a"
7571 echo 'echo "<$foo>"' >bar
7572 "$__progname" bar
7573 var=foo
7574 export $var=1
7575 "$__progname" bar
7576 export $var=~
7577 "$__progname" bar
7578 # unspecified
7579 command -- export a=~
7580 showargs 18 "$a"
7581 set -A bla
7582 typeset bla[1]=~:~
7583 global gbl=~ g2=$1
7584 local lcl=~ l2=$1
7585 readonly ro=~ r2=$1
7586 showargs 19 "${bla[1]}" a=~ "$gbl" "$lcl" "$ro" "$g2" "$l2" "$r2"
7587 set +o posix
7588 echo "20 some arbitrary stuff "=~
7589 set -o posix
7590 echo "21 some arbitrary stuff "=~
7591expected-stdout:
7592 <1> <1 b=2> <> <3> <4> .
7593 <2> </tmp> </tmp> </tmp> </tmp> </tmp> <ksh> .
7594 <3> <~> </tmp> </tmp> <~> </tmp> <posix> .
7595 <4> <1 b=2> <> <ksh> .
7596 <5> <a=1> <b=2> <ksh> .
7597 <6> <1> <2> <ksh> .
7598 <7> <1 b=2> <> <posix> .
7599 <8> <a=1> <b=2> <posix> .
7600 <9> <1> <2> <posix> .
7601 10 ksh a=/tmp
7602 <11> </tmp> .
7603 12 posix a=~
7604 <13> </tmp> .
7605 <14> <~> .
7606 <>
7607 <1>
7608 <~>
7609 <18> <~> .
7610 <19> </tmp:/tmp> <a=~> </tmp> </tmp> </tmp> <1 b=2> <1 b=2> <1 b=2> .
7611 20 some arbitrary stuff =/tmp
7612 21 some arbitrary stuff =~
7613---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007614name: exit-err-1
7615description:
7616 Check some "exit on error" conditions
7617stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007618 print '#!'"$__progname"'\nexec "$1"' >env
7619 print '#!'"$__progname"'\nexit 1' >false
7620 chmod +x env false
Elliott Hughes96b43632015-07-17 11:39:41 -07007621 PATH=.$PATHSEP$PATH
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007622 set -ex
Geremy Condra03ebf062011-10-12 18:17:24 -07007623 env false && echo something
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007624 echo END
7625expected-stdout:
7626 END
7627expected-stderr:
Geremy Condra03ebf062011-10-12 18:17:24 -07007628 + env false
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007629 + echo END
7630---
7631name: exit-err-2
7632description:
7633 Check some "exit on error" edge conditions (POSIXly)
7634stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007635 print '#!'"$__progname"'\nexec "$1"' >env
7636 print '#!'"$__progname"'\nexit 1' >false
7637 print '#!'"$__progname"'\nexit 0' >true
7638 chmod +x env false
Elliott Hughes96b43632015-07-17 11:39:41 -07007639 PATH=.$PATHSEP$PATH
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007640 set -ex
Geremy Condra03ebf062011-10-12 18:17:24 -07007641 if env true; then
7642 env false && echo something
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007643 fi
7644 echo END
7645expected-stdout:
7646 END
7647expected-stderr:
Geremy Condra03ebf062011-10-12 18:17:24 -07007648 + env true
7649 + env false
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007650 + echo END
7651---
7652name: exit-err-3
7653description:
7654 pdksh regression which AT&T ksh does right
7655 TFM says: [set] -e | errexit
7656 Exit (after executing the ERR trap) ...
7657stdin:
7658 trap 'echo EXIT' EXIT
7659 trap 'echo ERR' ERR
7660 set -e
7661 cd /XXXXX 2>/dev/null
7662 echo DONE
7663 exit 0
7664expected-stdout:
7665 ERR
7666 EXIT
7667expected-exit: e != 0
7668---
7669name: exit-err-4
7670description:
7671 "set -e" test suite (POSIX)
7672stdin:
7673 set -e
7674 echo pre
7675 if true ; then
7676 false && echo foo
7677 fi
7678 echo bar
7679expected-stdout:
7680 pre
7681 bar
7682---
7683name: exit-err-5
7684description:
7685 "set -e" test suite (POSIX)
7686stdin:
7687 set -e
7688 foo() {
7689 while [ "$1" ]; do
7690 for E in $x; do
7691 [ "$1" = "$E" ] && { shift ; continue 2 ; }
7692 done
7693 x="$x $1"
7694 shift
7695 done
7696 echo $x
7697 }
7698 echo pre
7699 foo a b b c
7700 echo post
7701expected-stdout:
7702 pre
7703 a b c
7704 post
7705---
7706name: exit-err-6
7707description:
7708 "set -e" test suite (BSD make)
7709category: os:mirbsd
7710stdin:
7711 mkdir zd zd/a zd/b
7712 print 'all:\n\t@echo eins\n\t@exit 42\n' >zd/a/Makefile
7713 print 'all:\n\t@echo zwei\n' >zd/b/Makefile
7714 wd=$(pwd)
7715 set -e
7716 for entry in a b; do ( set -e; if [[ -d $wd/zd/$entry.i386 ]]; then _newdir_="$entry.i386"; else _newdir_="$entry"; fi; if [[ -z $_THISDIR_ ]]; then _nextdir_="$_newdir_"; else _nextdir_="$_THISDIR_/$_newdir_"; fi; _makefile_spec_=; [[ ! -f $wd/zd/$_newdir_/Makefile.bsd-wrapper ]] || _makefile_spec_="-f Makefile.bsd-wrapper"; subskipdir=; for skipdir in ; do subentry=${skipdir#$entry}; if [[ $subentry != $skipdir ]]; then if [[ -z $subentry ]]; then echo "($_nextdir_ skipped)"; break; fi; subskipdir="$subskipdir ${subentry#/}"; fi; done; if [[ -z $skipdir || -n $subentry ]]; then echo "===> $_nextdir_"; cd $wd/zd/$_newdir_; make SKIPDIR="$subskipdir" $_makefile_spec_ _THISDIR_="$_nextdir_" all; fi; ) done 2>&1 | sed "s!$wd!WD!g"
7717expected-stdout:
7718 ===> a
7719 eins
7720 *** Error code 42
7721
7722 Stop in WD/zd/a (line 2 of Makefile).
7723---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007724name: exit-err-7
7725description:
7726 "set -e" regression (LP#1104543)
7727stdin:
7728 set -e
7729 bla() {
7730 [ -x $PWD/nonexistant ] && $PWD/nonexistant
7731 }
7732 echo x
7733 bla
7734 echo y$?
7735expected-stdout:
7736 x
7737expected-exit: 1
7738---
7739name: exit-err-8
7740description:
7741 "set -e" regression (Debian #700526)
7742stdin:
7743 set -e
7744 _db_cmd() { return $1; }
7745 db_input() { _db_cmd 30; }
7746 db_go() { _db_cmd 0; }
7747 db_input || :
7748 db_go
7749 exit 0
7750---
Elliott Hughes966dd552016-12-08 15:56:04 -08007751name: exit-err-9
7752description:
7753 "set -e" versus bang pipelines
7754stdin:
7755 set -e
7756 ! false | false
7757 echo 1 ok
7758 ! false && false
7759 echo 2 wrong
7760expected-stdout:
7761 1 ok
7762expected-exit: 1
7763---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007764name: exit-enoent-1
7765description:
7766 SUSv4 says that the shell should exit with 126/127 in some situations
7767stdin:
7768 i=0
7769 (echo; echo :) >x
7770 "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7771 "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7772 echo exit 42 >x
7773 "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7774 "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7775 rm -f x
7776 "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7777 "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7778expected-stdout:
7779 0 0 .
7780 1 126 .
7781 2 42 .
7782 3 126 .
7783 4 127 .
7784 5 127 .
7785---
7786name: exit-eval-1
7787description:
7788 Check eval vs substitution exit codes (ksh93 alike)
7789stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007790 (exit 12)
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007791 eval $(false)
7792 echo A $?
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007793 (exit 12)
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007794 eval ' $(false)'
7795 echo B $?
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007796 (exit 12)
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007797 eval " $(false)"
7798 echo C $?
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007799 (exit 12)
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007800 eval "eval $(false)"
7801 echo D $?
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007802 (exit 12)
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007803 eval 'eval '"$(false)"
7804 echo E $?
7805 IFS="$IFS:"
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007806 (exit 12)
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007807 eval $(echo :; false)
7808 echo F $?
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007809 echo -n "G "
7810 (exit 12)
7811 eval 'echo $?'
7812 echo H $?
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007813expected-stdout:
7814 A 0
7815 B 1
7816 C 0
7817 D 0
7818 E 0
7819 F 0
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007820 G 12
7821 H 0
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007822---
Geremy Condra03ebf062011-10-12 18:17:24 -07007823name: exit-trap-1
7824description:
7825 Check that "exit" with no arguments behaves SUSv4 conformant.
7826stdin:
7827 trap 'echo hi; exit' EXIT
7828 exit 9
7829expected-stdout:
7830 hi
7831expected-exit: 9
7832---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007833name: exit-trap-2
7834description:
7835 Check that ERR and EXIT traps are run just like ksh93 does.
7836 GNU bash does not run ERtrap in ±e eval-undef but runs it
7837 twice (bug?) in +e eval-false, so does ksh93 (bug?), which
7838 also has a bug to continue execution (echoing "and out" and
7839 returning 0) in +e eval-undef.
7840file-setup: file 644 "x"
7841 v=; unset v
7842 trap 'echo EXtrap' EXIT
7843 trap 'echo ERtrap' ERR
7844 set $1
7845 echo "and run $2"
7846 eval $2
7847 echo and out
7848file-setup: file 644 "xt"
7849 v=; unset v
7850 trap 'echo EXtrap' EXIT
7851 trap 'echo ERtrap' ERR
7852 set $1
7853 echo 'and run true'
7854 true
7855 echo and out
7856file-setup: file 644 "xf"
7857 v=; unset v
7858 trap 'echo EXtrap' EXIT
7859 trap 'echo ERtrap' ERR
7860 set $1
7861 echo 'and run false'
7862 false
7863 echo and out
7864file-setup: file 644 "xu"
7865 v=; unset v
7866 trap 'echo EXtrap' EXIT
7867 trap 'echo ERtrap' ERR
7868 set $1
7869 echo 'and run ${v?}'
7870 ${v?}
7871 echo and out
7872stdin:
7873 runtest() {
7874 rm -f rc
7875 (
7876 "$__progname" "$@"
7877 echo $? >rc
7878 ) 2>&1 | sed \
7879 -e 's/parameter not set/parameter null or not set/' \
7880 -e 's/[[]6]//' -e 's/: eval: line 1//' -e 's/: line 6//' \
7881 -e "s^${__progname%.exe}\.*e*x*e*: <stdin>\[[0-9]*]PROG"
7882 }
7883 xe=-e
7884 echo : $xe
7885 runtest x $xe true
7886 echo = eval-true $(<rc) .
7887 runtest x $xe false
7888 echo = eval-false $(<rc) .
7889 runtest x $xe '${v?}'
7890 echo = eval-undef $(<rc) .
7891 runtest xt $xe
7892 echo = noeval-true $(<rc) .
7893 runtest xf $xe
7894 echo = noeval-false $(<rc) .
7895 runtest xu $xe
7896 echo = noeval-undef $(<rc) .
7897 xe=+e
7898 echo : $xe
7899 runtest x $xe true
7900 echo = eval-true $(<rc) .
7901 runtest x $xe false
7902 echo = eval-false $(<rc) .
7903 runtest x $xe '${v?}'
7904 echo = eval-undef $(<rc) .
7905 runtest xt $xe
7906 echo = noeval-true $(<rc) .
7907 runtest xf $xe
7908 echo = noeval-false $(<rc) .
7909 runtest xu $xe
7910 echo = noeval-undef $(<rc) .
7911expected-stdout:
7912 : -e
7913 and run true
7914 and out
7915 EXtrap
7916 = eval-true 0 .
7917 and run false
7918 ERtrap
7919 EXtrap
7920 = eval-false 1 .
7921 and run ${v?}
7922 x: v: parameter null or not set
7923 ERtrap
7924 EXtrap
7925 = eval-undef 1 .
7926 and run true
7927 and out
7928 EXtrap
7929 = noeval-true 0 .
7930 and run false
7931 ERtrap
7932 EXtrap
7933 = noeval-false 1 .
7934 and run ${v?}
7935 xu: v: parameter null or not set
7936 EXtrap
7937 = noeval-undef 1 .
7938 : +e
7939 and run true
7940 and out
7941 EXtrap
7942 = eval-true 0 .
7943 and run false
7944 ERtrap
7945 and out
7946 EXtrap
7947 = eval-false 0 .
7948 and run ${v?}
7949 x: v: parameter null or not set
7950 ERtrap
7951 EXtrap
7952 = eval-undef 1 .
7953 and run true
7954 and out
7955 EXtrap
7956 = noeval-true 0 .
7957 and run false
7958 ERtrap
7959 and out
7960 EXtrap
7961 = noeval-false 0 .
7962 and run ${v?}
7963 xu: v: parameter null or not set
7964 EXtrap
7965 = noeval-undef 1 .
7966---
Elliott Hughes47086262019-03-26 12:34:31 -07007967name: exit-trap-3
7968description:
7969 Check that the EXIT trap is run in many places, Debian #910276
7970stdin:
7971 fkt() {
7972 trap -- "echo $1 >&2" EXIT
7973 }
7974 fkt shell_exit
7975 $(fkt fn_exit)
7976 $(trap -- "echo comsub_exit >&2" EXIT)
7977 (trap -- "echo subshell_exit >&2" EXIT)
7978expected-stderr:
7979 fn_exit
7980 comsub_exit
7981 subshell_exit
7982 shell_exit
7983---
Thorsten Glaser811a5752013-07-25 14:24:45 +00007984name: exit-trap-interactive
7985description:
7986 Check that interactive shell doesn't exit via EXIT trap on syntax error
7987arguments: !-i!
7988stdin:
7989 trap -- EXIT
7990 echo Syntax error <
7991 echo 'After error 1'
7992 trap 'echo Exit trap' EXIT
7993 echo Syntax error <
7994 echo 'After error 2'
7995 trap 'echo Exit trap' EXIT
7996 exit
7997 echo 'After exit'
7998expected-stdout:
7999 After error 1
8000 After error 2
8001 Exit trap
8002expected-stderr-pattern:
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008003 /syntax error: unexpected 'newline'/
Thorsten Glaser811a5752013-07-25 14:24:45 +00008004---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008005name: test-stlt-1
8006description:
8007 Check that test also can handle string1 < string2 etc.
8008stdin:
8009 test 2005/10/08 '<' 2005/08/21 && echo ja || echo nein
8010 test 2005/08/21 \< 2005/10/08 && echo ja || echo nein
8011 test 2005/10/08 '>' 2005/08/21 && echo ja || echo nein
8012 test 2005/08/21 \> 2005/10/08 && echo ja || echo nein
8013expected-stdout:
8014 nein
8015 ja
8016 ja
8017 nein
8018expected-stderr-pattern: !/unexpected op/
8019---
8020name: test-precedence-1
8021description:
8022 Check a weird precedence case (and POSIX echo)
8023stdin:
8024 test \( -f = -f \)
8025 rv=$?
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00008026 echo $rv
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008027expected-stdout:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00008028 0
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008029---
8030name: test-option-1
8031description:
8032 Test the test -o operator
8033stdin:
8034 runtest() {
8035 test -o $1; echo $?
8036 [ -o $1 ]; echo $?
8037 [[ -o $1 ]]; echo $?
8038 }
8039 if_test() {
8040 test -o $1 -o -o !$1; echo $?
8041 [ -o $1 -o -o !$1 ]; echo $?
8042 [[ -o $1 || -o !$1 ]]; echo $?
8043 test -o ?$1; echo $?
8044 }
8045 echo 0y $(if_test utf8-mode) =
8046 echo 0n $(if_test utf8-hack) =
8047 echo 1= $(runtest utf8-hack) =
8048 echo 2= $(runtest !utf8-hack) =
8049 echo 3= $(runtest ?utf8-hack) =
8050 set +U
8051 echo 1+ $(runtest utf8-mode) =
8052 echo 2+ $(runtest !utf8-mode) =
8053 echo 3+ $(runtest ?utf8-mode) =
8054 set -U
8055 echo 1- $(runtest utf8-mode) =
8056 echo 2- $(runtest !utf8-mode) =
8057 echo 3- $(runtest ?utf8-mode) =
8058 echo = short flags =
8059 echo 0y $(if_test -U) =
8060 echo 0y $(if_test +U) =
8061 echo 0n $(if_test -_) =
8062 echo 0n $(if_test -U-) =
8063 echo 1= $(runtest -_) =
8064 echo 2= $(runtest !-_) =
8065 echo 3= $(runtest ?-_) =
8066 set +U
8067 echo 1+ $(runtest -U) =
8068 echo 2+ $(runtest !-U) =
8069 echo 3+ $(runtest ?-U) =
8070 echo 1+ $(runtest +U) =
8071 echo 2+ $(runtest !+U) =
8072 echo 3+ $(runtest ?+U) =
8073 set -U
8074 echo 1- $(runtest -U) =
8075 echo 2- $(runtest !-U) =
8076 echo 3- $(runtest ?-U) =
8077 echo 1- $(runtest +U) =
8078 echo 2- $(runtest !+U) =
8079 echo 3- $(runtest ?+U) =
8080expected-stdout:
8081 0y 0 0 0 0 =
8082 0n 1 1 1 1 =
8083 1= 1 1 1 =
8084 2= 1 1 1 =
8085 3= 1 1 1 =
8086 1+ 1 1 1 =
8087 2+ 0 0 0 =
8088 3+ 0 0 0 =
8089 1- 0 0 0 =
8090 2- 1 1 1 =
8091 3- 0 0 0 =
8092 = short flags =
8093 0y 0 0 0 0 =
8094 0y 0 0 0 0 =
8095 0n 1 1 1 1 =
8096 0n 1 1 1 1 =
8097 1= 1 1 1 =
8098 2= 1 1 1 =
8099 3= 1 1 1 =
8100 1+ 1 1 1 =
8101 2+ 0 0 0 =
8102 3+ 0 0 0 =
8103 1+ 1 1 1 =
8104 2+ 0 0 0 =
8105 3+ 0 0 0 =
8106 1- 0 0 0 =
8107 2- 1 1 1 =
8108 3- 0 0 0 =
8109 1- 0 0 0 =
8110 2- 1 1 1 =
8111 3- 0 0 0 =
8112---
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008113name: test-varset-1
8114description:
8115 Test the test -v operator
8116stdin:
8117 [[ -v a ]]
8118 rv=$?; echo $((++i)) $rv
8119 a=
8120 [[ -v a ]]
8121 rv=$?; echo $((++i)) $rv
8122 unset a
8123 [[ -v a ]]
8124 rv=$?; echo $((++i)) $rv
8125 a=x
8126 [[ -v a ]]
8127 rv=$?; echo $((++i)) $rv
8128 nameref b=a
8129 [[ -v b ]]
8130 rv=$?; echo $((++i)) $rv
8131 unset a
8132 [[ -v b ]]
8133 rv=$?; echo $((++i)) $rv
8134 x[1]=y
8135 [[ -v x ]]
8136 rv=$?; echo $((++i)) $rv
8137 [[ -v x[0] ]]
8138 rv=$?; echo $((++i)) $rv
8139 [[ -v x[1] ]]
8140 rv=$?; echo $((++i)) $rv
8141 [[ -v x[2] ]]
8142 rv=$?; echo $((++i)) $rv
8143expected-stdout:
8144 1 1
8145 2 0
8146 3 1
8147 4 0
8148 5 0
8149 6 1
8150 7 1
8151 8 1
8152 9 0
8153 10 1
8154---
8155name: test-varset-2
8156description:
8157 test -v works only on scalars
8158stdin:
8159 [[ -v x[*] ]]
8160 echo ok
8161expected-exit: e != 0
8162expected-stderr-pattern:
8163 /unexpected '\*'/
8164---
Elliott Hughesfc0307d2016-02-02 15:26:47 -08008165name: test-stnze-1
8166description:
8167 Check that the short form [ $x ] works
8168stdin:
8169 i=0
8170 [ -n $x ]
8171 rv=$?; echo $((++i)) $rv
8172 [ $x ]
8173 rv=$?; echo $((++i)) $rv
8174 [ -n "$x" ]
8175 rv=$?; echo $((++i)) $rv
8176 [ "$x" ]
8177 rv=$?; echo $((++i)) $rv
8178 x=0
8179 [ -n $x ]
8180 rv=$?; echo $((++i)) $rv
8181 [ $x ]
8182 rv=$?; echo $((++i)) $rv
8183 [ -n "$x" ]
8184 rv=$?; echo $((++i)) $rv
8185 [ "$x" ]
8186 rv=$?; echo $((++i)) $rv
8187 x='1 -a 1 = 2'
8188 [ -n $x ]
8189 rv=$?; echo $((++i)) $rv
8190 [ $x ]
8191 rv=$?; echo $((++i)) $rv
8192 [ -n "$x" ]
8193 rv=$?; echo $((++i)) $rv
8194 [ "$x" ]
8195 rv=$?; echo $((++i)) $rv
8196expected-stdout:
8197 1 0
8198 2 1
8199 3 1
8200 4 1
8201 5 0
8202 6 0
8203 7 0
8204 8 0
8205 9 1
8206 10 1
8207 11 0
8208 12 0
8209---
8210name: test-stnze-2
8211description:
8212 Check that the short form [[ $x ]] works (ksh93 extension)
8213stdin:
8214 i=0
8215 [[ -n $x ]]
8216 rv=$?; echo $((++i)) $rv
8217 [[ $x ]]
8218 rv=$?; echo $((++i)) $rv
8219 [[ -n "$x" ]]
8220 rv=$?; echo $((++i)) $rv
8221 [[ "$x" ]]
8222 rv=$?; echo $((++i)) $rv
8223 x=0
8224 [[ -n $x ]]
8225 rv=$?; echo $((++i)) $rv
8226 [[ $x ]]
8227 rv=$?; echo $((++i)) $rv
8228 [[ -n "$x" ]]
8229 rv=$?; echo $((++i)) $rv
8230 [[ "$x" ]]
8231 rv=$?; echo $((++i)) $rv
8232 x='1 -a 1 = 2'
8233 [[ -n $x ]]
8234 rv=$?; echo $((++i)) $rv
8235 [[ $x ]]
8236 rv=$?; echo $((++i)) $rv
8237 [[ -n "$x" ]]
8238 rv=$?; echo $((++i)) $rv
8239 [[ "$x" ]]
8240 rv=$?; echo $((++i)) $rv
8241expected-stdout:
8242 1 1
8243 2 1
8244 3 1
8245 4 1
8246 5 0
8247 6 0
8248 7 0
8249 8 0
8250 9 0
8251 10 0
8252 11 0
8253 12 0
8254---
8255name: test-numeq
8256description:
8257 Check numeric -eq works (R40d regression); spotted by Martijn Dekker
8258stdin:
8259 tst() {
8260 eval "$2"
8261 case $? in
8262 (0) echo yepp 0 \#"$*" ;;
8263 (1) echo nope 1 \#"$*" ;;
8264 (2) echo terr 2 \#"$*" ;;
8265 (*) echo wtf\? $? \#"$*" ;;
8266 esac
8267 }
8268 tst 1 'test 2 -eq 2'
8269 tst 2 'test 2 -eq 2a'
8270 tst 3 'test 2 -eq 3'
8271 tst 4 'test 2 -ne 2'
8272 tst 5 'test 2 -ne 2a'
8273 tst 6 'test 2 -ne 3'
8274 tst 7 'test \! 2 -eq 2'
8275 tst 8 'test \! 2 -eq 2a'
8276 tst 9 'test \! 2 -eq 3'
8277expected-stdout:
8278 yepp 0 #1 test 2 -eq 2
8279 terr 2 #2 test 2 -eq 2a
8280 nope 1 #3 test 2 -eq 3
8281 nope 1 #4 test 2 -ne 2
8282 terr 2 #5 test 2 -ne 2a
8283 yepp 0 #6 test 2 -ne 3
8284 nope 1 #7 test \! 2 -eq 2
8285 terr 2 #8 test \! 2 -eq 2a
8286 yepp 0 #9 test \! 2 -eq 3
8287expected-stderr-pattern:
8288 /bad number/
8289---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008290name: mkshrc-1
8291description:
8292 Check that ~/.mkshrc works correctly.
8293 Part 1: verify user environment is not read (internal)
8294stdin:
8295 echo x $FNORD
8296expected-stdout:
8297 x
8298---
8299name: mkshrc-2a
8300description:
8301 Check that ~/.mkshrc works correctly.
8302 Part 2: verify mkshrc is not read (non-interactive shells)
8303file-setup: file 644 ".mkshrc"
8304 FNORD=42
8305env-setup: !HOME=.!ENV=!
8306stdin:
8307 echo x $FNORD
8308expected-stdout:
8309 x
8310---
8311name: mkshrc-2b
8312description:
8313 Check that ~/.mkshrc works correctly.
8314 Part 2: verify mkshrc can be read (interactive shells)
8315file-setup: file 644 ".mkshrc"
8316 FNORD=42
Geremy Condra03ebf062011-10-12 18:17:24 -07008317need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008318arguments: !-i!
8319env-setup: !HOME=.!ENV=!PS1=!
8320stdin:
8321 echo x $FNORD
8322expected-stdout:
8323 x 42
8324expected-stderr-pattern:
8325 /(# )*/
8326---
8327name: mkshrc-3
8328description:
8329 Check that ~/.mkshrc works correctly.
8330 Part 3: verify mkshrc can be turned off
8331file-setup: file 644 ".mkshrc"
8332 FNORD=42
8333env-setup: !HOME=.!ENV=nonexistant!
8334stdin:
8335 echo x $FNORD
8336expected-stdout:
8337 x
8338---
8339name: sh-mode-1
8340description:
8341 Check that sh mode turns braceexpand off
8342 and that that works correctly
8343stdin:
8344 set -o braceexpand
8345 set +o sh
8346 [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
8347 [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
8348 echo {a,b,c}
8349 set +o braceexpand
8350 echo {a,b,c}
8351 set -o braceexpand
8352 echo {a,b,c}
8353 set -o sh
8354 echo {a,b,c}
8355 [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
8356 [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
8357 set -o braceexpand
8358 echo {a,b,c}
8359 [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
8360 [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
8361expected-stdout:
8362 nosh
8363 brex
8364 a b c
8365 {a,b,c}
8366 a b c
8367 {a,b,c}
8368 sh
8369 nobrex
8370 a b c
8371 sh
8372 brex
8373---
8374name: sh-mode-2a
8375description:
Thorsten Glaser811a5752013-07-25 14:24:45 +00008376 Check that posix or sh mode is *not* automatically turned on
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008377category: !binsh
8378stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00008379 ln -s "$__progname" ksh || cp "$__progname" ksh
8380 ln -s "$__progname" sh || cp "$__progname" sh
8381 ln -s "$__progname" ./-ksh || cp "$__progname" ./-ksh
8382 ln -s "$__progname" ./-sh || cp "$__progname" ./-sh
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008383 for shell in {,-}{,k}sh; do
8384 print -- $shell $(./$shell +l -c \
Thorsten Glaser811a5752013-07-25 14:24:45 +00008385 '[[ $(set +o) == *"-o "@(sh|posix)@(| *) ]] && echo sh || echo nosh')
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008386 done
8387expected-stdout:
8388 sh nosh
8389 ksh nosh
8390 -sh nosh
8391 -ksh nosh
8392---
8393name: sh-mode-2b
8394description:
Thorsten Glaser811a5752013-07-25 14:24:45 +00008395 Check that posix or sh mode *is* automatically turned on
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008396category: binsh
8397stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00008398 ln -s "$__progname" ksh || cp "$__progname" ksh
8399 ln -s "$__progname" sh || cp "$__progname" sh
8400 ln -s "$__progname" ./-ksh || cp "$__progname" ./-ksh
8401 ln -s "$__progname" ./-sh || cp "$__progname" ./-sh
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008402 for shell in {,-}{,k}sh; do
8403 print -- $shell $(./$shell +l -c \
Thorsten Glaser811a5752013-07-25 14:24:45 +00008404 '[[ $(set +o) == *"-o "@(sh|posix)@(| *) ]] && echo sh || echo nosh')
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008405 done
8406expected-stdout:
8407 sh sh
8408 ksh nosh
8409 -sh sh
8410 -ksh nosh
8411---
8412name: pipeline-1
8413description:
8414 pdksh bug: last command of a pipeline is executed in a
8415 subshell - make sure it still is, scripts depend on it
8416file-setup: file 644 "abcx"
8417file-setup: file 644 "abcy"
8418stdin:
8419 echo *
8420 echo a | while read d; do
8421 echo $d
8422 echo $d*
8423 echo *
8424 set -o noglob
8425 echo $d*
8426 echo *
8427 done
8428 echo *
8429expected-stdout:
8430 abcx abcy
8431 a
8432 abcx abcy
8433 abcx abcy
8434 a*
8435 *
8436 abcx abcy
8437---
8438name: pipeline-2
8439description:
8440 check that co-processes work with TCOMs, TPIPEs and TPARENs
Geremy Condra03ebf062011-10-12 18:17:24 -07008441category: !nojsig
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008442stdin:
8443 "$__progname" -c 'i=100; echo hi |& while read -p line; do echo "$((i++)) $line"; done'
8444 "$__progname" -c 'i=200; echo hi | cat |& while read -p line; do echo "$((i++)) $line"; done'
8445 "$__progname" -c 'i=300; (echo hi | cat) |& while read -p line; do echo "$((i++)) $line"; done'
8446expected-stdout:
8447 100 hi
8448 200 hi
8449 300 hi
8450---
Geremy Condra03ebf062011-10-12 18:17:24 -07008451name: pipeline-3
8452description:
8453 Check that PIPESTATUS does what it's supposed to
8454stdin:
8455 echo 1 $PIPESTATUS .
8456 echo 2 ${PIPESTATUS[0]} .
8457 echo 3 ${PIPESTATUS[1]} .
8458 (echo x; exit 12) | (cat; exit 23) | (cat; exit 42)
8459 echo 5 $? , $PIPESTATUS , ${PIPESTATUS[0]} , ${PIPESTATUS[1]} , ${PIPESTATUS[2]} , ${PIPESTATUS[3]} .
8460 echo 6 ${PIPESTATUS[0]} .
8461 set | fgrep PIPESTATUS
8462 echo 8 $(set | fgrep PIPESTATUS) .
8463expected-stdout:
8464 1 0 .
8465 2 0 .
8466 3 .
8467 x
8468 5 42 , 12 , 12 , 23 , 42 , .
8469 6 0 .
8470 PIPESTATUS[0]=0
8471 8 PIPESTATUS[0]=0 PIPESTATUS[1]=0 .
8472---
Thorsten Glaser811a5752013-07-25 14:24:45 +00008473name: pipeline-4
8474description:
8475 Check that "set -o pipefail" does what it's supposed to
8476stdin:
8477 echo 1 "$("$__progname" -c '(exit 12) | (exit 23) | (exit 42); echo $?')" .
8478 echo 2 "$("$__progname" -c '! (exit 12) | (exit 23) | (exit 42); echo $?')" .
8479 echo 3 "$("$__progname" -o pipefail -c '(exit 12) | (exit 23) | (exit 42); echo $?')" .
8480 echo 4 "$("$__progname" -o pipefail -c '! (exit 12) | (exit 23) | (exit 42); echo $?')" .
8481 echo 5 "$("$__progname" -c '(exit 23) | (exit 42) | :; echo $?')" .
8482 echo 6 "$("$__progname" -c '! (exit 23) | (exit 42) | :; echo $?')" .
8483 echo 7 "$("$__progname" -o pipefail -c '(exit 23) | (exit 42) | :; echo $?')" .
8484 echo 8 "$("$__progname" -o pipefail -c '! (exit 23) | (exit 42) | :; echo $?')" .
Elliott Hughes737fdce2014-08-07 12:59:26 -07008485 echo 9 "$("$__progname" -o pipefail -c 'x=$( (exit 23) | (exit 42) | :); echo $?')" .
Thorsten Glaser811a5752013-07-25 14:24:45 +00008486expected-stdout:
8487 1 42 .
8488 2 0 .
8489 3 42 .
8490 4 0 .
8491 5 0 .
8492 6 1 .
8493 7 42 .
8494 8 0 .
Elliott Hughes737fdce2014-08-07 12:59:26 -07008495 9 42 .
Thorsten Glaser811a5752013-07-25 14:24:45 +00008496---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008497name: persist-history-1
8498description:
8499 Check if persistent history saving works
8500category: !no-histfile
Geremy Condra03ebf062011-10-12 18:17:24 -07008501need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008502arguments: !-i!
8503env-setup: !ENV=./Env!HISTFILE=hist.file!
8504file-setup: file 644 "Env"
8505 PS1=X
8506stdin:
8507 cat hist.file
8508expected-stdout-pattern:
8509 /cat hist.file/
8510expected-stderr-pattern:
8511 /^X*$/
8512---
Geremy Condra03ebf062011-10-12 18:17:24 -07008513name: typeset-1
8514description:
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008515 Check that typeset -g works correctly
Geremy Condra03ebf062011-10-12 18:17:24 -07008516stdin:
8517 set -A arrfoo 65
8518 foo() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008519 typeset -g -Uui16 arrfoo[*]
Geremy Condra03ebf062011-10-12 18:17:24 -07008520 }
8521 echo before ${arrfoo[0]} .
8522 foo
8523 echo after ${arrfoo[0]} .
8524 set -A arrbar 65
8525 bar() {
8526 echo inside before ${arrbar[0]} .
8527 arrbar[0]=97
8528 echo inside changed ${arrbar[0]} .
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008529 typeset -g -Uui16 arrbar[*]
Geremy Condra03ebf062011-10-12 18:17:24 -07008530 echo inside typeset ${arrbar[0]} .
8531 arrbar[0]=48
8532 echo inside changed ${arrbar[0]} .
8533 }
8534 echo before ${arrbar[0]} .
8535 bar
8536 echo after ${arrbar[0]} .
8537expected-stdout:
8538 before 65 .
8539 after 16#41 .
8540 before 65 .
8541 inside before 65 .
8542 inside changed 97 .
8543 inside typeset 16#61 .
8544 inside changed 16#30 .
8545 after 16#30 .
8546---
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008547name: typeset-2
8548description:
8549 Check that typeset -p on arrays works correctly
8550stdin:
8551 set -A x -- a b c
8552 echo =
8553 typeset -p x
8554 echo =
8555 typeset -p x[1]
8556expected-stdout:
8557 =
8558 set -A x
8559 typeset x[0]=a
8560 typeset x[1]=b
8561 typeset x[2]=c
8562 =
8563 typeset x[1]=b
8564---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008565name: typeset-padding-1
8566description:
8567 Check if left/right justification works as per TFM
8568stdin:
8569 typeset -L10 ln=0hall0
8570 typeset -R10 rn=0hall0
8571 typeset -ZL10 lz=0hall0
8572 typeset -ZR10 rz=0hall0
8573 typeset -Z10 rx=" hallo "
8574 echo "<$ln> <$rn> <$lz> <$rz> <$rx>"
8575expected-stdout:
8576 <0hall0 > < 0hall0> <hall0 > <00000hall0> <0000 hallo>
8577---
8578name: typeset-padding-2
8579description:
8580 Check if base-!10 integers are padded right
8581stdin:
8582 typeset -Uui16 -L9 ln=16#1
8583 typeset -Uui16 -R9 rn=16#1
8584 typeset -Uui16 -Z9 zn=16#1
8585 typeset -L9 ls=16#1
8586 typeset -R9 rs=16#1
8587 typeset -Z9 zs=16#1
8588 echo "<$ln> <$rn> <$zn> <$ls> <$rs> <$zs>"
8589expected-stdout:
8590 <16#1 > < 16#1> <16#000001> <16#1 > < 16#1> <0000016#1>
8591---
Elliott Hughes47086262019-03-26 12:34:31 -07008592name: typeset-padding-3
8593description:
8594 Check for a regression in which UTF-8 wasn’t left-padded right
8595stdin:
8596 set -U
8597 nl=$'\n'
8598 typeset -L20 x='. ak'
8599 typeset -R20 y='. ak'
8600 print -r -- "<$x> (1$nl<12345678910 345678920$nl<$y> 1)"
8601 typeset -L20 x='. aẞ'
8602 typeset -R20 y='. aẞ'
8603 print -r -- "<$x> (2$nl<12345678910 345678920$nl<$y> 2)"
8604expected-stdout:
8605 <. ak > (1
8606 <12345678910 345678920
8607 < . ak> 1)
8608 <. aẞ > (2
8609 <12345678910 345678920
8610 < . aẞ> 2)
8611---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008612name: utf8bom-1
8613description:
8614 Check that the UTF-8 Byte Order Mark is ignored as the first
8615 multibyte character of the shell input (with -c, from standard
8616 input, as file, or as eval argument), but nowhere else
Elliott Hughes47086262019-03-26 12:34:31 -07008617# breaks on Mac OSX (HFS+ non-standard UTF-8 canonical decomposition)
Elliott Hughes23925bb2017-09-22 16:04:20 -07008618category: !os:darwin,!shell:ebcdic-yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008619stdin:
8620 mkdir foo
8621 print '#!/bin/sh\necho ohne' >foo/fnord
8622 print '#!/bin/sh\necho mit' >foo/fnord
8623 print 'fnord\nfnord\nfnord\nfnord' >foo/bar
8624 print eval \''fnord\nfnord\nfnord\nfnord'\' >foo/zoo
8625 set -A anzahl -- foo/*
8626 echo got ${#anzahl[*]} files
8627 chmod +x foo/*
Elliott Hughes96b43632015-07-17 11:39:41 -07008628 export PATH=$(pwd)/foo$PATHSEP$PATH
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008629 "$__progname" -c 'fnord'
8630 echo =
8631 "$__progname" -c 'fnord; fnord; fnord; fnord'
8632 echo =
8633 "$__progname" foo/bar
8634 echo =
8635 "$__progname" <foo/bar
8636 echo =
8637 "$__progname" foo/zoo
8638 echo =
8639 "$__progname" -c 'echo : $(fnord)'
8640 rm -rf foo
8641expected-stdout:
8642 got 4 files
8643 ohne
8644 =
8645 ohne
8646 ohne
8647 mit
8648 ohne
8649 =
8650 ohne
8651 ohne
8652 mit
8653 ohne
8654 =
8655 ohne
8656 ohne
8657 mit
8658 ohne
8659 =
8660 ohne
8661 ohne
8662 mit
8663 ohne
8664 =
Geremy Condra03ebf062011-10-12 18:17:24 -07008665 : ohne
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008666---
8667name: utf8bom-2
8668description:
8669 Check that we can execute BOM-shebangs (failures not fatal)
8670 XXX if the OS can already execute them, we lose
8671 note: cygwin execve(2) doesn't return to us with ENOEXEC, we lose
8672 note: Ultrix perl5 t4 returns 65280 (exit-code 255) and no text
Elliott Hughes50012062015-03-10 22:22:24 -07008673 XXX fails when LD_PRELOAD is set with -e and Perl chokes it (ASan)
Geremy Condra03ebf062011-10-12 18:17:24 -07008674need-pass: no
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00008675category: !os:cygwin,!os:msys,!os:ultrix,!os:uwin-nt,!smksh
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008676env-setup: !FOO=BAR!
8677stdin:
8678 print '#!'"$__progname"'\nprint "1 a=$ENV{FOO}";' >t1
8679 print '#!'"$__progname"'\nprint "2 a=$ENV{FOO}";' >t2
8680 print '#!'"$__perlname"'\nprint "3 a=$ENV{FOO}\n";' >t3
8681 print '#!'"$__perlname"'\nprint "4 a=$ENV{FOO}\n";' >t4
8682 chmod +x t?
8683 ./t1
8684 ./t2
8685 ./t3
8686 ./t4
8687expected-stdout:
8688 1 a=/nonexistant{FOO}
8689 2 a=/nonexistant{FOO}
8690 3 a=BAR
8691 4 a=BAR
8692expected-stderr-pattern:
8693 /(Unrecognized character .... ignored at \..t4 line 1)*/
8694---
Elliott Hughes23925bb2017-09-22 16:04:20 -07008695name: utf8opt-1
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008696description:
8697 Check that the utf8-mode flag is not set at non-interactive startup
Elliott Hughes23925bb2017-09-22 16:04:20 -07008698env-setup: !PS1=!PS2=!LC_CTYPE=@utflocale@!
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008699stdin:
8700 if [[ $- = *U* ]]; then
8701 echo is set
8702 else
8703 echo is not set
8704 fi
8705expected-stdout:
8706 is not set
8707---
Elliott Hughes23925bb2017-09-22 16:04:20 -07008708name: utf8opt-2
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008709description:
8710 Check that the utf8-mode flag is set at interactive startup.
Elliott Hughes23925bb2017-09-22 16:04:20 -07008711 If your OS is old, try passing HAVE_SETLOCALE_CTYPE=0 to Build.sh
Geremy Condra03ebf062011-10-12 18:17:24 -07008712need-pass: no
Elliott Hughes23925bb2017-09-22 16:04:20 -07008713category: !noutf8
Geremy Condra03ebf062011-10-12 18:17:24 -07008714need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008715arguments: !-i!
Elliott Hughes23925bb2017-09-22 16:04:20 -07008716env-setup: !PS1=!PS2=!LC_CTYPE=@utflocale@!
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008717stdin:
8718 if [[ $- = *U* ]]; then
8719 echo is set
8720 else
8721 echo is not set
8722 fi
8723expected-stdout:
8724 is set
8725expected-stderr-pattern:
8726 /(# )*/
8727---
Geremy Condra03ebf062011-10-12 18:17:24 -07008728name: utf8opt-3a
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008729description:
8730 Ensure ±U on the command line is honoured
Geremy Condra03ebf062011-10-12 18:17:24 -07008731 (these two tests may pass falsely depending on CPPFLAGS)
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008732stdin:
8733 export i=0
8734 code='if [[ $- = *U* ]]; then echo $i on; else echo $i off; fi'
8735 let i++; "$__progname" -U -c "$code"
8736 let i++; "$__progname" +U -c "$code"
Geremy Condra03ebf062011-10-12 18:17:24 -07008737 echo $((++i)) done
8738expected-stdout:
8739 1 on
8740 2 off
8741 3 done
8742---
8743name: utf8opt-3b
8744description:
8745 Ensure ±U on the command line is honoured, interactive shells
8746need-ctty: yes
8747stdin:
8748 export i=0
8749 code='if [[ $- = *U* ]]; then echo $i on; else echo $i off; fi'
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008750 let i++; "$__progname" -U -ic "$code"
8751 let i++; "$__progname" +U -ic "$code"
8752 echo $((++i)) done
8753expected-stdout:
8754 1 on
8755 2 off
Geremy Condra03ebf062011-10-12 18:17:24 -07008756 3 done
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008757---
Elliott Hughes77740fc2016-08-12 15:06:53 -07008758name: utf8bug-1
8759description:
8760 Ensure trailing combining characters are not lost
8761stdin:
8762 set -U
8763 a=a
8764 b=$'\u0301'
8765 x=$a$b
8766 print -r -- "<e$x>"
8767 x=$a
8768 x+=$b
8769 print -r -- "<e$x>"
8770 b=$'\u0301'b
8771 x=$a
8772 x+=$b
8773 print -r -- "<e$x>"
8774expected-stdout:
8775 <eá>
8776 <eá>
8777 <eáb>
8778---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008779name: aliases-1
8780description:
8781 Check if built-in shell aliases are okay
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008782stdin:
8783 alias
8784 typeset -f
8785expected-stdout:
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008786 autoload='\\builtin typeset -fu'
8787 functions='\\builtin typeset -f'
8788 hash='\\builtin alias -t'
8789 history='\\builtin fc -l'
8790 integer='\\builtin typeset -i'
8791 local='\\builtin typeset'
8792 login='\\builtin exec login'
8793 nameref='\\builtin typeset -n'
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008794 nohup='nohup '
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008795 r='\\builtin fc -e -'
8796 type='\\builtin whence -v'
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008797---
8798name: aliases-2b
8799description:
8800 Check if “set -o sh” does not influence built-in aliases
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008801arguments: !-o!sh!
8802stdin:
8803 alias
8804 typeset -f
8805expected-stdout:
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008806 autoload='\\builtin typeset -fu'
8807 functions='\\builtin typeset -f'
8808 hash='\\builtin alias -t'
8809 history='\\builtin fc -l'
8810 integer='\\builtin typeset -i'
8811 local='\\builtin typeset'
8812 login='\\builtin exec login'
8813 nameref='\\builtin typeset -n'
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008814 nohup='nohup '
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008815 r='\\builtin fc -e -'
8816 type='\\builtin whence -v'
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008817---
8818name: aliases-3b
8819description:
8820 Check if running as sh does not influence built-in aliases
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008821stdin:
8822 cp "$__progname" sh
8823 ./sh -c 'alias; typeset -f'
8824 rm -f sh
8825expected-stdout:
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008826 autoload='\\builtin typeset -fu'
8827 functions='\\builtin typeset -f'
8828 hash='\\builtin alias -t'
8829 history='\\builtin fc -l'
8830 integer='\\builtin typeset -i'
8831 local='\\builtin typeset'
8832 login='\\builtin exec login'
8833 nameref='\\builtin typeset -n'
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008834 nohup='nohup '
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008835 r='\\builtin fc -e -'
8836 type='\\builtin whence -v'
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008837---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00008838name: aliases-cmdline
8839description:
8840 Check that aliases work from the command line (Debian #517009)
8841 Note that due to the nature of the lexing process, defining
8842 aliases in COMSUBs then immediately using them, and things
8843 like 'alias foo=bar && foo', still fail.
8844stdin:
8845 "$__progname" -c $'alias a="echo OK"\na'
8846expected-stdout:
8847 OK
8848---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008849name: aliases-funcdef-1
8850description:
8851 Check if POSIX functions take precedences over aliases
Elliott Hughes96b43632015-07-17 11:39:41 -07008852stdin:
8853 alias foo='echo makro'
8854 foo() {
8855 echo funktion
8856 }
8857 foo
8858expected-stdout:
8859 makro
8860---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008861name: aliases-funcdef-2
8862description:
8863 Check if POSIX functions take precedences over aliases
Elliott Hughes96b43632015-07-17 11:39:41 -07008864stdin:
8865 alias foo='echo makro'
8866 foo () {
8867 echo funktion
8868 }
8869 foo
8870expected-stdout:
8871 makro
8872---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008873name: aliases-funcdef-3
8874description:
8875 Check if aliases take precedences over Korn functions
8876stdin:
8877 alias foo='echo makro'
8878 function foo {
8879 echo funktion
8880 }
8881 foo
8882expected-stdout:
8883 makro
8884---
Geremy Condra03ebf062011-10-12 18:17:24 -07008885name: aliases-funcdef-4
8886description:
8887 Functions should only take over if actually being defined
8888stdin:
8889 alias local
8890 :|| local() { :; }
8891 alias local
8892expected-stdout:
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008893 local='\\builtin typeset'
8894 local='\\builtin typeset'
Geremy Condra03ebf062011-10-12 18:17:24 -07008895---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008896name: arrays-1
8897description:
8898 Check if Korn Shell arrays work as expected
8899stdin:
8900 v="c d"
8901 set -A foo -- a \$v "$v" '$v' b
8902 echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|"
8903expected-stdout:
8904 5|a|$v|c d|$v|b|
8905---
Geremy Condra03ebf062011-10-12 18:17:24 -07008906name: arrays-2a
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008907description:
8908 Check if bash-style arrays work as expected
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008909stdin:
8910 v="c d"
8911 foo=(a \$v "$v" '$v' b)
8912 echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|"
8913expected-stdout:
8914 5|a|$v|c d|$v|b|
8915---
Geremy Condra03ebf062011-10-12 18:17:24 -07008916name: arrays-2b
8917description:
8918 Check if bash-style arrays work as expected, with newlines
Geremy Condra03ebf062011-10-12 18:17:24 -07008919stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00008920 print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "$x|"; done' >pfp
8921 chmod +x pfp
Geremy Condra03ebf062011-10-12 18:17:24 -07008922 test -n "$ZSH_VERSION" && setopt KSH_ARRAYS
8923 v="e f"
8924 foo=(a
8925 bc
8926 d \$v "$v" '$v' g
8927 )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00008928 ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
Geremy Condra03ebf062011-10-12 18:17:24 -07008929 foo=(a\
8930 bc
8931 d \$v "$v" '$v' g
8932 )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00008933 ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
Geremy Condra03ebf062011-10-12 18:17:24 -07008934 foo=(a\
8935 bc\\
8936 d \$v "$v" '$v'
8937 g)
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00008938 ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
Geremy Condra03ebf062011-10-12 18:17:24 -07008939expected-stdout:
8940 7|a|bc|d|$v|e f|$v|g|
8941 7|a|bc|d|$v|e f|$v|g|
8942 6|abc\|d|$v|e f|$v|g||
8943---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008944name: arrays-3
8945description:
8946 Check if array bounds are uint32_t
8947stdin:
8948 set -A foo a b c
8949 foo[4097]=d
8950 foo[2147483637]=e
8951 echo ${foo[*]}
8952 foo[-1]=f
8953 echo ${foo[4294967295]} g ${foo[*]}
8954expected-stdout:
8955 a b c d e
8956 f g a b c d e f
8957---
8958name: arrays-4
8959description:
8960 Check if Korn Shell arrays with specified indices work as expected
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008961stdin:
8962 v="c d"
8963 set -A foo -- [1]=\$v [2]="$v" [4]='$v' [0]=a [5]=b
8964 echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|${foo[5]}|"
Elliott Hughes737fdce2014-08-07 12:59:26 -07008965 # we don't want this at all:
8966 # 5|a|$v|c d||$v|b|
8967 set -A arr "[5]=meh"
8968 echo "<${arr[0]}><${arr[5]}>"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008969expected-stdout:
Elliott Hughes737fdce2014-08-07 12:59:26 -07008970 5|[1]=$v|[2]=c d|[4]=$v|[0]=a|[5]=b||
8971 <[5]=meh><>
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008972---
8973name: arrays-5
8974description:
8975 Check if bash-style arrays with specified indices work as expected
Elliott Hughes737fdce2014-08-07 12:59:26 -07008976 (taken out temporarily to fix arrays-4; see also arrays-9a comment)
8977category: disabled
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008978stdin:
8979 v="c d"
8980 foo=([1]=\$v [2]="$v" [4]='$v' [0]=a [5]=b)
8981 echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|${foo[5]}|"
8982 x=([128]=foo bar baz)
8983 echo k= ${!x[*]} .
8984 echo v= ${x[*]} .
Elliott Hughes737fdce2014-08-07 12:59:26 -07008985 # Check that we do not break this by globbing
8986 :>b=blah
8987 bleh=5
8988 typeset -a arr
8989 arr+=([bleh]=blah)
8990 echo "<${arr[0]}><${arr[5]}>"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008991expected-stdout:
8992 5|a|$v|c d||$v|b|
8993 k= 128 129 130 .
8994 v= foo bar baz .
Elliott Hughes737fdce2014-08-07 12:59:26 -07008995 <><blah>
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008996---
8997name: arrays-6
8998description:
8999 Check if we can get the array keys (indices) for indexed arrays,
9000 Korn shell style
9001stdin:
9002 of() {
9003 i=0
9004 for x in "$@"; do
9005 echo -n "$((i++))<$x>"
9006 done
9007 echo
9008 }
9009 foo[1]=eins
9010 set | grep '^foo'
9011 echo =
9012 foo[0]=zwei
9013 foo[4]=drei
9014 set | grep '^foo'
9015 echo =
9016 echo a $(of ${foo[*]}) = $(of ${bar[*]}) a
9017 echo b $(of "${foo[*]}") = $(of "${bar[*]}") b
9018 echo c $(of ${foo[@]}) = $(of ${bar[@]}) c
9019 echo d $(of "${foo[@]}") = $(of "${bar[@]}") d
9020 echo e $(of ${!foo[*]}) = $(of ${!bar[*]}) e
9021 echo f $(of "${!foo[*]}") = $(of "${!bar[*]}") f
9022 echo g $(of ${!foo[@]}) = $(of ${!bar[@]}) g
9023 echo h $(of "${!foo[@]}") = $(of "${!bar[@]}") h
9024expected-stdout:
9025 foo[1]=eins
9026 =
9027 foo[0]=zwei
9028 foo[1]=eins
9029 foo[4]=drei
9030 =
9031 a 0<zwei>1<eins>2<drei> = a
9032 b 0<zwei eins drei> = 0<> b
9033 c 0<zwei>1<eins>2<drei> = c
9034 d 0<zwei>1<eins>2<drei> = d
9035 e 0<0>1<1>2<4> = e
9036 f 0<0 1 4> = 0<> f
9037 g 0<0>1<1>2<4> = g
9038 h 0<0>1<1>2<4> = h
9039---
9040name: arrays-7
9041description:
9042 Check if we can get the array keys (indices) for indexed arrays,
9043 Korn shell style, in some corner cases
9044stdin:
9045 echo !arz: ${!arz}
9046 echo !arz[0]: ${!arz[0]}
9047 echo !arz[1]: ${!arz[1]}
9048 arz=foo
9049 echo !arz: ${!arz}
9050 echo !arz[0]: ${!arz[0]}
9051 echo !arz[1]: ${!arz[1]}
9052 unset arz
9053 echo !arz: ${!arz}
9054 echo !arz[0]: ${!arz[0]}
9055 echo !arz[1]: ${!arz[1]}
9056expected-stdout:
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009057 !arz: arz
Elliott Hughes737fdce2014-08-07 12:59:26 -07009058 !arz[0]: arz[0]
9059 !arz[1]: arz[1]
9060 !arz: arz
9061 !arz[0]: arz[0]
9062 !arz[1]: arz[1]
9063 !arz: arz
9064 !arz[0]: arz[0]
9065 !arz[1]: arz[1]
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009066---
9067name: arrays-8
9068description:
9069 Check some behavioural rules for arrays.
9070stdin:
9071 fna() {
9072 set -A aa 9
9073 }
9074 fnb() {
9075 typeset ab
9076 set -A ab 9
9077 }
9078 fnc() {
9079 typeset ac
9080 set -A ac 91
9081 unset ac
9082 set -A ac 92
9083 }
9084 fnd() {
9085 set +A ad 9
9086 }
9087 fne() {
9088 unset ae
9089 set +A ae 9
9090 }
9091 fnf() {
9092 unset af[0]
9093 set +A af 9
9094 }
9095 fng() {
9096 unset ag[*]
9097 set +A ag 9
9098 }
9099 set -A aa 1 2
9100 set -A ab 1 2
9101 set -A ac 1 2
9102 set -A ad 1 2
9103 set -A ae 1 2
9104 set -A af 1 2
9105 set -A ag 1 2
9106 set -A ah 1 2
9107 typeset -Z3 aa ab ac ad ae af ag
9108 print 1a ${aa[*]} .
9109 print 1b ${ab[*]} .
9110 print 1c ${ac[*]} .
9111 print 1d ${ad[*]} .
9112 print 1e ${ae[*]} .
9113 print 1f ${af[*]} .
9114 print 1g ${ag[*]} .
9115 print 1h ${ah[*]} .
9116 fna
9117 fnb
9118 fnc
9119 fnd
9120 fne
9121 fnf
9122 fng
9123 typeset -Z5 ah[*]
9124 print 2a ${aa[*]} .
9125 print 2b ${ab[*]} .
9126 print 2c ${ac[*]} .
9127 print 2d ${ad[*]} .
9128 print 2e ${ae[*]} .
9129 print 2f ${af[*]} .
9130 print 2g ${ag[*]} .
9131 print 2h ${ah[*]} .
9132expected-stdout:
9133 1a 001 002 .
9134 1b 001 002 .
9135 1c 001 002 .
9136 1d 001 002 .
9137 1e 001 002 .
9138 1f 001 002 .
9139 1g 001 002 .
9140 1h 1 2 .
9141 2a 9 .
9142 2b 001 002 .
9143 2c 92 .
9144 2d 009 002 .
9145 2e 9 .
9146 2f 9 002 .
9147 2g 009 .
9148 2h 00001 00002 .
9149---
Geremy Condra03ebf062011-10-12 18:17:24 -07009150name: arrays-9a
9151description:
9152 Check that we can concatenate arrays
Geremy Condra03ebf062011-10-12 18:17:24 -07009153stdin:
9154 unset foo; foo=(bar); foo+=(baz); echo 1 ${!foo[*]} : ${foo[*]} .
9155 unset foo; foo=(foo bar); foo+=(baz); echo 2 ${!foo[*]} : ${foo[*]} .
Elliott Hughes737fdce2014-08-07 12:59:26 -07009156# unset foo; foo=([2]=foo [0]=bar); foo+=(baz [5]=quux); echo 3 ${!foo[*]} : ${foo[*]} .
Geremy Condra03ebf062011-10-12 18:17:24 -07009157expected-stdout:
9158 1 0 1 : bar baz .
9159 2 0 1 2 : foo bar baz .
Elliott Hughes737fdce2014-08-07 12:59:26 -07009160# 3 0 2 3 5 : bar foo baz quux .
Geremy Condra03ebf062011-10-12 18:17:24 -07009161---
9162name: arrays-9b
9163description:
9164 Check that we can concatenate parameters too
9165stdin:
9166 unset foo; foo=bar; foo+=baz; echo 1 $foo .
9167 unset foo; typeset -i16 foo=10; foo+=20; echo 2 $foo .
9168expected-stdout:
9169 1 barbaz .
9170 2 16#a20 .
9171---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009172name: arrassign-basic
9173description:
9174 Check basic whitespace conserving properties of wdarrassign
9175stdin:
9176 a=($(echo a b))
9177 b=($(echo "a b"))
9178 c=("$(echo "a b")")
9179 d=("$(echo a b)")
9180 a+=($(echo c d))
9181 b+=($(echo "c d"))
9182 c+=("$(echo "c d")")
9183 d+=("$(echo c d)")
9184 echo ".a:${a[0]}.${a[1]}.${a[2]}.${a[3]}:"
9185 echo ".b:${b[0]}.${b[1]}.${b[2]}.${b[3]}:"
9186 echo ".c:${c[0]}.${c[1]}.${c[2]}.${c[3]}:"
9187 echo ".d:${d[0]}.${d[1]}.${d[2]}.${d[3]}:"
9188expected-stdout:
9189 .a:a.b.c.d:
9190 .b:a.b.c.d:
9191 .c:a b.c d..:
9192 .d:a b.c d..:
9193---
Elliott Hughesdd4abe02018-02-05 15:55:19 -08009194name: arrassign-eol
9195description:
9196 Commands after array assignments are not permitted
9197stdin:
9198 foo=(a b) env
9199expected-exit: e != 0
9200expected-stderr-pattern:
9201 /syntax error: unexpected 'env'/
9202---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009203name: arrassign-fnc-none
9204description:
9205 Check locality of array access inside a function
9206stdin:
9207 function fn {
9208 x+=(f)
9209 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9210 }
9211 function rfn {
9212 if [[ -n $BASH_VERSION ]]; then
9213 y=()
9214 else
9215 set -A y
9216 fi
9217 y+=(f)
9218 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9219 }
9220 x=(m m)
9221 y=(m m)
9222 echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9223 fn
9224 echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9225 fn
9226 echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9227 echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9228 rfn
9229 echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9230 rfn
9231 echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9232expected-stdout:
9233 .f0:m.m..:
9234 .fn:m.m.f.:
9235 .f1:m.m.f.:
9236 .fn:m.m.f.f:
9237 .f2:m.m.f.f:
9238 .rf0:m.m..:
9239 .rfn:f...:
9240 .rf1:f...:
9241 .rfn:f...:
9242 .rf2:f...:
9243---
9244name: arrassign-fnc-local
9245description:
9246 Check locality of array access inside a function
9247 with the bash/mksh/ksh93 local/typeset keyword
9248 (note: ksh93 has no local; typeset works only in FKSH)
9249stdin:
9250 function fn {
9251 typeset x
9252 x+=(f)
9253 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9254 }
9255 function rfn {
9256 if [[ -n $BASH_VERSION ]]; then
9257 y=()
9258 else
9259 set -A y
9260 fi
9261 typeset y
9262 y+=(f)
9263 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9264 }
9265 function fnr {
9266 typeset z
9267 if [[ -n $BASH_VERSION ]]; then
9268 z=()
9269 else
9270 set -A z
9271 fi
9272 z+=(f)
9273 echo ".fnr:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
9274 }
9275 x=(m m)
9276 y=(m m)
9277 z=(m m)
9278 echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9279 fn
9280 echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9281 fn
9282 echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9283 echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9284 rfn
9285 echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9286 rfn
9287 echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9288 echo ".f0r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
9289 fnr
9290 echo ".f1r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
9291 fnr
9292 echo ".f2r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
9293expected-stdout:
9294 .f0:m.m..:
9295 .fn:f...:
9296 .f1:m.m..:
9297 .fn:f...:
9298 .f2:m.m..:
9299 .rf0:m.m..:
9300 .rfn:f...:
9301 .rf1:...:
9302 .rfn:f...:
9303 .rf2:...:
9304 .f0r:m.m..:
9305 .fnr:f...:
9306 .f1r:m.m..:
9307 .fnr:f...:
9308 .f2r:m.m..:
9309---
9310name: arrassign-fnc-global
9311description:
9312 Check locality of array access inside a function
Elliott Hughesa3c3f962017-04-12 16:52:30 -07009313 with the bash4/mksh/yash/zsh typeset -g keyword
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009314stdin:
9315 function fn {
Elliott Hughesa3c3f962017-04-12 16:52:30 -07009316 typeset -g x
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009317 x+=(f)
9318 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9319 }
9320 function rfn {
9321 set -A y
Elliott Hughesa3c3f962017-04-12 16:52:30 -07009322 typeset -g y
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009323 y+=(f)
9324 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9325 }
9326 function fnr {
Elliott Hughesa3c3f962017-04-12 16:52:30 -07009327 typeset -g z
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009328 set -A z
9329 z+=(f)
9330 echo ".fnr:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
9331 }
9332 x=(m m)
9333 y=(m m)
9334 z=(m m)
9335 echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9336 fn
9337 echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9338 fn
9339 echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
9340 echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9341 rfn
9342 echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9343 rfn
9344 echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
9345 echo ".f0r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
9346 fnr
9347 echo ".f1r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
9348 fnr
9349 echo ".f2r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
9350expected-stdout:
9351 .f0:m.m..:
9352 .fn:m.m.f.:
9353 .f1:m.m.f.:
9354 .fn:m.m.f.f:
9355 .f2:m.m.f.f:
9356 .rf0:m.m..:
9357 .rfn:f...:
9358 .rf1:f...:
9359 .rfn:f...:
9360 .rf2:f...:
9361 .f0r:m.m..:
9362 .fnr:f...:
9363 .f1r:f...:
9364 .fnr:f...:
9365 .f2r:f...:
9366---
9367name: strassign-fnc-none
9368description:
9369 Check locality of string access inside a function
9370stdin:
9371 function fn {
9372 x+=f
9373 echo ".fn:$x:"
9374 }
9375 function rfn {
9376 y=
9377 y+=f
9378 echo ".rfn:$y:"
9379 }
9380 x=m
9381 y=m
9382 echo ".f0:$x:"
9383 fn
9384 echo ".f1:$x:"
9385 fn
9386 echo ".f2:$x:"
9387 echo ".rf0:$y:"
9388 rfn
9389 echo ".rf1:$y:"
9390 rfn
9391 echo ".rf2:$y:"
9392expected-stdout:
9393 .f0:m:
9394 .fn:mf:
9395 .f1:mf:
9396 .fn:mff:
9397 .f2:mff:
9398 .rf0:m:
9399 .rfn:f:
9400 .rf1:f:
9401 .rfn:f:
9402 .rf2:f:
9403---
9404name: strassign-fnc-local
9405description:
9406 Check locality of string access inside a function
9407 with the bash/mksh/ksh93 local/typeset keyword
9408 (note: ksh93 has no local; typeset works only in FKSH)
9409stdin:
9410 function fn {
9411 typeset x
9412 x+=f
9413 echo ".fn:$x:"
9414 }
9415 function rfn {
9416 y=
9417 typeset y
9418 y+=f
9419 echo ".rfn:$y:"
9420 }
9421 function fnr {
9422 typeset z
9423 z=
9424 z+=f
9425 echo ".fnr:$z:"
9426 }
9427 x=m
9428 y=m
9429 z=m
9430 echo ".f0:$x:"
9431 fn
9432 echo ".f1:$x:"
9433 fn
9434 echo ".f2:$x:"
9435 echo ".rf0:$y:"
9436 rfn
9437 echo ".rf1:$y:"
9438 rfn
9439 echo ".rf2:$y:"
9440 echo ".f0r:$z:"
9441 fnr
9442 echo ".f1r:$z:"
9443 fnr
9444 echo ".f2r:$z:"
9445expected-stdout:
9446 .f0:m:
9447 .fn:f:
9448 .f1:m:
9449 .fn:f:
9450 .f2:m:
9451 .rf0:m:
9452 .rfn:f:
9453 .rf1::
9454 .rfn:f:
9455 .rf2::
9456 .f0r:m:
9457 .fnr:f:
9458 .f1r:m:
9459 .fnr:f:
9460 .f2r:m:
9461---
9462name: strassign-fnc-global
9463description:
9464 Check locality of string access inside a function
Elliott Hughesa3c3f962017-04-12 16:52:30 -07009465 with the bash4/mksh/yash/zsh typeset -g keyword
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009466stdin:
9467 function fn {
Elliott Hughesa3c3f962017-04-12 16:52:30 -07009468 typeset -g x
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009469 x+=f
9470 echo ".fn:$x:"
9471 }
9472 function rfn {
9473 y=
Elliott Hughesa3c3f962017-04-12 16:52:30 -07009474 typeset -g y
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009475 y+=f
9476 echo ".rfn:$y:"
9477 }
9478 function fnr {
Elliott Hughesa3c3f962017-04-12 16:52:30 -07009479 typeset -g z
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009480 z=
9481 z+=f
9482 echo ".fnr:$z:"
9483 }
9484 x=m
9485 y=m
9486 z=m
9487 echo ".f0:$x:"
9488 fn
9489 echo ".f1:$x:"
9490 fn
9491 echo ".f2:$x:"
9492 echo ".rf0:$y:"
9493 rfn
9494 echo ".rf1:$y:"
9495 rfn
9496 echo ".rf2:$y:"
9497 echo ".f0r:$z:"
9498 fnr
9499 echo ".f1r:$z:"
9500 fnr
9501 echo ".f2r:$z:"
9502expected-stdout:
9503 .f0:m:
9504 .fn:mf:
9505 .f1:mf:
9506 .fn:mff:
9507 .f2:mff:
9508 .rf0:m:
9509 .rfn:f:
9510 .rf1:f:
9511 .rfn:f:
9512 .rf2:f:
9513 .f0r:m:
9514 .fnr:f:
9515 .f1r:f:
9516 .fnr:f:
9517 .f2r:f:
9518---
Elliott Hughes50012062015-03-10 22:22:24 -07009519name: unset-fnc-local-ksh
9520description:
9521 Check that “unset” removes a previous “local”
9522 (ksh93 syntax compatible version); apparently,
9523 there are shells which fail this?
9524stdin:
9525 function f {
9526 echo f0: $x
9527 typeset x
9528 echo f1: $x
9529 x=fa
9530 echo f2: $x
9531 unset x
9532 echo f3: $x
9533 x=fb
9534 echo f4: $x
9535 }
9536 x=o
9537 echo before: $x
9538 f
9539 echo after: $x
9540expected-stdout:
9541 before: o
9542 f0: o
9543 f1:
9544 f2: fa
9545 f3: o
9546 f4: fb
9547 after: fb
9548---
9549name: unset-fnc-local-sh
9550description:
9551 Check that “unset” removes a previous “local”
9552 (Debian Policy §10.4 sh version); apparently,
9553 there are shells which fail this?
9554stdin:
9555 f() {
9556 echo f0: $x
9557 local x
9558 echo f1: $x
9559 x=fa
9560 echo f2: $x
9561 unset x
9562 echo f3: $x
9563 x=fb
9564 echo f4: $x
9565 }
9566 x=o
9567 echo before: $x
9568 f
9569 echo after: $x
9570expected-stdout:
9571 before: o
9572 f0: o
9573 f1:
9574 f2: fa
9575 f3: o
9576 f4: fb
9577 after: fb
9578---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009579name: varexpand-substr-1
9580description:
9581 Check if bash-style substring expansion works
9582 when using positive numerics
9583stdin:
9584 x=abcdefghi
9585 typeset -i y=123456789
9586 typeset -i 16 z=123456789 # 16#75bcd15
9587 echo a t${x:2:2} ${y:2:3} ${z:2:3} a
9588 echo b ${x::3} ${y::3} ${z::3} b
9589 echo c ${x:2:} ${y:2:} ${z:2:} c
9590 echo d ${x:2} ${y:2} ${z:2} d
9591 echo e ${x:2:6} ${y:2:6} ${z:2:7} e
9592 echo f ${x:2:7} ${y:2:7} ${z:2:8} f
9593 echo g ${x:2:8} ${y:2:8} ${z:2:9} g
9594expected-stdout:
9595 a tcd 345 #75 a
9596 b abc 123 16# b
9597 c c
9598 d cdefghi 3456789 #75bcd15 d
9599 e cdefgh 345678 #75bcd1 e
9600 f cdefghi 3456789 #75bcd15 f
9601 g cdefghi 3456789 #75bcd15 g
9602---
9603name: varexpand-substr-2
9604description:
9605 Check if bash-style substring expansion works
9606 when using negative numerics or expressions
9607stdin:
9608 x=abcdefghi
9609 typeset -i y=123456789
9610 typeset -i 16 z=123456789 # 16#75bcd15
9611 n=2
9612 echo a ${x:$n:3} ${y:$n:3} ${z:$n:3} a
9613 echo b ${x:(n):3} ${y:(n):3} ${z:(n):3} b
9614 echo c ${x:(-2):1} ${y:(-2):1} ${z:(-2):1} c
9615 echo d t${x: n:2} ${y: n:3} ${z: n:3} d
9616expected-stdout:
9617 a cde 345 #75 a
9618 b cde 345 #75 b
9619 c h 8 1 c
9620 d tcd 345 #75 d
9621---
9622name: varexpand-substr-3
9623description:
9624 Check that some things that work in bash fail.
Elliott Hughesfc0307d2016-02-02 15:26:47 -08009625 This is by design. Oh and vice versa, nowadays.
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009626stdin:
9627 export x=abcdefghi n=2
9628 "$__progname" -c 'echo v${x:(n)}x'
9629 "$__progname" -c 'echo w${x: n}x'
9630 "$__progname" -c 'echo x${x:n}x'
9631 "$__progname" -c 'echo y${x:}x'
9632 "$__progname" -c 'echo z${x}x'
Elliott Hughesfc0307d2016-02-02 15:26:47 -08009633 # next fails only in bash
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009634 "$__progname" -c 'x=abcdef;y=123;echo ${x:${y:2:1}:2}' >/dev/null 2>&1; echo $?
9635expected-stdout:
9636 vcdefghix
9637 wcdefghix
9638 zabcdefghix
Elliott Hughesfc0307d2016-02-02 15:26:47 -08009639 0
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009640expected-stderr-pattern:
9641 /x:n.*bad substitution.*\n.*bad substitution/
9642---
9643name: varexpand-substr-4
9644description:
9645 Check corner cases for substring expansion
9646stdin:
9647 x=abcdefghi
9648 integer y=2
9649 echo a ${x:(y == 1 ? 2 : 3):4} a
9650expected-stdout:
9651 a defg a
9652---
9653name: varexpand-substr-5A
9654description:
9655 Check that substring expansions work on characters
9656stdin:
9657 set +U
9658 x=mäh
9659 echo a ${x::1} ${x: -1} a
9660 echo b ${x::3} ${x: -3} b
9661 echo c ${x:1:2} ${x: -3:2} c
9662 echo d ${#x} d
9663expected-stdout:
9664 a m h a
9665 b mä äh b
9666 c ä ä c
9667 d 4 d
9668---
9669name: varexpand-substr-5W
9670description:
9671 Check that substring expansions work on characters
9672stdin:
9673 set -U
9674 x=mäh
9675 echo a ${x::1} ${x: -1} a
9676 echo b ${x::2} ${x: -2} b
9677 echo c ${x:1:1} ${x: -2:1} c
9678 echo d ${#x} d
9679expected-stdout:
9680 a m h a
9681 b mä äh b
9682 c ä ä c
9683 d 3 d
9684---
9685name: varexpand-substr-6
9686description:
9687 Check that string substitution works correctly
9688stdin:
9689 foo=1
9690 bar=2
9691 baz=qwertyuiop
9692 echo a ${baz: foo: bar}
9693 echo b ${baz: foo: $bar}
9694 echo c ${baz: $foo: bar}
9695 echo d ${baz: $foo: $bar}
9696expected-stdout:
9697 a we
9698 b we
9699 c we
9700 d we
9701---
Geremy Condra03ebf062011-10-12 18:17:24 -07009702name: varexpand-special-hash
9703description:
9704 Check special ${var@x} expansion for x=hash
Elliott Hughes23925bb2017-09-22 16:04:20 -07009705category: !shell:ebcdic-yes
Geremy Condra03ebf062011-10-12 18:17:24 -07009706stdin:
9707 typeset -i8 foo=10
9708 bar=baz
9709 unset baz
9710 print ${foo@#} ${bar@#} ${baz@#} .
9711expected-stdout:
Elliott Hughes737fdce2014-08-07 12:59:26 -07009712 9B15FBFB CFBDD32B 00000000 .
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009713---
Elliott Hughes23925bb2017-09-22 16:04:20 -07009714name: varexpand-special-hash-ebcdic
9715description:
9716 Check special ${var@x} expansion for x=hash
9717category: !shell:ebcdic-no
9718stdin:
9719 typeset -i8 foo=10
9720 bar=baz
9721 unset baz
9722 print ${foo@#} ${bar@#} ${baz@#} .
9723expected-stdout:
9724 016AE33D 9769C4AF 00000000 .
9725---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009726name: varexpand-special-quote
9727description:
9728 Check special ${var@Q} expansion for quoted strings
Elliott Hughes23925bb2017-09-22 16:04:20 -07009729category: !shell:faux-ebcdic
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009730stdin:
9731 set +U
9732 i=x
9733 j=a\ b
9734 k=$'c
9735 d\xA0''e€f'
9736 print -r -- "<i=$i j=$j k=$k>"
9737 s="u=${i@Q} v=${j@Q} w=${k@Q}"
9738 print -r -- "s=\"$s\""
9739 eval "$s"
9740 typeset -p u v w
9741expected-stdout:
9742 <i=x j=a b k=c
9743 d e€f>
9744 s="u=x v='a b' w=$'c\nd\240e\u20ACf'"
9745 typeset u=x
9746 typeset v='a b'
9747 typeset w=$'c\nd\240e\u20ACf'
Geremy Condra03ebf062011-10-12 18:17:24 -07009748---
Elliott Hughes23925bb2017-09-22 16:04:20 -07009749name: varexpand-special-quote-faux-EBCDIC
9750description:
9751 Check special ${var@Q} expansion for quoted strings
9752category: shell:faux-ebcdic
9753stdin:
9754 set +U
9755 i=x
9756 j=a\ b
9757 k=$'c
9758 d\xA0''e€f'
9759 print -r -- "<i=$i j=$j k=$k>"
9760 s="u=${i@Q} v=${j@Q} w=${k@Q}"
9761 print -r -- "s=\"$s\""
9762 eval "$s"
9763 typeset -p u v w
9764expected-stdout:
9765 <i=x j=a b k=c
9766 d e€f>
9767 s="u=x v='a b' w=$'c\nd e\u20ACf'"
9768 typeset u=x
9769 typeset v='a b'
9770 typeset w=$'c\nd e\u20ACf'
9771---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009772name: varexpand-null-1
9773description:
9774 Ensure empty strings expand emptily
9775stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07009776 print s ${a} . ${b} S
9777 print t ${a#?} . ${b%?} T
9778 print r ${a=} . ${b/c/d} R
9779 print q
9780 print s "${a}" . "${b}" S
9781 print t "${a#?}" . "${b%?}" T
9782 print r "${a=}" . "${b/c/d}" R
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009783expected-stdout:
Elliott Hughes50012062015-03-10 22:22:24 -07009784 s . S
9785 t . T
9786 r . R
9787 q
9788 s . S
9789 t . T
9790 r . R
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009791---
9792name: varexpand-null-2
9793description:
9794 Ensure empty strings, when quoted, are expanded as empty strings
9795stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009796 print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "<$x> "; done' >pfs
9797 chmod +x pfs
9798 ./pfs 1 "${a}" 2 "${a#?}" + "${b%?}" 3 "${a=}" + "${b/c/d}"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009799 echo .
9800expected-stdout:
9801 <1> <> <2> <> <+> <> <3> <> <+> <> .
9802---
Elliott Hughes56b517d2014-10-06 11:30:44 -07009803name: varexpand-null-3
9804description:
9805 Ensure concatenating behaviour matches other shells
Elliott Hughes56b517d2014-10-06 11:30:44 -07009806stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07009807 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
Elliott Hughes96b43632015-07-17 11:39:41 -07009808 showargs 0 ""$@
Elliott Hughes50012062015-03-10 22:22:24 -07009809 x=; showargs 1 "$x"$@
9810 set A; showargs 2 "${@:+}"
9811 n() { echo "$#"; }
9812 unset e
9813 set -- a b
9814 n """$@"
9815 n "$@"
9816 n "$@"""
9817 n "$e""$@"
9818 n "$@"
9819 n "$@""$e"
9820 set --
9821 n """$@"
9822 n "$@"
9823 n "$@"""
9824 n "$e""$@"
9825 n "$@"
9826 n "$@""$e"
Elliott Hughes56b517d2014-10-06 11:30:44 -07009827expected-stdout:
Elliott Hughes96b43632015-07-17 11:39:41 -07009828 <0> <> .
Elliott Hughes50012062015-03-10 22:22:24 -07009829 <1> <> .
9830 <2> <> .
9831 2
9832 2
9833 2
9834 2
9835 2
9836 2
9837 1
9838 0
9839 1
9840 1
9841 0
9842 1
Elliott Hughes56b517d2014-10-06 11:30:44 -07009843---
Elliott Hughesfc0307d2016-02-02 15:26:47 -08009844name: varexpand-funny-chars
9845description:
9846 Check some characters
9847 XXX \uEF80 is asymmetric, possibly buggy so we don’t check this
9848stdin:
9849 x=$'<\x00>'; typeset -p x
9850 x=$'<\x01>'; typeset -p x
9851 x=$'<\u0000>'; typeset -p x
9852 x=$'<\u0001>'; typeset -p x
9853expected-stdout:
9854 typeset x='<'
9855 typeset x=$'<\001>'
9856 typeset x='<'
9857 typeset x=$'<\001>'
9858---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009859name: print-funny-chars
9860description:
9861 Check print builtin's capability to output designated characters
9862stdin:
Elliott Hughes77740fc2016-08-12 15:06:53 -07009863 {
9864 print '<\0144\0344\xDB\u00DB\u20AC\uDB\x40>'
9865 print '<\x00>'
9866 print '<\x01>'
9867 print '<\u0000>'
9868 print '<\u0001>'
9869 } | {
9870 # integer-base-one-3Ar
9871 typeset -Uui16 -Z11 pos=0
9872 typeset -Uui16 -Z5 hv=2147483647
9873 dasc=
9874 if read -arN -1 line; then
9875 typeset -i1 line
9876 i=0
9877 while (( i < ${#line[*]} )); do
9878 hv=${line[i++]}
9879 if (( (pos & 15) == 0 )); then
Elliott Hughesa3c3f962017-04-12 16:52:30 -07009880 (( pos )) && print -r -- "$dasc|"
Elliott Hughes77740fc2016-08-12 15:06:53 -07009881 print -n "${pos#16#} "
9882 dasc=' |'
9883 fi
9884 print -n "${hv#16#} "
9885 if (( (hv < 32) || (hv > 126) )); then
9886 dasc=$dasc.
9887 else
9888 dasc=$dasc${line[i-1]#1#}
9889 fi
9890 (( (pos++ & 15) == 7 )) && print -n -- '- '
9891 done
9892 fi
9893 while (( pos & 15 )); do
9894 print -n ' '
9895 (( (pos++ & 15) == 7 )) && print -n -- '- '
9896 done
Elliott Hughesa3c3f962017-04-12 16:52:30 -07009897 (( hv == 2147483647 )) || print -r -- "$dasc|"
Elliott Hughes77740fc2016-08-12 15:06:53 -07009898 }
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009899expected-stdout:
Elliott Hughes77740fc2016-08-12 15:06:53 -07009900 00000000 3C 64 E4 DB C3 9B E2 82 - AC C3 9B 40 3E 0A 3C 00 |<d.........@>.<.|
9901 00000010 3E 0A 3C 01 3E 0A 3C 00 - 3E 0A 3C 01 3E 0A |>.<.>.<.>.<.>.|
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009902---
9903name: print-bksl-c
9904description:
9905 Check print builtin's \c escape
9906stdin:
9907 print '\ca'; print b
9908expected-stdout:
9909 ab
9910---
Thorsten Glaser811a5752013-07-25 14:24:45 +00009911name: print-cr
9912description:
9913 Check that CR+LF is not collapsed into LF as some MSYS shells wrongly do
9914stdin:
9915 echo '#!'"$__progname" >foo
9916 cat >>foo <<-'EOF'
9917 print -n -- '220-blau.mirbsd.org ESMTP ready at Thu, 25 Jul 2013 15:57:57 GMT\r\n220->> Bitte keine Werbung einwerfen! <<\r\r\n220 Who do you wanna pretend to be today'
9918 print \?
9919 EOF
9920 chmod +x foo
9921 echo "[$(./foo)]"
9922 ./foo | while IFS= read -r line; do
9923 print -r -- "{$line}"
9924 done
9925expected-stdout:
9926 [220-blau.mirbsd.org ESMTP ready at Thu, 25 Jul 2013 15:57:57 GMT
9927 220->> Bitte keine Werbung einwerfen! <<
9928 220 Who do you wanna pretend to be today? ]
9929 {220-blau.mirbsd.org ESMTP ready at Thu, 25 Jul 2013 15:57:57 GMT }
9930 {220->> Bitte keine Werbung einwerfen! << }
9931 {220 Who do you wanna pretend to be today? }
9932---
Elliott Hughesb27ce952015-04-21 13:39:18 -07009933name: print-crlf
9934description:
9935 Check that CR+LF is shown and read as-is
Elliott Hughesa3c3f962017-04-12 16:52:30 -07009936category: shell:textmode-no
Elliott Hughesb27ce952015-04-21 13:39:18 -07009937stdin:
9938 cat >foo <<-'EOF'
9939 x='bar
9940 ' #
Elliott Hughes96b43632015-07-17 11:39:41 -07009941 echo .${#x} #
Elliott Hughesb27ce952015-04-21 13:39:18 -07009942 if test x"$KSH_VERSION" = x""; then #
9943 printf '<%s>' "$x" #
9944 else #
9945 print -nr -- "<$x>" #
9946 fi #
9947 EOF
9948 echo "[$("$__progname" foo)]"
9949 "$__progname" foo | while IFS= read -r line; do
9950 print -r -- "{$line}"
9951 done
9952expected-stdout:
Elliott Hughes96b43632015-07-17 11:39:41 -07009953 [.5
9954 <bar
Elliott Hughesb27ce952015-04-21 13:39:18 -07009955 >]
Elliott Hughes96b43632015-07-17 11:39:41 -07009956 {.5}
Elliott Hughesb27ce952015-04-21 13:39:18 -07009957 {<bar }
9958---
Elliott Hughesa3c3f962017-04-12 16:52:30 -07009959name: print-crlf-textmode
9960description:
9961 Check that CR+LF is treated as newline
9962category: shell:textmode-yes
9963stdin:
9964 cat >foo <<-'EOF'
9965 x='bar
9966 ' #
9967 echo .${#x} #
9968 if test x"$KSH_VERSION" = x""; then #
9969 printf '<%s>' "$x" #
9970 else #
9971 print -nr -- "<$x>" #
9972 fi #
9973 EOF
9974 echo "[$("$__progname" foo)]"
9975 "$__progname" foo | while IFS= read -r line; do
9976 print -r -- "{$line}"
9977 done
9978expected-stdout:
9979 [.4
9980 <bar
9981 >]
9982 {.4}
9983 {<bar}
9984---
Elliott Hughesb27ce952015-04-21 13:39:18 -07009985name: print-lf
9986description:
9987 Check that LF-only is shown and read as-is
9988stdin:
9989 cat >foo <<-'EOF'
9990 x='bar
9991 ' #
Elliott Hughes96b43632015-07-17 11:39:41 -07009992 echo .${#x} #
Elliott Hughesb27ce952015-04-21 13:39:18 -07009993 if test x"$KSH_VERSION" = x""; then #
9994 printf '<%s>' "$x" #
9995 else #
9996 print -nr -- "<$x>" #
9997 fi #
9998 EOF
9999 echo "[$("$__progname" foo)]"
10000 "$__progname" foo | while IFS= read -r line; do
10001 print -r -- "{$line}"
10002 done
10003expected-stdout:
Elliott Hughes96b43632015-07-17 11:39:41 -070010004 [.4
10005 <bar
Elliott Hughesb27ce952015-04-21 13:39:18 -070010006 >]
Elliott Hughes96b43632015-07-17 11:39:41 -070010007 {.4}
Elliott Hughesb27ce952015-04-21 13:39:18 -070010008 {<bar}
10009---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010010name: print-nul-chars
10011description:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000010012 Check handling of NUL characters for print and COMSUB
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010013stdin:
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010014 x=$(print '<\0>')
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000010015 print $(($(print '<\0>' | wc -c))) $(($(print "$x" | wc -c))) \
10016 ${#x} "$x" '<\0>'
10017expected-stdout-pattern:
10018 /^4 3 2 <> <\0>$/
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010019---
Elliott Hughes77740fc2016-08-12 15:06:53 -070010020name: print-array
10021description:
10022 Check that print -A works as expected
10023stdin:
10024 print -An 0x20AC 0xC3 0xBC 8#101
10025 set -U
10026 print -A 0x20AC 0xC3 0xBC 8#102
10027expected-stdout:
10028 ¬Ã¼A€Ã¼B
10029---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010030name: print-escapes
10031description:
10032 Check backslash expansion by the print builtin
10033stdin:
10034 print '\ \!\"\#\$\%\&'\\\''\(\)\*\+\,\-\.\/\0\1\2\3\4\5\6\7\8' \
10035 '\9\:\;\<\=\>\?\@\A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T' \
10036 '\U\V\W\X\Y\Z\[\\\]\^\_\`\a\b \d\e\f\g\h\i\j\k\l\m\n\o\p' \
10037 '\q\r\s\t\u\v\w\x\y\z\{\|\}\~' '\u20acd' '\U20acd' '\x123' \
10038 '\0x' '\0123' '\01234' | {
Geremy Condra03ebf062011-10-12 18:17:24 -070010039 # integer-base-one-3As
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010040 typeset -Uui16 -Z11 pos=0
Geremy Condra03ebf062011-10-12 18:17:24 -070010041 typeset -Uui16 -Z5 hv=2147483647
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010042 typeset -i1 wc=0x0A
10043 dasc=
10044 nl=${wc#1#}
10045 while IFS= read -r line; do
10046 line=$line$nl
10047 while [[ -n $line ]]; do
10048 hv=1#${line::1}
10049 if (( (pos & 15) == 0 )); then
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010050 (( pos )) && print -r -- "$dasc|"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010051 print -n "${pos#16#} "
10052 dasc=' |'
10053 fi
10054 print -n "${hv#16#} "
10055 if (( (hv < 32) || (hv > 126) )); then
10056 dasc=$dasc.
10057 else
10058 dasc=$dasc${line::1}
10059 fi
10060 (( (pos++ & 15) == 7 )) && print -n -- '- '
10061 line=${line:1}
10062 done
10063 done
Geremy Condra03ebf062011-10-12 18:17:24 -070010064 while (( pos & 15 )); do
10065 print -n ' '
10066 (( (pos++ & 15) == 7 )) && print -n -- '- '
10067 done
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010068 (( hv == 2147483647 )) || print -r -- "$dasc|"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010069 }
10070expected-stdout:
10071 00000000 5C 20 5C 21 5C 22 5C 23 - 5C 24 5C 25 5C 26 5C 27 |\ \!\"\#\$\%\&\'|
10072 00000010 5C 28 5C 29 5C 2A 5C 2B - 5C 2C 5C 2D 5C 2E 5C 2F |\(\)\*\+\,\-\.\/|
10073 00000020 5C 31 5C 32 5C 33 5C 34 - 5C 35 5C 36 5C 37 5C 38 |\1\2\3\4\5\6\7\8|
10074 00000030 20 5C 39 5C 3A 5C 3B 5C - 3C 5C 3D 5C 3E 5C 3F 5C | \9\:\;\<\=\>\?\|
10075 00000040 40 5C 41 5C 42 5C 43 5C - 44 1B 5C 46 5C 47 5C 48 |@\A\B\C\D.\F\G\H|
10076 00000050 5C 49 5C 4A 5C 4B 5C 4C - 5C 4D 5C 4E 5C 4F 5C 50 |\I\J\K\L\M\N\O\P|
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010077 00000060 5C 51 5C 52 5C 53 5C 54 - 20 5C 55 5C 56 5C 57 5C |\Q\R\S\T \U\V\W\|
10078 00000070 58 5C 59 5C 5A 5C 5B 5C - 5C 5D 5C 5E 5C 5F 5C 60 |X\Y\Z\[\\]\^\_\`|
10079 00000080 07 08 20 20 5C 64 1B 0C - 5C 67 5C 68 5C 69 5C 6A |.. \d..\g\h\i\j|
10080 00000090 5C 6B 5C 6C 5C 6D 0A 5C - 6F 5C 70 20 5C 71 0D 5C |\k\l\m.\o\p \q.\|
10081 000000A0 73 09 5C 75 0B 5C 77 5C - 78 5C 79 5C 7A 5C 7B 5C |s.\u.\w\x\y\z\{\|
10082 000000B0 7C 5C 7D 5C 7E 20 E2 82 - AC 64 20 EF BF BD 20 12 ||\}\~ ...d ... .|
10083 000000C0 33 20 78 20 53 20 53 34 - 0A |3 x S S4.|
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010084---
Geremy Condra03ebf062011-10-12 18:17:24 -070010085name: dollar-doublequoted-strings
10086description:
10087 Check that a $ preceding "…" is ignored
10088stdin:
10089 echo $"Localise me!"
10090 cat <<<$"Me too!"
10091 V=X
10092 aol=aol
10093 cat <<-$"aol"
10094 I do not take a $V for a V!
10095 aol
10096expected-stdout:
10097 Localise me!
10098 Me too!
10099 I do not take a $V for a V!
10100---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010101name: dollar-quoted-strings
10102description:
10103 Check backslash expansion by $'…' strings
10104stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000010105 print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
10106 chmod +x pfn
10107 ./pfn $'\ \!\"\#\$\%\&\'\(\)\*\+\,\-\.\/ \1\2\3\4\5\6' \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010108 $'a\0b' $'a\01b' $'\7\8\9\:\;\<\=\>\?\@\A\B\C\D\E\F\G\H\I' \
10109 $'\J\K\L\M\N\O\P\Q\R\S\T\U1\V\W\X\Y\Z\[\\\]\^\_\`\a\b\d\e' \
10110 $'\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u1\v\w\x1\y\z\{\|\}\~ $x' \
10111 $'\u20acd' $'\U20acd' $'\x123' $'fn\x0rd' $'\0234' $'\234' \
Elliott Hughes23925bb2017-09-22 16:04:20 -070010112 $'\2345' $'\ca' $'\c!' $'\c?' $'\c…' $'a\
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010113 b' | {
Geremy Condra03ebf062011-10-12 18:17:24 -070010114 # integer-base-one-3As
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010115 typeset -Uui16 -Z11 pos=0
Geremy Condra03ebf062011-10-12 18:17:24 -070010116 typeset -Uui16 -Z5 hv=2147483647
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010117 typeset -i1 wc=0x0A
10118 dasc=
10119 nl=${wc#1#}
10120 while IFS= read -r line; do
10121 line=$line$nl
10122 while [[ -n $line ]]; do
10123 hv=1#${line::1}
10124 if (( (pos & 15) == 0 )); then
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010125 (( pos )) && print -r -- "$dasc|"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010126 print -n "${pos#16#} "
10127 dasc=' |'
10128 fi
10129 print -n "${hv#16#} "
10130 if (( (hv < 32) || (hv > 126) )); then
10131 dasc=$dasc.
10132 else
10133 dasc=$dasc${line::1}
10134 fi
10135 (( (pos++ & 15) == 7 )) && print -n -- '- '
10136 line=${line:1}
10137 done
10138 done
Geremy Condra03ebf062011-10-12 18:17:24 -070010139 while (( pos & 15 )); do
10140 print -n ' '
10141 (( (pos++ & 15) == 7 )) && print -n -- '- '
10142 done
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010143 (( hv == 2147483647 )) || print -r -- "$dasc|"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010144 }
10145expected-stdout:
10146 00000000 20 21 22 23 24 25 26 27 - 28 29 2A 2B 2C 2D 2E 2F | !"#$%&'()*+,-./|
10147 00000010 20 01 02 03 04 05 06 0A - 61 0A 61 01 62 0A 07 38 | .......a.a.b..8|
10148 00000020 39 3A 3B 3C 3D 3E 3F 40 - 41 42 43 44 1B 46 47 48 |9:;<=>?@ABCD.FGH|
10149 00000030 49 0A 4A 4B 4C 4D 4E 4F - 50 51 52 53 54 01 56 57 |I.JKLMNOPQRST.VW|
10150 00000040 58 59 5A 5B 5C 5D 5E 5F - 60 07 08 64 1B 0A 0C 67 |XYZ[\]^_`..d...g|
10151 00000050 68 69 6A 6B 6C 6D 0A 6F - 70 71 0D 73 09 01 0B 77 |hijklm.opq.s...w|
10152 00000060 01 79 7A 7B 7C 7D 7E 20 - 24 78 0A E2 82 AC 64 0A |.yz{|}~ $x....d.|
10153 00000070 EF BF BD 0A C4 A3 0A 66 - 6E 0A 13 34 0A 9C 0A 9C |.......fn..4....|
Elliott Hughes23925bb2017-09-22 16:04:20 -070010154 00000080 35 0A 01 0A 01 0A 7F 0A - 82 80 A6 0A 61 0A 62 0A |5...........a.b.|
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010155---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000010156name: dollar-quotes-in-heredocs-strings
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010157description:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000010158 They are, however, not parsed in here documents, here strings
10159 (outside of string delimiters) or regular strings, but in
10160 parameter substitutions.
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010161stdin:
10162 cat <<EOF
10163 dollar = strchr(s, '$'); /* ' */
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000010164 foo " bar \" baz
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010165 EOF
10166 cat <<$'a\tb'
10167 a\tb
10168 a b
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010169 cat <<<"dollar = strchr(s, '$'); /* ' */"
10170 cat <<<'dollar = strchr(s, '\''$'\''); /* '\'' */'
10171 x="dollar = strchr(s, '$'); /* ' */"
10172 cat <<<"$x"
10173 cat <<<$'a\E[0m\tb'
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000010174 unset nl; print -r -- "x${nl:=$'\n'}y"
10175 echo "1 foo\"bar"
10176 # cf & HEREDOC
10177 cat <<EOF
10178 2 foo\"bar
10179 EOF
10180 # probably never reached for here strings?
10181 cat <<<"3 foo\"bar"
10182 cat <<<"4 foo\\\"bar"
10183 cat <<<'5 foo\"bar'
10184 # old scripts use this (e.g. ncurses)
10185 echo "^$"
10186 # make sure this works, outside of quotes
10187 cat <<<'7'$'\t''.'
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010188expected-stdout:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000010189 dollar = strchr(s, '$'); /* ' */
10190 foo " bar \" baz
10191 a\tb
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010192 dollar = strchr(s, '$'); /* ' */
10193 dollar = strchr(s, '$'); /* ' */
10194 dollar = strchr(s, '$'); /* ' */
10195 a b
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000010196 x
10197 y
10198 1 foo"bar
10199 2 foo\"bar
10200 3 foo"bar
10201 4 foo\"bar
10202 5 foo\"bar
10203 ^$
10204 7 .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010205---
10206name: dot-needs-argument
10207description:
10208 check Debian #415167 solution: '.' without arguments should fail
10209stdin:
10210 "$__progname" -c .
10211 "$__progname" -c source
10212expected-exit: e != 0
10213expected-stderr-pattern:
Elliott Hughesfc0307d2016-02-02 15:26:47 -080010214 /\.: missing argument.*\n.*source: missing argument/
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010215---
Elliott Hughes77740fc2016-08-12 15:06:53 -070010216name: dot-errorlevel
10217description:
10218 Ensure dot resets $?
10219stdin:
10220 :>dotfile
10221 (exit 42)
10222 . ./dotfile
10223 echo 1 $? .
10224expected-stdout:
10225 1 0 .
10226---
Elliott Hughes96b43632015-07-17 11:39:41 -070010227name: alias-function-no-conflict
10228description:
10229 make aliases not conflict with function definitions
Elliott Hughes96b43632015-07-17 11:39:41 -070010230stdin:
10231 # POSIX function can be defined, but alias overrides it
10232 alias foo='echo bar'
10233 foo
10234 foo() {
10235 echo baz
10236 }
10237 foo
10238 unset -f foo
10239 foo 2>/dev/null || echo rab
10240 # alias overrides ksh function
10241 alias korn='echo bar'
10242 korn
10243 function korn {
10244 echo baz
10245 }
10246 korn
10247 # alias temporarily overrides POSIX function
10248 bla() {
10249 echo bfn
10250 }
10251 bla
10252 alias bla='echo bal'
10253 bla
10254 unalias bla
10255 bla
10256expected-stdout:
10257 bar
10258 bar
10259 bar
10260 bar
10261 bar
10262 bfn
10263 bal
10264 bfn
10265---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010266name: bash-function-parens
10267description:
10268 ensure the keyword function is ignored when preceding
10269 POSIX style function declarations (bashism)
10270stdin:
10271 mk() {
10272 echo '#!'"$__progname"
10273 echo "$1 {"
10274 echo ' echo "bar='\''$0'\'\"
10275 echo '}'
Elliott Hughesb27ce952015-04-21 13:39:18 -070010276 print -r -- "${2:-foo}"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010277 }
10278 mk 'function foo' >f-korn
10279 mk 'foo ()' >f-dash
10280 mk 'function foo ()' >f-bash
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000010281 print '#!'"$__progname"'\nprint -r -- "${0%/f-argh}"' >f-argh
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010282 chmod +x f-*
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000010283 u=$(./f-argh)
10284 x="korn: $(./f-korn)"; echo "${x/@("$u")/.}"
10285 x="dash: $(./f-dash)"; echo "${x/@("$u")/.}"
10286 x="bash: $(./f-bash)"; echo "${x/@("$u")/.}"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010287expected-stdout:
10288 korn: bar='foo'
10289 dash: bar='./f-dash'
10290 bash: bar='./f-bash'
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010291---
10292name: integer-base-one-1
10293description:
10294 check if the use of fake integer base 1 works
10295stdin:
10296 set -U
10297 typeset -Uui16 i0=1#ï i1=1#€
10298 typeset -i1 o0a=64
10299 typeset -i1 o1a=0x263A
10300 typeset -Uui1 o0b=0x7E
10301 typeset -Uui1 o1b=0xFDD0
10302 integer px=0xCAFE 'p0=1# ' p1=1#… pl=1#f
10303 echo "in <$i0> <$i1>"
10304 echo "out <${o0a#1#}|${o0b#1#}> <${o1a#1#}|${o1b#1#}>"
10305 typeset -Uui1 i0 i1
10306 echo "pass <$px> <$p0> <$p1> <$pl> <${i0#1#}|${i1#1#}>"
10307 typeset -Uui16 tv1=1#~ tv2=1# tv3=1#€ tv4=1# tv5=1#À tv6=1#Á tv7=1#  tv8=1#€
10308 echo "specX <${tv1#16#}> <${tv2#16#}> <${tv3#16#}> <${tv4#16#}> <${tv5#16#}> <${tv6#16#}> <${tv7#16#}> <${tv8#16#}>"
10309 typeset -i1 tv1 tv2 tv3 tv4 tv5 tv6 tv7 tv8
10310 echo "specW <${tv1#1#}> <${tv2#1#}> <${tv3#1#}> <${tv4#1#}> <${tv5#1#}> <${tv6#1#}> <${tv7#1#}> <${tv8#1#}>"
10311 typeset -i1 xs1=0xEF7F xs2=0xEF80 xs3=0xFDD0
10312 echo "specU <${xs1#1#}> <${xs2#1#}> <${xs3#1#}>"
10313expected-stdout:
10314 in <16#EFEF> <16#20AC>
10315 out <@|~> <☺|﷐>
10316 pass <16#cafe> <1# > <1#…> <1#f> <ï|€>
10317 specX <7E> <7F> <EF80> <EF81> <EFC0> <EFC1> <A0> <80>
10318 specW <~> <> <€> <> <À> <Á> < > <€>
10319 specU <> <€> <﷐>
10320---
10321name: integer-base-one-2a
10322description:
10323 check if the use of fake integer base 1 stops at correct characters
10324stdin:
10325 set -U
10326 integer x=1#foo
10327 echo /$x/
10328expected-stderr-pattern:
10329 /1#foo: unexpected 'oo'/
10330expected-exit: e != 0
10331---
10332name: integer-base-one-2b
10333description:
10334 check if the use of fake integer base 1 stops at correct characters
10335stdin:
10336 set -U
10337 integer x=1#
10338 echo /$x/
10339expected-stderr-pattern:
10340 /1#À€: unexpected '€'/
10341expected-exit: e != 0
10342---
10343name: integer-base-one-2c1
10344description:
10345 check if the use of fake integer base 1 stops at correct characters
10346stdin:
10347 set -U
10348 integer x=1#…
10349 echo /$x/
10350expected-stdout:
10351 /1#…/
10352---
10353name: integer-base-one-2c2
10354description:
10355 check if the use of fake integer base 1 stops at correct characters
10356stdin:
10357 set +U
10358 integer x=1#…
10359 echo /$x/
10360expected-stderr-pattern:
10361 /1#…: unexpected '€'/
10362expected-exit: e != 0
10363---
10364name: integer-base-one-2d1
10365description:
10366 check if the use of fake integer base 1 handles octets okay
10367stdin:
10368 set -U
10369 typeset -i16 x=1#ÿ
10370 echo /$x/ # invalid utf-8
10371expected-stdout:
10372 /16#efff/
10373---
10374name: integer-base-one-2d2
10375description:
10376 check if the use of fake integer base 1 handles octets
10377stdin:
10378 set -U
10379 typeset -i16 x=1#Â
10380 echo /$x/ # invalid 2-byte
10381expected-stdout:
10382 /16#efc2/
10383---
10384name: integer-base-one-2d3
10385description:
10386 check if the use of fake integer base 1 handles octets
10387stdin:
10388 set -U
10389 typeset -i16 x=1#ï
10390 echo /$x/ # invalid 2-byte
10391expected-stdout:
10392 /16#efef/
10393---
10394name: integer-base-one-2d4
10395description:
10396 check if the use of fake integer base 1 stops at invalid input
10397stdin:
10398 set -U
10399 typeset -i16 x=1#ï¿À
10400 echo /$x/ # invalid 3-byte
10401expected-stderr-pattern:
10402 /1#ï¿À: unexpected '¿'/
10403expected-exit: e != 0
10404---
10405name: integer-base-one-2d5
10406description:
10407 check if the use of fake integer base 1 stops at invalid input
10408stdin:
10409 set -U
10410 typeset -i16 x=1#
10411 echo /$x/ # non-minimalistic
10412expected-stderr-pattern:
10413 /1#À€: unexpected '€'/
10414expected-exit: e != 0
10415---
10416name: integer-base-one-2d6
10417description:
10418 check if the use of fake integer base 1 stops at invalid input
10419stdin:
10420 set -U
10421 typeset -i16 x=1#à€€
10422 echo /$x/ # non-minimalistic
10423expected-stderr-pattern:
10424 /1#à€€: unexpected '€'/
10425expected-exit: e != 0
10426---
Geremy Condra03ebf062011-10-12 18:17:24 -070010427name: integer-base-one-3As
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010428description:
10429 some sample code for hexdumping
Geremy Condra03ebf062011-10-12 18:17:24 -070010430 not NUL safe; input lines must be NL terminated
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010431stdin:
10432 {
10433 print 'Hello, World!\\\nこんにちは!'
10434 typeset -Uui16 i=0x100
10435 # change that to 0xFF once we can handle embedded
10436 # NUL characters in strings / here documents
10437 while (( i++ < 0x1FF )); do
10438 print -n "\x${i#16#1}"
10439 done
Geremy Condra03ebf062011-10-12 18:17:24 -070010440 print '\0z'
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010441 } | {
Geremy Condra03ebf062011-10-12 18:17:24 -070010442 # integer-base-one-3As
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010443 typeset -Uui16 -Z11 pos=0
Geremy Condra03ebf062011-10-12 18:17:24 -070010444 typeset -Uui16 -Z5 hv=2147483647
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010445 typeset -i1 wc=0x0A
10446 dasc=
10447 nl=${wc#1#}
10448 while IFS= read -r line; do
10449 line=$line$nl
10450 while [[ -n $line ]]; do
10451 hv=1#${line::1}
10452 if (( (pos & 15) == 0 )); then
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010453 (( pos )) && print -r -- "$dasc|"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010454 print -n "${pos#16#} "
10455 dasc=' |'
10456 fi
10457 print -n "${hv#16#} "
10458 if (( (hv < 32) || (hv > 126) )); then
10459 dasc=$dasc.
10460 else
10461 dasc=$dasc${line::1}
10462 fi
10463 (( (pos++ & 15) == 7 )) && print -n -- '- '
10464 line=${line:1}
10465 done
10466 done
Geremy Condra03ebf062011-10-12 18:17:24 -070010467 while (( pos & 15 )); do
10468 print -n ' '
10469 (( (pos++ & 15) == 7 )) && print -n -- '- '
10470 done
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010471 (( hv == 2147483647 )) || print -r -- "$dasc|"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010472 }
10473expected-stdout:
10474 00000000 48 65 6C 6C 6F 2C 20 57 - 6F 72 6C 64 21 5C 0A E3 |Hello, World!\..|
10475 00000010 81 93 E3 82 93 E3 81 AB - E3 81 A1 E3 81 AF EF BC |................|
10476 00000020 81 0A 01 02 03 04 05 06 - 07 08 09 0A 0B 0C 0D 0E |................|
10477 00000030 0F 10 11 12 13 14 15 16 - 17 18 19 1A 1B 1C 1D 1E |................|
10478 00000040 1F 20 21 22 23 24 25 26 - 27 28 29 2A 2B 2C 2D 2E |. !"#$%&'()*+,-.|
10479 00000050 2F 30 31 32 33 34 35 36 - 37 38 39 3A 3B 3C 3D 3E |/0123456789:;<=>|
10480 00000060 3F 40 41 42 43 44 45 46 - 47 48 49 4A 4B 4C 4D 4E |?@ABCDEFGHIJKLMN|
10481 00000070 4F 50 51 52 53 54 55 56 - 57 58 59 5A 5B 5C 5D 5E |OPQRSTUVWXYZ[\]^|
10482 00000080 5F 60 61 62 63 64 65 66 - 67 68 69 6A 6B 6C 6D 6E |_`abcdefghijklmn|
10483 00000090 6F 70 71 72 73 74 75 76 - 77 78 79 7A 7B 7C 7D 7E |opqrstuvwxyz{|}~|
10484 000000A0 7F 80 81 82 83 84 85 86 - 87 88 89 8A 8B 8C 8D 8E |................|
10485 000000B0 8F 90 91 92 93 94 95 96 - 97 98 99 9A 9B 9C 9D 9E |................|
10486 000000C0 9F A0 A1 A2 A3 A4 A5 A6 - A7 A8 A9 AA AB AC AD AE |................|
10487 000000D0 AF B0 B1 B2 B3 B4 B5 B6 - B7 B8 B9 BA BB BC BD BE |................|
10488 000000E0 BF C0 C1 C2 C3 C4 C5 C6 - C7 C8 C9 CA CB CC CD CE |................|
10489 000000F0 CF D0 D1 D2 D3 D4 D5 D6 - D7 D8 D9 DA DB DC DD DE |................|
10490 00000100 DF E0 E1 E2 E3 E4 E5 E6 - E7 E8 E9 EA EB EC ED EE |................|
10491 00000110 EF F0 F1 F2 F3 F4 F5 F6 - F7 F8 F9 FA FB FC FD FE |................|
Geremy Condra03ebf062011-10-12 18:17:24 -070010492 00000120 FF 7A 0A - |.z.|
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010493---
Geremy Condra03ebf062011-10-12 18:17:24 -070010494name: integer-base-one-3Ws
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010495description:
Elliott Hughes47086262019-03-26 12:34:31 -070010496 some sample code for hexdumping UCS-2
Geremy Condra03ebf062011-10-12 18:17:24 -070010497 not NUL safe; input lines must be NL terminated
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010498stdin:
10499 set -U
10500 {
10501 print 'Hello, World!\\\nこんにちは!'
10502 typeset -Uui16 i=0x100
10503 # change that to 0xFF once we can handle embedded
10504 # NUL characters in strings / here documents
10505 while (( i++ < 0x1FF )); do
10506 print -n "\u${i#16#1}"
10507 done
10508 print
10509 print \\xff # invalid utf-8
10510 print \\xc2 # invalid 2-byte
10511 print \\xef\\xbf\\xc0 # invalid 3-byte
10512 print \\xc0\\x80 # non-minimalistic
10513 print \\xe0\\x80\\x80 # non-minimalistic
10514 print '�￾￿' # end of range
Geremy Condra03ebf062011-10-12 18:17:24 -070010515 print '\0z' # embedded NUL
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010516 } | {
Geremy Condra03ebf062011-10-12 18:17:24 -070010517 # integer-base-one-3Ws
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010518 typeset -Uui16 -Z11 pos=0
10519 typeset -Uui16 -Z7 hv
10520 typeset -i1 wc=0x0A
10521 typeset -i lpos
10522 dasc=
10523 nl=${wc#1#}
10524 while IFS= read -r line; do
10525 line=$line$nl
10526 lpos=0
10527 while (( lpos < ${#line} )); do
10528 wc=1#${line:(lpos++):1}
10529 if (( (wc < 32) || \
10530 ((wc > 126) && (wc < 160)) )); then
10531 dch=.
10532 elif (( (wc & 0xFF80) == 0xEF80 )); then
10533 dch=�
10534 else
10535 dch=${wc#1#}
10536 fi
10537 if (( (pos & 7) == 7 )); then
10538 dasc=$dasc$dch
10539 dch=
10540 elif (( (pos & 7) == 0 )); then
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010541 (( pos )) && print -r -- "$dasc|"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010542 print -n "${pos#16#} "
10543 dasc=' |'
10544 fi
10545 let hv=wc
10546 print -n "${hv#16#} "
10547 (( (pos++ & 7) == 3 )) && \
10548 print -n -- '- '
10549 dasc=$dasc$dch
10550 done
10551 done
Geremy Condra03ebf062011-10-12 18:17:24 -070010552 while (( pos & 7 )); do
10553 print -n ' '
10554 (( (pos++ & 7) == 3 )) && print -n -- '- '
10555 done
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010556 (( hv == 2147483647 )) || print -r -- "$dasc|"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010557 }
10558expected-stdout:
10559 00000000 0048 0065 006C 006C - 006F 002C 0020 0057 |Hello, W|
10560 00000008 006F 0072 006C 0064 - 0021 005C 000A 3053 |orld!\.こ|
10561 00000010 3093 306B 3061 306F - FF01 000A 0001 0002 |んにちは!...|
10562 00000018 0003 0004 0005 0006 - 0007 0008 0009 000A |........|
10563 00000020 000B 000C 000D 000E - 000F 0010 0011 0012 |........|
10564 00000028 0013 0014 0015 0016 - 0017 0018 0019 001A |........|
10565 00000030 001B 001C 001D 001E - 001F 0020 0021 0022 |..... !"|
10566 00000038 0023 0024 0025 0026 - 0027 0028 0029 002A |#$%&'()*|
10567 00000040 002B 002C 002D 002E - 002F 0030 0031 0032 |+,-./012|
10568 00000048 0033 0034 0035 0036 - 0037 0038 0039 003A |3456789:|
10569 00000050 003B 003C 003D 003E - 003F 0040 0041 0042 |;<=>?@AB|
10570 00000058 0043 0044 0045 0046 - 0047 0048 0049 004A |CDEFGHIJ|
10571 00000060 004B 004C 004D 004E - 004F 0050 0051 0052 |KLMNOPQR|
10572 00000068 0053 0054 0055 0056 - 0057 0058 0059 005A |STUVWXYZ|
10573 00000070 005B 005C 005D 005E - 005F 0060 0061 0062 |[\]^_`ab|
10574 00000078 0063 0064 0065 0066 - 0067 0068 0069 006A |cdefghij|
10575 00000080 006B 006C 006D 006E - 006F 0070 0071 0072 |klmnopqr|
10576 00000088 0073 0074 0075 0076 - 0077 0078 0079 007A |stuvwxyz|
10577 00000090 007B 007C 007D 007E - 007F 0080 0081 0082 |{|}~....|
10578 00000098 0083 0084 0085 0086 - 0087 0088 0089 008A |........|
10579 000000A0 008B 008C 008D 008E - 008F 0090 0091 0092 |........|
10580 000000A8 0093 0094 0095 0096 - 0097 0098 0099 009A |........|
10581 000000B0 009B 009C 009D 009E - 009F 00A0 00A1 00A2 |..... ¡¢|
10582 000000B8 00A3 00A4 00A5 00A6 - 00A7 00A8 00A9 00AA |£¤¥¦§¨©ª|
10583 000000C0 00AB 00AC 00AD 00AE - 00AF 00B0 00B1 00B2 |«¬­®¯°±²|
10584 000000C8 00B3 00B4 00B5 00B6 - 00B7 00B8 00B9 00BA |³´µ¶·¸¹º|
10585 000000D0 00BB 00BC 00BD 00BE - 00BF 00C0 00C1 00C2 |»¼½¾¿ÀÁÂ|
10586 000000D8 00C3 00C4 00C5 00C6 - 00C7 00C8 00C9 00CA |ÃÄÅÆÇÈÉÊ|
10587 000000E0 00CB 00CC 00CD 00CE - 00CF 00D0 00D1 00D2 |ËÌÍÎÏÐÑÒ|
10588 000000E8 00D3 00D4 00D5 00D6 - 00D7 00D8 00D9 00DA |ÓÔÕÖרÙÚ|
10589 000000F0 00DB 00DC 00DD 00DE - 00DF 00E0 00E1 00E2 |ÛÜÝÞßàáâ|
10590 000000F8 00E3 00E4 00E5 00E6 - 00E7 00E8 00E9 00EA |ãäåæçèéê|
10591 00000100 00EB 00EC 00ED 00EE - 00EF 00F0 00F1 00F2 |ëìíîïðñò|
10592 00000108 00F3 00F4 00F5 00F6 - 00F7 00F8 00F9 00FA |óôõö÷øùú|
10593 00000110 00FB 00FC 00FD 00FE - 00FF 000A EFFF 000A |ûüýþÿ.�.|
10594 00000118 EFC2 000A EFEF EFBF - EFC0 000A EFC0 EF80 |�.���.��|
10595 00000120 000A EFE0 EF80 EF80 - 000A FFFD EFEF EFBF |.���.���|
Geremy Condra03ebf062011-10-12 18:17:24 -070010596 00000128 EFBE EFEF EFBF EFBF - 000A 007A 000A |����.z.|
10597---
10598name: integer-base-one-3Ar
10599description:
10600 some sample code for hexdumping; NUL and binary safe
10601stdin:
10602 {
10603 print 'Hello, World!\\\nこんにちは!'
10604 typeset -Uui16 i=0x100
10605 # change that to 0xFF once we can handle embedded
10606 # NUL characters in strings / here documents
10607 while (( i++ < 0x1FF )); do
10608 print -n "\x${i#16#1}"
10609 done
10610 print '\0z'
10611 } | {
10612 # integer-base-one-3Ar
10613 typeset -Uui16 -Z11 pos=0
10614 typeset -Uui16 -Z5 hv=2147483647
10615 dasc=
10616 if read -arN -1 line; then
10617 typeset -i1 line
10618 i=0
10619 while (( i < ${#line[*]} )); do
10620 hv=${line[i++]}
10621 if (( (pos & 15) == 0 )); then
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010622 (( pos )) && print -r -- "$dasc|"
Geremy Condra03ebf062011-10-12 18:17:24 -070010623 print -n "${pos#16#} "
10624 dasc=' |'
10625 fi
10626 print -n "${hv#16#} "
10627 if (( (hv < 32) || (hv > 126) )); then
10628 dasc=$dasc.
10629 else
10630 dasc=$dasc${line[i-1]#1#}
10631 fi
10632 (( (pos++ & 15) == 7 )) && print -n -- '- '
10633 done
10634 fi
10635 while (( pos & 15 )); do
10636 print -n ' '
10637 (( (pos++ & 15) == 7 )) && print -n -- '- '
10638 done
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010639 (( hv == 2147483647 )) || print -r -- "$dasc|"
Geremy Condra03ebf062011-10-12 18:17:24 -070010640 }
10641expected-stdout:
10642 00000000 48 65 6C 6C 6F 2C 20 57 - 6F 72 6C 64 21 5C 0A E3 |Hello, World!\..|
10643 00000010 81 93 E3 82 93 E3 81 AB - E3 81 A1 E3 81 AF EF BC |................|
10644 00000020 81 0A 01 02 03 04 05 06 - 07 08 09 0A 0B 0C 0D 0E |................|
10645 00000030 0F 10 11 12 13 14 15 16 - 17 18 19 1A 1B 1C 1D 1E |................|
10646 00000040 1F 20 21 22 23 24 25 26 - 27 28 29 2A 2B 2C 2D 2E |. !"#$%&'()*+,-.|
10647 00000050 2F 30 31 32 33 34 35 36 - 37 38 39 3A 3B 3C 3D 3E |/0123456789:;<=>|
10648 00000060 3F 40 41 42 43 44 45 46 - 47 48 49 4A 4B 4C 4D 4E |?@ABCDEFGHIJKLMN|
10649 00000070 4F 50 51 52 53 54 55 56 - 57 58 59 5A 5B 5C 5D 5E |OPQRSTUVWXYZ[\]^|
10650 00000080 5F 60 61 62 63 64 65 66 - 67 68 69 6A 6B 6C 6D 6E |_`abcdefghijklmn|
10651 00000090 6F 70 71 72 73 74 75 76 - 77 78 79 7A 7B 7C 7D 7E |opqrstuvwxyz{|}~|
10652 000000A0 7F 80 81 82 83 84 85 86 - 87 88 89 8A 8B 8C 8D 8E |................|
10653 000000B0 8F 90 91 92 93 94 95 96 - 97 98 99 9A 9B 9C 9D 9E |................|
10654 000000C0 9F A0 A1 A2 A3 A4 A5 A6 - A7 A8 A9 AA AB AC AD AE |................|
10655 000000D0 AF B0 B1 B2 B3 B4 B5 B6 - B7 B8 B9 BA BB BC BD BE |................|
10656 000000E0 BF C0 C1 C2 C3 C4 C5 C6 - C7 C8 C9 CA CB CC CD CE |................|
10657 000000F0 CF D0 D1 D2 D3 D4 D5 D6 - D7 D8 D9 DA DB DC DD DE |................|
10658 00000100 DF E0 E1 E2 E3 E4 E5 E6 - E7 E8 E9 EA EB EC ED EE |................|
10659 00000110 EF F0 F1 F2 F3 F4 F5 F6 - F7 F8 F9 FA FB FC FD FE |................|
10660 00000120 FF 00 7A 0A - |..z.|
10661---
10662name: integer-base-one-3Wr
10663description:
Elliott Hughes47086262019-03-26 12:34:31 -070010664 some sample code for hexdumping UCS-2; NUL and binary safe
Geremy Condra03ebf062011-10-12 18:17:24 -070010665stdin:
10666 set -U
10667 {
10668 print 'Hello, World!\\\nこんにちは!'
10669 typeset -Uui16 i=0x100
10670 # change that to 0xFF once we can handle embedded
10671 # NUL characters in strings / here documents
10672 while (( i++ < 0x1FF )); do
10673 print -n "\u${i#16#1}"
10674 done
10675 print
10676 print \\xff # invalid utf-8
10677 print \\xc2 # invalid 2-byte
10678 print \\xef\\xbf\\xc0 # invalid 3-byte
10679 print \\xc0\\x80 # non-minimalistic
10680 print \\xe0\\x80\\x80 # non-minimalistic
10681 print '�￾￿' # end of range
10682 print '\0z' # embedded NUL
10683 } | {
10684 # integer-base-one-3Wr
10685 typeset -Uui16 -Z11 pos=0
10686 typeset -Uui16 -Z7 hv=2147483647
10687 dasc=
10688 if read -arN -1 line; then
10689 typeset -i1 line
10690 i=0
10691 while (( i < ${#line[*]} )); do
10692 hv=${line[i++]}
10693 if (( (hv < 32) || \
10694 ((hv > 126) && (hv < 160)) )); then
10695 dch=.
10696 elif (( (hv & 0xFF80) == 0xEF80 )); then
10697 dch=�
10698 else
10699 dch=${line[i-1]#1#}
10700 fi
10701 if (( (pos & 7) == 7 )); then
10702 dasc=$dasc$dch
10703 dch=
10704 elif (( (pos & 7) == 0 )); then
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010705 (( pos )) && print -r -- "$dasc|"
Geremy Condra03ebf062011-10-12 18:17:24 -070010706 print -n "${pos#16#} "
10707 dasc=' |'
10708 fi
10709 print -n "${hv#16#} "
10710 (( (pos++ & 7) == 3 )) && \
10711 print -n -- '- '
10712 dasc=$dasc$dch
10713 done
10714 fi
10715 while (( pos & 7 )); do
10716 print -n ' '
10717 (( (pos++ & 7) == 3 )) && print -n -- '- '
10718 done
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010719 (( hv == 2147483647 )) || print -r -- "$dasc|"
Geremy Condra03ebf062011-10-12 18:17:24 -070010720 }
10721expected-stdout:
10722 00000000 0048 0065 006C 006C - 006F 002C 0020 0057 |Hello, W|
10723 00000008 006F 0072 006C 0064 - 0021 005C 000A 3053 |orld!\.こ|
10724 00000010 3093 306B 3061 306F - FF01 000A 0001 0002 |んにちは!...|
10725 00000018 0003 0004 0005 0006 - 0007 0008 0009 000A |........|
10726 00000020 000B 000C 000D 000E - 000F 0010 0011 0012 |........|
10727 00000028 0013 0014 0015 0016 - 0017 0018 0019 001A |........|
10728 00000030 001B 001C 001D 001E - 001F 0020 0021 0022 |..... !"|
10729 00000038 0023 0024 0025 0026 - 0027 0028 0029 002A |#$%&'()*|
10730 00000040 002B 002C 002D 002E - 002F 0030 0031 0032 |+,-./012|
10731 00000048 0033 0034 0035 0036 - 0037 0038 0039 003A |3456789:|
10732 00000050 003B 003C 003D 003E - 003F 0040 0041 0042 |;<=>?@AB|
10733 00000058 0043 0044 0045 0046 - 0047 0048 0049 004A |CDEFGHIJ|
10734 00000060 004B 004C 004D 004E - 004F 0050 0051 0052 |KLMNOPQR|
10735 00000068 0053 0054 0055 0056 - 0057 0058 0059 005A |STUVWXYZ|
10736 00000070 005B 005C 005D 005E - 005F 0060 0061 0062 |[\]^_`ab|
10737 00000078 0063 0064 0065 0066 - 0067 0068 0069 006A |cdefghij|
10738 00000080 006B 006C 006D 006E - 006F 0070 0071 0072 |klmnopqr|
10739 00000088 0073 0074 0075 0076 - 0077 0078 0079 007A |stuvwxyz|
10740 00000090 007B 007C 007D 007E - 007F 0080 0081 0082 |{|}~....|
10741 00000098 0083 0084 0085 0086 - 0087 0088 0089 008A |........|
10742 000000A0 008B 008C 008D 008E - 008F 0090 0091 0092 |........|
10743 000000A8 0093 0094 0095 0096 - 0097 0098 0099 009A |........|
10744 000000B0 009B 009C 009D 009E - 009F 00A0 00A1 00A2 |..... ¡¢|
10745 000000B8 00A3 00A4 00A5 00A6 - 00A7 00A8 00A9 00AA |£¤¥¦§¨©ª|
10746 000000C0 00AB 00AC 00AD 00AE - 00AF 00B0 00B1 00B2 |«¬­®¯°±²|
10747 000000C8 00B3 00B4 00B5 00B6 - 00B7 00B8 00B9 00BA |³´µ¶·¸¹º|
10748 000000D0 00BB 00BC 00BD 00BE - 00BF 00C0 00C1 00C2 |»¼½¾¿ÀÁÂ|
10749 000000D8 00C3 00C4 00C5 00C6 - 00C7 00C8 00C9 00CA |ÃÄÅÆÇÈÉÊ|
10750 000000E0 00CB 00CC 00CD 00CE - 00CF 00D0 00D1 00D2 |ËÌÍÎÏÐÑÒ|
10751 000000E8 00D3 00D4 00D5 00D6 - 00D7 00D8 00D9 00DA |ÓÔÕÖרÙÚ|
10752 000000F0 00DB 00DC 00DD 00DE - 00DF 00E0 00E1 00E2 |ÛÜÝÞßàáâ|
10753 000000F8 00E3 00E4 00E5 00E6 - 00E7 00E8 00E9 00EA |ãäåæçèéê|
10754 00000100 00EB 00EC 00ED 00EE - 00EF 00F0 00F1 00F2 |ëìíîïðñò|
10755 00000108 00F3 00F4 00F5 00F6 - 00F7 00F8 00F9 00FA |óôõö÷øùú|
10756 00000110 00FB 00FC 00FD 00FE - 00FF 000A EFFF 000A |ûüýþÿ.�.|
10757 00000118 EFC2 000A EFEF EFBF - EFC0 000A EFC0 EF80 |�.���.��|
10758 00000120 000A EFE0 EF80 EF80 - 000A FFFD EFEF EFBF |.���.���|
10759 00000128 EFBE EFEF EFBF EFBF - 000A 0000 007A 000A |����..z.|
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010760---
10761name: integer-base-one-4
10762description:
10763 Check if ksh93-style base-one integers work
10764category: !smksh
10765stdin:
10766 set -U
10767 echo 1 $(('a'))
10768 (echo 2f $(('aa'))) 2>&1 | sed "s/^[^']*'/2p '/"
10769 echo 3 $(('…'))
10770 x="'a'"
10771 echo "4 <$x>"
10772 echo 5 $(($x))
10773 echo 6 $((x))
10774expected-stdout:
10775 1 97
10776 2p 'aa': multi-character character constant
10777 3 8230
10778 4 <'a'>
10779 5 97
10780 6 97
10781---
Geremy Condra03ebf062011-10-12 18:17:24 -070010782name: integer-base-one-5A
10783description:
Elliott Hughes47086262019-03-26 12:34:31 -070010784 Check to see that we’re NUL and UCS safe
Elliott Hughes23925bb2017-09-22 16:04:20 -070010785category: !shell:ebcdic-yes
Geremy Condra03ebf062011-10-12 18:17:24 -070010786stdin:
10787 set +U
10788 print 'a\0b\xfdz' >x
10789 read -a y <x
10790 set -U
10791 typeset -Uui16 y
10792 print ${y[*]} .
10793expected-stdout:
10794 16#61 16#0 16#62 16#FD 16#7A .
10795---
Elliott Hughes23925bb2017-09-22 16:04:20 -070010796name: integer-base-one-5E
10797description:
Elliott Hughes47086262019-03-26 12:34:31 -070010798 Check to see that we’re NUL and UCS safe
Elliott Hughes23925bb2017-09-22 16:04:20 -070010799category: !shell:ebcdic-no
10800stdin:
10801 set +U
10802 print 'a\0b\xfdz' >x
10803 read -a y <x
10804 set -U
10805 typeset -Uui16 y
10806 print ${y[*]} .
10807expected-stdout:
10808 16#81 16#0 16#82 16#FD 16#A9 .
10809---
Geremy Condra03ebf062011-10-12 18:17:24 -070010810name: integer-base-one-5W
10811description:
Elliott Hughes47086262019-03-26 12:34:31 -070010812 Check to see that we’re NUL and UCS safe
Geremy Condra03ebf062011-10-12 18:17:24 -070010813stdin:
10814 set -U
10815 print 'a\0b€c' >x
10816 read -a y <x
10817 set +U
10818 typeset -Uui16 y
10819 print ${y[*]} .
10820expected-stdout:
10821 16#61 16#0 16#62 16#20AC 16#63 .
10822---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010823name: ulimit-1
10824description:
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010825 Check that ulimit as used in dot.mksh works or is stubbed
10826stdin:
10827 ulimit -c 0
10828---
10829name: ulimit-2
10830description:
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010831 Check if we can use a specific syntax idiom for ulimit
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010832 XXX Haiku works, but only for -n and -V
10833category: !os:haiku,!os:syllable
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010834stdin:
10835 if ! x=$(ulimit -d) || [[ $x = unknown ]]; then
10836 #echo expected to fail on this OS
10837 echo okay
10838 else
10839 ulimit -dS $x && echo okay
10840 fi
10841expected-stdout:
10842 okay
10843---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000010844name: redir-1
10845description:
10846 Check some of the most basic invariants of I/O redirection
10847stdin:
10848 i=0
10849 function d {
10850 print o$i.
10851 print -u2 e$((i++)).
10852 }
10853 d >a 2>b
10854 echo =1=
10855 cat a
10856 echo =2=
10857 cat b
10858 echo =3=
10859 d 2>&1 >c
10860 echo =4=
10861 cat c
10862 echo =5=
10863expected-stdout:
10864 =1=
10865 o0.
10866 =2=
10867 e0.
10868 =3=
10869 e1.
10870 =4=
10871 o1.
10872 =5=
10873---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010874name: bashiop-1
10875description:
10876 Check if GNU bash-like I/O redirection works
10877 Part 1: this is also supported by GNU bash
10878stdin:
10879 exec 3>&1
10880 function threeout {
10881 echo ras
10882 echo dwa >&2
10883 echo tri >&3
10884 }
10885 threeout &>foo
10886 echo ===
10887 cat foo
10888expected-stdout:
10889 tri
10890 ===
10891 ras
10892 dwa
10893---
10894name: bashiop-2a
10895description:
10896 Check if GNU bash-like I/O redirection works
10897 Part 2: this is *not* supported by GNU bash
10898stdin:
10899 exec 3>&1
10900 function threeout {
10901 echo ras
10902 echo dwa >&2
10903 echo tri >&3
10904 }
10905 threeout 3&>foo
10906 echo ===
10907 cat foo
10908expected-stdout:
10909 ras
10910 ===
10911 dwa
10912 tri
10913---
10914name: bashiop-2b
10915description:
10916 Check if GNU bash-like I/O redirection works
10917 Part 2: this is *not* supported by GNU bash
10918stdin:
10919 exec 3>&1
10920 function threeout {
10921 echo ras
10922 echo dwa >&2
10923 echo tri >&3
10924 }
10925 threeout 3>foo &>&3
10926 echo ===
10927 cat foo
10928expected-stdout:
10929 ===
10930 ras
10931 dwa
10932 tri
10933---
10934name: bashiop-2c
10935description:
10936 Check if GNU bash-like I/O redirection works
10937 Part 2: this is supported by GNU bash 4 only
10938stdin:
10939 echo mir >foo
10940 set -o noclobber
10941 exec 3>&1
10942 function threeout {
10943 echo ras
10944 echo dwa >&2
10945 echo tri >&3
10946 }
10947 threeout &>>foo
10948 echo ===
10949 cat foo
10950expected-stdout:
10951 tri
10952 ===
10953 mir
10954 ras
10955 dwa
10956---
10957name: bashiop-3a
10958description:
10959 Check if GNU bash-like I/O redirection fails correctly
10960 Part 1: this is also supported by GNU bash
10961stdin:
10962 echo mir >foo
10963 set -o noclobber
10964 exec 3>&1
10965 function threeout {
10966 echo ras
10967 echo dwa >&2
10968 echo tri >&3
10969 }
10970 threeout &>foo
10971 echo ===
10972 cat foo
10973expected-stdout:
10974 ===
10975 mir
Geremy Condra03ebf062011-10-12 18:17:24 -070010976expected-stderr-pattern: /.*: can't (create|overwrite) .*/
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010977---
10978name: bashiop-3b
10979description:
10980 Check if GNU bash-like I/O redirection fails correctly
10981 Part 2: this is *not* supported by GNU bash
10982stdin:
10983 echo mir >foo
10984 set -o noclobber
10985 exec 3>&1
10986 function threeout {
10987 echo ras
10988 echo dwa >&2
10989 echo tri >&3
10990 }
10991 threeout &>|foo
10992 echo ===
10993 cat foo
10994expected-stdout:
10995 tri
10996 ===
10997 ras
10998 dwa
10999---
11000name: bashiop-4
11001description:
11002 Check if GNU bash-like I/O redirection works
11003 Part 4: this is also supported by GNU bash,
11004 but failed in some mksh versions
11005stdin:
11006 exec 3>&1
11007 function threeout {
11008 echo ras
11009 echo dwa >&2
11010 echo tri >&3
11011 }
11012 function blubb {
11013 [[ -e bar ]] && threeout "$bf" &>foo
11014 }
11015 blubb
11016 echo -n >bar
11017 blubb
11018 echo ===
11019 cat foo
11020expected-stdout:
11021 tri
11022 ===
11023 ras
11024 dwa
11025---
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011026name: bashiop-5
Thorsten Glaser811a5752013-07-25 14:24:45 +000011027description:
11028 Check if GNU bash-like I/O redirection is only supported
11029 in !POSIX !sh mode as it breaks existing scripts' syntax
Thorsten Glaser811a5752013-07-25 14:24:45 +000011030stdin:
11031 :>x; echo 1 "$("$__progname" -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
11032 :>x; echo 2 "$("$__progname" -o posix -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
11033 :>x; echo 3 "$("$__progname" -o sh -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
11034expected-stdout:
11035 1 = foo echo bar .
11036 2 = bar .
11037 3 = bar .
11038---
Thorsten Glaser811a5752013-07-25 14:24:45 +000011039name: oksh-eval
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070011040description:
Elliott Hughes737fdce2014-08-07 12:59:26 -070011041 Check expansions.
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070011042stdin:
Thorsten Glaser811a5752013-07-25 14:24:45 +000011043 a=
11044 for n in ${a#*=}; do echo 1hu ${n} .; done
11045 for n in "${a#*=}"; do echo 1hq ${n} .; done
11046 for n in ${a##*=}; do echo 2hu ${n} .; done
11047 for n in "${a##*=}"; do echo 2hq ${n} .; done
11048 for n in ${a%=*}; do echo 1pu ${n} .; done
11049 for n in "${a%=*}"; do echo 1pq ${n} .; done
11050 for n in ${a%%=*}; do echo 2pu ${n} .; done
11051 for n in "${a%%=*}"; do echo 2pq ${n} .; done
11052expected-stdout:
11053 1hq .
11054 2hq .
11055 1pq .
11056 2pq .
11057---
11058name: oksh-and-list-error-1
11059description:
11060 Test exit status of rightmost element in 2 element && list in -e mode
11061stdin:
11062 true && false
11063 echo "should not print"
11064arguments: !-e!
11065expected-exit: e != 0
11066---
11067name: oksh-and-list-error-2
11068description:
11069 Test exit status of rightmost element in 3 element && list in -e mode
11070stdin:
11071 true && true && false
11072 echo "should not print"
11073arguments: !-e!
11074expected-exit: e != 0
11075---
11076name: oksh-or-list-error-1
11077description:
11078 Test exit status of || list in -e mode
11079stdin:
11080 false || false
11081 echo "should not print"
11082arguments: !-e!
11083expected-exit: e != 0
11084---
11085name: oksh-longline-crash
11086description:
11087 This used to cause a core dump
11088stdin:
11089 ulimit -c 0
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070011090 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"
11091 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"
11092 for deplib in $deplibs; do
11093 case $deplib in
11094 -L*)
11095 new_libs="$deplib $new_libs"
11096 ;;
11097 *)
11098 case " $specialdeplibs " in
11099 *" $deplib "*)
11100 new_libs="$deplib $new_libs";;
11101 esac
11102 ;;
11103 esac
11104 done
11105---
Thorsten Glaser811a5752013-07-25 14:24:45 +000011106name: oksh-seterror-1
11107description:
11108 The -e flag should be ignored when executing a compound list
11109 followed by an if statement.
11110stdin:
11111 if true; then false && false; fi
11112 true
11113arguments: !-e!
11114expected-exit: e == 0
11115---
11116name: oksh-seterror-2
11117description:
11118 The -e flag should be ignored when executing a compound list
11119 followed by an if statement.
11120stdin:
11121 if true; then if true; then false && false; fi; fi
11122 true
11123arguments: !-e!
11124expected-exit: e == 0
11125---
11126name: oksh-seterror-3
11127description:
11128 The -e flag should be ignored when executing a compound list
11129 followed by an elif statement.
11130stdin:
11131 if true; then :; elif true; then false && false; fi
11132arguments: !-e!
11133expected-exit: e == 0
11134---
11135name: oksh-seterror-4
11136description:
11137 The -e flag should be ignored when executing a pipeline
11138 beginning with '!'
11139stdin:
11140 for i in 1 2 3
11141 do
11142 false && false
11143 true || false
11144 done
11145arguments: !-e!
11146expected-exit: e == 0
11147---
11148name: oksh-seterror-5
11149description:
11150 The -e flag should be ignored when executing a pipeline
11151 beginning with '!'
11152stdin:
11153 ! true | false
11154 true
11155arguments: !-e!
11156expected-exit: e == 0
11157---
11158name: oksh-seterror-6
11159description:
11160 When trapping ERR and EXIT, both traps should run in -e mode
11161 when an error occurs.
11162stdin:
11163 trap 'echo EXIT' EXIT
11164 trap 'echo ERR' ERR
11165 set -e
11166 false
11167 echo DONE
11168 exit 0
11169arguments: !-e!
11170expected-exit: e != 0
11171expected-stdout:
11172 ERR
11173 EXIT
11174---
11175name: oksh-seterror-7
11176description:
11177 The -e flag within a command substitution should be honored
11178stdin:
11179 echo $( set -e; false; echo foo )
11180arguments: !-e!
11181expected-stdout:
11182
11183---
11184name: oksh-input-comsub
11185description:
11186 A command substitution using input redirection should exit with
11187 failure if the input file does not exist.
11188stdin:
11189 var=$(< non-existent)
11190expected-exit: e != 0
11191expected-stderr-pattern: /non-existent/
11192---
11193name: oksh-empty-for-list
11194description:
11195 A for list which expands to zero items should not execute the body.
11196stdin:
11197 set foo bar baz ; for out in ; do echo $out ; done
11198---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070011199name: oksh-varfunction-mod1
11200description:
Elliott Hughes737fdce2014-08-07 12:59:26 -070011201 (Inspired by PR 2450 on OpenBSD.) Calling
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070011202 FOO=bar f
11203 where f is a ksh style function, should not set FOO in the current
11204 env. If f is a Bourne style function, FOO should be set. Furthermore,
11205 the function should receive a correct value of FOO. However, differing
11206 from oksh, setting FOO in the function itself must change the value in
11207 setting FOO in the function itself should not change the value in
11208 global environment.
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070011209stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011210 print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
11211 'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
Elliott Hughes96b43632015-07-17 11:39:41 -070011212 done >env; chmod +x env; PATH=.$PATHSEP$PATH
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070011213 function k {
11214 if [ x$FOO != xbar ]; then
11215 echo 1
11216 return 1
11217 fi
11218 x=$(env | grep FOO)
11219 if [ "x$x" != "xFOO=bar" ]; then
11220 echo 2
11221 return 1;
11222 fi
11223 FOO=foo
11224 return 0
11225 }
11226 b () {
11227 if [ x$FOO != xbar ]; then
11228 echo 3
11229 return 1
11230 fi
11231 x=$(env | grep FOO)
11232 if [ "x$x" != "xFOO=bar" ]; then
11233 echo 4
11234 return 1;
11235 fi
11236 FOO=foo
11237 return 0
11238 }
11239 FOO=bar k
11240 if [ $? != 0 ]; then
11241 exit 1
11242 fi
11243 if [ x$FOO != x ]; then
11244 exit 1
11245 fi
11246 FOO=bar b
11247 if [ $? != 0 ]; then
11248 exit 1
11249 fi
11250 if [ x$FOO != xfoo ]; then
11251 exit 1
11252 fi
11253 FOO=barbar
11254 FOO=bar k
11255 if [ $? != 0 ]; then
11256 exit 1
11257 fi
11258 if [ x$FOO != xbarbar ]; then
11259 exit 1
11260 fi
11261 FOO=bar b
11262 if [ $? != 0 ]; then
11263 exit 1
11264 fi
11265 if [ x$FOO != xfoo ]; then
11266 exit 1
11267 fi
11268---
11269name: fd-cloexec-1
11270description:
11271 Verify that file descriptors > 2 are private for Korn shells
Geremy Condra03ebf062011-10-12 18:17:24 -070011272 AT&T ksh93 does this still, which means we must keep it as well
Elliott Hughes77740fc2016-08-12 15:06:53 -070011273 XXX fails on some old Perl installations
11274need-pass: no
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070011275stdin:
Elliott Hughesb27ce952015-04-21 13:39:18 -070011276 cat >cld <<-EOF
11277 #!$__perlname
11278 open(my \$fh, ">&", 9) or die "E: open \$!";
11279 syswrite(\$fh, "Fowl\\n", 5) or die "E: write \$!";
11280 EOF
11281 chmod +x cld
11282 exec 9>&1
11283 ./cld
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070011284expected-exit: e != 0
Geremy Condra03ebf062011-10-12 18:17:24 -070011285expected-stderr-pattern:
Elliott Hughesb27ce952015-04-21 13:39:18 -070011286 /E: open /
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070011287---
11288name: fd-cloexec-2
11289description:
11290 Verify that file descriptors > 2 are not private for POSIX shells
11291 See Debian Bug #154540, Closes: #499139
Elliott Hughes77740fc2016-08-12 15:06:53 -070011292 XXX fails on some old Perl installations
11293need-pass: no
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070011294stdin:
Elliott Hughesb27ce952015-04-21 13:39:18 -070011295 cat >cld <<-EOF
11296 #!$__perlname
11297 open(my \$fh, ">&", 9) or die "E: open \$!";
11298 syswrite(\$fh, "Fowl\\n", 5) or die "E: write \$!";
11299 EOF
11300 chmod +x cld
11301 test -n "$POSH_VERSION" || set -o posix
11302 exec 9>&1
11303 ./cld
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070011304expected-stdout:
11305 Fowl
11306---
Elliott Hughes47086262019-03-26 12:34:31 -070011307name: fd-cloexec-3
11308description:
11309 Another check for close-on-exec
11310stdin:
11311 print '#!'"$__progname" >ts
11312 cat >>ts <<'EOF'
11313 s=ERR
11314 read -rN-1 -u$1 s 2>/dev/null; e=$?
11315 print -r -- "($1, $((!e)), $s)"
11316 EOF
11317 chmod +x ts
11318 print foo >tx
11319 runtest() {
11320 s=$1; shift
11321 print -r -- $("$__progname" "$@" -c "$s") "$@" .
11322 }
11323 runtest 'exec 3<tx; ./ts 3 3<&3; ./ts 3'
11324 runtest 'exec 3<tx; ./ts 3 3<&3; ./ts 3' -o posix
11325 runtest 'exec 3<tx; ./ts 3 3<&3; ./ts 3' -o sh
11326 runtest 'exec 3<tx; ./ts 4 4<&3; ./ts 4 4<&3'
11327 runtest 'exec 3<tx; ./ts 3 3<&3; ./ts 3 3<&3'
11328expected-stdout:
11329 (3, 1, foo) (3, 0, ERR) .
11330 (3, 1, foo) (3, 1, ) -o posix .
11331 (3, 1, foo) (3, 1, ) -o sh .
11332 (4, 1, foo) (4, 1, ) .
11333 (3, 1, foo) (3, 1, ) .
11334---
Geremy Condra03ebf062011-10-12 18:17:24 -070011335name: comsub-1a
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070011336description:
Geremy Condra03ebf062011-10-12 18:17:24 -070011337 COMSUB are now parsed recursively, so this works
11338 see also regression-6: matching parenthesēs bug
11339 Fails on: pdksh bash2 bash3 zsh
11340 Passes on: bash4 ksh93 mksh(20110313+)
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070011341stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011342 echo 1 $(case 1 in (1) echo yes;; (2) echo no;; esac) .
11343 echo 2 $(case 1 in 1) echo yes;; 2) echo no;; esac) .
11344 TEST=1234; echo 3 ${TEST: $(case 1 in (1) echo 1;; (*) echo 2;; esac)} .
11345 TEST=5678; echo 4 ${TEST: $(case 1 in 1) echo 1;; *) echo 2;; esac)} .
11346 a=($(case 1 in (1) echo 1;; (*) echo 2;; esac)); echo 5 ${a[0]} .
11347 a=($(case 1 in 1) echo 1;; *) echo 2;; esac)); echo 6 ${a[0]} .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070011348expected-stdout:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011349 1 yes .
11350 2 yes .
11351 3 234 .
11352 4 678 .
11353 5 1 .
11354 6 1 .
Geremy Condra03ebf062011-10-12 18:17:24 -070011355---
11356name: comsub-1b
11357description:
11358 COMSUB are now parsed recursively, so this works
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011359 Fails on: pdksh bash2 bash3 bash4 zsh
11360 Passes on: ksh93 mksh(20110313+)
Geremy Condra03ebf062011-10-12 18:17:24 -070011361stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011362 echo 1 $(($(case 1 in (1) echo 1;; (*) echo 2;; esac)+10)) .
11363 echo 2 $(($(case 1 in 1) echo 1;; *) echo 2;; esac)+20)) .
11364 (( a = $(case 1 in (1) echo 1;; (*) echo 2;; esac) )); echo 3 $a .
11365 (( a = $(case 1 in 1) echo 1;; *) echo 2;; esac) )); echo 4 $a .
11366 a=($(($(case 1 in (1) echo 1;; (*) echo 2;; esac)+10))); echo 5 ${a[0]} .
11367 a=($(($(case 1 in 1) echo 1;; *) echo 2;; esac)+20))); echo 6 ${a[0]} .
Geremy Condra03ebf062011-10-12 18:17:24 -070011368expected-stdout:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011369 1 11 .
11370 2 21 .
11371 3 1 .
11372 4 1 .
11373 5 11 .
11374 6 21 .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070011375---
11376name: comsub-2
11377description:
11378 RedHat BZ#496791 – another case of missing recursion
11379 in parsing COMSUB expressions
Geremy Condra03ebf062011-10-12 18:17:24 -070011380 Fails on: pdksh bash2 bash3¹ bash4¹ zsh
11381 Passes on: ksh93 mksh(20110305+)
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070011382 ① bash[34] seem to choke on comment ending with backslash-newline
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070011383stdin:
11384 # a comment with " ' \
11385 x=$(
11386 echo yes
11387 # a comment with " ' \
11388 )
11389 echo $x
11390expected-stdout:
11391 yes
11392---
Geremy Condra03ebf062011-10-12 18:17:24 -070011393name: comsub-3
11394description:
11395 Extended test for COMSUB explaining why a recursive parser
11396 is a must (a non-recursive parser cannot pass all three of
11397 these test cases, especially the ‘#’ is difficult)
11398stdin:
Elliott Hughes96b43632015-07-17 11:39:41 -070011399 print '#!'"$__progname"'\necho 1234' >id; chmod +x id; PATH=.$PATHSEP$PATH
Geremy Condra03ebf062011-10-12 18:17:24 -070011400 echo $(typeset -i10 x=16#20; echo $x)
11401 echo $(typeset -Uui16 x=16#$(id -u)
11402 ) .
11403 echo $(c=1; d=1
11404 typeset -Uui16 a=36#foo; c=2
11405 typeset -Uui16 b=36 #foo; d=2
11406 echo $a $b $c $d)
11407expected-stdout:
11408 32
11409 .
11410 16#4F68 16#24 2 1
11411---
11412name: comsub-4
11413description:
11414 Check the tree dump functions for !MKSH_SMALL functionality
11415category: !smksh
11416stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011417 x() { case $1 in u) echo x ;;& *) echo $1 ;; esac; }
Geremy Condra03ebf062011-10-12 18:17:24 -070011418 typeset -f x
11419expected-stdout:
11420 x() {
11421 case $1 in
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011422 (u)
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011423 \echo x
Geremy Condra03ebf062011-10-12 18:17:24 -070011424 ;|
11425 (*)
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011426 \echo $1
Geremy Condra03ebf062011-10-12 18:17:24 -070011427 ;;
11428 esac
11429 }
11430---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011431name: comsub-5
11432description:
11433 Check COMSUB works with aliases (does not expand them twice)
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011434 and reentrancy safety
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011435stdin:
11436 print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
11437 chmod +x pfn
11438 alias echo='echo a'
11439 foo() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011440 echo moo
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011441 ./pfn "$(echo foo)"
11442 }
11443 ./pfn "$(echo b)"
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011444 typeset -f foo >x
11445 cat x
11446 foo
11447 . ./x
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011448 typeset -f foo
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011449 foo
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011450expected-stdout:
11451 a b
11452 foo() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011453 \echo a moo
11454 ./pfn "$(\echo a foo )"
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011455 }
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011456 a moo
11457 a foo
11458 foo() {
11459 \echo a moo
11460 ./pfn "$(\echo a foo )"
11461 }
11462 a moo
11463 a foo
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011464---
Geremy Condra03ebf062011-10-12 18:17:24 -070011465name: comsub-torture
11466description:
11467 Check the tree dump functions work correctly
11468stdin:
11469 if [[ -z $__progname ]]; then echo >&2 call me with __progname; exit 1; fi
11470 while IFS= read -r line; do
11471 if [[ $line = '#1' ]]; then
11472 lastf=0
11473 continue
11474 elif [[ $line = EOFN* ]]; then
11475 fbody=$fbody$'\n'$line
11476 continue
11477 elif [[ $line != '#'* ]]; then
11478 fbody=$fbody$'\n\t'$line
11479 continue
11480 fi
11481 if (( lastf )); then
11482 x="inline_${nextf}() {"$fbody$'\n}\n'
11483 print -nr -- "$x"
11484 print -r -- "${x}typeset -f inline_$nextf" | "$__progname"
11485 x="function comsub_$nextf { x=\$("$fbody$'\n); }\n'
11486 print -nr -- "$x"
11487 print -r -- "${x}typeset -f comsub_$nextf" | "$__progname"
11488 x="function reread_$nextf { x=\$(("$fbody$'\n)|tr u x); }\n'
11489 print -nr -- "$x"
11490 print -r -- "${x}typeset -f reread_$nextf" | "$__progname"
11491 fi
11492 lastf=1
11493 fbody=
11494 nextf=${line#?}
11495 done <<'EOD'
11496 #1
11497 #TCOM
11498 vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4"
11499 #TPAREN_TPIPE_TLIST
11500 (echo $foo | tr -dc 0-9; echo)
11501 #TAND_TOR
11502 cmd && echo ja || echo nein
11503 #TSELECT
11504 select file in *; do echo "<$file>" ; break ; done
11505 #TFOR_TTIME
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011506 time for i in {1,2,3} ; do echo $i ; done
Geremy Condra03ebf062011-10-12 18:17:24 -070011507 #TCASE
11508 case $foo in 1) echo eins;& 2) echo zwei ;| *) echo kann net bis drei zählen;; esac
11509 #TIF_TBANG_TDBRACKET_TELIF
11510 if ! [[ 1 = 1 ]] ; then echo eins; elif [[ 1 = 2 ]]; then echo zwei ;else echo drei; fi
11511 #TWHILE
11512 i=1; while (( i < 10 )); do echo $i; let ++i; done
11513 #TUNTIL
11514 i=10; until (( !--i )) ; do echo $i; done
11515 #TCOPROC
11516 cat * |& ls
11517 #TFUNCT_TBRACE_TASYNC
11518 function korn { echo eins; echo zwei ; }
11519 bourne () { logger * & }
11520 #IOREAD_IOCAT
11521 tr x u 0<foo >>bar
11522 #IOWRITE_IOCLOB_IOHERE_noIOSKIP
11523 cat >|bar <<'EOFN'
11524 foo
11525 EOFN
11526 #IOWRITE_noIOCLOB_IOHERE_IOSKIP
11527 cat 1>bar <<-EOFI
11528 foo
11529 EOFI
11530 #IORDWR_IODUP
11531 sh 1<>/dev/console 0<&1 2>&1
Thorsten Glaser811a5752013-07-25 14:24:45 +000011532 #COMSUB_EXPRSUB_FUNSUB_VALSUB
11533 echo $(true) $((1+ 2)) ${ :;} ${| REPLY=x;}
Geremy Condra03ebf062011-10-12 18:17:24 -070011534 #QCHAR_OQUOTE_CQUOTE
11535 echo fo\ob\"a\`r\'b\$az
11536 echo "fo\ob\"a\`r\'b\$az"
11537 echo 'fo\ob\"a\`r'\''b\$az'
11538 #OSUBST_CSUBST_OPAT_SPAT_CPAT
11539 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
11540 #heredoc_closed
11541 x=$(cat <<EOFN
11542 note there must be no space between EOFN and )
11543 EOFN); echo $x
11544 #heredoc_space
11545 x=$(cat <<EOFN\
11546 note the space between EOFN and ) is actually part of the here document marker
11547 EOFN ); echo $x
11548 #patch_motd
11549 x=$(sysctl -n kern.version | sed 1q)
11550 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
11551 ed -s /etc/motd 2>&1 <<-EOF
11552 1,/^\$/d
11553 0a
11554 $x
11555
11556 .
11557 wq
11558 EOF)" = @(?) ]] && rm -f /etc/motd
11559 if [[ ! -s /etc/motd ]]; then
11560 install -c -o root -g wheel -m 664 /dev/null /etc/motd
11561 print -- "$x\n" >/etc/motd
11562 fi
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011563 #wdarrassign
11564 case x in
11565 x) a+=b; c+=(d e)
11566 esac
Geremy Condra03ebf062011-10-12 18:17:24 -070011567 #0
11568 EOD
11569expected-stdout:
11570 inline_TCOM() {
11571 vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4"
11572 }
11573 inline_TCOM() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011574 vara=1 varb="2 3" \cmd arg1 $arg2 "$arg3 4"
Geremy Condra03ebf062011-10-12 18:17:24 -070011575 }
11576 function comsub_TCOM { x=$(
11577 vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4"
11578 ); }
11579 function comsub_TCOM {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011580 x=$(vara=1 varb="2 3" \cmd arg1 $arg2 "$arg3 4" )
Geremy Condra03ebf062011-10-12 18:17:24 -070011581 }
11582 function reread_TCOM { x=$((
11583 vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4"
11584 )|tr u x); }
11585 function reread_TCOM {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011586 x=$( ( vara=1 varb="2 3" \cmd arg1 $arg2 "$arg3 4" ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011587 }
11588 inline_TPAREN_TPIPE_TLIST() {
11589 (echo $foo | tr -dc 0-9; echo)
11590 }
11591 inline_TPAREN_TPIPE_TLIST() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011592 ( \echo $foo | \tr -dc 0-9
11593 \echo )
Geremy Condra03ebf062011-10-12 18:17:24 -070011594 }
11595 function comsub_TPAREN_TPIPE_TLIST { x=$(
11596 (echo $foo | tr -dc 0-9; echo)
11597 ); }
11598 function comsub_TPAREN_TPIPE_TLIST {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011599 x=$( ( \echo $foo | \tr -dc 0-9 ; \echo ) )
Geremy Condra03ebf062011-10-12 18:17:24 -070011600 }
11601 function reread_TPAREN_TPIPE_TLIST { x=$((
11602 (echo $foo | tr -dc 0-9; echo)
11603 )|tr u x); }
11604 function reread_TPAREN_TPIPE_TLIST {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011605 x=$( ( ( \echo $foo | \tr -dc 0-9 ; \echo ) ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011606 }
11607 inline_TAND_TOR() {
11608 cmd && echo ja || echo nein
11609 }
11610 inline_TAND_TOR() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011611 \cmd && \echo ja || \echo nein
Geremy Condra03ebf062011-10-12 18:17:24 -070011612 }
11613 function comsub_TAND_TOR { x=$(
11614 cmd && echo ja || echo nein
11615 ); }
11616 function comsub_TAND_TOR {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011617 x=$(\cmd && \echo ja || \echo nein )
Geremy Condra03ebf062011-10-12 18:17:24 -070011618 }
11619 function reread_TAND_TOR { x=$((
11620 cmd && echo ja || echo nein
11621 )|tr u x); }
11622 function reread_TAND_TOR {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011623 x=$( ( \cmd && \echo ja || \echo nein ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011624 }
11625 inline_TSELECT() {
11626 select file in *; do echo "<$file>" ; break ; done
11627 }
11628 inline_TSELECT() {
11629 select file in *
11630 do
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011631 \echo "<$file>"
11632 \break
Geremy Condra03ebf062011-10-12 18:17:24 -070011633 done
11634 }
11635 function comsub_TSELECT { x=$(
11636 select file in *; do echo "<$file>" ; break ; done
11637 ); }
11638 function comsub_TSELECT {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011639 x=$(select file in * ; do \echo "<$file>" ; \break ; done )
Geremy Condra03ebf062011-10-12 18:17:24 -070011640 }
11641 function reread_TSELECT { x=$((
11642 select file in *; do echo "<$file>" ; break ; done
11643 )|tr u x); }
11644 function reread_TSELECT {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011645 x=$( ( select file in * ; do \echo "<$file>" ; \break ; done ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011646 }
11647 inline_TFOR_TTIME() {
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011648 time for i in {1,2,3} ; do echo $i ; done
Geremy Condra03ebf062011-10-12 18:17:24 -070011649 }
11650 inline_TFOR_TTIME() {
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011651 time for i in {1,2,3}
Geremy Condra03ebf062011-10-12 18:17:24 -070011652 do
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011653 \echo $i
Geremy Condra03ebf062011-10-12 18:17:24 -070011654 done
11655 }
11656 function comsub_TFOR_TTIME { x=$(
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011657 time for i in {1,2,3} ; do echo $i ; done
Geremy Condra03ebf062011-10-12 18:17:24 -070011658 ); }
11659 function comsub_TFOR_TTIME {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011660 x=$(time for i in {1,2,3} ; do \echo $i ; done )
Geremy Condra03ebf062011-10-12 18:17:24 -070011661 }
11662 function reread_TFOR_TTIME { x=$((
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011663 time for i in {1,2,3} ; do echo $i ; done
Geremy Condra03ebf062011-10-12 18:17:24 -070011664 )|tr u x); }
11665 function reread_TFOR_TTIME {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011666 x=$( ( time for i in {1,2,3} ; do \echo $i ; done ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011667 }
11668 inline_TCASE() {
11669 case $foo in 1) echo eins;& 2) echo zwei ;| *) echo kann net bis drei zählen;; esac
11670 }
11671 inline_TCASE() {
11672 case $foo in
11673 (1)
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011674 \echo eins
Geremy Condra03ebf062011-10-12 18:17:24 -070011675 ;&
11676 (2)
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011677 \echo zwei
Geremy Condra03ebf062011-10-12 18:17:24 -070011678 ;|
11679 (*)
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011680 \echo kann net bis drei zählen
Geremy Condra03ebf062011-10-12 18:17:24 -070011681 ;;
11682 esac
11683 }
11684 function comsub_TCASE { x=$(
11685 case $foo in 1) echo eins;& 2) echo zwei ;| *) echo kann net bis drei zählen;; esac
11686 ); }
11687 function comsub_TCASE {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011688 x=$(case $foo in (1) \echo eins ;& (2) \echo zwei ;| (*) \echo kann net bis drei zählen ;; esac )
Geremy Condra03ebf062011-10-12 18:17:24 -070011689 }
11690 function reread_TCASE { x=$((
11691 case $foo in 1) echo eins;& 2) echo zwei ;| *) echo kann net bis drei zählen;; esac
11692 )|tr u x); }
11693 function reread_TCASE {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011694 x=$( ( case $foo in (1) \echo eins ;& (2) \echo zwei ;| (*) \echo kann net bis drei zählen ;; esac ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011695 }
11696 inline_TIF_TBANG_TDBRACKET_TELIF() {
11697 if ! [[ 1 = 1 ]] ; then echo eins; elif [[ 1 = 2 ]]; then echo zwei ;else echo drei; fi
11698 }
11699 inline_TIF_TBANG_TDBRACKET_TELIF() {
11700 if ! [[ 1 = 1 ]]
11701 then
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011702 \echo eins
Geremy Condra03ebf062011-10-12 18:17:24 -070011703 elif [[ 1 = 2 ]]
11704 then
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011705 \echo zwei
Geremy Condra03ebf062011-10-12 18:17:24 -070011706 else
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011707 \echo drei
Geremy Condra03ebf062011-10-12 18:17:24 -070011708 fi
11709 }
11710 function comsub_TIF_TBANG_TDBRACKET_TELIF { x=$(
11711 if ! [[ 1 = 1 ]] ; then echo eins; elif [[ 1 = 2 ]]; then echo zwei ;else echo drei; fi
11712 ); }
11713 function comsub_TIF_TBANG_TDBRACKET_TELIF {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011714 x=$(if ! [[ 1 = 1 ]] ; then \echo eins ; elif [[ 1 = 2 ]] ; then \echo zwei ; else \echo drei ; fi )
Geremy Condra03ebf062011-10-12 18:17:24 -070011715 }
11716 function reread_TIF_TBANG_TDBRACKET_TELIF { x=$((
11717 if ! [[ 1 = 1 ]] ; then echo eins; elif [[ 1 = 2 ]]; then echo zwei ;else echo drei; fi
11718 )|tr u x); }
11719 function reread_TIF_TBANG_TDBRACKET_TELIF {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011720 x=$( ( if ! [[ 1 = 1 ]] ; then \echo eins ; elif [[ 1 = 2 ]] ; then \echo zwei ; else \echo drei ; fi ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011721 }
11722 inline_TWHILE() {
11723 i=1; while (( i < 10 )); do echo $i; let ++i; done
11724 }
11725 inline_TWHILE() {
11726 i=1
Elliott Hughesfc0307d2016-02-02 15:26:47 -080011727 while {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011728 \\builtin let " i < 10 "
Elliott Hughesfc0307d2016-02-02 15:26:47 -080011729 }
Geremy Condra03ebf062011-10-12 18:17:24 -070011730 do
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011731 \echo $i
11732 \let ++i
Geremy Condra03ebf062011-10-12 18:17:24 -070011733 done
11734 }
11735 function comsub_TWHILE { x=$(
11736 i=1; while (( i < 10 )); do echo $i; let ++i; done
11737 ); }
11738 function comsub_TWHILE {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011739 x=$(i=1 ; while { \\builtin let " i < 10 " ; } ; do \echo $i ; \let ++i ; done )
Geremy Condra03ebf062011-10-12 18:17:24 -070011740 }
11741 function reread_TWHILE { x=$((
11742 i=1; while (( i < 10 )); do echo $i; let ++i; done
11743 )|tr u x); }
11744 function reread_TWHILE {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011745 x=$( ( i=1 ; while { \\builtin let " i < 10 " ; } ; do \echo $i ; \let ++i ; done ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011746 }
11747 inline_TUNTIL() {
11748 i=10; until (( !--i )) ; do echo $i; done
11749 }
11750 inline_TUNTIL() {
11751 i=10
Elliott Hughesfc0307d2016-02-02 15:26:47 -080011752 until {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011753 \\builtin let " !--i "
Elliott Hughesfc0307d2016-02-02 15:26:47 -080011754 }
Geremy Condra03ebf062011-10-12 18:17:24 -070011755 do
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011756 \echo $i
Geremy Condra03ebf062011-10-12 18:17:24 -070011757 done
11758 }
11759 function comsub_TUNTIL { x=$(
11760 i=10; until (( !--i )) ; do echo $i; done
11761 ); }
11762 function comsub_TUNTIL {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011763 x=$(i=10 ; until { \\builtin let " !--i " ; } ; do \echo $i ; done )
Geremy Condra03ebf062011-10-12 18:17:24 -070011764 }
11765 function reread_TUNTIL { x=$((
11766 i=10; until (( !--i )) ; do echo $i; done
11767 )|tr u x); }
11768 function reread_TUNTIL {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011769 x=$( ( i=10 ; until { \\builtin let " !--i " ; } ; do \echo $i ; done ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011770 }
11771 inline_TCOPROC() {
11772 cat * |& ls
11773 }
11774 inline_TCOPROC() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011775 \cat * |&
11776 \ls
Geremy Condra03ebf062011-10-12 18:17:24 -070011777 }
11778 function comsub_TCOPROC { x=$(
11779 cat * |& ls
11780 ); }
11781 function comsub_TCOPROC {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011782 x=$(\cat * |& \ls )
Geremy Condra03ebf062011-10-12 18:17:24 -070011783 }
11784 function reread_TCOPROC { x=$((
11785 cat * |& ls
11786 )|tr u x); }
11787 function reread_TCOPROC {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011788 x=$( ( \cat * |& \ls ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011789 }
11790 inline_TFUNCT_TBRACE_TASYNC() {
11791 function korn { echo eins; echo zwei ; }
11792 bourne () { logger * & }
11793 }
11794 inline_TFUNCT_TBRACE_TASYNC() {
11795 function korn {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011796 \echo eins
11797 \echo zwei
Geremy Condra03ebf062011-10-12 18:17:24 -070011798 }
11799 bourne() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011800 \logger * &
Geremy Condra03ebf062011-10-12 18:17:24 -070011801 }
11802 }
11803 function comsub_TFUNCT_TBRACE_TASYNC { x=$(
11804 function korn { echo eins; echo zwei ; }
11805 bourne () { logger * & }
11806 ); }
11807 function comsub_TFUNCT_TBRACE_TASYNC {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011808 x=$(function korn { \echo eins ; \echo zwei ; } ; bourne() { \logger * & } )
Geremy Condra03ebf062011-10-12 18:17:24 -070011809 }
11810 function reread_TFUNCT_TBRACE_TASYNC { x=$((
11811 function korn { echo eins; echo zwei ; }
11812 bourne () { logger * & }
11813 )|tr u x); }
11814 function reread_TFUNCT_TBRACE_TASYNC {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011815 x=$( ( function korn { \echo eins ; \echo zwei ; } ; bourne() { \logger * & } ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011816 }
11817 inline_IOREAD_IOCAT() {
11818 tr x u 0<foo >>bar
11819 }
11820 inline_IOREAD_IOCAT() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011821 \tr x u <foo >>bar
Geremy Condra03ebf062011-10-12 18:17:24 -070011822 }
11823 function comsub_IOREAD_IOCAT { x=$(
11824 tr x u 0<foo >>bar
11825 ); }
11826 function comsub_IOREAD_IOCAT {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011827 x=$(\tr x u <foo >>bar )
Geremy Condra03ebf062011-10-12 18:17:24 -070011828 }
11829 function reread_IOREAD_IOCAT { x=$((
11830 tr x u 0<foo >>bar
11831 )|tr u x); }
11832 function reread_IOREAD_IOCAT {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011833 x=$( ( \tr x u <foo >>bar ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011834 }
11835 inline_IOWRITE_IOCLOB_IOHERE_noIOSKIP() {
11836 cat >|bar <<'EOFN'
11837 foo
11838 EOFN
11839 }
11840 inline_IOWRITE_IOCLOB_IOHERE_noIOSKIP() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011841 \cat >|bar <<"EOFN"
Geremy Condra03ebf062011-10-12 18:17:24 -070011842 foo
11843 EOFN
11844
11845 }
11846 function comsub_IOWRITE_IOCLOB_IOHERE_noIOSKIP { x=$(
11847 cat >|bar <<'EOFN'
11848 foo
11849 EOFN
11850 ); }
11851 function comsub_IOWRITE_IOCLOB_IOHERE_noIOSKIP {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011852 x=$(\cat >|bar <<"EOFN"
Geremy Condra03ebf062011-10-12 18:17:24 -070011853 foo
11854 EOFN
11855 )
11856 }
11857 function reread_IOWRITE_IOCLOB_IOHERE_noIOSKIP { x=$((
11858 cat >|bar <<'EOFN'
11859 foo
11860 EOFN
11861 )|tr u x); }
11862 function reread_IOWRITE_IOCLOB_IOHERE_noIOSKIP {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011863 x=$( ( \cat >|bar <<"EOFN"
Geremy Condra03ebf062011-10-12 18:17:24 -070011864 foo
11865 EOFN
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011866 ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011867 }
11868 inline_IOWRITE_noIOCLOB_IOHERE_IOSKIP() {
11869 cat 1>bar <<-EOFI
11870 foo
11871 EOFI
11872 }
11873 inline_IOWRITE_noIOCLOB_IOHERE_IOSKIP() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011874 \cat >bar <<-EOFI
Geremy Condra03ebf062011-10-12 18:17:24 -070011875 foo
11876 EOFI
11877
11878 }
11879 function comsub_IOWRITE_noIOCLOB_IOHERE_IOSKIP { x=$(
11880 cat 1>bar <<-EOFI
11881 foo
11882 EOFI
11883 ); }
11884 function comsub_IOWRITE_noIOCLOB_IOHERE_IOSKIP {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011885 x=$(\cat >bar <<-EOFI
Geremy Condra03ebf062011-10-12 18:17:24 -070011886 foo
11887 EOFI
11888 )
11889 }
11890 function reread_IOWRITE_noIOCLOB_IOHERE_IOSKIP { x=$((
11891 cat 1>bar <<-EOFI
11892 foo
11893 EOFI
11894 )|tr u x); }
11895 function reread_IOWRITE_noIOCLOB_IOHERE_IOSKIP {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011896 x=$( ( \cat >bar <<-EOFI
Geremy Condra03ebf062011-10-12 18:17:24 -070011897 foo
11898 EOFI
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011899 ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011900 }
11901 inline_IORDWR_IODUP() {
11902 sh 1<>/dev/console 0<&1 2>&1
11903 }
11904 inline_IORDWR_IODUP() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011905 \sh 1<>/dev/console <&1 2>&1
Geremy Condra03ebf062011-10-12 18:17:24 -070011906 }
11907 function comsub_IORDWR_IODUP { x=$(
11908 sh 1<>/dev/console 0<&1 2>&1
11909 ); }
11910 function comsub_IORDWR_IODUP {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011911 x=$(\sh 1<>/dev/console <&1 2>&1 )
Geremy Condra03ebf062011-10-12 18:17:24 -070011912 }
11913 function reread_IORDWR_IODUP { x=$((
11914 sh 1<>/dev/console 0<&1 2>&1
11915 )|tr u x); }
11916 function reread_IORDWR_IODUP {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011917 x=$( ( \sh 1<>/dev/console <&1 2>&1 ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011918 }
Thorsten Glaser811a5752013-07-25 14:24:45 +000011919 inline_COMSUB_EXPRSUB_FUNSUB_VALSUB() {
11920 echo $(true) $((1+ 2)) ${ :;} ${| REPLY=x;}
Geremy Condra03ebf062011-10-12 18:17:24 -070011921 }
Thorsten Glaser811a5752013-07-25 14:24:45 +000011922 inline_COMSUB_EXPRSUB_FUNSUB_VALSUB() {
Elliott Hughes23925bb2017-09-22 16:04:20 -070011923 \echo $(\true ) $((1+ 2)) ${ \: ;} ${|REPLY=x ;}
Geremy Condra03ebf062011-10-12 18:17:24 -070011924 }
Thorsten Glaser811a5752013-07-25 14:24:45 +000011925 function comsub_COMSUB_EXPRSUB_FUNSUB_VALSUB { x=$(
11926 echo $(true) $((1+ 2)) ${ :;} ${| REPLY=x;}
Geremy Condra03ebf062011-10-12 18:17:24 -070011927 ); }
Thorsten Glaser811a5752013-07-25 14:24:45 +000011928 function comsub_COMSUB_EXPRSUB_FUNSUB_VALSUB {
Elliott Hughes23925bb2017-09-22 16:04:20 -070011929 x=$(\echo $(\true ) $((1+ 2)) ${ \: ;} ${|REPLY=x ;} )
Geremy Condra03ebf062011-10-12 18:17:24 -070011930 }
Thorsten Glaser811a5752013-07-25 14:24:45 +000011931 function reread_COMSUB_EXPRSUB_FUNSUB_VALSUB { x=$((
11932 echo $(true) $((1+ 2)) ${ :;} ${| REPLY=x;}
Geremy Condra03ebf062011-10-12 18:17:24 -070011933 )|tr u x); }
Thorsten Glaser811a5752013-07-25 14:24:45 +000011934 function reread_COMSUB_EXPRSUB_FUNSUB_VALSUB {
Elliott Hughes23925bb2017-09-22 16:04:20 -070011935 x=$( ( \echo $(\true ) $((1+ 2)) ${ \: ;} ${|REPLY=x ;} ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011936 }
11937 inline_QCHAR_OQUOTE_CQUOTE() {
11938 echo fo\ob\"a\`r\'b\$az
11939 echo "fo\ob\"a\`r\'b\$az"
11940 echo 'fo\ob\"a\`r'\''b\$az'
11941 }
11942 inline_QCHAR_OQUOTE_CQUOTE() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011943 \echo fo\ob\"a\`r\'b\$az
11944 \echo "fo\ob\"a\`r\'b\$az"
11945 \echo "fo\\ob\\\"a\\\`r"\'"b\\\$az"
Geremy Condra03ebf062011-10-12 18:17:24 -070011946 }
11947 function comsub_QCHAR_OQUOTE_CQUOTE { x=$(
11948 echo fo\ob\"a\`r\'b\$az
11949 echo "fo\ob\"a\`r\'b\$az"
11950 echo 'fo\ob\"a\`r'\''b\$az'
11951 ); }
11952 function comsub_QCHAR_OQUOTE_CQUOTE {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011953 x=$(\echo fo\ob\"a\`r\'b\$az ; \echo "fo\ob\"a\`r\'b\$az" ; \echo "fo\\ob\\\"a\\\`r"\'"b\\\$az" )
Geremy Condra03ebf062011-10-12 18:17:24 -070011954 }
11955 function reread_QCHAR_OQUOTE_CQUOTE { x=$((
11956 echo fo\ob\"a\`r\'b\$az
11957 echo "fo\ob\"a\`r\'b\$az"
11958 echo 'fo\ob\"a\`r'\''b\$az'
11959 )|tr u x); }
11960 function reread_QCHAR_OQUOTE_CQUOTE {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011961 x=$( ( \echo fo\ob\"a\`r\'b\$az ; \echo "fo\ob\"a\`r\'b\$az" ; \echo "fo\\ob\\\"a\\\`r"\'"b\\\$az" ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011962 }
11963 inline_OSUBST_CSUBST_OPAT_SPAT_CPAT() {
11964 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
11965 }
11966 inline_OSUBST_CSUBST_OPAT_SPAT_CPAT() {
11967 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
11968 }
11969 function comsub_OSUBST_CSUBST_OPAT_SPAT_CPAT { x=$(
11970 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
11971 ); }
11972 function comsub_OSUBST_CSUBST_OPAT_SPAT_CPAT {
11973 x=$([[ ${foo#bl\(u\)b} = @(bar|baz) ]] )
11974 }
11975 function reread_OSUBST_CSUBST_OPAT_SPAT_CPAT { x=$((
11976 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
11977 )|tr u x); }
11978 function reread_OSUBST_CSUBST_OPAT_SPAT_CPAT {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011979 x=$( ( [[ ${foo#bl\(u\)b} = @(bar|baz) ]] ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011980 }
11981 inline_heredoc_closed() {
11982 x=$(cat <<EOFN
11983 note there must be no space between EOFN and )
11984 EOFN); echo $x
11985 }
11986 inline_heredoc_closed() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011987 x=$(\cat <<EOFN
Geremy Condra03ebf062011-10-12 18:17:24 -070011988 note there must be no space between EOFN and )
11989 EOFN
11990 )
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011991 \echo $x
Geremy Condra03ebf062011-10-12 18:17:24 -070011992 }
11993 function comsub_heredoc_closed { x=$(
11994 x=$(cat <<EOFN
11995 note there must be no space between EOFN and )
11996 EOFN); echo $x
11997 ); }
11998 function comsub_heredoc_closed {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011999 x=$(x=$(\cat <<EOFN
Geremy Condra03ebf062011-10-12 18:17:24 -070012000 note there must be no space between EOFN and )
12001 EOFN
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012002 ) ; \echo $x )
Geremy Condra03ebf062011-10-12 18:17:24 -070012003 }
12004 function reread_heredoc_closed { x=$((
12005 x=$(cat <<EOFN
12006 note there must be no space between EOFN and )
12007 EOFN); echo $x
12008 )|tr u x); }
12009 function reread_heredoc_closed {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012010 x=$( ( x=$(\cat <<EOFN
Geremy Condra03ebf062011-10-12 18:17:24 -070012011 note there must be no space between EOFN and )
12012 EOFN
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012013 ) ; \echo $x ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070012014 }
12015 inline_heredoc_space() {
12016 x=$(cat <<EOFN\
12017 note the space between EOFN and ) is actually part of the here document marker
12018 EOFN ); echo $x
12019 }
12020 inline_heredoc_space() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012021 x=$(\cat <<EOFN\
Geremy Condra03ebf062011-10-12 18:17:24 -070012022 note the space between EOFN and ) is actually part of the here document marker
12023 EOFN
12024 )
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012025 \echo $x
Geremy Condra03ebf062011-10-12 18:17:24 -070012026 }
12027 function comsub_heredoc_space { x=$(
12028 x=$(cat <<EOFN\
12029 note the space between EOFN and ) is actually part of the here document marker
12030 EOFN ); echo $x
12031 ); }
12032 function comsub_heredoc_space {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012033 x=$(x=$(\cat <<EOFN\
Geremy Condra03ebf062011-10-12 18:17:24 -070012034 note the space between EOFN and ) is actually part of the here document marker
12035 EOFN
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012036 ) ; \echo $x )
Geremy Condra03ebf062011-10-12 18:17:24 -070012037 }
12038 function reread_heredoc_space { x=$((
12039 x=$(cat <<EOFN\
12040 note the space between EOFN and ) is actually part of the here document marker
12041 EOFN ); echo $x
12042 )|tr u x); }
12043 function reread_heredoc_space {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012044 x=$( ( x=$(\cat <<EOFN\
Geremy Condra03ebf062011-10-12 18:17:24 -070012045 note the space between EOFN and ) is actually part of the here document marker
12046 EOFN
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012047 ) ; \echo $x ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070012048 }
12049 inline_patch_motd() {
12050 x=$(sysctl -n kern.version | sed 1q)
12051 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
12052 ed -s /etc/motd 2>&1 <<-EOF
12053 1,/^\$/d
12054 0a
12055 $x
12056
12057 .
12058 wq
12059 EOF)" = @(?) ]] && rm -f /etc/motd
12060 if [[ ! -s /etc/motd ]]; then
12061 install -c -o root -g wheel -m 664 /dev/null /etc/motd
12062 print -- "$x\n" >/etc/motd
12063 fi
12064 }
12065 inline_patch_motd() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012066 x=$(\sysctl -n kern.version | \sed 1q )
12067 [[ -s /etc/motd && "$([[ "$(\head -1 /etc/motd )" != $x ]] && \ed -s /etc/motd 2>&1 <<-EOF
Geremy Condra03ebf062011-10-12 18:17:24 -070012068 1,/^\$/d
12069 0a
12070 $x
12071
12072 .
12073 wq
12074 EOF
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012075 )" = @(?) ]] && \rm -f /etc/motd
Geremy Condra03ebf062011-10-12 18:17:24 -070012076 if [[ ! -s /etc/motd ]]
12077 then
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012078 \install -c -o root -g wheel -m 664 /dev/null /etc/motd
12079 \print -- "$x\n" >/etc/motd
Geremy Condra03ebf062011-10-12 18:17:24 -070012080 fi
12081 }
12082 function comsub_patch_motd { x=$(
12083 x=$(sysctl -n kern.version | sed 1q)
12084 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
12085 ed -s /etc/motd 2>&1 <<-EOF
12086 1,/^\$/d
12087 0a
12088 $x
12089
12090 .
12091 wq
12092 EOF)" = @(?) ]] && rm -f /etc/motd
12093 if [[ ! -s /etc/motd ]]; then
12094 install -c -o root -g wheel -m 664 /dev/null /etc/motd
12095 print -- "$x\n" >/etc/motd
12096 fi
12097 ); }
12098 function comsub_patch_motd {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012099 x=$(x=$(\sysctl -n kern.version | \sed 1q ) ; [[ -s /etc/motd && "$([[ "$(\head -1 /etc/motd )" != $x ]] && \ed -s /etc/motd 2>&1 <<-EOF
Geremy Condra03ebf062011-10-12 18:17:24 -070012100 1,/^\$/d
12101 0a
12102 $x
12103
12104 .
12105 wq
12106 EOF
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012107 )" = @(?) ]] && \rm -f /etc/motd ; if [[ ! -s /etc/motd ]] ; then \install -c -o root -g wheel -m 664 /dev/null /etc/motd ; \print -- "$x\n" >/etc/motd ; fi )
Geremy Condra03ebf062011-10-12 18:17:24 -070012108 }
12109 function reread_patch_motd { x=$((
12110 x=$(sysctl -n kern.version | sed 1q)
12111 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
12112 ed -s /etc/motd 2>&1 <<-EOF
12113 1,/^\$/d
12114 0a
12115 $x
12116
12117 .
12118 wq
12119 EOF)" = @(?) ]] && rm -f /etc/motd
12120 if [[ ! -s /etc/motd ]]; then
12121 install -c -o root -g wheel -m 664 /dev/null /etc/motd
12122 print -- "$x\n" >/etc/motd
12123 fi
12124 )|tr u x); }
12125 function reread_patch_motd {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012126 x=$( ( x=$(\sysctl -n kern.version | \sed 1q ) ; [[ -s /etc/motd && "$([[ "$(\head -1 /etc/motd )" != $x ]] && \ed -s /etc/motd 2>&1 <<-EOF
Geremy Condra03ebf062011-10-12 18:17:24 -070012127 1,/^\$/d
12128 0a
12129 $x
12130
12131 .
12132 wq
12133 EOF
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012134 )" = @(?) ]] && \rm -f /etc/motd ; if [[ ! -s /etc/motd ]] ; then \install -c -o root -g wheel -m 664 /dev/null /etc/motd ; \print -- "$x\n" >/etc/motd ; fi ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070012135 }
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012136 inline_wdarrassign() {
12137 case x in
12138 x) a+=b; c+=(d e)
12139 esac
12140 }
12141 inline_wdarrassign() {
12142 case x in
12143 (x)
12144 a+=b
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012145 \\builtin set -A c+ -- d e
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012146 ;;
12147 esac
12148 }
12149 function comsub_wdarrassign { x=$(
12150 case x in
12151 x) a+=b; c+=(d e)
12152 esac
12153 ); }
12154 function comsub_wdarrassign {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012155 x=$(case x in (x) a+=b ; \\builtin set -A c+ -- d e ;; esac )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012156 }
12157 function reread_wdarrassign { x=$((
12158 case x in
12159 x) a+=b; c+=(d e)
12160 esac
12161 )|tr u x); }
12162 function reread_wdarrassign {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012163 x=$( ( case x in (x) a+=b ; \\builtin set -A c+ -- d e ;; esac ) | \tr u x )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012164 }
12165---
12166name: comsub-torture-io
12167description:
12168 Check the tree dump functions work correctly with I/O redirection
12169stdin:
12170 if [[ -z $__progname ]]; then echo >&2 call me with __progname; exit 1; fi
12171 while IFS= read -r line; do
12172 if [[ $line = '#1' ]]; then
12173 lastf=0
12174 continue
12175 elif [[ $line = EOFN* ]]; then
12176 fbody=$fbody$'\n'$line
12177 continue
12178 elif [[ $line != '#'* ]]; then
12179 fbody=$fbody$'\n\t'$line
12180 continue
12181 fi
12182 if (( lastf )); then
12183 x="inline_${nextf}() {"$fbody$'\n}\n'
12184 print -nr -- "$x"
12185 print -r -- "${x}typeset -f inline_$nextf" | "$__progname"
12186 x="function comsub_$nextf { x=\$("$fbody$'\n); }\n'
12187 print -nr -- "$x"
12188 print -r -- "${x}typeset -f comsub_$nextf" | "$__progname"
12189 x="function reread_$nextf { x=\$(("$fbody$'\n)|tr u x); }\n'
12190 print -nr -- "$x"
12191 print -r -- "${x}typeset -f reread_$nextf" | "$__progname"
12192 fi
12193 lastf=1
12194 fbody=
12195 nextf=${line#?}
12196 done <<'EOD'
12197 #1
12198 #TCOM
12199 vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4" >&3
12200 #TPAREN_TPIPE_TLIST
12201 (echo $foo | tr -dc 0-9 >&3; echo >&3) >&3
12202 #TAND_TOR
12203 cmd >&3 && >&3 echo ja || echo >&3 nein
12204 #TSELECT
12205 select file in *; do echo "<$file>" ; break >&3 ; done >&3
12206 #TFOR_TTIME
12207 for i in {1,2,3} ; do time >&3 echo $i ; done >&3
12208 #TCASE
12209 case $foo in 1) echo eins >&3;& 2) echo zwei >&3 ;| *) echo kann net bis drei zählen >&3;; esac >&3
12210 #TIF_TBANG_TDBRACKET_TELIF
12211 if ! [[ 1 = 1 ]] >&3 ; then echo eins; elif [[ 1 = 2 ]] >&3; then echo zwei ;else echo drei; fi >&3
12212 #TWHILE
12213 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
12214 #TUNTIL
12215 i=10; until (( !--i )) >&3 ; do echo $i; done >&3
12216 #TCOPROC
12217 cat * >&3 |& >&3 ls
12218 #TFUNCT_TBRACE_TASYNC
12219 function korn { echo eins; echo >&3 zwei ; }
12220 bourne () { logger * >&3 & }
12221 #COMSUB_EXPRSUB
12222 echo $(true >&3) $((1+ 2))
12223 #0
12224 EOD
12225expected-stdout:
12226 inline_TCOM() {
12227 vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4" >&3
12228 }
12229 inline_TCOM() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012230 vara=1 varb="2 3" \cmd arg1 $arg2 "$arg3 4" >&3
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012231 }
12232 function comsub_TCOM { x=$(
12233 vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4" >&3
12234 ); }
12235 function comsub_TCOM {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012236 x=$(vara=1 varb="2 3" \cmd arg1 $arg2 "$arg3 4" >&3 )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012237 }
12238 function reread_TCOM { x=$((
12239 vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4" >&3
12240 )|tr u x); }
12241 function reread_TCOM {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012242 x=$( ( vara=1 varb="2 3" \cmd arg1 $arg2 "$arg3 4" >&3 ) | \tr u x )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012243 }
12244 inline_TPAREN_TPIPE_TLIST() {
12245 (echo $foo | tr -dc 0-9 >&3; echo >&3) >&3
12246 }
12247 inline_TPAREN_TPIPE_TLIST() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012248 ( \echo $foo | \tr -dc 0-9 >&3
12249 \echo >&3 ) >&3
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012250 }
12251 function comsub_TPAREN_TPIPE_TLIST { x=$(
12252 (echo $foo | tr -dc 0-9 >&3; echo >&3) >&3
12253 ); }
12254 function comsub_TPAREN_TPIPE_TLIST {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012255 x=$( ( \echo $foo | \tr -dc 0-9 >&3 ; \echo >&3 ) >&3 )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012256 }
12257 function reread_TPAREN_TPIPE_TLIST { x=$((
12258 (echo $foo | tr -dc 0-9 >&3; echo >&3) >&3
12259 )|tr u x); }
12260 function reread_TPAREN_TPIPE_TLIST {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012261 x=$( ( ( \echo $foo | \tr -dc 0-9 >&3 ; \echo >&3 ) >&3 ) | \tr u x )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012262 }
12263 inline_TAND_TOR() {
12264 cmd >&3 && >&3 echo ja || echo >&3 nein
12265 }
12266 inline_TAND_TOR() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012267 \cmd >&3 && \echo ja >&3 || \echo nein >&3
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012268 }
12269 function comsub_TAND_TOR { x=$(
12270 cmd >&3 && >&3 echo ja || echo >&3 nein
12271 ); }
12272 function comsub_TAND_TOR {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012273 x=$(\cmd >&3 && \echo ja >&3 || \echo nein >&3 )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012274 }
12275 function reread_TAND_TOR { x=$((
12276 cmd >&3 && >&3 echo ja || echo >&3 nein
12277 )|tr u x); }
12278 function reread_TAND_TOR {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012279 x=$( ( \cmd >&3 && \echo ja >&3 || \echo nein >&3 ) | \tr u x )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012280 }
12281 inline_TSELECT() {
12282 select file in *; do echo "<$file>" ; break >&3 ; done >&3
12283 }
12284 inline_TSELECT() {
12285 select file in *
12286 do
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012287 \echo "<$file>"
12288 \break >&3
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012289 done >&3
12290 }
12291 function comsub_TSELECT { x=$(
12292 select file in *; do echo "<$file>" ; break >&3 ; done >&3
12293 ); }
12294 function comsub_TSELECT {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012295 x=$(select file in * ; do \echo "<$file>" ; \break >&3 ; done >&3 )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012296 }
12297 function reread_TSELECT { x=$((
12298 select file in *; do echo "<$file>" ; break >&3 ; done >&3
12299 )|tr u x); }
12300 function reread_TSELECT {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012301 x=$( ( select file in * ; do \echo "<$file>" ; \break >&3 ; done >&3 ) | \tr u x )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012302 }
12303 inline_TFOR_TTIME() {
12304 for i in {1,2,3} ; do time >&3 echo $i ; done >&3
12305 }
12306 inline_TFOR_TTIME() {
12307 for i in {1,2,3}
12308 do
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012309 time \echo $i >&3
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012310 done >&3
12311 }
12312 function comsub_TFOR_TTIME { x=$(
12313 for i in {1,2,3} ; do time >&3 echo $i ; done >&3
12314 ); }
12315 function comsub_TFOR_TTIME {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012316 x=$(for i in {1,2,3} ; do time \echo $i >&3 ; done >&3 )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012317 }
12318 function reread_TFOR_TTIME { x=$((
12319 for i in {1,2,3} ; do time >&3 echo $i ; done >&3
12320 )|tr u x); }
12321 function reread_TFOR_TTIME {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012322 x=$( ( for i in {1,2,3} ; do time \echo $i >&3 ; done >&3 ) | \tr u x )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012323 }
12324 inline_TCASE() {
12325 case $foo in 1) echo eins >&3;& 2) echo zwei >&3 ;| *) echo kann net bis drei zählen >&3;; esac >&3
12326 }
12327 inline_TCASE() {
12328 case $foo in
12329 (1)
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012330 \echo eins >&3
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012331 ;&
12332 (2)
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012333 \echo zwei >&3
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012334 ;|
12335 (*)
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012336 \echo kann net bis drei zählen >&3
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012337 ;;
12338 esac >&3
12339 }
12340 function comsub_TCASE { x=$(
12341 case $foo in 1) echo eins >&3;& 2) echo zwei >&3 ;| *) echo kann net bis drei zählen >&3;; esac >&3
12342 ); }
12343 function comsub_TCASE {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012344 x=$(case $foo in (1) \echo eins >&3 ;& (2) \echo zwei >&3 ;| (*) \echo kann net bis drei zählen >&3 ;; esac >&3 )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012345 }
12346 function reread_TCASE { x=$((
12347 case $foo in 1) echo eins >&3;& 2) echo zwei >&3 ;| *) echo kann net bis drei zählen >&3;; esac >&3
12348 )|tr u x); }
12349 function reread_TCASE {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012350 x=$( ( case $foo in (1) \echo eins >&3 ;& (2) \echo zwei >&3 ;| (*) \echo kann net bis drei zählen >&3 ;; esac >&3 ) | \tr u x )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012351 }
12352 inline_TIF_TBANG_TDBRACKET_TELIF() {
12353 if ! [[ 1 = 1 ]] >&3 ; then echo eins; elif [[ 1 = 2 ]] >&3; then echo zwei ;else echo drei; fi >&3
12354 }
12355 inline_TIF_TBANG_TDBRACKET_TELIF() {
12356 if ! [[ 1 = 1 ]] >&3
12357 then
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012358 \echo eins
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012359 elif [[ 1 = 2 ]] >&3
12360 then
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012361 \echo zwei
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012362 else
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012363 \echo drei
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012364 fi >&3
12365 }
12366 function comsub_TIF_TBANG_TDBRACKET_TELIF { x=$(
12367 if ! [[ 1 = 1 ]] >&3 ; then echo eins; elif [[ 1 = 2 ]] >&3; then echo zwei ;else echo drei; fi >&3
12368 ); }
12369 function comsub_TIF_TBANG_TDBRACKET_TELIF {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012370 x=$(if ! [[ 1 = 1 ]] >&3 ; then \echo eins ; elif [[ 1 = 2 ]] >&3 ; then \echo zwei ; else \echo drei ; fi >&3 )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012371 }
12372 function reread_TIF_TBANG_TDBRACKET_TELIF { x=$((
12373 if ! [[ 1 = 1 ]] >&3 ; then echo eins; elif [[ 1 = 2 ]] >&3; then echo zwei ;else echo drei; fi >&3
12374 )|tr u x); }
12375 function reread_TIF_TBANG_TDBRACKET_TELIF {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012376 x=$( ( if ! [[ 1 = 1 ]] >&3 ; then \echo eins ; elif [[ 1 = 2 ]] >&3 ; then \echo zwei ; else \echo drei ; fi >&3 ) | \tr u x )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012377 }
12378 inline_TWHILE() {
12379 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
12380 }
12381 inline_TWHILE() {
12382 i=1
Elliott Hughesfc0307d2016-02-02 15:26:47 -080012383 while {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012384 \\builtin let " i < 10 "
Elliott Hughesfc0307d2016-02-02 15:26:47 -080012385 } >&3
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012386 do
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012387 \echo $i
12388 \let ++i
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012389 done >&3
12390 }
12391 function comsub_TWHILE { x=$(
12392 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
12393 ); }
12394 function comsub_TWHILE {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012395 x=$(i=1 ; while { \\builtin let " i < 10 " ; } >&3 ; do \echo $i ; \let ++i ; done >&3 )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012396 }
12397 function reread_TWHILE { x=$((
12398 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
12399 )|tr u x); }
12400 function reread_TWHILE {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012401 x=$( ( i=1 ; while { \\builtin let " i < 10 " ; } >&3 ; do \echo $i ; \let ++i ; done >&3 ) | \tr u x )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012402 }
12403 inline_TUNTIL() {
12404 i=10; until (( !--i )) >&3 ; do echo $i; done >&3
12405 }
12406 inline_TUNTIL() {
12407 i=10
Elliott Hughesfc0307d2016-02-02 15:26:47 -080012408 until {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012409 \\builtin let " !--i "
Elliott Hughesfc0307d2016-02-02 15:26:47 -080012410 } >&3
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012411 do
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012412 \echo $i
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012413 done >&3
12414 }
12415 function comsub_TUNTIL { x=$(
12416 i=10; until (( !--i )) >&3 ; do echo $i; done >&3
12417 ); }
12418 function comsub_TUNTIL {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012419 x=$(i=10 ; until { \\builtin let " !--i " ; } >&3 ; do \echo $i ; done >&3 )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012420 }
12421 function reread_TUNTIL { x=$((
12422 i=10; until (( !--i )) >&3 ; do echo $i; done >&3
12423 )|tr u x); }
12424 function reread_TUNTIL {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012425 x=$( ( i=10 ; until { \\builtin let " !--i " ; } >&3 ; do \echo $i ; done >&3 ) | \tr u x )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012426 }
12427 inline_TCOPROC() {
12428 cat * >&3 |& >&3 ls
12429 }
12430 inline_TCOPROC() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012431 \cat * >&3 |&
12432 \ls >&3
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012433 }
12434 function comsub_TCOPROC { x=$(
12435 cat * >&3 |& >&3 ls
12436 ); }
12437 function comsub_TCOPROC {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012438 x=$(\cat * >&3 |& \ls >&3 )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012439 }
12440 function reread_TCOPROC { x=$((
12441 cat * >&3 |& >&3 ls
12442 )|tr u x); }
12443 function reread_TCOPROC {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012444 x=$( ( \cat * >&3 |& \ls >&3 ) | \tr u x )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012445 }
12446 inline_TFUNCT_TBRACE_TASYNC() {
12447 function korn { echo eins; echo >&3 zwei ; }
12448 bourne () { logger * >&3 & }
12449 }
12450 inline_TFUNCT_TBRACE_TASYNC() {
12451 function korn {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012452 \echo eins
12453 \echo zwei >&3
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012454 }
12455 bourne() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012456 \logger * >&3 &
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012457 }
12458 }
12459 function comsub_TFUNCT_TBRACE_TASYNC { x=$(
12460 function korn { echo eins; echo >&3 zwei ; }
12461 bourne () { logger * >&3 & }
12462 ); }
12463 function comsub_TFUNCT_TBRACE_TASYNC {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012464 x=$(function korn { \echo eins ; \echo zwei >&3 ; } ; bourne() { \logger * >&3 & } )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012465 }
12466 function reread_TFUNCT_TBRACE_TASYNC { x=$((
12467 function korn { echo eins; echo >&3 zwei ; }
12468 bourne () { logger * >&3 & }
12469 )|tr u x); }
12470 function reread_TFUNCT_TBRACE_TASYNC {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012471 x=$( ( function korn { \echo eins ; \echo zwei >&3 ; } ; bourne() { \logger * >&3 & } ) | \tr u x )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012472 }
12473 inline_COMSUB_EXPRSUB() {
12474 echo $(true >&3) $((1+ 2))
12475 }
12476 inline_COMSUB_EXPRSUB() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012477 \echo $(\true >&3 ) $((1+ 2))
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012478 }
12479 function comsub_COMSUB_EXPRSUB { x=$(
12480 echo $(true >&3) $((1+ 2))
12481 ); }
12482 function comsub_COMSUB_EXPRSUB {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012483 x=$(\echo $(\true >&3 ) $((1+ 2)) )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012484 }
12485 function reread_COMSUB_EXPRSUB { x=$((
12486 echo $(true >&3) $((1+ 2))
12487 )|tr u x); }
12488 function reread_COMSUB_EXPRSUB {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012489 x=$( ( \echo $(\true >&3 ) $((1+ 2)) ) | \tr u x )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012490 }
12491---
12492name: funsub-1
12493description:
12494 Check that non-subenvironment command substitution works
12495stdin:
12496 set -e
12497 foo=bar
12498 echo "ob $foo ."
12499 echo "${
12500 echo "ib $foo :"
12501 foo=baz
12502 echo "ia $foo :"
12503 false
12504 }" .
12505 echo "oa $foo ."
12506expected-stdout:
12507 ob bar .
12508 ib bar :
12509 ia baz : .
12510 oa baz .
12511---
12512name: funsub-2
12513description:
12514 You can now reliably use local and return in funsubs
12515 (not exit though)
12516stdin:
12517 x=q; e=1; x=${ echo a; e=2; echo x$e;}; echo 1:y$x,$e,$?.
12518 x=q; e=1; x=${ echo a; typeset e=2; echo x$e;}; echo 2:y$x,$e,$?.
12519 x=q; e=1; x=${ echo a; typeset e=2; return 3; echo x$e;}; echo 3:y$x,$e,$?.
12520expected-stdout:
12521 1:ya x2,2,0.
12522 2:ya x2,1,0.
12523 3:ya,1,3.
Geremy Condra03ebf062011-10-12 18:17:24 -070012524---
Thorsten Glaser811a5752013-07-25 14:24:45 +000012525name: valsub-1
12526description:
12527 Check that "value substitutions" work as advertised
12528stdin:
12529 x=1
12530 y=2
12531 z=3
12532 REPLY=4
12533 echo "before: x<$x> y<$y> z<$z> R<$REPLY>"
12534 x=${|
12535 local y
Elliott Hughes966dd552016-12-08 15:56:04 -080012536 echo "start: x<$x> y<$y> z<$z> R<$REPLY>"
Thorsten Glaser811a5752013-07-25 14:24:45 +000012537 x=5
12538 y=6
12539 z=7
12540 REPLY=8
12541 echo "end: x<$x> y<$y> z<$z> R<$REPLY>"
12542 }
12543 echo "after: x<$x> y<$y> z<$z> R<$REPLY>"
12544 # ensure trailing newlines are kept
12545 t=${|REPLY=$'foo\n\n';}
12546 typeset -p t
12547 echo -n this used to segfault
12548 echo ${|true;}$(true).
12549expected-stdout:
12550 before: x<1> y<2> z<3> R<4>
Elliott Hughes966dd552016-12-08 15:56:04 -080012551 start: x<1> y<> z<3> R<>
Thorsten Glaser811a5752013-07-25 14:24:45 +000012552 end: x<5> y<6> z<7> R<8>
12553 after: x<8> y<2> z<7> R<4>
12554 typeset t=$'foo\n\n'
12555 this used to segfault.
12556---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012557name: event-subst-3
12558description:
12559 Check that '!' substitution in noninteractive mode is ignored
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012560file-setup: file 755 "falsetto"
12561 #! /bin/sh
12562 echo molto bene
12563 exit 42
12564file-setup: file 755 "!false"
12565 #! /bin/sh
12566 echo si
12567stdin:
Elliott Hughes96b43632015-07-17 11:39:41 -070012568 export PATH=.$PATHSEP$PATH
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012569 falsetto
12570 echo yeap
12571 !false
12572 echo meow
12573 ! false
12574 echo = $?
12575 if
12576 ! false; then echo foo; else echo bar; fi
12577expected-stdout:
12578 molto bene
12579 yeap
12580 si
12581 meow
12582 = 0
12583 foo
12584---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012585name: event-subst-0
12586description:
12587 Check that '!' substitution in interactive mode is ignored
12588need-ctty: yes
12589arguments: !-i!
12590file-setup: file 755 "falsetto"
12591 #! /bin/sh
12592 echo molto bene
12593 exit 42
12594file-setup: file 755 "!false"
12595 #! /bin/sh
12596 echo si
12597stdin:
Elliott Hughes96b43632015-07-17 11:39:41 -070012598 export PATH=.$PATHSEP$PATH
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012599 falsetto
12600 echo yeap
12601 !false
12602 echo meow
12603 ! false
12604 echo = $?
12605 if
12606 ! false; then echo foo; else echo bar; fi
12607expected-stdout:
12608 molto bene
12609 yeap
12610 si
12611 meow
12612 = 0
12613 foo
12614expected-stderr-pattern:
12615 /.*/
12616---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012617name: nounset-1
12618description:
12619 Check that "set -u" matches (future) SUSv4 requirement
12620stdin:
12621 (set -u
12622 try() {
12623 local v
12624 eval v=\$$1
12625 if [[ -n $v ]]; then
12626 echo $1=nz
12627 else
12628 echo $1=zf
12629 fi
12630 }
12631 x=y
12632 (echo $x)
12633 echo =1
12634 (echo $y)
12635 echo =2
12636 (try x)
12637 echo =3
12638 (try y)
12639 echo =4
12640 (try 0)
12641 echo =5
12642 (try 2)
12643 echo =6
12644 (try)
12645 echo =7
12646 (echo at=$@)
12647 echo =8
12648 (echo asterisk=$*)
12649 echo =9
12650 (echo $?)
12651 echo =10
12652 (echo $!)
12653 echo =11
12654 (echo $-)
12655 echo =12
12656 #(echo $_)
12657 #echo =13
12658 (echo $#)
12659 echo =14
12660 (mypid=$$; try mypid)
12661 echo =15
12662 ) 2>&1 | sed -e 's/^[^]]*]//' -e 's/^[^:]*: *//'
Elliott Hughes50012062015-03-10 22:22:24 -070012663 exit ${PIPESTATUS[0]}
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012664expected-stdout:
12665 y
12666 =1
12667 y: parameter not set
12668 =2
12669 x=nz
12670 =3
12671 y: parameter not set
12672 =4
12673 0=nz
12674 =5
12675 2: parameter not set
12676 =6
12677 1: parameter not set
12678 =7
12679 at=
12680 =8
12681 asterisk=
12682 =9
12683 0
12684 =10
12685 !: parameter not set
12686 =11
12687 ush
12688 =12
12689 0
12690 =14
12691 mypid=nz
12692 =15
12693---
12694name: nameref-1
12695description:
12696 Testsuite for nameref (bound variables)
12697stdin:
12698 bar=global
12699 typeset -n ir2=bar
12700 typeset -n ind=ir2
12701 echo !ind: ${!ind}
12702 echo ind: $ind
12703 echo !ir2: ${!ir2}
12704 echo ir2: $ir2
12705 typeset +n ind
12706 echo !ind: ${!ind}
12707 echo ind: $ind
12708 typeset -n ir2=ind
12709 echo !ir2: ${!ir2}
12710 echo ir2: $ir2
12711 set|grep ^ir2|sed 's/^/s1: /'
12712 typeset|grep ' ir2'|sed -e 's/^/s2: /' -e 's/nameref/typeset -n/'
12713 set -A blub -- e1 e2 e3
12714 typeset -n ind=blub
12715 typeset -n ir2=blub[2]
12716 echo !ind[1]: ${!ind[1]}
12717 echo !ir2: $!ir2
12718 echo ind[1]: ${ind[1]}
12719 echo ir2: $ir2
12720expected-stdout:
12721 !ind: bar
12722 ind: global
12723 !ir2: bar
12724 ir2: global
12725 !ind: ind
12726 ind: ir2
12727 !ir2: ind
12728 ir2: ir2
12729 s1: ir2=ind
12730 s2: typeset -n ir2
Elliott Hughes737fdce2014-08-07 12:59:26 -070012731 !ind[1]: blub[1]
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012732 !ir2: ir2
12733 ind[1]: e2
12734 ir2: e3
12735---
12736name: nameref-2da
12737description:
12738 Testsuite for nameref (bound variables)
12739 Functions, argument given directly, after local
12740stdin:
12741 function foo {
12742 typeset bar=lokal baz=auch
12743 typeset -n v=bar
12744 echo entering
12745 echo !v: ${!v}
12746 echo !bar: ${!bar}
12747 echo !baz: ${!baz}
12748 echo bar: $bar
12749 echo v: $v
12750 v=123
12751 echo bar: $bar
12752 echo v: $v
12753 echo exiting
12754 }
12755 bar=global
12756 echo bar: $bar
12757 foo bar
12758 echo bar: $bar
12759expected-stdout:
12760 bar: global
12761 entering
12762 !v: bar
12763 !bar: bar
12764 !baz: baz
12765 bar: lokal
12766 v: lokal
12767 bar: 123
12768 v: 123
12769 exiting
12770 bar: global
12771---
12772name: nameref-3
12773description:
12774 Advanced testsuite for bound variables (ksh93 fails this)
12775stdin:
12776 typeset -n foo=bar[i]
12777 set -A bar -- b c a
12778 for i in 0 1 2 3; do
12779 print $i $foo .
12780 done
12781expected-stdout:
12782 0 b .
12783 1 c .
12784 2 a .
12785 3 .
12786---
Geremy Condra03ebf062011-10-12 18:17:24 -070012787name: nameref-4
12788description:
12789 Ensure we don't run in an infinite loop
12790time-limit: 3
12791stdin:
12792 baz() {
Thorsten Glaser811a5752013-07-25 14:24:45 +000012793 typeset -n foo=fnord fnord=foo
Geremy Condra03ebf062011-10-12 18:17:24 -070012794 foo[0]=bar
12795 }
12796 set -A foo bad
12797 echo sind $foo .
12798 baz
12799 echo blah $foo .
12800expected-stdout:
12801 sind bad .
Thorsten Glaser811a5752013-07-25 14:24:45 +000012802 blah bad .
12803expected-stderr-pattern:
12804 /fnord: expression recurses on parameter/
Geremy Condra03ebf062011-10-12 18:17:24 -070012805---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012806name: better-parens-1a
12807description:
12808 Check support for ((…)) and $((…)) vs (…) and $(…)
12809stdin:
Geremy Condra03ebf062011-10-12 18:17:24 -070012810 if ( (echo fubar)|tr u x); then
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012811 echo ja
12812 else
12813 echo nein
12814 fi
12815expected-stdout:
12816 fxbar
12817 ja
12818---
12819name: better-parens-1b
12820description:
12821 Check support for ((…)) and $((…)) vs (…) and $(…)
12822stdin:
Geremy Condra03ebf062011-10-12 18:17:24 -070012823 echo $( (echo fubar)|tr u x) $?
12824expected-stdout:
12825 fxbar 0
12826---
12827name: better-parens-1c
12828description:
12829 Check support for ((…)) and $((…)) vs (…) and $(…)
12830stdin:
12831 x=$( (echo fubar)|tr u x); echo $x $?
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012832expected-stdout:
12833 fxbar 0
12834---
12835name: better-parens-2a
12836description:
12837 Check support for ((…)) and $((…)) vs (…) and $(…)
12838stdin:
Geremy Condra03ebf062011-10-12 18:17:24 -070012839 if ((echo fubar)|tr u x); then
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012840 echo ja
12841 else
12842 echo nein
12843 fi
12844expected-stdout:
12845 fxbar
12846 ja
12847---
12848name: better-parens-2b
12849description:
12850 Check support for ((…)) and $((…)) vs (…) and $(…)
12851stdin:
Geremy Condra03ebf062011-10-12 18:17:24 -070012852 echo $((echo fubar)|tr u x) $?
12853expected-stdout:
12854 fxbar 0
12855---
12856name: better-parens-2c
12857description:
12858 Check support for ((…)) and $((…)) vs (…) and $(…)
12859stdin:
12860 x=$((echo fubar)|tr u x); echo $x $?
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012861expected-stdout:
12862 fxbar 0
12863---
12864name: better-parens-3a
12865description:
12866 Check support for ((…)) and $((…)) vs (…) and $(…)
12867stdin:
Geremy Condra03ebf062011-10-12 18:17:24 -070012868 if ( (echo fubar)|(tr u x)); then
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012869 echo ja
12870 else
12871 echo nein
12872 fi
12873expected-stdout:
12874 fxbar
12875 ja
12876---
12877name: better-parens-3b
12878description:
12879 Check support for ((…)) and $((…)) vs (…) and $(…)
12880stdin:
Geremy Condra03ebf062011-10-12 18:17:24 -070012881 echo $( (echo fubar)|(tr u x)) $?
12882expected-stdout:
12883 fxbar 0
12884---
12885name: better-parens-3c
12886description:
12887 Check support for ((…)) and $((…)) vs (…) and $(…)
12888stdin:
12889 x=$( (echo fubar)|(tr u x)); echo $x $?
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012890expected-stdout:
12891 fxbar 0
12892---
12893name: better-parens-4a
12894description:
12895 Check support for ((…)) and $((…)) vs (…) and $(…)
12896stdin:
Geremy Condra03ebf062011-10-12 18:17:24 -070012897 if ((echo fubar)|(tr u x)); then
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012898 echo ja
12899 else
12900 echo nein
12901 fi
12902expected-stdout:
12903 fxbar
12904 ja
12905---
12906name: better-parens-4b
12907description:
12908 Check support for ((…)) and $((…)) vs (…) and $(…)
12909stdin:
Geremy Condra03ebf062011-10-12 18:17:24 -070012910 echo $((echo fubar)|(tr u x)) $?
12911expected-stdout:
12912 fxbar 0
12913---
12914name: better-parens-4c
12915description:
12916 Check support for ((…)) and $((…)) vs (…) and $(…)
12917stdin:
12918 x=$((echo fubar)|(tr u x)); echo $x $?
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012919expected-stdout:
12920 fxbar 0
12921---
Elliott Hughesfc0307d2016-02-02 15:26:47 -080012922name: better-parens-5
12923description:
12924 Another corner case
12925stdin:
12926 ( (echo 'fo o$bar' "baz\$bla\"" m\$eh) | tr a A)
12927 ((echo 'fo o$bar' "baz\$bla\"" m\$eh) | tr a A)
12928expected-stdout:
12929 fo o$bAr bAz$blA" m$eh
12930 fo o$bAr bAz$blA" m$eh
12931---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012932name: echo-test-1
12933description:
12934 Test what the echo builtin does (mksh)
Elliott Hughes23925bb2017-09-22 16:04:20 -070012935category: !shell:ebcdic-yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012936stdin:
12937 echo -n 'foo\x40bar'
12938 echo -e '\tbaz'
12939expected-stdout:
12940 foo@bar baz
12941---
Elliott Hughes23925bb2017-09-22 16:04:20 -070012942name: echo-test-1-ebcdic
12943description:
12944 Test what the echo builtin does (mksh)
12945category: !shell:ebcdic-no
12946stdin:
12947 echo -n 'foo\x7Cbar'
12948 echo -e '\tbaz'
12949expected-stdout:
12950 foo@bar baz
12951---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012952name: echo-test-2
12953description:
12954 Test what the echo builtin does (POSIX)
12955 Note: this follows Debian Policy 10.4 which mandates
12956 that -n shall be treated as an option, not XSI which
12957 mandates it shall be treated as string but escapes
12958 shall be expanded.
12959stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012960 test -n "$POSH_VERSION" || set -o posix
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012961 echo -n 'foo\x40bar'
12962 echo -e '\tbaz'
12963expected-stdout:
12964 foo\x40bar-e \tbaz
12965---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012966name: echo-test-3-mnbsd
12967description:
12968 Test what the echo builtin does, and test a compatibility flag.
12969category: mnbsdash
12970stdin:
12971 "$__progname" -c 'echo -n 1=\\x40$1; echo -e \\x2E' -- foo bar
12972 "$__progname" -o posix -c 'echo -n 2=\\x40$1; echo -e \\x2E' -- foo bar
12973 "$__progname" -o sh -c 'echo -n 3=\\x40$1; echo -e \\x2E' -- foo bar
12974expected-stdout:
12975 1=@foo.
12976 2=\x40foo-e \x2E
12977 3=\x40bar.
12978---
12979name: echo-test-3-normal
12980description:
12981 Test what the echo builtin does, and test a compatibility flag.
Elliott Hughes23925bb2017-09-22 16:04:20 -070012982category: !mnbsdash,!shell:ebcdic-yes
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012983stdin:
12984 "$__progname" -c 'echo -n 1=\\x40$1; echo -e \\x2E' -- foo bar
12985 "$__progname" -o posix -c 'echo -n 2=\\x40$1; echo -e \\x2E' -- foo bar
12986 "$__progname" -o sh -c 'echo -n 3=\\x40$1; echo -e \\x2E' -- foo bar
12987expected-stdout:
12988 1=@foo.
12989 2=\x40foo-e \x2E
12990 3=\x40foo-e \x2E
12991---
Elliott Hughes23925bb2017-09-22 16:04:20 -070012992name: echo-test-3-ebcdic
12993description:
12994 Test what the echo builtin does, and test a compatibility flag.
12995category: !mnbsdash,!shell:ebcdic-no
12996stdin:
12997 "$__progname" -c 'echo -n 1=\\x7C$1; echo -e \\x4B' -- foo bar
12998 "$__progname" -o posix -c 'echo -n 2=\\x7C$1; echo -e \\x4B' -- foo bar
12999 "$__progname" -o sh -c 'echo -n 3=\\x7C$1; echo -e \\x4B' -- foo bar
13000expected-stdout:
13001 1=@foo.
13002 2=\x7Cfoo-e \x4B
13003 3=\x7Cfoo-e \x4B
13004---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070013005name: utilities-getopts-1
13006description:
13007 getopts sets OPTIND correctly for unparsed option
13008stdin:
13009 set -- -a -a -x
13010 while getopts :a optc; do
13011 echo "OPTARG=$OPTARG, OPTIND=$OPTIND, optc=$optc."
13012 done
13013 echo done
13014expected-stdout:
13015 OPTARG=, OPTIND=2, optc=a.
13016 OPTARG=, OPTIND=3, optc=a.
13017 OPTARG=x, OPTIND=4, optc=?.
13018 done
13019---
13020name: utilities-getopts-2
13021description:
13022 Check OPTARG
13023stdin:
13024 set -- -a Mary -x
13025 while getopts a: optc; do
13026 echo "OPTARG=$OPTARG, OPTIND=$OPTIND, optc=$optc."
13027 done
13028 echo done
13029expected-stdout:
13030 OPTARG=Mary, OPTIND=3, optc=a.
13031 OPTARG=, OPTIND=4, optc=?.
13032 done
13033expected-stderr-pattern: /.*-x.*option/
13034---
Elliott Hughes77740fc2016-08-12 15:06:53 -070013035name: utilities-getopts-3
13036description:
13037 Check unsetting OPTARG
13038stdin:
13039 set -- -x arg -y
13040 getopts x:y opt && echo "${OPTARG-unset}"
13041 getopts x:y opt && echo "${OPTARG-unset}"
13042expected-stdout:
13043 arg
13044 unset
13045---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070013046name: wcswidth-1
13047description:
13048 Check the new wcswidth feature
13049stdin:
13050 s=何
13051 set +U
13052 print octets: ${#s} .
13053 print 8-bit width: ${%s} .
13054 set -U
13055 print characters: ${#s} .
13056 print columns: ${%s} .
13057 s=�
13058 set +U
13059 print octets: ${#s} .
13060 print 8-bit width: ${%s} .
13061 set -U
13062 print characters: ${#s} .
13063 print columns: ${%s} .
13064expected-stdout:
13065 octets: 3 .
13066 8-bit width: -1 .
13067 characters: 1 .
13068 columns: 2 .
13069 octets: 3 .
13070 8-bit width: 3 .
13071 characters: 1 .
13072 columns: 1 .
13073---
13074name: wcswidth-2
13075description:
13076 Check some corner cases
13077stdin:
13078 print % $% .
13079 set -U
13080 x='a b'
13081 print c ${%x} .
13082 set +U
13083 x='a b'
13084 print d ${%x} .
13085expected-stdout:
13086 % $% .
13087 c -1 .
13088 d -1 .
13089---
13090name: wcswidth-3
13091description:
13092 Check some corner cases
13093stdin:
13094 print ${%} .
13095expected-stderr-pattern:
13096 /bad substitution/
13097expected-exit: 1
13098---
13099name: wcswidth-4a
13100description:
13101 Check some corner cases
13102stdin:
13103 print ${%*} .
13104expected-stderr-pattern:
13105 /bad substitution/
13106expected-exit: 1
13107---
13108name: wcswidth-4b
13109description:
13110 Check some corner cases
13111stdin:
13112 print ${%@} .
13113expected-stderr-pattern:
13114 /bad substitution/
13115expected-exit: 1
13116---
13117name: wcswidth-4c
13118description:
13119 Check some corner cases
13120stdin:
13121 :
13122 print ${%?} .
13123expected-stdout:
13124 1 .
13125---
13126name: realpath-1
13127description:
13128 Check proper return values for realpath
13129category: os:mirbsd
13130stdin:
13131 wd=$(realpath .)
13132 mkdir dir
13133 :>file
13134 :>dir/file
13135 ln -s dir lndir
13136 ln -s file lnfile
13137 ln -s nix lnnix
13138 ln -s . lnself
13139 i=0
13140 chk() {
13141 typeset x y
13142 x=$(realpath "$wd/$1" 2>&1); y=$?
13143 print $((++i)) "?$1" =${x##*$wd/} !$y
13144 }
13145 chk dir
13146 chk dir/
13147 chk dir/file
13148 chk dir/nix
13149 chk file
13150 chk file/
13151 chk file/file
13152 chk file/nix
13153 chk nix
13154 chk nix/
13155 chk nix/file
13156 chk nix/nix
13157 chk lndir
13158 chk lndir/
13159 chk lndir/file
13160 chk lndir/nix
13161 chk lnfile
13162 chk lnfile/
13163 chk lnfile/file
13164 chk lnfile/nix
13165 chk lnnix
13166 chk lnnix/
13167 chk lnnix/file
13168 chk lnnix/nix
13169 chk lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself
13170 rm lnself
13171expected-stdout:
13172 1 ?dir =dir !0
13173 2 ?dir/ =dir !0
13174 3 ?dir/file =dir/file !0
13175 4 ?dir/nix =dir/nix !0
13176 5 ?file =file !0
13177 6 ?file/ =file/: Not a directory !20
13178 7 ?file/file =file/file: Not a directory !20
13179 8 ?file/nix =file/nix: Not a directory !20
13180 9 ?nix =nix !0
13181 10 ?nix/ =nix !0
13182 11 ?nix/file =nix/file: No such file or directory !2
13183 12 ?nix/nix =nix/nix: No such file or directory !2
13184 13 ?lndir =dir !0
13185 14 ?lndir/ =dir !0
13186 15 ?lndir/file =dir/file !0
13187 16 ?lndir/nix =dir/nix !0
13188 17 ?lnfile =file !0
13189 18 ?lnfile/ =lnfile/: Not a directory !20
13190 19 ?lnfile/file =lnfile/file: Not a directory !20
13191 20 ?lnfile/nix =lnfile/nix: Not a directory !20
13192 21 ?lnnix =nix !0
13193 22 ?lnnix/ =nix !0
13194 23 ?lnnix/file =lnnix/file: No such file or directory !2
13195 24 ?lnnix/nix =lnnix/nix: No such file or directory !2
13196 25 ?lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself =lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself/lnself: Too many levels of symbolic links !62
13197---
Geremy Condra03ebf062011-10-12 18:17:24 -070013198name: realpath-2
13199description:
13200 Ensure that exactly two leading slashes are not collapsed
13201 POSIX guarantees this exception, e.g. for UNC paths on Cygwin
13202category: os:mirbsd
13203stdin:
13204 ln -s /bin t1
13205 ln -s //bin t2
13206 ln -s ///bin t3
13207 realpath /bin
13208 realpath //bin
13209 realpath ///bin
13210 realpath /usr/bin
13211 realpath /usr//bin
13212 realpath /usr///bin
13213 realpath t1
13214 realpath t2
13215 realpath t3
13216 rm -f t1 t2 t3
13217 cd //usr/bin
13218 pwd
13219 cd ../lib
13220 pwd
13221 realpath //usr/include/../bin
13222expected-stdout:
13223 /bin
13224 //bin
13225 /bin
13226 /usr/bin
13227 /usr/bin
13228 /usr/bin
13229 /bin
13230 //bin
13231 /bin
13232 //usr/bin
13233 //usr/lib
13234 //usr/bin
13235---
13236name: crash-1
13237description:
13238 Crashed during March 2011, fixed on vernal equinōx ☺
13239category: os:mirbsd,os:openbsd
13240stdin:
13241 export MALLOC_OPTIONS=FGJPRSX
13242 "$__progname" -c 'x=$(tr z r <<<baz); echo $x'
13243expected-stdout:
13244 bar
13245---
13246name: debian-117-1
13247description:
13248 Check test - bug#465250
13249stdin:
13250 test \( ! -e \) ; echo $?
13251expected-stdout:
13252 1
13253---
13254name: debian-117-2
13255description:
13256 Check test - bug#465250
13257stdin:
13258 test \( -e \) ; echo $?
13259expected-stdout:
13260 0
13261---
13262name: debian-117-3
13263description:
13264 Check test - bug#465250
13265stdin:
13266 test ! -e ; echo $?
13267expected-stdout:
13268 1
13269---
13270name: debian-117-4
13271description:
13272 Check test - bug#465250
13273stdin:
13274 test -e ; echo $?
13275expected-stdout:
13276 0
13277---
13278name: case-zsh
13279description:
13280 Check that zsh case variants work
13281stdin:
13282 case 'b' in
13283 a) echo a ;;
13284 b) echo b ;;
13285 c) echo c ;;
13286 *) echo x ;;
13287 esac
13288 echo =
13289 case 'b' in
13290 a) echo a ;&
13291 b) echo b ;&
13292 c) echo c ;&
13293 *) echo x ;&
13294 esac
13295 echo =
13296 case 'b' in
13297 a) echo a ;|
13298 b) echo b ;|
13299 c) echo c ;|
13300 *) echo x ;|
13301 esac
13302expected-stdout:
13303 b
13304 =
13305 b
13306 c
13307 x
13308 =
13309 b
13310 x
13311---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000013312name: case-braces
13313description:
13314 Check that case end tokens are not mixed up (Debian #220272)
13315stdin:
13316 i=0
13317 for value in 'x' '}' 'esac'; do
13318 print -n "$((++i))($value)bourne "
13319 case $value in
13320 }) echo brace ;;
13321 *) echo no ;;
13322 esac
13323 print -n "$((++i))($value)korn "
13324 case $value {
13325 esac) echo esac ;;
13326 *) echo no ;;
13327 }
13328 done
13329expected-stdout:
13330 1(x)bourne no
13331 2(x)korn no
13332 3(})bourne brace
13333 4(})korn no
13334 5(esac)bourne no
13335 6(esac)korn esac
13336---
13337name: command-shift
13338description:
13339 Check that 'command shift' works
13340stdin:
13341 function snc {
13342 echo "before 0='$0' 1='$1' 2='$2'"
13343 shift
13344 echo "after 0='$0' 1='$1' 2='$2'"
13345 }
13346 function swc {
13347 echo "before 0='$0' 1='$1' 2='$2'"
13348 command shift
13349 echo "after 0='$0' 1='$1' 2='$2'"
13350 }
13351 echo = without command
13352 snc 一 二
13353 echo = with command
13354 swc 一 二
13355 echo = done
13356expected-stdout:
13357 = without command
13358 before 0='snc' 1='一' 2='二'
13359 after 0='snc' 1='二' 2=''
13360 = with command
13361 before 0='swc' 1='一' 2='二'
13362 after 0='swc' 1='二' 2=''
13363 = done
13364---
Elliott Hughes77740fc2016-08-12 15:06:53 -070013365name: command-pvV-posix-priorities
13366description:
13367 For POSIX compatibility, command -v should find aliases and reserved
13368 words, and command -p[vV] should find aliases, reserved words, and
13369 builtins over external commands.
13370stdin:
13371 PATH=/bin:/usr/bin
13372 alias foo="bar baz"
13373 bar() { :; }
13374 for word in 'if' 'foo' 'bar' 'set' 'true'; do
13375 command -v "$word"
13376 command -pv "$word"
13377 command -V "$word"
13378 command -pV "$word"
13379 done
13380expected-stdout:
13381 if
13382 if
13383 if is a reserved word
13384 if is a reserved word
13385 alias foo='bar baz'
13386 alias foo='bar baz'
13387 foo is an alias for 'bar baz'
13388 foo is an alias for 'bar baz'
13389 bar
13390 bar
13391 bar is a function
13392 bar is a function
13393 set
13394 set
13395 set is a special shell builtin
13396 set is a special shell builtin
13397 true
13398 true
13399 true is a shell builtin
13400 true is a shell builtin
13401---
13402name: whence-preserve-tradition
13403description:
13404 This regression test is to ensure that the POSIX compatibility
13405 changes for 'command' (see previous test) do not affect traditional
13406 'whence' behaviour.
13407category: os:mirbsd
13408stdin:
13409 PATH=/bin:/usr/bin
13410 alias foo="bar baz"
13411 bar() { :; }
13412 for word in 'if' 'foo' 'bar' 'set' 'true'; do
13413 whence "$word"
13414 whence -p "$word"
13415 whence -v "$word"
13416 whence -pv "$word"
13417 done
13418expected-stdout:
13419 if
13420 if is a reserved word
13421 if not found
13422 'bar baz'
13423 foo is an alias for 'bar baz'
13424 foo not found
13425 bar
13426 bar is a function
13427 bar not found
13428 set
13429 set is a special shell builtin
13430 set not found
13431 true
13432 /bin/true
13433 true is a shell builtin
13434 true is a tracked alias for /bin/true
13435---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000013436name: duffs-device
13437description:
13438 Check that the compiler did not optimise-break them
13439 (lex.c has got a similar one in SHEREDELIM)
Elliott Hughes23925bb2017-09-22 16:04:20 -070013440category: !shell:faux-ebcdic,!shell:ebcdic-yes
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000013441stdin:
13442 set +U
13443 s=
13444 typeset -i1 i=0
13445 while (( ++i < 256 )); do
13446 s+=${i#1#}
13447 done
13448 s+=$'\xC2\xA0\xE2\x82\xAC\xEF\xBF\xBD\xEF\xBF\xBE\xEF\xBF\xBF\xF0\x90\x80\x80.'
13449 typeset -p s
13450expected-stdout:
13451 typeset s=$'\001\002\003\004\005\006\a\b\t\n\v\f\r\016\017\020\021\022\023\024\025\026\027\030\031\032\E\034\035\036\037 !"#$%&\047()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377\u00A0\u20AC\uFFFD\357\277\276\357\277\277\360\220\200\200.'
13452---
Elliott Hughes23925bb2017-09-22 16:04:20 -070013453name: duffs-device-ebcdic
13454description:
13455 Check that the compiler did not optimise-break them
13456category: !shell:ebcdic-no
13457stdin:
13458 set +U
13459 s=
13460 typeset -i1 i=0
13461 while (( ++i < 256 )); do
13462 s+=${i#1#}
13463 done
13464 #s+=$'\xC2\xA0\xE2\x82\xAC\xEF\xBF\xBD\xEF\xBF\xBE\xEF\xBF\xBF\xF0\x90\x80\x80.' #XXX
13465 typeset -p s
13466expected-stdout:
13467 typeset s=$'\001\002\003\004\t\006\007\010\011\012\v\f\r\016\017\020\021\022\023\024\n\b\027\030\031\032\033\034\035\036\037\040\041\042\043\044\045\046\E\050\051\052\053\054\055\056\a\060\061\062\063\064\065\066\067\070\071\072\073\074\075\076\077  âäàáãåçñ¢.<(+|&éêëèíîïìß!$*);^-/ÂÄÀÁÃÅÇѦ,%_>?øÉÊËÈÍÎÏÌ`:#@\175="Øabcdefghi«»ðýþ±°jklmnopqrªºæ¸Æ¤µ~stuvwxyz¡¿Ð[Þ®¬£¥·©§¶¼½¾Ý¨¯]´×{ABCDEFGHI­ôöòóõ}JKLMNOPQR¹ûüùúÿ\\÷STUVWXYZ²ÔÖÒÓÕ0123456789³ÛÜÙÚ\377'
13468---
13469name: duffs-device-faux-EBCDIC
13470description:
13471 Check that the compiler did not optimise-break them
13472category: shell:faux-ebcdic
13473stdin:
13474 set +U
13475 s=
13476 typeset -i1 i=0
13477 while (( ++i < 256 )); do
13478 s+=${i#1#}
13479 done
13480 s+=$'\xC2\xA0\xE2\x82\xAC\xEF\xBF\xBD\xEF\xBF\xBE\xEF\xBF\xBF\xF0\x90\x80\x80.'
13481 typeset -p s
13482expected-stdout:
13483 typeset s=$'\001\002\003\004\005\006\a\b\t\n\v\f\r\016\017\020\021\022\023\024\025\026\027\030\031\032\E\034\035\036\037 !"#$%&\047()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237 ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ\u00A0\u20AC\uFFFD￾￿ð\220\200\200.'
13484---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000013485name: stateptr-underflow
13486description:
13487 This check overflows an Xrestpos stored in a short in R40
13488category: fastbox
13489stdin:
13490 function Lb64decode {
13491 [[ -o utf8-mode ]]; local u=$?
13492 set +U
13493 local c s="$*" t=
13494 [[ -n $s ]] || { s=$(cat;print x); s=${s%x}; }
13495 local -i i=0 n=${#s} p=0 v x
13496 local -i16 o
13497
13498 while (( i < n )); do
13499 c=${s:(i++):1}
13500 case $c {
13501 (=) break ;;
13502 ([A-Z]) (( v = 1#$c - 65 )) ;;
13503 ([a-z]) (( v = 1#$c - 71 )) ;;
13504 ([0-9]) (( v = 1#$c + 4 )) ;;
13505 (+) v=62 ;;
13506 (/) v=63 ;;
13507 (*) continue ;;
13508 }
13509 (( x = (x << 6) | v ))
13510 case $((p++)) {
13511 (0) continue ;;
13512 (1) (( o = (x >> 4) & 255 )) ;;
13513 (2) (( o = (x >> 2) & 255 )) ;;
13514 (3) (( o = x & 255 ))
13515 p=0
13516 ;;
13517 }
13518 t=$t\\x${o#16#}
13519 done
13520 print -n $t
13521 (( u )) || set -U
13522 }
13523
13524 i=-1
13525 s=
13526 while (( ++i < 12120 )); do
13527 s+=a
13528 done
13529 Lb64decode $s >/dev/null
13530---
Thorsten Glaser811a5752013-07-25 14:24:45 +000013531name: xtrace-1
13532description:
13533 Check that "set -x" doesn't redirect too quickly
13534stdin:
13535 print '#!'"$__progname" >bash
13536 cat >>bash <<'EOF'
13537 echo 'GNU bash, version 2.05b.0(1)-release (i386-ecce-mirbsd10)
13538 Copyright (C) 2002 Free Software Foundation, Inc.'
13539 EOF
13540 chmod +x bash
Elliott Hughes77740fc2016-08-12 15:06:53 -070013541 "$__progname" -xc 'foo=$(./bash --version 2>&1 | sed q); echo "=$foo="'
Thorsten Glaser811a5752013-07-25 14:24:45 +000013542expected-stdout:
13543 =GNU bash, version 2.05b.0(1)-release (i386-ecce-mirbsd10)=
13544expected-stderr-pattern:
13545 /.*/
13546---
Elliott Hughes50012062015-03-10 22:22:24 -070013547name: xtrace-2
13548description:
13549 Check that "set -x" is off during PS4 expansion
13550stdin:
13551 f() {
13552 print -n "(f1:$-)"
13553 set -x
13554 print -n "(f2:$-)"
13555 }
13556 PS4='[(p:$-)$(f)] '
13557 print "(o0:$-)"
13558 set -x -o inherit-xtrace
13559 print "(o1:$-)"
13560 set +x
13561 print "(o2:$-)"
13562expected-stdout:
13563 (o0:sh)
13564 (o1:shx)
13565 (o2:sh)
13566expected-stderr:
13567 [(p:sh)(f1:sh)(f2:sh)] print '(o1:shx)'
13568 [(p:sh)(f1:sh)(f2:sh)] set +x
13569---
Elliott Hughes96b43632015-07-17 11:39:41 -070013570name: fksh-flags
13571description:
13572 Check that FKSH functions have their own shell flags
13573category: shell:legacy-no
13574stdin:
13575 [[ $KSH_VERSION = Version* ]] && set +B
13576 function foo {
13577 set +f
13578 set -e
13579 echo 2 "${-/s}" .
13580 }
13581 set -fh
13582 echo 1 "${-/s}" .
13583 foo
13584 echo 3 "${-/s}" .
13585expected-stdout:
13586 1 fh .
13587 2 eh .
13588 3 fh .
13589---
Elliott Hughesb27ce952015-04-21 13:39:18 -070013590name: fksh-flags-legacy
13591description:
13592 Check that even FKSH functions share the shell flags
Elliott Hughes96b43632015-07-17 11:39:41 -070013593category: shell:legacy-yes
Elliott Hughesb27ce952015-04-21 13:39:18 -070013594stdin:
13595 [[ $KSH_VERSION = Version* ]] && set +B
13596 foo() {
13597 set +f
13598 set -e
13599 echo 2 "${-/s}" .
13600 }
13601 set -fh
13602 echo 1 "${-/s}" .
13603 foo
13604 echo 3 "${-/s}" .
13605expected-stdout:
13606 1 fh .
13607 2 eh .
13608 3 eh .
13609---
13610name: fsh-flags
13611description:
13612 Check that !FKSH functions share the shell flags
13613stdin:
13614 [[ $KSH_VERSION = Version* ]] && set +B
13615 foo() {
13616 set +f
13617 set -e
13618 echo 2 "${-/s}" .
13619 }
13620 set -fh
13621 echo 1 "${-/s}" .
13622 foo
13623 echo 3 "${-/s}" .
13624expected-stdout:
13625 1 fh .
13626 2 eh .
13627 3 eh .
13628---