OSDN Git Service

Merge "Upgrade to mksh 50e."
[android-x86/external-mksh.git] / src / check.t
1 # $MirOS: src/bin/mksh/check.t,v 1.667.2.3 2015/03/01 15:42:51 tg Exp $
2 # -*- mode: sh -*-
3 #-
4 # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
5 #             2011, 2012, 2013, 2014, 2015
6 #       Thorsten Glaser <tg@mirbsd.org>
7 #
8 # Provided that these terms and disclaimer and all copyright notices
9 # are retained or reproduced in an accompanying document, permission
10 # is granted to deal in this work without restriction, including un‐
11 # limited rights to use, publicly perform, distribute, sell, modify,
12 # merge, give away, or sublicence.
13 #
14 # This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
15 # the utmost extent permitted by applicable law, neither express nor
16 # implied; without malicious intent or gross negligence. In no event
17 # may a licensor, author or contributor be held liable for indirect,
18 # direct, other damage, loss, or other issues arising in any way out
19 # of dealing in the work, even if advised of the possibility of such
20 # damage or existence of a defect, except proven that it results out
21 # of said person’s immediate fault when using the work as intended.
22 #-
23 # You may also want to test IFS with the script at
24 # http://www.research.att.com/~gsf/public/ifs.sh
25 #
26 # More testsuites at:
27 # http://svnweb.freebsd.org/base/head/bin/test/tests/legacy_test.sh?view=co&content-type=text%2Fplain
28 #
29 # Integrated testsuites from:
30 # (2013/12/02 20:39:44) http://openbsd.cs.toronto.edu/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date
31
32 expected-stdout:
33         @(#)MIRBSD KSH R50 2015/03/01
34 description:
35         Check version of shell.
36 stdin:
37         echo $KSH_VERSION
38 name: KSH_VERSION
39 category: shell:legacy-no
40 ---
41 expected-stdout:
42         @(#)LEGACY KSH R50 2015/03/01
43 description:
44         Check version of legacy shell.
45 stdin:
46         echo $KSH_VERSION
47 name: KSH_VERSION-legacy
48 category: shell:legacy-yes
49 ---
50 name: selftest-1
51 description:
52         Regression test self-testing
53 stdin:
54         echo ${foo:-baz}
55 expected-stdout:
56         baz
57 ---
58 name: selftest-2
59 description:
60         Regression test self-testing
61 env-setup: !foo=bar!
62 stdin:
63         echo ${foo:-baz}
64 expected-stdout:
65         bar
66 ---
67 name: selftest-3
68 description:
69         Regression test self-testing
70 env-setup: !ENV=fnord!
71 stdin:
72         echo "<$ENV>"
73 expected-stdout:
74         <fnord>
75 ---
76 name: selftest-exec
77 description:
78         Ensure that the test run directory (default /tmp but can be changed
79         with check.pl flag -T or test.sh $TMPDIR) is not mounted noexec, as
80         we execute scripts from the scratch directory during several tests.
81 stdin:
82         print '#!'"$__progname"'\necho tf' >lq
83         chmod +x lq
84         ./lq
85 expected-stdout:
86         tf
87 ---
88 name: selftest-env
89 description:
90         Just output the environment variables set (always fails)
91 category: disabled
92 stdin:
93         set
94 ---
95 name: selftest-legacy
96 description:
97         Check some things in the LEGACY KSH
98 category: shell:legacy-yes
99 stdin:
100         set +o emacs
101         set +o vi
102         [[ "$(set +o) -o" = *"-o emacs -o"* ]] && echo 1=emacs
103         [[ "$(set +o) -o" = *"-o vi -o"* ]] && echo 1=vi
104         set -o emacs
105         set -o vi
106         [[ "$(set +o) -o" = *"-o emacs -o"* ]] && echo 2=emacs
107         [[ "$(set +o) -o" = *"-o vi -o"* ]] && echo 2=vi
108 expected-stdout:
109         2=emacs
110         2=vi
111 ---
112 name: selftest-direct-builtin-call
113 description:
114         Check that direct builtin calls work
115 stdin:
116         ln -s "$__progname" cat || cp "$__progname" cat
117         ln -s "$__progname" echo || cp "$__progname" echo
118         ./echo -c 'echo  foo' | ./cat -u
119 expected-stdout:
120         -c echo  foo
121 ---
122 name: alias-1
123 description:
124         Check that recursion is detected/avoided in aliases.
125 stdin:
126         alias fooBar=fooBar
127         fooBar
128         exit 0
129 expected-stderr-pattern:
130         /fooBar.*not found.*/
131 ---
132 name: alias-2
133 description:
134         Check that recursion is detected/avoided in aliases.
135 stdin:
136         alias fooBar=barFoo
137         alias barFoo=fooBar
138         fooBar
139         barFoo
140         exit 0
141 expected-stderr-pattern:
142         /fooBar.*not found.*\n.*barFoo.*not found/
143 ---
144 name: alias-3
145 description:
146         Check that recursion is detected/avoided in aliases.
147 stdin:
148         alias Echo='echo '
149         alias fooBar=barFoo
150         alias barFoo=fooBar
151         Echo fooBar
152         unalias barFoo
153         Echo fooBar
154 expected-stdout:
155         fooBar
156         barFoo
157 ---
158 name: alias-4
159 description:
160         Check that alias expansion isn't done on keywords (in keyword
161         postitions).
162 stdin:
163         alias Echo='echo '
164         alias while=While
165         while false; do echo hi ; done
166         Echo while
167 expected-stdout:
168         While
169 ---
170 name: alias-5
171 description:
172         Check that alias expansion done after alias with trailing space.
173 stdin:
174         alias Echo='echo '
175         alias foo='bar stuff '
176         alias bar='Bar1 Bar2 '
177         alias stuff='Stuff'
178         alias blah='Blah'
179         Echo foo blah
180 expected-stdout:
181         Bar1 Bar2 Stuff Blah
182 ---
183 name: alias-6
184 description:
185         Check that alias expansion done after alias with trailing space.
186 stdin:
187         alias Echo='echo '
188         alias foo='bar bar'
189         alias bar='Bar '
190         alias blah=Blah
191         Echo foo blah
192 expected-stdout:
193         Bar Bar Blah
194 ---
195 name: alias-7
196 description:
197         Check that alias expansion done after alias with trailing space
198         after a keyword.
199 stdin:
200         alias X='case '
201         alias Y=Z
202         X Y in 'Y') echo is y ;; Z) echo is z ; esac
203 expected-stdout:
204         is z
205 ---
206 name: alias-8
207 description:
208         Check that newlines in an alias don't cause the command to be lost.
209 stdin:
210         alias foo='
211         
212         
213         echo hi
214         
215         
216         
217         echo there
218         
219         
220         '
221         foo
222 expected-stdout:
223         hi
224         there
225 ---
226 name: alias-9
227 description:
228         Check that recursion is detected/avoided in aliases.
229         This check fails for slow machines or Cygwin, raise
230         the time-limit clause (e.g. to 7) if this occurs.
231 time-limit: 3
232 stdin:
233         print '#!'"$__progname"'\necho tf' >lq
234         chmod +x lq
235         PATH=$PWD:$PATH
236         alias lq=lq
237         lq
238         echo = now
239         i=`lq`
240         print -r -- $i
241         echo = out
242         exit 0
243 expected-stdout:
244         tf
245         = now
246         tf
247         = out
248 ---
249 name: alias-10
250 description:
251         Check that recursion is detected/avoided in aliases.
252         Regression, introduced during an old bugfix.
253 stdin:
254         alias foo='print hello '
255         alias bar='foo world'
256         echo $(bar)
257 expected-stdout:
258         hello world
259 ---
260 name: arith-lazy-1
261 description:
262         Check that only one side of ternary operator is evaluated
263 stdin:
264         x=i+=2
265         y=j+=2
266         typeset -i i=1 j=1
267         echo $((1 ? 20 : (x+=2)))
268         echo $i,$x
269         echo $((0 ? (y+=2) : 30))
270         echo $j,$y
271 expected-stdout:
272         20
273         1,i+=2
274         30
275         1,j+=2
276 ---
277 name: arith-lazy-2
278 description:
279         Check that assignments not done on non-evaluated side of ternary
280         operator
281 stdin:
282         x=i+=2
283         y=j+=2
284         typeset -i i=1 j=1
285         echo $((1 ? 20 : (x+=2)))
286         echo $i,$x
287         echo $((0 ? (y+=2) : 30))
288         echo $i,$y
289 expected-stdout:
290         20
291         1,i+=2
292         30
293         1,j+=2
294 ---
295 name: arith-lazy-3
296 description:
297         Check that assignments not done on non-evaluated side of ternary
298         operator and this construct is parsed correctly (Debian #445651)
299 stdin:
300         x=4
301         y=$((0 ? x=1 : 2))
302         echo = $x $y =
303 expected-stdout:
304         = 4 2 =
305 ---
306 name: arith-lazy-4
307 description:
308         Check that preun/postun not done on non-evaluated side of ternary
309         operator
310 stdin:
311         (( m = n = 0, 1 ? n++ : m++ ? 2 : 3 ))
312         echo "($n, $m)"
313         m=0; echo $(( 0 ? ++m : 2 )); echo $m
314         m=0; echo $(( 0 ? m++ : 2 )); echo $m
315 expected-stdout:
316         (1, 0)
317         2
318         0
319         2
320         0
321 ---
322 name: arith-ternary-prec-1
323 description:
324         Check precedence of ternary operator vs assignment
325 stdin:
326         typeset -i x=2
327         y=$((1 ? 20 : x+=2))
328 expected-exit: e != 0
329 expected-stderr-pattern:
330         /.*:.*1 \? 20 : x\+=2.*lvalue.*\n$/
331 ---
332 name: arith-ternary-prec-2
333 description:
334         Check precedence of ternary operator vs assignment
335 stdin:
336         typeset -i x=2
337         echo $((0 ? x+=2 : 20))
338 expected-stdout:
339         20
340 ---
341 name: arith-div-assoc-1
342 description:
343         Check associativity of division operator
344 stdin:
345         echo $((20 / 2 / 2))
346 expected-stdout:
347         5
348 ---
349 name: arith-div-byzero
350 description:
351         Check division by zero errors out
352 stdin:
353         x=$(echo $((1 / 0)))
354         echo =$?:$x.
355 expected-stdout:
356         =1:.
357 expected-stderr-pattern:
358         /.*divisor/
359 ---
360 name: arith-div-intmin-by-minusone
361 description:
362         Check division overflow wraps around silently
363 category: int:32
364 stdin:
365         echo signed:$((-2147483648 / -1))r$((-2147483648 % -1)).
366         echo unsigned:$((# -2147483648 / -1))r$((# -2147483648 % -1)).
367 expected-stdout:
368         signed:-2147483648r0.
369         unsigned:0r2147483648.
370 ---
371 name: arith-div-intmin-by-minusone-64
372 description:
373         Check division overflow wraps around silently
374 category: int:64
375 stdin:
376         echo signed:$((-9223372036854775808 / -1))r$((-9223372036854775808 % -1)).
377         echo unsigned:$((# -9223372036854775808 / -1))r$((# -9223372036854775808 % -1)).
378 expected-stdout:
379         signed:-9223372036854775808r0.
380         unsigned:0r9223372036854775808.
381 ---
382 name: arith-assop-assoc-1
383 description:
384         Check associativity of assignment-operator operator
385 stdin:
386         typeset -i i=1 j=2 k=3
387         echo $((i += j += k))
388         echo $i,$j,$k
389 expected-stdout:
390         6
391         6,5,3
392 ---
393 name: arith-mandatory
394 description:
395         Passing of this test is *mandatory* for a valid mksh executable!
396 category: shell:legacy-no
397 stdin:
398         typeset -i sari=0
399         typeset -Ui uari=0
400         typeset -i x=0
401         print -r -- $((x++)):$sari=$uari. #0
402         let --sari --uari
403         print -r -- $((x++)):$sari=$uari. #1
404         sari=2147483647 uari=2147483647
405         print -r -- $((x++)):$sari=$uari. #2
406         let ++sari ++uari
407         print -r -- $((x++)):$sari=$uari. #3
408         let --sari --uari
409         let 'sari *= 2' 'uari *= 2'
410         let ++sari ++uari
411         print -r -- $((x++)):$sari=$uari. #4
412         let ++sari ++uari
413         print -r -- $((x++)):$sari=$uari. #5
414         sari=-2147483648 uari=-2147483648
415         print -r -- $((x++)):$sari=$uari. #6
416         let --sari --uari
417         print -r -- $((x++)):$sari=$uari. #7
418         (( sari = -5 >> 1 ))
419         ((# uari = -5 >> 1 ))
420         print -r -- $((x++)):$sari=$uari. #8
421         (( sari = -2 ))
422         ((# uari = sari ))
423         print -r -- $((x++)):$sari=$uari. #9
424 expected-stdout:
425         0:0=0.
426         1:-1=4294967295.
427         2:2147483647=2147483647.
428         3:-2147483648=2147483648.
429         4:-1=4294967295.
430         5:0=0.
431         6:-2147483648=2147483648.
432         7:2147483647=2147483647.
433         8:-3=2147483645.
434         9:-2=4294967294.
435 ---
436 name: arith-unsigned-1
437 description:
438         Check if unsigned arithmetics work
439 category: int:32
440 stdin:
441         # signed vs unsigned
442         echo x1 $((-1)) $((#-1))
443         # calculating
444         typeset -i vs
445         typeset -Ui vu
446         vs=4123456789; vu=4123456789
447         echo x2 $vs $vu
448         (( vs %= 2147483647 ))
449         (( vu %= 2147483647 ))
450         echo x3 $vs $vu
451         vs=4123456789; vu=4123456789
452         (( # vs %= 2147483647 ))
453         (( # vu %= 2147483647 ))
454         echo x4 $vs $vu
455         # make sure the calculation does not change unsigned flag
456         vs=4123456789; vu=4123456789
457         echo x5 $vs $vu
458         # short form
459         echo x6 $((# vs % 2147483647)) $((# vu % 2147483647))
460         # array refs
461         set -A va
462         va[1975973142]=right
463         va[4123456789]=wrong
464         echo x7 ${va[#4123456789%2147483647]}
465 expected-stdout:
466         x1 -1 4294967295
467         x2 -171510507 4123456789
468         x3 -171510507 4123456789
469         x4 1975973142 1975973142
470         x5 -171510507 4123456789
471         x6 1975973142 1975973142
472         x7 right
473 ---
474 name: arith-limit32-1
475 description:
476         Check if arithmetics are 32 bit
477 category: int:32
478 stdin:
479         # signed vs unsigned
480         echo x1 $((-1)) $((#-1))
481         # calculating
482         typeset -i vs
483         typeset -Ui vu
484         vs=2147483647; vu=2147483647
485         echo x2 $vs $vu
486         let vs++ vu++
487         echo x3 $vs $vu
488         vs=4294967295; vu=4294967295
489         echo x4 $vs $vu
490         let vs++ vu++
491         echo x5 $vs $vu
492         let vs++ vu++
493         echo x6 $vs $vu
494 expected-stdout:
495         x1 -1 4294967295
496         x2 2147483647 2147483647
497         x3 -2147483648 2147483648
498         x4 -1 4294967295
499         x5 0 0
500         x6 1 1
501 ---
502 name: arith-limit64-1
503 description:
504         Check if arithmetics are 64 bit
505 category: int:64
506 stdin:
507         # signed vs unsigned
508         echo x1 $((-1)) $((#-1))
509         # calculating
510         typeset -i vs
511         typeset -Ui vu
512         vs=9223372036854775807; vu=9223372036854775807
513         echo x2 $vs $vu
514         let vs++ vu++
515         echo x3 $vs $vu
516         vs=18446744073709551615; vu=18446744073709551615
517         echo x4 $vs $vu
518         let vs++ vu++
519         echo x5 $vs $vu
520         let vs++ vu++
521         echo x6 $vs $vu
522 expected-stdout:
523         x1 -1 18446744073709551615
524         x2 9223372036854775807 9223372036854775807
525         x3 -9223372036854775808 9223372036854775808
526         x4 -1 18446744073709551615
527         x5 0 0
528         x6 1 1
529 ---
530 name: bksl-nl-ign-1
531 description:
532         Check that \newline is not collapsed after #
533 stdin:
534         echo hi #there \
535         echo folks
536 expected-stdout:
537         hi
538         folks
539 ---
540 name: bksl-nl-ign-2
541 description:
542         Check that \newline is not collapsed inside single quotes
543 stdin:
544         echo 'hi \
545         there'
546         echo folks
547 expected-stdout:
548         hi \
549         there
550         folks
551 ---
552 name: bksl-nl-ign-3
553 description:
554         Check that \newline is not collapsed inside single quotes
555 stdin:
556         cat << \EOF
557         hi \
558         there
559         EOF
560 expected-stdout:
561         hi \
562         there
563 ---
564 name: bksl-nl-ign-4
565 description:
566         Check interaction of aliases, single quotes and here-documents
567         with backslash-newline
568         (don't know what POSIX has to say about this)
569 stdin:
570         a=2
571         alias x='echo hi
572         cat << "EOF"
573         foo\
574         bar
575         some'
576         x
577         more\
578         stuff$a
579         EOF
580 expected-stdout:
581         hi
582         foo\
583         bar
584         some
585         more\
586         stuff$a
587 ---
588 name: bksl-nl-ign-5
589 description:
590         Check what happens with backslash at end of input
591         (the old Bourne shell trashes them; so do we)
592 stdin: !
593         echo `echo foo\\`bar
594         echo hi\
595 expected-stdout:
596         foobar
597         hi
598 ---
599 #
600 # Places \newline should be collapsed
601 #
602 name: bksl-nl-1
603 description:
604         Check that \newline is collapsed before, in the middle of, and
605         after words
606 stdin:
607                         \
608                          echo hi\
609         There, \
610         folks
611 expected-stdout:
612         hiThere, folks
613 ---
614 name: bksl-nl-2
615 description:
616         Check that \newline is collapsed in $ sequences
617         (ksh93 fails this)
618 stdin:
619         a=12
620         ab=19
621         echo $\
622         a
623         echo $a\
624         b
625         echo $\
626         {a}
627         echo ${a\
628         b}
629         echo ${ab\
630         }
631 expected-stdout:
632         12
633         19
634         12
635         19
636         19
637 ---
638 name: bksl-nl-3
639 description:
640         Check that \newline is collapsed in $(..) and `...` sequences
641         (ksh93 fails this)
642 stdin:
643         echo $\
644         (echo foobar1)
645         echo $(\
646         echo foobar2)
647         echo $(echo foo\
648         bar3)
649         echo $(echo foobar4\
650         )
651         echo `
652         echo stuff1`
653         echo `echo st\
654         uff2`
655 expected-stdout:
656         foobar1
657         foobar2
658         foobar3
659         foobar4
660         stuff1
661         stuff2
662 ---
663 name: bksl-nl-4
664 description:
665         Check that \newline is collapsed in $((..)) sequences
666         (ksh93 fails this)
667 stdin:
668         echo $\
669         ((1+2))
670         echo $(\
671         (1+2+3))
672         echo $((\
673         1+2+3+4))
674         echo $((1+\
675         2+3+4+5))
676         echo $((1+2+3+4+5+6)\
677         )
678 expected-stdout:
679         3
680         6
681         10
682         15
683         21
684 ---
685 name: bksl-nl-5
686 description:
687         Check that \newline is collapsed in double quoted strings
688 stdin:
689         echo "\
690         hi"
691         echo "foo\
692         bar"
693         echo "folks\
694         "
695 expected-stdout:
696         hi
697         foobar
698         folks
699 ---
700 name: bksl-nl-6
701 description:
702         Check that \newline is collapsed in here document delimiters
703         (ksh93 fails second part of this)
704 stdin:
705         a=12
706         cat << EO\
707         F
708         a=$a
709         foo\
710         bar
711         EOF
712         cat << E_O_F
713         foo
714         E_O_\
715         F
716         echo done
717 expected-stdout:
718         a=12
719         foobar
720         foo
721         done
722 ---
723 name: bksl-nl-7
724 description:
725         Check that \newline is collapsed in double-quoted here-document
726         delimiter.
727 stdin:
728         a=12
729         cat << "EO\
730         F"
731         a=$a
732         foo\
733         bar
734         EOF
735         echo done
736 expected-stdout:
737         a=$a
738         foo\
739         bar
740         done
741 ---
742 name: bksl-nl-8
743 description:
744         Check that \newline is collapsed in various 2+ character tokens
745         delimiter.
746         (ksh93 fails this)
747 stdin:
748         echo hi &\
749         & echo there
750         echo foo |\
751         | echo bar
752         cat <\
753         < EOF
754         stuff
755         EOF
756         cat <\
757         <\
758         - EOF
759                 more stuff
760         EOF
761         cat <<\
762         EOF
763         abcdef
764         EOF
765         echo hi >\
766         > /dev/null
767         echo $?
768         i=1
769         case $i in
770         (\
771         x|\
772         1\
773         ) echo hi;\
774         ;
775         (*) echo oops
776         esac
777 expected-stdout:
778         hi
779         there
780         foo
781         stuff
782         more stuff
783         abcdef
784         0
785         hi
786 ---
787 name: bksl-nl-9
788 description:
789         Check that \ at the end of an alias is collapsed when followed
790         by a newline
791         (don't know what POSIX has to say about this)
792 stdin:
793         alias x='echo hi\'
794         x
795         echo there
796 expected-stdout:
797         hiecho there
798 ---
799 name: bksl-nl-10
800 description:
801         Check that \newline in a keyword is collapsed
802 stdin:
803         i\
804         f true; then\
805          echo pass; el\
806         se echo fail; fi
807 expected-stdout:
808         pass
809 ---
810 #
811 # Places \newline should be collapsed (ksh extensions)
812 #
813 name: bksl-nl-ksh-1
814 description:
815         Check that \newline is collapsed in extended globbing
816         (ksh93 fails this)
817 stdin:
818         xxx=foo
819         case $xxx in
820         (f*\
821         (\
822         o\
823         )\
824         ) echo ok ;;
825         *) echo bad
826         esac
827 expected-stdout:
828         ok
829 ---
830 name: bksl-nl-ksh-2
831 description:
832         Check that \newline is collapsed in ((...)) expressions
833         (ksh93 fails this)
834 stdin:
835         i=1
836         (\
837         (\
838         i=i+2\
839         )\
840         )
841         echo $i
842 expected-stdout:
843         3
844 ---
845 name: break-1
846 description:
847         See if break breaks out of loops
848 stdin:
849         for i in a b c; do echo $i; break; echo bad-$i; done
850         echo end-1
851         for i in a b c; do echo $i; break 1; echo bad-$i; done
852         echo end-2
853         for i in a b c; do
854             for j in x y z; do
855                 echo $i:$j
856                 break
857                 echo bad-$i
858             done
859             echo end-$i
860         done
861         echo end-3
862 expected-stdout:
863         a
864         end-1
865         a
866         end-2
867         a:x
868         end-a
869         b:x
870         end-b
871         c:x
872         end-c
873         end-3
874 ---
875 name: break-2
876 description:
877         See if break breaks out of nested loops
878 stdin:
879         for i in a b c; do
880             for j in x y z; do
881                 echo $i:$j
882                 break 2
883                 echo bad-$i
884             done
885             echo end-$i
886         done
887         echo end
888 expected-stdout:
889         a:x
890         end
891 ---
892 name: break-3
893 description:
894         What if break used outside of any loops
895         (ksh88,ksh93 don't print error messages here)
896 stdin:
897         break
898 expected-stderr-pattern:
899         /.*break.*/
900 ---
901 name: break-4
902 description:
903         What if break N used when only N-1 loops
904         (ksh88,ksh93 don't print error messages here)
905 stdin:
906         for i in a b c; do echo $i; break 2; echo bad-$i; done
907         echo end
908 expected-stdout:
909         a
910         end
911 expected-stderr-pattern:
912         /.*break.*/
913 ---
914 name: break-5
915 description:
916         Error if break argument isn't a number
917 stdin:
918         for i in a b c; do echo $i; break abc; echo more-$i; done
919         echo end
920 expected-stdout:
921         a
922 expected-exit: e != 0
923 expected-stderr-pattern:
924         /.*break.*/
925 ---
926 name: continue-1
927 description:
928         See if continue continues loops
929 stdin:
930         for i in a b c; do echo $i; continue; echo bad-$i ; done
931         echo end-1
932         for i in a b c; do echo $i; continue 1; echo bad-$i; done
933         echo end-2
934         for i in a b c; do
935             for j in x y z; do
936                 echo $i:$j
937                 continue
938                 echo bad-$i-$j
939             done
940             echo end-$i
941         done
942         echo end-3
943 expected-stdout:
944         a
945         b
946         c
947         end-1
948         a
949         b
950         c
951         end-2
952         a:x
953         a:y
954         a:z
955         end-a
956         b:x
957         b:y
958         b:z
959         end-b
960         c:x
961         c:y
962         c:z
963         end-c
964         end-3
965 ---
966 name: continue-2
967 description:
968         See if continue breaks out of nested loops
969 stdin:
970         for i in a b c; do
971             for j in x y z; do
972                 echo $i:$j
973                 continue 2
974                 echo bad-$i-$j
975             done
976             echo end-$i
977         done
978         echo end
979 expected-stdout:
980         a:x
981         b:x
982         c:x
983         end
984 ---
985 name: continue-3
986 description:
987         What if continue used outside of any loops
988         (ksh88,ksh93 don't print error messages here)
989 stdin:
990         continue
991 expected-stderr-pattern:
992         /.*continue.*/
993 ---
994 name: continue-4
995 description:
996         What if continue N used when only N-1 loops
997         (ksh88,ksh93 don't print error messages here)
998 stdin:
999         for i in a b c; do echo $i; continue 2; echo bad-$i; done
1000         echo end
1001 expected-stdout:
1002         a
1003         b
1004         c
1005         end
1006 expected-stderr-pattern:
1007         /.*continue.*/
1008 ---
1009 name: continue-5
1010 description:
1011         Error if continue argument isn't a number
1012 stdin:
1013         for i in a b c; do echo $i; continue abc; echo more-$i; done
1014         echo end
1015 expected-stdout:
1016         a
1017 expected-exit: e != 0
1018 expected-stderr-pattern:
1019         /.*continue.*/
1020 ---
1021 name: cd-history
1022 description:
1023         Test someone's CD history package (uses arrays)
1024 stdin:
1025         # go to known place before doing anything
1026         cd /
1027         
1028         alias cd=_cd
1029         function _cd
1030         {
1031                 typeset -i cdlen i
1032                 typeset t
1033         
1034                 if [ $# -eq 0 ]
1035                 then
1036                         set -- $HOME
1037                 fi
1038         
1039                 if [ "$CDHISTFILE" -a -r "$CDHISTFILE" ] # if directory history exists
1040                 then
1041                         typeset CDHIST
1042                         i=-1
1043                         while read -r t                 # read directory history file
1044                         do
1045                                 CDHIST[i=i+1]=$t
1046                         done <$CDHISTFILE
1047                 fi
1048         
1049                 if [ "${CDHIST[0]}" != "$PWD" -a "$PWD" != "" ]
1050                 then
1051                         _cdins                          # insert $PWD into cd history
1052                 fi
1053         
1054                 cdlen=${#CDHIST[*]}                     # number of elements in history
1055         
1056                 case "$@" in
1057                 -)                                      # cd to new dir
1058                         if [ "$OLDPWD" = "" ] && ((cdlen>1))
1059                         then
1060                                 'print' ${CDHIST[1]}
1061                                 'cd' ${CDHIST[1]}
1062                                 _pwd
1063                         else
1064                                 'cd' $@
1065                                 _pwd
1066                         fi
1067                         ;;
1068                 -l)                                     # print directory list
1069                         typeset -R3 num
1070                         ((i=cdlen))
1071                         while (((i=i-1)>=0))
1072                         do
1073                                 num=$i
1074                                 'print' "$num ${CDHIST[i]}"
1075                         done
1076                         return
1077                         ;;
1078                 -[0-9]|-[0-9][0-9])                     # cd to dir in list
1079                         if (((i=${1#-})<cdlen))
1080                         then
1081                                 'print' ${CDHIST[i]}
1082                                 'cd' ${CDHIST[i]}
1083                                 _pwd
1084                         else
1085                                 'cd' $@
1086                                 _pwd
1087                         fi
1088                         ;;
1089                 -*)                                     # cd to matched dir in list
1090                         t=${1#-}
1091                         i=1
1092                         while ((i<cdlen))
1093                         do
1094                                 case ${CDHIST[i]} in
1095                                 *$t*)
1096                                         'print' ${CDHIST[i]}
1097                                         'cd' ${CDHIST[i]}
1098                                         _pwd
1099                                         break
1100                                         ;;
1101                                 esac
1102                                 ((i=i+1))
1103                         done
1104                         if ((i>=cdlen))
1105                         then
1106                                 'cd' $@
1107                                 _pwd
1108                         fi
1109                         ;;
1110                 *)                                      # cd to new dir
1111                         'cd' $@
1112                         _pwd
1113                         ;;
1114                 esac
1115         
1116                 _cdins                                  # insert $PWD into cd history
1117         
1118                 if [ "$CDHISTFILE" ]
1119                 then
1120                         cdlen=${#CDHIST[*]}             # number of elements in history
1121         
1122                         i=0
1123                         while ((i<cdlen))
1124                         do
1125                                 'print' -r ${CDHIST[i]} # update directory history
1126                                 ((i=i+1))
1127                         done >$CDHISTFILE
1128                 fi
1129         }
1130         
1131         function _cdins                                 # insert $PWD into cd history
1132         {                                               # meant to be called only by _cd
1133                 typeset -i i
1134         
1135                 ((i=0))
1136                 while ((i<${#CDHIST[*]}))               # see if dir is already in list
1137                 do
1138                         if [ "${CDHIST[$i]}" = "$PWD" ]
1139                         then
1140                                 break
1141                         fi
1142                         ((i=i+1))
1143                 done
1144         
1145                 if ((i>22))                             # limit max size of list
1146                 then
1147                         i=22
1148                 fi
1149         
1150                 while (((i=i-1)>=0))                    # bump old dirs in list
1151                 do
1152                         CDHIST[i+1]=${CDHIST[i]}
1153                 done
1154         
1155                 CDHIST[0]=$PWD                          # insert new directory in list
1156         }
1157         
1158         
1159         function _pwd
1160         {
1161                 if [ -n "$ECD" ]
1162                 then
1163                         pwd 1>&6
1164                 fi
1165         }
1166         # Start of test
1167         cd /tmp
1168         cd /bin
1169         cd /etc
1170         cd -
1171         cd -2
1172         cd -l
1173 expected-stdout:
1174         /bin
1175         /tmp
1176           3 /
1177           2 /etc
1178           1 /bin
1179           0 /tmp
1180 ---
1181 name: cd-pe
1182 description:
1183         Check package for cd -Pe
1184 need-pass: no
1185 # the mv command fails on Cygwin
1186 # Hurd aborts the testsuite (permission denied)
1187 # QNX does not find subdir to cd into
1188 category: !os:cygwin,!os:gnu,!os:msys,!os:nto,!nosymlink
1189 file-setup: file 644 "x"
1190         mkdir noread noread/target noread/target/subdir
1191         ln -s noread link
1192         chmod 311 noread
1193         cd -P$1 .
1194         echo 0=$?
1195         bwd=$PWD
1196         cd -P$1 link/target
1197         echo 1=$?,${PWD#$bwd/}
1198         epwd=$($TSHELL -c pwd 2>/dev/null)
1199         # This unexpectedly succeeds on GNU/Linux and MidnightBSD
1200         #echo pwd=$?,$epwd
1201         # expect:       pwd=1,
1202         mv ../../noread ../../renamed
1203         cd -P$1 subdir
1204         echo 2=$?,${PWD#$bwd/}
1205         cd $bwd
1206         chmod 755 renamed
1207         rm -rf noread link renamed
1208 stdin:
1209         export TSHELL="$__progname"
1210         "$__progname" x
1211         echo "now with -e:"
1212         "$__progname" x e
1213 expected-stdout:
1214         0=0
1215         1=0,noread/target
1216         2=0,noread/target/subdir
1217         now with -e:
1218         0=0
1219         1=0,noread/target
1220         2=1,noread/target/subdir
1221 ---
1222 name: env-prompt
1223 description:
1224         Check that prompt not printed when processing ENV
1225 env-setup: !ENV=./foo!
1226 file-setup: file 644 "foo"
1227         XXX=_
1228         PS1=X
1229         false && echo hmmm
1230 need-ctty: yes
1231 arguments: !-i!
1232 stdin:
1233         echo hi${XXX}there
1234 expected-stdout:
1235         hi_there
1236 expected-stderr: !
1237         XX
1238 ---
1239 name: expand-ugly
1240 description:
1241         Check that weird ${foo+bar} constructs are parsed correctly
1242 stdin:
1243         print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
1244         print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "<$x> "; done' >pfs
1245         chmod +x pfn pfs
1246         (echo 1 ${IFS+'}'z}) 2>/dev/null || echo failed in 1
1247         (echo 2 "${IFS+'}'z}") 2>/dev/null || echo failed in 2
1248         (echo 3 "foo ${IFS+'bar} baz") 2>/dev/null || echo failed in 3
1249         (echo -n '4 '; ./pfn "foo ${IFS+"b   c"} baz") 2>/dev/null || echo failed in 4
1250         (echo -n '5 '; ./pfn "foo ${IFS+b   c} baz") 2>/dev/null || echo failed in 5
1251         (echo 6 ${IFS+"}"z}) 2>/dev/null || echo failed in 6
1252         (echo 7 "${IFS+"}"z}") 2>/dev/null || echo failed in 7
1253         (echo 8 "${IFS+\"}\"z}") 2>/dev/null || echo failed in 8
1254         (echo 9 "${IFS+\"\}\"z}") 2>/dev/null || echo failed in 9
1255         (echo 10 foo ${IFS+'bar} baz'}) 2>/dev/null || echo failed in 10
1256         (echo 11 "$(echo "${IFS+'}'z}")") 2>/dev/null || echo failed in 11
1257         (echo 12 "$(echo ${IFS+'}'z})") 2>/dev/null || echo failed in 12
1258         (echo 13 ${IFS+\}z}) 2>/dev/null || echo failed in 13
1259         (echo 14 "${IFS+\}z}") 2>/dev/null || echo failed in 14
1260         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
1261         l=t; (echo 16 ${IFS+h`echo -n i ${IFS+$l}h`ere}) 2>/dev/null || echo failed in 16
1262         l=t; (echo 17 ${IFS+h$(echo -n i ${IFS+$l}h)ere}) 2>/dev/null || echo failed in 17
1263         l=t; (echo 18 "${IFS+h`echo -n i ${IFS+$l}h`ere}") 2>/dev/null || echo failed in 18
1264         l=t; (echo 19 "${IFS+h$(echo -n i ${IFS+$l}h)ere}") 2>/dev/null || echo failed in 19
1265         l=t; (echo 20 ${IFS+h`echo -n i "${IFS+$l}"h`ere}) 2>/dev/null || echo failed in 20
1266         l=t; (echo 21 ${IFS+h$(echo -n i "${IFS+$l}"h)ere}) 2>/dev/null || echo failed in 21
1267         l=t; (echo 22 "${IFS+h`echo -n i "${IFS+$l}"h`ere}") 2>/dev/null || echo failed in 22
1268         l=t; (echo 23 "${IFS+h$(echo -n i "${IFS+$l}"h)ere}") 2>/dev/null || echo failed in 23
1269         key=value; (echo -n '24 '; ./pfn "${IFS+'$key'}") 2>/dev/null || echo failed in 24
1270         key=value; (echo -n '25 '; ./pfn "${IFS+"'$key'"}") 2>/dev/null || echo failed in 25    # ksh93: “'$key'”
1271         key=value; (echo -n '26 '; ./pfn ${IFS+'$key'}) 2>/dev/null || echo failed in 26
1272         key=value; (echo -n '27 '; ./pfn ${IFS+"'$key'"}) 2>/dev/null || echo failed in 27
1273         (echo -n '28 '; ./pfn "${IFS+"'"x ~ x'}'x"'}"x}" #') 2>/dev/null || echo failed in 28
1274         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
1275         (echo -n '30 '; ./pfs ${IFS+foo 'b\
1276         ar' baz}; echo .) 2>/dev/null || (echo failed in 30; echo failed in 31)
1277         (echo -n '32 '; ./pfs ${IFS+foo "b\
1278         ar" baz}; echo .) 2>/dev/null || echo failed in 32
1279         (echo -n '33 '; ./pfs "${IFS+foo 'b\
1280         ar' baz}"; echo .) 2>/dev/null || echo failed in 33
1281         (echo -n '34 '; ./pfs "${IFS+foo "b\
1282         ar" baz}"; echo .) 2>/dev/null || echo failed in 34
1283         (echo -n '35 '; ./pfs ${v=a\ b} x ${v=c\ d}; echo .) 2>/dev/null || echo failed in 35
1284         (echo -n '36 '; ./pfs "${v=a\ b}" x "${v=c\ d}"; echo .) 2>/dev/null || echo failed in 36
1285         (echo -n '37 '; ./pfs ${v-a\ b} x ${v-c\ d}; echo .) 2>/dev/null || echo failed in 37
1286         (echo 38 ${IFS+x'a'y} / "${IFS+x'a'y}" .) 2>/dev/null || echo failed in 38
1287         foo="x'a'y"; (echo 39 ${foo%*'a'*} / "${foo%*'a'*}" .) 2>/dev/null || echo failed in 39
1288         foo="a b c"; (echo -n '40 '; ./pfs "${foo#a}"; echo .) 2>/dev/null || echo failed in 40
1289 expected-stdout:
1290         1 }z
1291         2 ''z}
1292         3 foo 'bar baz
1293         4 foo b   c baz
1294         5 foo b   c baz
1295         6 }z
1296         7 }z
1297         8 ""z}
1298         9 "}"z
1299         10 foo bar} baz
1300         11 ''z}
1301         12 }z
1302         13 }z
1303         14 }z
1304         15 <foo abx{ {{{}b c d{} bar> <}> <baz> .
1305         16 hi there
1306         17 hi there
1307         18 hi there
1308         19 hi there
1309         20 hi there
1310         21 hi there
1311         22 hi there
1312         23 hi there
1313         24 'value'
1314         25 'value'
1315         26 $key
1316         27 'value'
1317         28 'x ~ x''x}"x}" #
1318         29 <foo> <abx{ {{> <{}b> <c> <d{}> <bar> <}> <baz> .
1319         30 <foo> <b\
1320         ar> <baz> .
1321         32 <foo> <bar> <baz> .
1322         33 <foo 'bar' baz> .
1323         34 <foo bar baz> .
1324         35 <a> <b> <x> <a> <b> .
1325         36 <a\ b> <x> <a\ b> .
1326         37 <a b> <x> <c d> .
1327         38 xay / x'a'y .
1328         39 x' / x' .
1329         40 < b c> .
1330 ---
1331 name: expand-unglob-dblq
1332 description:
1333         Check that regular "${foo+bar}" constructs are parsed correctly
1334 stdin:
1335         u=x
1336         tl_norm() {
1337                 v=$2
1338                 test x"$v" = x"-" && unset v
1339                 (echo "$1 plus norm foo ${v+'bar'} baz")
1340                 (echo "$1 dash norm foo ${v-'bar'} baz")
1341                 (echo "$1 eqal norm foo ${v='bar'} baz")
1342                 (echo "$1 qstn norm foo ${v?'bar'} baz") 2>/dev/null || \
1343                     echo "$1 qstn norm -> error"
1344                 (echo "$1 PLUS norm foo ${v:+'bar'} baz")
1345                 (echo "$1 DASH norm foo ${v:-'bar'} baz")
1346                 (echo "$1 EQAL norm foo ${v:='bar'} baz")
1347                 (echo "$1 QSTN norm foo ${v:?'bar'} baz") 2>/dev/null || \
1348                     echo "$1 QSTN norm -> error"
1349         }
1350         tl_paren() {
1351                 v=$2
1352                 test x"$v" = x"-" && unset v
1353                 (echo "$1 plus parn foo ${v+(bar)} baz")
1354                 (echo "$1 dash parn foo ${v-(bar)} baz")
1355                 (echo "$1 eqal parn foo ${v=(bar)} baz")
1356                 (echo "$1 qstn parn foo ${v?(bar)} baz") 2>/dev/null || \
1357                     echo "$1 qstn parn -> error"
1358                 (echo "$1 PLUS parn foo ${v:+(bar)} baz")
1359                 (echo "$1 DASH parn foo ${v:-(bar)} baz")
1360                 (echo "$1 EQAL parn foo ${v:=(bar)} baz")
1361                 (echo "$1 QSTN parn foo ${v:?(bar)} baz") 2>/dev/null || \
1362                     echo "$1 QSTN parn -> error"
1363         }
1364         tl_brace() {
1365                 v=$2
1366                 test x"$v" = x"-" && unset v
1367                 (echo "$1 plus brac foo ${v+a$u{{{\}b} c ${v+d{}} baz")
1368                 (echo "$1 dash brac foo ${v-a$u{{{\}b} c ${v-d{}} baz")
1369                 (echo "$1 eqal brac foo ${v=a$u{{{\}b} c ${v=d{}} baz")
1370                 (echo "$1 qstn brac foo ${v?a$u{{{\}b} c ${v?d{}} baz") 2>/dev/null || \
1371                     echo "$1 qstn brac -> error"
1372                 (echo "$1 PLUS brac foo ${v:+a$u{{{\}b} c ${v:+d{}} baz")
1373                 (echo "$1 DASH brac foo ${v:-a$u{{{\}b} c ${v:-d{}} baz")
1374                 (echo "$1 EQAL brac foo ${v:=a$u{{{\}b} c ${v:=d{}} baz")
1375                 (echo "$1 QSTN brac foo ${v:?a$u{{{\}b} c ${v:?d{}} baz") 2>/dev/null || \
1376                     echo "$1 QSTN brac -> error"
1377         }
1378         tl_norm 1 -
1379         tl_norm 2 ''
1380         tl_norm 3 x
1381         tl_paren 4 -
1382         tl_paren 5 ''
1383         tl_paren 6 x
1384         tl_brace 7 -
1385         tl_brace 8 ''
1386         tl_brace 9 x
1387 expected-stdout:
1388         1 plus norm foo  baz
1389         1 dash norm foo 'bar' baz
1390         1 eqal norm foo 'bar' baz
1391         1 qstn norm -> error
1392         1 PLUS norm foo  baz
1393         1 DASH norm foo 'bar' baz
1394         1 EQAL norm foo 'bar' baz
1395         1 QSTN norm -> error
1396         2 plus norm foo 'bar' baz
1397         2 dash norm foo  baz
1398         2 eqal norm foo  baz
1399         2 qstn norm foo  baz
1400         2 PLUS norm foo  baz
1401         2 DASH norm foo 'bar' baz
1402         2 EQAL norm foo 'bar' baz
1403         2 QSTN norm -> error
1404         3 plus norm foo 'bar' baz
1405         3 dash norm foo x baz
1406         3 eqal norm foo x baz
1407         3 qstn norm foo x baz
1408         3 PLUS norm foo 'bar' baz
1409         3 DASH norm foo x baz
1410         3 EQAL norm foo x baz
1411         3 QSTN norm foo x baz
1412         4 plus parn foo  baz
1413         4 dash parn foo (bar) baz
1414         4 eqal parn foo (bar) baz
1415         4 qstn parn -> error
1416         4 PLUS parn foo  baz
1417         4 DASH parn foo (bar) baz
1418         4 EQAL parn foo (bar) baz
1419         4 QSTN parn -> error
1420         5 plus parn foo (bar) baz
1421         5 dash parn foo  baz
1422         5 eqal parn foo  baz
1423         5 qstn parn foo  baz
1424         5 PLUS parn foo  baz
1425         5 DASH parn foo (bar) baz
1426         5 EQAL parn foo (bar) baz
1427         5 QSTN parn -> error
1428         6 plus parn foo (bar) baz
1429         6 dash parn foo x baz
1430         6 eqal parn foo x baz
1431         6 qstn parn foo x baz
1432         6 PLUS parn foo (bar) baz
1433         6 DASH parn foo x baz
1434         6 EQAL parn foo x baz
1435         6 QSTN parn foo x baz
1436         7 plus brac foo  c } baz
1437         7 dash brac foo ax{{{}b c d{} baz
1438         7 eqal brac foo ax{{{}b c ax{{{}b} baz
1439         7 qstn brac -> error
1440         7 PLUS brac foo  c } baz
1441         7 DASH brac foo ax{{{}b c d{} baz
1442         7 EQAL brac foo ax{{{}b c ax{{{}b} baz
1443         7 QSTN brac -> error
1444         8 plus brac foo ax{{{}b c d{} baz
1445         8 dash brac foo  c } baz
1446         8 eqal brac foo  c } baz
1447         8 qstn brac foo  c } baz
1448         8 PLUS brac foo  c } baz
1449         8 DASH brac foo ax{{{}b c d{} baz
1450         8 EQAL brac foo ax{{{}b c ax{{{}b} baz
1451         8 QSTN brac -> error
1452         9 plus brac foo ax{{{}b c d{} baz
1453         9 dash brac foo x c x} baz
1454         9 eqal brac foo x c x} baz
1455         9 qstn brac foo x c x} baz
1456         9 PLUS brac foo ax{{{}b c d{} baz
1457         9 DASH brac foo x c x} baz
1458         9 EQAL brac foo x c x} baz
1459         9 QSTN brac foo x c x} baz
1460 ---
1461 name: expand-unglob-unq
1462 description:
1463         Check that regular ${foo+bar} constructs are parsed correctly
1464 stdin:
1465         u=x
1466         tl_norm() {
1467                 v=$2
1468                 test x"$v" = x"-" && unset v
1469                 (echo $1 plus norm foo ${v+'bar'} baz)
1470                 (echo $1 dash norm foo ${v-'bar'} baz)
1471                 (echo $1 eqal norm foo ${v='bar'} baz)
1472                 (echo $1 qstn norm foo ${v?'bar'} baz) 2>/dev/null || \
1473                     echo "$1 qstn norm -> error"
1474                 (echo $1 PLUS norm foo ${v:+'bar'} baz)
1475                 (echo $1 DASH norm foo ${v:-'bar'} baz)
1476                 (echo $1 EQAL norm foo ${v:='bar'} baz)
1477                 (echo $1 QSTN norm foo ${v:?'bar'} baz) 2>/dev/null || \
1478                     echo "$1 QSTN norm -> error"
1479         }
1480         tl_paren() {
1481                 v=$2
1482                 test x"$v" = x"-" && unset v
1483                 (echo $1 plus parn foo ${v+\(bar')'} baz)
1484                 (echo $1 dash parn foo ${v-\(bar')'} baz)
1485                 (echo $1 eqal parn foo ${v=\(bar')'} baz)
1486                 (echo $1 qstn parn foo ${v?\(bar')'} baz) 2>/dev/null || \
1487                     echo "$1 qstn parn -> error"
1488                 (echo $1 PLUS parn foo ${v:+\(bar')'} baz)
1489                 (echo $1 DASH parn foo ${v:-\(bar')'} baz)
1490                 (echo $1 EQAL parn foo ${v:=\(bar')'} baz)
1491                 (echo $1 QSTN parn foo ${v:?\(bar')'} baz) 2>/dev/null || \
1492                     echo "$1 QSTN parn -> error"
1493         }
1494         tl_brace() {
1495                 v=$2
1496                 test x"$v" = x"-" && unset v
1497                 (echo $1 plus brac foo ${v+a$u{{{\}b} c ${v+d{}} baz)
1498                 (echo $1 dash brac foo ${v-a$u{{{\}b} c ${v-d{}} baz)
1499                 (echo $1 eqal brac foo ${v=a$u{{{\}b} c ${v=d{}} baz)
1500                 (echo $1 qstn brac foo ${v?a$u{{{\}b} c ${v?d{}} baz) 2>/dev/null || \
1501                     echo "$1 qstn brac -> error"
1502                 (echo $1 PLUS brac foo ${v:+a$u{{{\}b} c ${v:+d{}} baz)
1503                 (echo $1 DASH brac foo ${v:-a$u{{{\}b} c ${v:-d{}} baz)
1504                 (echo $1 EQAL brac foo ${v:=a$u{{{\}b} c ${v:=d{}} baz)
1505                 (echo $1 QSTN brac foo ${v:?a$u{{{\}b} c ${v:?d{}} baz) 2>/dev/null || \
1506                     echo "$1 QSTN brac -> error"
1507         }
1508         tl_norm 1 -
1509         tl_norm 2 ''
1510         tl_norm 3 x
1511         tl_paren 4 -
1512         tl_paren 5 ''
1513         tl_paren 6 x
1514         tl_brace 7 -
1515         tl_brace 8 ''
1516         tl_brace 9 x
1517 expected-stdout:
1518         1 plus norm foo baz
1519         1 dash norm foo bar baz
1520         1 eqal norm foo bar baz
1521         1 qstn norm -> error
1522         1 PLUS norm foo baz
1523         1 DASH norm foo bar baz
1524         1 EQAL norm foo bar baz
1525         1 QSTN norm -> error
1526         2 plus norm foo bar baz
1527         2 dash norm foo baz
1528         2 eqal norm foo baz
1529         2 qstn norm foo baz
1530         2 PLUS norm foo baz
1531         2 DASH norm foo bar baz
1532         2 EQAL norm foo bar baz
1533         2 QSTN norm -> error
1534         3 plus norm foo bar baz
1535         3 dash norm foo x baz
1536         3 eqal norm foo x baz
1537         3 qstn norm foo x baz
1538         3 PLUS norm foo bar baz
1539         3 DASH norm foo x baz
1540         3 EQAL norm foo x baz
1541         3 QSTN norm foo x baz
1542         4 plus parn foo baz
1543         4 dash parn foo (bar) baz
1544         4 eqal parn foo (bar) baz
1545         4 qstn parn -> error
1546         4 PLUS parn foo baz
1547         4 DASH parn foo (bar) baz
1548         4 EQAL parn foo (bar) baz
1549         4 QSTN parn -> error
1550         5 plus parn foo (bar) baz
1551         5 dash parn foo baz
1552         5 eqal parn foo baz
1553         5 qstn parn foo baz
1554         5 PLUS parn foo baz
1555         5 DASH parn foo (bar) baz
1556         5 EQAL parn foo (bar) baz
1557         5 QSTN parn -> error
1558         6 plus parn foo (bar) baz
1559         6 dash parn foo x baz
1560         6 eqal parn foo x baz
1561         6 qstn parn foo x baz
1562         6 PLUS parn foo (bar) baz
1563         6 DASH parn foo x baz
1564         6 EQAL parn foo x baz
1565         6 QSTN parn foo x baz
1566         7 plus brac foo c } baz
1567         7 dash brac foo ax{{{}b c d{} baz
1568         7 eqal brac foo ax{{{}b c ax{{{}b} baz
1569         7 qstn brac -> error
1570         7 PLUS brac foo c } baz
1571         7 DASH brac foo ax{{{}b c d{} baz
1572         7 EQAL brac foo ax{{{}b c ax{{{}b} baz
1573         7 QSTN brac -> error
1574         8 plus brac foo ax{{{}b c d{} baz
1575         8 dash brac foo c } baz
1576         8 eqal brac foo c } baz
1577         8 qstn brac foo c } baz
1578         8 PLUS brac foo c } baz
1579         8 DASH brac foo ax{{{}b c d{} baz
1580         8 EQAL brac foo ax{{{}b c ax{{{}b} baz
1581         8 QSTN brac -> error
1582         9 plus brac foo ax{{{}b c d{} baz
1583         9 dash brac foo x c x} baz
1584         9 eqal brac foo x c x} baz
1585         9 qstn brac foo x c x} baz
1586         9 PLUS brac foo ax{{{}b c d{} baz
1587         9 DASH brac foo x c x} baz
1588         9 EQAL brac foo x c x} baz
1589         9 QSTN brac foo x c x} baz
1590 ---
1591 name: expand-threecolons-dblq
1592 description:
1593         Check for a particular thing that used to segfault
1594 stdin:
1595         TEST=1234
1596         echo "${TEST:1:2:3}"
1597         echo $? but still living
1598 expected-stderr-pattern:
1599         /bad substitution/
1600 expected-exit: 1
1601 ---
1602 name: expand-threecolons-unq
1603 description:
1604         Check for a particular thing that used to not error out
1605 stdin:
1606         TEST=1234
1607         echo ${TEST:1:2:3}
1608         echo $? but still living
1609 expected-stderr-pattern:
1610         /bad substitution/
1611 expected-exit: 1
1612 ---
1613 name: expand-weird-1
1614 description:
1615         Check corner case of trim expansion vs. $# vs. ${#var}
1616 stdin:
1617         set 1 2 3 4 5 6 7 8 9 10 11
1618         echo ${#}       # value of $#
1619         echo ${##}      # length of $#
1620         echo ${##1}     # $# trimmed 1
1621         set 1 2 3 4 5 6 7 8 9 10 11 12
1622         echo ${##1}
1623 expected-stdout:
1624         11
1625         2
1626         1
1627         2
1628 ---
1629 name: expand-weird-2
1630 description:
1631         Check corner case of ${var?} vs. ${#var}
1632 stdin:
1633         (exit 0)
1634         echo $? = ${#?} .
1635         (exit 111)
1636         echo $? = ${#?} .
1637 expected-stdout:
1638         0 = 1 .
1639         111 = 3 .
1640 ---
1641 name: expand-weird-3
1642 description:
1643         Check that trimming works with positional parameters (Debian #48453)
1644 stdin:
1645         A=9999-02
1646         B=9999
1647         echo 1=${A#$B?}.
1648         set -- $A $B
1649         echo 2=${1#$2?}.
1650 expected-stdout:
1651         1=02.
1652         2=02.
1653 ---
1654 name: expand-number-1
1655 description:
1656         Check that positional arguments do not overflow
1657 stdin:
1658         echo "1 ${12345678901234567890} ."
1659 expected-stdout:
1660         1  .
1661 ---
1662 name: eglob-bad-1
1663 description:
1664         Check that globbing isn't done when glob has syntax error
1665 file-setup: file 644 "abcx"
1666 file-setup: file 644 "abcz"
1667 file-setup: file 644 "bbc"
1668 stdin:
1669         echo !([*)*
1670         echo +(a|b[)*
1671 expected-stdout:
1672         !([*)*
1673         +(a|b[)*
1674 ---
1675 name: eglob-bad-2
1676 description:
1677         Check that globbing isn't done when glob has syntax error
1678         (AT&T ksh fails this test)
1679 file-setup: file 644 "abcx"
1680 file-setup: file 644 "abcz"
1681 file-setup: file 644 "bbc"
1682 stdin:
1683         echo [a*(]*)z
1684 expected-stdout:
1685         [a*(]*)z
1686 ---
1687 name: eglob-infinite-plus
1688 description:
1689         Check that shell doesn't go into infinite loop expanding +(...)
1690         expressions.
1691 file-setup: file 644 "abc"
1692 time-limit: 3
1693 stdin:
1694         echo +()c
1695         echo +()x
1696         echo +(*)c
1697         echo +(*)x
1698 expected-stdout:
1699         +()c
1700         +()x
1701         abc
1702         +(*)x
1703 ---
1704 name: eglob-subst-1
1705 description:
1706         Check that eglobbing isn't done on substitution results
1707 file-setup: file 644 "abc"
1708 stdin:
1709         x='@(*)'
1710         echo $x
1711 expected-stdout:
1712         @(*)
1713 ---
1714 name: eglob-nomatch-1
1715 description:
1716         Check that the pattern doesn't match
1717 stdin:
1718         echo 1: no-file+(a|b)stuff
1719         echo 2: no-file+(a*(c)|b)stuff
1720         echo 3: no-file+((((c)))|b)stuff
1721 expected-stdout:
1722         1: no-file+(a|b)stuff
1723         2: no-file+(a*(c)|b)stuff
1724         3: no-file+((((c)))|b)stuff
1725 ---
1726 name: eglob-match-1
1727 description:
1728         Check that the pattern matches correctly
1729 file-setup: file 644 "abd"
1730 file-setup: file 644 "acd"
1731 file-setup: file 644 "abac"
1732 stdin:
1733         echo 1: a+(b|c)d
1734         echo 2: a!(@(b|B))d
1735         echo 3: *(a(b|c))               # (...|...) can be used within X(..)
1736         echo 4: a[b*(foo|bar)]d         # patterns not special inside [...]
1737 expected-stdout:
1738         1: abd acd
1739         2: acd
1740         3: abac
1741         4: abd
1742 ---
1743 name: eglob-case-1
1744 description:
1745         Simple negation tests
1746 stdin:
1747         case foo in !(foo|bar)) echo yes;; *) echo no;; esac
1748         case bar in !(foo|bar)) echo yes;; *) echo no;; esac
1749 expected-stdout:
1750         no
1751         no
1752 ---
1753 name: eglob-case-2
1754 description:
1755         Simple kleene tests
1756 stdin:
1757         case foo in *(a|b[)) echo yes;; *) echo no;; esac
1758         case foo in *(a|b[)|f*) echo yes;; *) echo no;; esac
1759         case '*(a|b[)' in *(a|b[)) echo yes;; *) echo no;; esac
1760 expected-stdout:
1761         no
1762         yes
1763         yes
1764 ---
1765 name: eglob-trim-1
1766 description:
1767         Eglobbing in trim expressions...
1768         (AT&T ksh fails this - docs say # matches shortest string, ## matches
1769         longest...)
1770 stdin:
1771         x=abcdef
1772         echo 1: ${x#a|abc}
1773         echo 2: ${x##a|abc}
1774         echo 3: ${x%def|f}
1775         echo 4: ${x%%f|def}
1776 expected-stdout:
1777         1: bcdef
1778         2: def
1779         3: abcde
1780         4: abc
1781 ---
1782 name: eglob-trim-2
1783 description:
1784         Check eglobbing works in trims...
1785 stdin:
1786         x=abcdef
1787         echo 1: ${x#*(a|b)cd}
1788         echo 2: "${x#*(a|b)cd}"
1789         echo 3: ${x#"*(a|b)cd"}
1790         echo 4: ${x#a(b|c)}
1791 expected-stdout:
1792         1: ef
1793         2: ef
1794         3: abcdef
1795         4: cdef
1796 ---
1797 name: eglob-trim-3
1798 description:
1799         Check eglobbing works in trims, for Korn Shell
1800         Ensure eglobbing does not work for reduced-feature /bin/sh
1801 stdin:
1802         set +o sh
1803         x=foobar
1804         y=foobaz
1805         z=fooba\?
1806         echo "<${x%bar|baz},${y%bar|baz},${z%\?}>"
1807         echo "<${x%ba(r|z)},${y%ba(r|z)}>"
1808         set -o sh
1809         echo "<${x%bar|baz},${y%bar|baz},${z%\?}>"
1810         z='foo(bar'
1811         echo "<${z%(*}>"
1812 expected-stdout:
1813         <foo,foo,fooba>
1814         <foo,foo>
1815         <foobar,foobaz,fooba>
1816         <foo>
1817 ---
1818 name: eglob-substrpl-1
1819 description:
1820         Check eglobbing works in substs... and they work at all
1821 stdin:
1822         [[ -n $BASH_VERSION ]] && shopt -s extglob
1823         x=1222321_ab/cde_b/c_1221
1824         y=xyz
1825         echo 1: ${x/2}
1826         echo 2: ${x//2}
1827         echo 3: ${x/+(2)}
1828         echo 4: ${x//+(2)}
1829         echo 5: ${x/2/4}
1830         echo 6: ${x//2/4}
1831         echo 7: ${x/+(2)/4}
1832         echo 8: ${x//+(2)/4}
1833         echo 9: ${x/b/c/e/f}
1834         echo 10: ${x/b\/c/e/f}
1835         echo 11: ${x/b\/c/e\/f}
1836         echo 12: ${x/b\/c/e\\/f}
1837         echo 13: ${x/b\\/c/e\\/f}
1838         echo 14: ${x//b/c/e/f}
1839         echo 15: ${x//b\/c/e/f}
1840         echo 16: ${x//b\/c/e\/f}
1841         echo 17: ${x//b\/c/e\\/f}
1842         echo 18: ${x//b\\/c/e\\/f}
1843         echo 19: ${x/b\/*\/c/x}
1844         echo 20: ${x/\//.}
1845         echo 21: ${x//\//.}
1846         echo 22: ${x///.}
1847         echo 23: ${x//#1/9}
1848         echo 24: ${x//%1/9}
1849         echo 25: ${x//\%1/9}
1850         echo 26: ${x//\\%1/9}
1851         echo 27: ${x//\a/9}
1852         echo 28: ${x//\\a/9}
1853         echo 29: ${x/2/$y}
1854 expected-stdout:
1855         1: 122321_ab/cde_b/c_1221
1856         2: 131_ab/cde_b/c_11
1857         3: 1321_ab/cde_b/c_1221
1858         4: 131_ab/cde_b/c_11
1859         5: 1422321_ab/cde_b/c_1221
1860         6: 1444341_ab/cde_b/c_1441
1861         7: 14321_ab/cde_b/c_1221
1862         8: 14341_ab/cde_b/c_141
1863         9: 1222321_ac/e/f/cde_b/c_1221
1864         10: 1222321_ae/fde_b/c_1221
1865         11: 1222321_ae/fde_b/c_1221
1866         12: 1222321_ae\/fde_b/c_1221
1867         13: 1222321_ab/cde_b/c_1221
1868         14: 1222321_ac/e/f/cde_c/e/f/c_1221
1869         15: 1222321_ae/fde_e/f_1221
1870         16: 1222321_ae/fde_e/f_1221
1871         17: 1222321_ae\/fde_e\/f_1221
1872         18: 1222321_ab/cde_b/c_1221
1873         19: 1222321_ax_1221
1874         20: 1222321_ab.cde_b/c_1221
1875         21: 1222321_ab.cde_b.c_1221
1876         22: 1222321_ab/cde_b/c_1221
1877         23: 9222321_ab/cde_b/c_1221
1878         24: 1222321_ab/cde_b/c_1229
1879         25: 1222321_ab/cde_b/c_1229
1880         26: 1222321_ab/cde_b/c_1221
1881         27: 1222321_9b/cde_b/c_1221
1882         28: 1222321_9b/cde_b/c_1221
1883         29: 1xyz22321_ab/cde_b/c_1221
1884 ---
1885 name: eglob-substrpl-2
1886 description:
1887         Check anchored substring replacement works, corner cases
1888 stdin:
1889         foo=123
1890         echo 1: ${foo/#/x}
1891         echo 2: ${foo/%/x}
1892         echo 3: ${foo/#/}
1893         echo 4: ${foo/#}
1894         echo 5: ${foo/%/}
1895         echo 6: ${foo/%}
1896 expected-stdout:
1897         1: x123
1898         2: 123x
1899         3: 123
1900         4: 123
1901         5: 123
1902         6: 123
1903 ---
1904 name: eglob-substrpl-3a
1905 description:
1906         Check substring replacement works with variables and slashes, too
1907 stdin:
1908         pfx=/home/user
1909         wd=/home/user/tmp
1910         echo "${wd/#$pfx/~}"
1911         echo "${wd/#\$pfx/~}"
1912         echo "${wd/#"$pfx"/~}"
1913         echo "${wd/#'$pfx'/~}"
1914         echo "${wd/#"\$pfx"/~}"
1915         echo "${wd/#'\$pfx'/~}"
1916 expected-stdout:
1917         ~/tmp
1918         /home/user/tmp
1919         ~/tmp
1920         /home/user/tmp
1921         /home/user/tmp
1922         /home/user/tmp
1923 ---
1924 name: eglob-substrpl-3b
1925 description:
1926         More of this, bash fails it (bash4 passes)
1927 stdin:
1928         pfx=/home/user
1929         wd=/home/user/tmp
1930         echo "${wd/#$(echo /home/user)/~}"
1931         echo "${wd/#"$(echo /home/user)"/~}"
1932         echo "${wd/#'$(echo /home/user)'/~}"
1933 expected-stdout:
1934         ~/tmp
1935         ~/tmp
1936         /home/user/tmp
1937 ---
1938 name: eglob-substrpl-3c
1939 description:
1940         Even more weird cases
1941 stdin:
1942         pfx=/home/user
1943         wd='$pfx/tmp'
1944         echo 1: ${wd/#$pfx/~}
1945         echo 2: ${wd/#\$pfx/~}
1946         echo 3: ${wd/#"$pfx"/~}
1947         echo 4: ${wd/#'$pfx'/~}
1948         echo 5: ${wd/#"\$pfx"/~}
1949         echo 6: ${wd/#'\$pfx'/~}
1950         ts='a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)'
1951         tp=a/b
1952         tr=c/d
1953         [[ -n $BASH_VERSION ]] && shopt -s extglob
1954         echo 7: ${ts/a\/b/$tr}
1955         echo 8: ${ts/a\/b/\$tr}
1956         echo 9: ${ts/$tp/$tr}
1957         echo 10: ${ts/\$tp/$tr}
1958         echo 11: ${ts/\\$tp/$tr}
1959         echo 12: ${ts/$tp/c/d}
1960         echo 13: ${ts/$tp/c\/d}
1961         echo 14: ${ts/$tp/c\\/d}
1962         echo 15: ${ts/+(a\/b)/$tr}
1963         echo 16: ${ts/+(a\/b)/\$tr}
1964         echo 17: ${ts/+($tp)/$tr}
1965         echo 18: ${ts/+($tp)/c/d}
1966         echo 19: ${ts/+($tp)/c\/d}
1967         echo 25: ${ts//a\/b/$tr}
1968         echo 26: ${ts//a\/b/\$tr}
1969         echo 27: ${ts//$tp/$tr}
1970         echo 28: ${ts//$tp/c/d}
1971         echo 29: ${ts//$tp/c\/d}
1972         echo 30: ${ts//+(a\/b)/$tr}
1973         echo 31: ${ts//+(a\/b)/\$tr}
1974         echo 32: ${ts//+($tp)/$tr}
1975         echo 33: ${ts//+($tp)/c/d}
1976         echo 34: ${ts//+($tp)/c\/d}
1977         tp="+($tp)"
1978         echo 40: ${ts/$tp/$tr}
1979         echo 41: ${ts//$tp/$tr}
1980 expected-stdout:
1981         1: $pfx/tmp
1982         2: ~/tmp
1983         3: $pfx/tmp
1984         4: ~/tmp
1985         5: ~/tmp
1986         6: ~/tmp
1987         7: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
1988         8: $tra/b$tp$tp_a/b$tp_*(a/b)_*($tp)
1989         9: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
1990         10: a/ba/bc/d$tp_a/b$tp_*(a/b)_*($tp)
1991         11: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
1992         12: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
1993         13: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
1994         14: c\/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
1995         15: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
1996         16: $tr$tp$tp_a/b$tp_*(a/b)_*($tp)
1997         17: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
1998         18: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
1999         19: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2000         25: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2001         26: $tr$tr$tp$tp_$tr$tp_*($tr)_*($tp)
2002         27: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2003         28: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2004         29: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2005         30: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2006         31: $tr$tp$tp_$tr$tp_*($tr)_*($tp)
2007         32: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2008         33: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2009         34: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2010         40: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2011         41: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2012 #       This is what GNU bash does:
2013 #       40: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2014 #       41: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2015 ---
2016 name: eglob-utf8-1
2017 description:
2018         UTF-8 mode differences for eglobbing
2019 stdin:
2020         s=blöd
2021         set +U
2022         print 1: ${s%???} .
2023         print 2: ${s/b???d/x} .
2024         set -U
2025         print 3: ${s%???} .
2026         print 4: ${s/b??d/x} .
2027         x=nö
2028         print 5: ${x%?} ${x%%?} .
2029         x=äh
2030         print 6: ${x#?} ${x##?} .
2031         x=\81\82
2032         print 7: ${x%?} ${x%%?} .
2033         x=mä\80
2034         print 8: ${x%?} ${x%%?} .
2035         x=何
2036         print 9: ${x%?} ${x%%?} .
2037 expected-stdout:
2038         1: bl .
2039         2: x .
2040         3: b .
2041         4: x .
2042         5: n n .
2043         6: h h .
2044         7: \81 \81 .
2045         8: mä mä .
2046         9: .
2047 ---
2048 name: glob-bad-1
2049 description:
2050         Check that globbing isn't done when glob has syntax error
2051 file-setup: dir 755 "[x"
2052 file-setup: file 644 "[x/foo"
2053 stdin:
2054         echo [*
2055         echo *[x
2056         echo [x/*
2057 expected-stdout:
2058         [*
2059         *[x
2060         [x/foo
2061 ---
2062 name: glob-bad-2
2063 description:
2064         Check that symbolic links aren't stat()'d
2065 # breaks on FreeMiNT (cannot unlink dangling symlinks)
2066 # breaks on MSYS (does not support symlinks)
2067 # breaks on Dell UNIX 4.0 R2.2 (SVR4) where unlink also fails
2068 category: !os:mint,!os:msys,!os:svr4.0,!nosymlink
2069 file-setup: dir 755 "dir"
2070 file-setup: symlink 644 "dir/abc"
2071         non-existent-file
2072 stdin:
2073         echo d*/*
2074         echo d*/abc
2075 expected-stdout:
2076         dir/abc
2077         dir/abc
2078 ---
2079 name: glob-range-1
2080 description:
2081         Test range matching
2082 file-setup: file 644 ".bc"
2083 file-setup: file 644 "abc"
2084 file-setup: file 644 "bbc"
2085 file-setup: file 644 "cbc"
2086 file-setup: file 644 "-bc"
2087 stdin:
2088         echo [ab-]*
2089         echo [-ab]*
2090         echo [!-ab]*
2091         echo [!ab]*
2092         echo []ab]*
2093         :>'./!bc'
2094         :>'./^bc'
2095         echo [^ab]*
2096         echo [!ab]*
2097 expected-stdout:
2098         -bc abc bbc
2099         -bc abc bbc
2100         cbc
2101         -bc cbc
2102         abc bbc
2103         ^bc abc bbc
2104         !bc -bc ^bc cbc
2105 ---
2106 name: glob-range-2
2107 description:
2108         Test range matching
2109         (AT&T ksh fails this; POSIX says invalid)
2110 file-setup: file 644 "abc"
2111 stdin:
2112         echo [a--]*
2113 expected-stdout:
2114         [a--]*
2115 ---
2116 name: glob-range-3
2117 description:
2118         Check that globbing matches the right things...
2119 # breaks on Mac OSX (HFS+ non-standard Unicode canonical decomposition)
2120 # breaks on Cygwin 1.7 (files are now UTF-16 or something)
2121 # breaks on QNX 6.4.1 (says RT)
2122 category: !os:cygwin,!os:darwin,!os:msys,!os:nto
2123 need-pass: no
2124 file-setup: file 644 "aÂc"
2125 stdin:
2126         echo a[Á-Ú]*
2127 expected-stdout:
2128         aÂc
2129 ---
2130 name: glob-range-4
2131 description:
2132         Results unspecified according to POSIX
2133 file-setup: file 644 ".bc"
2134 stdin:
2135         echo [a.]*
2136 expected-stdout:
2137         [a.]*
2138 ---
2139 name: glob-range-5
2140 description:
2141         Results unspecified according to POSIX
2142         (AT&T ksh treats this like [a-cc-e]*)
2143 file-setup: file 644 "abc"
2144 file-setup: file 644 "bbc"
2145 file-setup: file 644 "cbc"
2146 file-setup: file 644 "dbc"
2147 file-setup: file 644 "ebc"
2148 file-setup: file 644 "-bc"
2149 stdin:
2150         echo [a-c-e]*
2151 expected-stdout:
2152         -bc abc bbc cbc ebc
2153 ---
2154 name: glob-trim-1
2155 description:
2156         Check against a regression from fixing IFS-subst-2
2157 stdin:
2158         x='#foo'
2159         print -r "before='$x'"
2160         x=${x%%#*}
2161         print -r "after ='$x'"
2162 expected-stdout:
2163         before='#foo'
2164         after =''
2165 ---
2166 name: heredoc-1
2167 description:
2168         Check ordering/content of redundent here documents.
2169 stdin:
2170         cat << EOF1 << EOF2
2171         hi
2172         EOF1
2173         there
2174         EOF2
2175 expected-stdout:
2176         there
2177 ---
2178 name: heredoc-2
2179 description:
2180         Check quoted here-doc is protected.
2181 stdin:
2182         a=foo
2183         cat << 'EOF'
2184         hi\
2185         there$a
2186         stuff
2187         EO\
2188         F
2189         EOF
2190 expected-stdout:
2191         hi\
2192         there$a
2193         stuff
2194         EO\
2195         F
2196 ---
2197 name: heredoc-3
2198 description:
2199         Check that newline isn't needed after heredoc-delimiter marker.
2200 stdin: !
2201         cat << EOF
2202         hi
2203         there
2204         EOF
2205 expected-stdout:
2206         hi
2207         there
2208 ---
2209 name: heredoc-4
2210 description:
2211         Check that an error occurs if the heredoc-delimiter is missing.
2212 stdin: !
2213         cat << EOF
2214         hi
2215         there
2216 expected-exit: e > 0
2217 expected-stderr-pattern: /.*/
2218 ---
2219 name: heredoc-5
2220 description:
2221         Check that backslash quotes a $, ` and \ and kills a \newline
2222 stdin:
2223         a=BAD
2224         b=ok
2225         cat << EOF
2226         h\${a}i
2227         h\\${b}i
2228         th\`echo not-run\`ere
2229         th\\`echo is-run`ere
2230         fol\\ks
2231         more\\
2232         last \
2233         line
2234         EOF
2235 expected-stdout:
2236         h${a}i
2237         h\oki
2238         th`echo not-run`ere
2239         th\is-runere
2240         fol\ks
2241         more\
2242         last line
2243 ---
2244 name: heredoc-6
2245 description:
2246         Check that \newline in initial here-delim word doesn't imply
2247         a quoted here-doc.
2248 stdin:
2249         a=i
2250         cat << EO\
2251         F
2252         h$a
2253         there
2254         EOF
2255 expected-stdout:
2256         hi
2257         there
2258 ---
2259 name: heredoc-7
2260 description:
2261         Check that double quoted $ expressions in here delimiters are
2262         not expanded and match the delimiter.
2263         POSIX says only quote removal is applied to the delimiter.
2264 stdin:
2265         a=b
2266         cat << "E$a"
2267         hi
2268         h$a
2269         hb
2270         E$a
2271         echo done
2272 expected-stdout:
2273         hi
2274         h$a
2275         hb
2276         done
2277 ---
2278 name: heredoc-8
2279 description:
2280         Check that double quoted escaped $ expressions in here
2281         delimiters are not expanded and match the delimiter.
2282         POSIX says only quote removal is applied to the delimiter
2283         (\ counts as a quote).
2284 stdin:
2285         a=b
2286         cat << "E\$a"
2287         hi
2288         h$a
2289         h\$a
2290         hb
2291         h\b
2292         E$a
2293         echo done
2294 expected-stdout:
2295         hi
2296         h$a
2297         h\$a
2298         hb
2299         h\b
2300         done
2301 ---
2302 name: heredoc-9a
2303 description:
2304         Check that here strings work.
2305 stdin:
2306         bar="bar
2307                 baz"
2308         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<foo
2309         "$__progname" -c "tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<foo"
2310         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"$bar"
2311         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<'$bar'
2312         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<\$bar
2313         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<-foo
2314         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"$(echo "foo bar")"
2315 expected-stdout:
2316         sbb
2317         sbb
2318         one
2319                 onm
2320         $one
2321         $one
2322         -sbb
2323         sbb one
2324 ---
2325 name: heredoc-9b
2326 description:
2327         Check that a corner case of here strings works like bash
2328 stdin:
2329         fnord=42
2330         bar="bar
2331                  \$fnord baz"
2332         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<$bar
2333 expected-stdout:
2334         one $sabeq onm
2335 category: bash
2336 ---
2337 name: heredoc-9c
2338 description:
2339         Check that a corner case of here strings works like ksh93, zsh
2340 stdin:
2341         fnord=42
2342         bar="bar
2343                  \$fnord baz"
2344         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<$bar
2345 expected-stdout:
2346         one
2347                  $sabeq onm
2348 ---
2349 name: heredoc-9d
2350 description:
2351         Check another corner case of here strings
2352 stdin:
2353         tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<< bar
2354 expected-stdout:
2355         one
2356 ---
2357 name: heredoc-9e
2358 description:
2359         Check here string related regression with multiple iops
2360 stdin:
2361         echo $(tr r z <<<'bar' 2>/dev/null)
2362 expected-stdout:
2363         baz
2364 ---
2365 name: heredoc-9f
2366 description:
2367         Check long here strings
2368 stdin:
2369         cat <<< "$(  :                                                             )aa"
2370 expected-stdout:
2371         aa
2372 ---
2373 name: heredoc-10
2374 description:
2375         Check direct here document assignment
2376 stdin:
2377         x=u
2378         va=<<EOF
2379         =a $x \x40=
2380         EOF
2381         vb=<<'EOF'
2382         =b $x \x40=
2383         EOF
2384         function foo {
2385                 vc=<<-EOF
2386                         =c $x \x40=
2387                 EOF
2388         }
2389         fnd=$(typeset -f foo)
2390         print -r -- "$fnd"
2391         function foo {
2392                 echo blub
2393         }
2394         foo
2395         eval "$fnd"
2396         foo
2397         # rather nonsensical, but…
2398         vd=<<<"=d $x \x40="
2399         ve=<<<'=e $x \x40='
2400         vf=<<<$'=f $x \x40='
2401         # now check
2402         print -r -- "| va={$va} vb={$vb} vc={$vc} vd={$vd} ve={$ve} vf={$vf} |"
2403         # check append
2404         v=<<-EOF
2405                 vapp1
2406         EOF
2407         v+=<<-EOF
2408                 vapp2
2409         EOF
2410         print -r -- "| ${v//$'\n'/^} |"
2411 expected-stdout:
2412         function foo {
2413                 vc=<<-EOF
2414         =c $x \x40=
2415         EOF
2416         
2417         } 
2418         blub
2419         | va={=a u \x40=
2420         } vb={=b $x \x40=
2421         } vc={=c u \x40=
2422         } vd={=d u \x40=
2423         } ve={=e $x \x40=
2424         } vf={=f $x @=
2425         } |
2426         | vapp1^vapp2^ |
2427 ---
2428 name: heredoc-11
2429 description:
2430         Check here documents with no or empty delimiter
2431 stdin:
2432         x=u
2433         va=<<
2434         =a $x \x40=
2435         <<
2436         vb=<<''
2437         =b $x \x40=
2438         
2439         function foo {
2440                 vc=<<-
2441                         =c $x \x40=
2442                 <<
2443                 vd=<<-''
2444                         =d $x \x40=
2445         
2446         }
2447         fnd=$(typeset -f foo)
2448         print -r -- "$fnd"
2449         function foo {
2450                 echo blub
2451         }
2452         foo
2453         eval "$fnd"
2454         foo
2455         print -r -- "| va={$va} vb={$vb} vc={$vc} vd={$vd} |"
2456         # check append
2457         v=<<-
2458                 vapp1
2459         <<
2460         v+=<<-''
2461                 vapp2
2462         
2463         print -r -- "| ${v//$'\n'/^} |"
2464 expected-stdout:
2465         function foo {
2466                 vc=<<-
2467         =c $x \x40=
2468         <<
2469         
2470                 vd=<<-""
2471         =d $x \x40=
2472         
2473         
2474         } 
2475         blub
2476         | va={=a u \x40=
2477         } vb={=b $x \x40=
2478         } vc={=c u \x40=
2479         } vd={=d $x \x40=
2480         } |
2481         | vapp1^vapp2^ |
2482 ---
2483 name: heredoc-12
2484 description:
2485         Check here documents can use $* and $@; note shells vary:
2486         • pdksh 5.2.14 acts the same
2487         • dash has 1 and 2 the same but 3 lacks the space
2488         • ksh93, bash4 differ in 2 by using space ipv colon
2489 stdin:
2490         set -- a b
2491         nl='
2492         '
2493         IFS="   $nl"; n=1
2494         cat <<EOF
2495         $n foo $* foo
2496         $n bar "$*" bar
2497         $n baz $@ baz
2498         $n bla "$@" bla
2499         EOF
2500         IFS=":"; n=2
2501         cat <<EOF
2502         $n foo $* foo
2503         $n bar "$*" bar
2504         $n baz $@ baz
2505         $n bla "$@" bla
2506         EOF
2507         IFS=; n=3
2508         cat <<EOF
2509         $n foo $* foo
2510         $n bar "$*" bar
2511         $n baz $@ baz
2512         $n bla "$@" bla
2513         EOF
2514 expected-stdout:
2515         1 foo a b foo
2516         1 bar "a b" bar
2517         1 baz a b baz
2518         1 bla "a b" bla
2519         2 foo a:b foo
2520         2 bar "a:b" bar
2521         2 baz a:b baz
2522         2 bla "a:b" bla
2523         3 foo a b foo
2524         3 bar "a b" bar
2525         3 baz a b baz
2526         3 bla "a b" bla
2527 ---
2528 name: heredoc-comsub-1
2529 description:
2530         Tests for here documents in COMSUB, taken from Austin ML
2531 stdin:
2532         text=$(cat <<EOF
2533         here is the text
2534         EOF)
2535         echo = $text =
2536 expected-stdout:
2537         = here is the text =
2538 ---
2539 name: heredoc-comsub-2
2540 description:
2541         Tests for here documents in COMSUB, taken from Austin ML
2542 stdin:
2543         unbalanced=$(cat <<EOF
2544         this paren ) is a problem
2545         EOF)
2546         echo = $unbalanced =
2547 expected-stdout:
2548         = this paren ) is a problem =
2549 ---
2550 name: heredoc-comsub-3
2551 description:
2552         Tests for here documents in COMSUB, taken from Austin ML
2553 stdin:
2554         balanced=$(cat <<EOF
2555         these parens ( ) are not a problem
2556         EOF)
2557         echo = $balanced =
2558 expected-stdout:
2559         = these parens ( ) are not a problem =
2560 ---
2561 name: heredoc-comsub-4
2562 description:
2563         Tests for here documents in COMSUB, taken from Austin ML
2564 stdin:
2565         balanced=$(cat <<EOF
2566         these parens \( ) are a problem
2567         EOF)
2568         echo = $balanced =
2569 expected-stdout:
2570         = these parens \( ) are a problem =
2571 ---
2572 name: heredoc-subshell-1
2573 description:
2574         Tests for here documents in subshells, taken from Austin ML
2575 stdin:
2576         (cat <<EOF
2577         some text
2578         EOF)
2579         echo end
2580 expected-stdout:
2581         some text
2582         end
2583 ---
2584 name: heredoc-subshell-2
2585 description:
2586         Tests for here documents in subshells, taken from Austin ML
2587 stdin:
2588         (cat <<EOF
2589         some text
2590         EOF
2591         )
2592         echo end
2593 expected-stdout:
2594         some text
2595         end
2596 ---
2597 name: heredoc-subshell-3
2598 description:
2599         Tests for here documents in subshells, taken from Austin ML
2600 stdin:
2601         (cat <<EOF; )
2602         some text
2603         EOF
2604         echo end
2605 expected-stdout:
2606         some text
2607         end
2608 ---
2609 name: heredoc-weird-1
2610 description:
2611         Tests for here documents, taken from Austin ML
2612         Documents current state in mksh, *NOT* necessarily correct!
2613 stdin:
2614         cat <<END
2615         hello
2616         END\
2617         END
2618         END
2619         echo end
2620 expected-stdout:
2621         hello
2622         ENDEND
2623         end
2624 ---
2625 name: heredoc-weird-2
2626 description:
2627         Tests for here documents, taken from Austin ML
2628 stdin:
2629         cat <<'    END    '
2630         hello
2631             END    
2632         echo end
2633 expected-stdout:
2634         hello
2635         end
2636 ---
2637 name: heredoc-weird-4
2638 description:
2639         Tests for here documents, taken from Austin ML
2640         Documents current state in mksh, *NOT* necessarily correct!
2641 stdin:
2642         cat <<END
2643         hello\
2644         END
2645         END
2646         echo end
2647 expected-stdout:
2648         helloEND
2649         end
2650 ---
2651 name: heredoc-weird-5
2652 description:
2653         Tests for here documents, taken from Austin ML
2654         Documents current state in mksh, *NOT* necessarily correct!
2655 stdin:
2656         cat <<END
2657         hello
2658         \END
2659         END
2660         echo end
2661 expected-stdout:
2662         hello
2663         \END
2664         end
2665 ---
2666 name: heredoc-tmpfile-1
2667 description:
2668         Check that heredoc temp files aren't removed too soon or too late.
2669         Heredoc in simple command.
2670 stdin:
2671         TMPDIR=$PWD
2672         eval '
2673                 cat <<- EOF
2674                 hi
2675                 EOF
2676                 for i in a b ; do
2677                         cat <<- EOF
2678                         more
2679                         EOF
2680                 done
2681             ' &
2682         sleep 1
2683         echo Left overs: *
2684 expected-stdout:
2685         hi
2686         more
2687         more
2688         Left overs: *
2689 ---
2690 name: heredoc-tmpfile-2
2691 description:
2692         Check that heredoc temp files aren't removed too soon or too late.
2693         Heredoc in function, multiple calls to function.
2694 stdin:
2695         TMPDIR=$PWD
2696         eval '
2697                 foo() {
2698                         cat <<- EOF
2699                         hi
2700                         EOF
2701                 }
2702                 foo
2703                 foo
2704             ' &
2705         sleep 1
2706         echo Left overs: *
2707 expected-stdout:
2708         hi
2709         hi
2710         Left overs: *
2711 ---
2712 name: heredoc-tmpfile-3
2713 description:
2714         Check that heredoc temp files aren't removed too soon or too late.
2715         Heredoc in function in loop, multiple calls to function.
2716 stdin:
2717         TMPDIR=$PWD
2718         eval '
2719                 foo() {
2720                         cat <<- EOF
2721                         hi
2722                         EOF
2723                 }
2724                 for i in a b; do
2725                         foo
2726                         foo() {
2727                                 cat <<- EOF
2728                                 folks $i
2729                                 EOF
2730                         }
2731                 done
2732                 foo
2733             ' &
2734         sleep 1
2735         echo Left overs: *
2736 expected-stdout:
2737         hi
2738         folks b
2739         folks b
2740         Left overs: *
2741 ---
2742 name: heredoc-tmpfile-4
2743 description:
2744         Check that heredoc temp files aren't removed too soon or too late.
2745         Backgrounded simple command with here doc
2746 stdin:
2747         TMPDIR=$PWD
2748         eval '
2749                 cat <<- EOF &
2750                 hi
2751                 EOF
2752             ' &
2753         sleep 1
2754         echo Left overs: *
2755 expected-stdout:
2756         hi
2757         Left overs: *
2758 ---
2759 name: heredoc-tmpfile-5
2760 description:
2761         Check that heredoc temp files aren't removed too soon or too late.
2762         Backgrounded subshell command with here doc
2763 stdin:
2764         TMPDIR=$PWD
2765         eval '
2766               (
2767                 sleep 1 # so parent exits
2768                 echo A
2769                 cat <<- EOF
2770                 hi
2771                 EOF
2772                 echo B
2773               ) &
2774             ' &
2775         sleep 2
2776         echo Left overs: *
2777 expected-stdout:
2778         A
2779         hi
2780         B
2781         Left overs: *
2782 ---
2783 name: heredoc-tmpfile-6
2784 description:
2785         Check that heredoc temp files aren't removed too soon or too late.
2786         Heredoc in pipeline.
2787 stdin:
2788         TMPDIR=$PWD
2789         eval '
2790                 cat <<- EOF | sed "s/hi/HI/"
2791                 hi
2792                 EOF
2793             ' &
2794         sleep 1
2795         echo Left overs: *
2796 expected-stdout:
2797         HI
2798         Left overs: *
2799 ---
2800 name: heredoc-tmpfile-7
2801 description:
2802         Check that heredoc temp files aren't removed too soon or too late.
2803         Heredoc in backgrounded pipeline.
2804 stdin:
2805         TMPDIR=$PWD
2806         eval '
2807                 cat <<- EOF | sed 's/hi/HI/' &
2808                 hi
2809                 EOF
2810             ' &
2811         sleep 1
2812         echo Left overs: *
2813 expected-stdout:
2814         HI
2815         Left overs: *
2816 ---
2817 name: heredoc-tmpfile-8
2818 description:
2819         Check that heredoc temp files aren't removed too soon or too
2820         late. Heredoc in function, backgrounded call to function.
2821         This check can fail on slow machines (<100 MHz), or Cygwin,
2822         that's normal.
2823 need-pass: no
2824 stdin:
2825         TMPDIR=$PWD
2826         # Background eval so main shell doesn't do parsing
2827         eval '
2828                 foo() {
2829                         cat <<- EOF
2830                         hi
2831                         EOF
2832                 }
2833                 foo
2834                 # sleep so eval can die
2835                 (sleep 1; foo) &
2836                 (sleep 1; foo) &
2837                 foo
2838             ' &
2839         sleep 2
2840         echo Left overs: *
2841 expected-stdout:
2842         hi
2843         hi
2844         hi
2845         hi
2846         Left overs: *
2847 ---
2848 name: heredoc-quoting-unsubst
2849 description:
2850         Check for correct handling of quoted characters in
2851         here documents without substitution (marker is quoted).
2852 stdin:
2853         foo=bar
2854         cat <<-'EOF'
2855                 x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
2856         EOF
2857 expected-stdout:
2858         x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
2859 ---
2860 name: heredoc-quoting-subst
2861 description:
2862         Check for correct handling of quoted characters in
2863         here documents with substitution (marker is not quoted).
2864 stdin:
2865         foo=bar
2866         cat <<-EOF
2867                 x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
2868         EOF
2869 expected-stdout:
2870         x " \" \ \ $ $ baz `echo baz` bar $foo x
2871 ---
2872 name: single-quotes-in-braces
2873 description:
2874         Check that single quotes inside unquoted {} are treated as quotes
2875 stdin:
2876         foo=1
2877         echo ${foo:+'blah  $foo'}
2878 expected-stdout:
2879         blah  $foo
2880 ---
2881 name: single-quotes-in-quoted-braces
2882 description:
2883         Check that single quotes inside quoted {} are treated as
2884         normal char
2885 stdin:
2886         foo=1
2887         echo "${foo:+'blah  $foo'}"
2888 expected-stdout:
2889         'blah  1'
2890 ---
2891 name: single-quotes-in-braces-nested
2892 description:
2893         Check that single quotes inside unquoted {} are treated as quotes,
2894         even if that's inside a double-quoted command expansion
2895 stdin:
2896         foo=1
2897         echo "$( echo ${foo:+'blah  $foo'})"
2898 expected-stdout:
2899         blah  $foo
2900 ---
2901 name: single-quotes-in-brace-pattern
2902 description:
2903         Check that single quotes inside {} pattern are treated as quotes
2904 stdin:
2905         foo=1234
2906         echo ${foo%'2'*} "${foo%'2'*}" ${foo%2'*'} "${foo%2'*'}"
2907 expected-stdout:
2908         1 1 1234 1234
2909 ---
2910 name: single-quotes-in-heredoc-braces
2911 description:
2912         Check that single quotes inside {} in heredoc are treated
2913         as normal char
2914 stdin:
2915         foo=1
2916         cat <<EOM
2917         ${foo:+'blah  $foo'}
2918         EOM
2919 expected-stdout:
2920         'blah  1'
2921 ---
2922 name: single-quotes-in-nested-braces
2923 description:
2924         Check that single quotes inside nested unquoted {} are
2925         treated as quotes
2926 stdin:
2927         foo=1
2928         echo ${foo:+${foo:+'blah  $foo'}}
2929 expected-stdout:
2930         blah  $foo
2931 ---
2932 name: single-quotes-in-nested-quoted-braces
2933 description:
2934         Check that single quotes inside nested quoted {} are treated
2935         as normal char
2936 stdin:
2937         foo=1
2938         echo "${foo:+${foo:+'blah  $foo'}}"
2939 expected-stdout:
2940         'blah  1'
2941 ---
2942 name: single-quotes-in-nested-braces-nested
2943 description:
2944         Check that single quotes inside nested unquoted {} are treated
2945         as quotes, even if that's inside a double-quoted command expansion
2946 stdin:
2947         foo=1
2948         echo "$( echo ${foo:+${foo:+'blah  $foo'}})"
2949 expected-stdout:
2950         blah  $foo
2951 ---
2952 name: single-quotes-in-nested-brace-pattern
2953 description:
2954         Check that single quotes inside nested {} pattern are treated as quotes
2955 stdin:
2956         foo=1234
2957         echo ${foo:+${foo%'2'*}} "${foo:+${foo%'2'*}}" ${foo:+${foo%2'*'}} "${foo:+${foo%2'*'}}"
2958 expected-stdout:
2959         1 1 1234 1234
2960 ---
2961 name: single-quotes-in-heredoc-nested-braces
2962 description:
2963         Check that single quotes inside nested {} in heredoc are treated
2964         as normal char
2965 stdin:
2966         foo=1
2967         cat <<EOM
2968         ${foo:+${foo:+'blah  $foo'}}
2969         EOM
2970 expected-stdout:
2971         'blah  1'
2972 ---
2973 name: history-basic
2974 description:
2975         See if we can test history at all
2976 need-ctty: yes
2977 arguments: !-i!
2978 env-setup: !ENV=./Env!HISTFILE=hist.file!
2979 file-setup: file 644 "Env"
2980         PS1=X
2981 stdin:
2982         echo hi
2983         fc -l
2984 expected-stdout:
2985         hi
2986         1       echo hi
2987 expected-stderr-pattern:
2988         /^X*$/
2989 ---
2990 name: history-dups
2991 description:
2992         Verify duplicates and spaces are not entered
2993 need-ctty: yes
2994 arguments: !-i!
2995 env-setup: !ENV=./Env!HISTFILE=hist.file!
2996 file-setup: file 644 "Env"
2997         PS1=X
2998 stdin:
2999         echo hi
3000          echo yo
3001         echo hi
3002         fc -l
3003 expected-stdout:
3004         hi
3005         yo
3006         hi
3007         1       echo hi
3008 expected-stderr-pattern:
3009         /^X*$/
3010 ---
3011 name: history-unlink
3012 description:
3013         Check if broken HISTFILEs do not cause trouble
3014 need-ctty: yes
3015 arguments: !-i!
3016 env-setup: !ENV=./Env!HISTFILE=foo/hist.file!
3017 file-setup: file 644 "Env"
3018         PS1=X
3019 file-setup: dir 755 "foo"
3020 file-setup: file 644 "foo/hist.file"
3021         sometext
3022 time-limit: 5
3023 perl-setup: chmod(0555, "foo");
3024 stdin:
3025         echo hi
3026         fc -l
3027         chmod 0755 foo
3028 expected-stdout:
3029         hi
3030         1       echo hi
3031 expected-stderr-pattern:
3032         /(.*can't unlink HISTFILE.*\n)?X*$/
3033 ---
3034 name: history-e-minus-1
3035 description:
3036         Check if more recent command is executed
3037 need-ctty: yes
3038 arguments: !-i!
3039 env-setup: !ENV=./Env!HISTFILE=hist.file!
3040 file-setup: file 644 "Env"
3041         PS1=X
3042 stdin:
3043         echo hi
3044         echo there
3045         fc -e -
3046 expected-stdout:
3047         hi
3048         there
3049         there
3050 expected-stderr-pattern:
3051         /^X*echo there\nX*$/
3052 ---
3053 name: history-e-minus-2
3054 description:
3055         Check that repeated command is printed before command
3056         is re-executed.
3057 need-ctty: yes
3058 arguments: !-i!
3059 env-setup: !ENV=./Env!HISTFILE=hist.file!
3060 file-setup: file 644 "Env"
3061         PS1=X
3062 stdin:
3063         exec 2>&1
3064         echo hi
3065         echo there
3066         fc -e -
3067 expected-stdout-pattern:
3068         /X*hi\nX*there\nX*echo there\nthere\nX*/
3069 expected-stderr-pattern:
3070         /^X*$/
3071 ---
3072 name: history-e-minus-3
3073 description:
3074         fc -e - fails when there is no history
3075         (ksh93 has a bug that causes this to fail)
3076         (ksh88 loops on this)
3077 need-ctty: yes
3078 arguments: !-i!
3079 env-setup: !ENV=./Env!HISTFILE=hist.file!
3080 file-setup: file 644 "Env"
3081         PS1=X
3082 stdin:
3083         fc -e -
3084         echo ok
3085 expected-stdout:
3086         ok
3087 expected-stderr-pattern:
3088         /^X*.*:.*history.*\nX*$/
3089 ---
3090 name: history-e-minus-4
3091 description:
3092         Check if "fc -e -" command output goes to stdout.
3093 need-ctty: yes
3094 arguments: !-i!
3095 env-setup: !ENV=./Env!HISTFILE=hist.file!
3096 file-setup: file 644 "Env"
3097         PS1=X
3098 stdin:
3099         echo abc
3100         fc -e - | (read x; echo "A $x")
3101         echo ok
3102 expected-stdout:
3103         abc
3104         A abc
3105         ok
3106 expected-stderr-pattern:
3107         /^X*echo abc\nX*/
3108 ---
3109 name: history-e-minus-5
3110 description:
3111         fc is replaced in history by new command.
3112 need-ctty: yes
3113 arguments: !-i!
3114 env-setup: !ENV=./Env!HISTFILE=hist.file!
3115 file-setup: file 644 "Env"
3116         PS1=X
3117 stdin:
3118         echo abc def
3119         echo ghi jkl
3120         :
3121         fc -e - echo
3122         fc -l 2 5
3123 expected-stdout:
3124         abc def
3125         ghi jkl
3126         ghi jkl
3127         2       echo ghi jkl
3128         3       :
3129         4       echo ghi jkl
3130         5       fc -l 2 5
3131 expected-stderr-pattern:
3132         /^X*echo ghi jkl\nX*$/
3133 ---
3134 name: history-list-1
3135 description:
3136         List lists correct range
3137         (ksh88 fails 'cause it lists the fc command)
3138 need-ctty: yes
3139 arguments: !-i!
3140 env-setup: !ENV=./Env!HISTFILE=hist.file!
3141 file-setup: file 644 "Env"
3142         PS1=X
3143 stdin:
3144         echo line 1
3145         echo line 2
3146         echo line 3
3147         fc -l -- -2
3148 expected-stdout:
3149         line 1
3150         line 2
3151         line 3
3152         2       echo line 2
3153         3       echo line 3
3154 expected-stderr-pattern:
3155         /^X*$/
3156 ---
3157 name: history-list-2
3158 description:
3159         Lists oldest history if given pre-historic number
3160         (ksh93 has a bug that causes this to fail)
3161         (ksh88 fails 'cause it lists the fc command)
3162 need-ctty: yes
3163 arguments: !-i!
3164 env-setup: !ENV=./Env!HISTFILE=hist.file!
3165 file-setup: file 644 "Env"
3166         PS1=X
3167 stdin:
3168         echo line 1
3169         echo line 2
3170         echo line 3
3171         fc -l -- -40
3172 expected-stdout:
3173         line 1
3174         line 2
3175         line 3
3176         1       echo line 1
3177         2       echo line 2
3178         3       echo line 3
3179 expected-stderr-pattern:
3180         /^X*$/
3181 ---
3182 name: history-list-3
3183 description:
3184         Can give number 'options' to fc
3185 need-ctty: yes
3186 arguments: !-i!
3187 env-setup: !ENV=./Env!HISTFILE=hist.file!
3188 file-setup: file 644 "Env"
3189         PS1=X
3190 stdin:
3191         echo line 1
3192         echo line 2
3193         echo line 3
3194         echo line 4
3195         fc -l -3 -2
3196 expected-stdout:
3197         line 1
3198         line 2
3199         line 3
3200         line 4
3201         2       echo line 2
3202         3       echo line 3
3203 expected-stderr-pattern:
3204         /^X*$/
3205 ---
3206 name: history-list-4
3207 description:
3208         -1 refers to previous command
3209 need-ctty: yes
3210 arguments: !-i!
3211 env-setup: !ENV=./Env!HISTFILE=hist.file!
3212 file-setup: file 644 "Env"
3213         PS1=X
3214 stdin:
3215         echo line 1
3216         echo line 2
3217         echo line 3
3218         echo line 4
3219         fc -l -1 -1
3220 expected-stdout:
3221         line 1
3222         line 2
3223         line 3
3224         line 4
3225         4       echo line 4
3226 expected-stderr-pattern:
3227         /^X*$/
3228 ---
3229 name: history-list-5
3230 description:
3231         List command stays in history
3232 need-ctty: yes
3233 arguments: !-i!
3234 env-setup: !ENV=./Env!HISTFILE=hist.file!
3235 file-setup: file 644 "Env"
3236         PS1=X
3237 stdin:
3238         echo line 1
3239         echo line 2
3240         echo line 3
3241         echo line 4
3242         fc -l -1 -1
3243         fc -l -2 -1
3244 expected-stdout:
3245         line 1
3246         line 2
3247         line 3
3248         line 4
3249         4       echo line 4
3250         4       echo line 4
3251         5       fc -l -1 -1
3252 expected-stderr-pattern:
3253         /^X*$/
3254 ---
3255 name: history-list-6
3256 description:
3257         HISTSIZE limits about of history kept.
3258         (ksh88 fails 'cause it lists the fc command)
3259 need-ctty: yes
3260 arguments: !-i!
3261 env-setup: !ENV=./Env!HISTFILE=hist.file!HISTSIZE=3!
3262 file-setup: file 644 "Env"
3263         PS1=X
3264 stdin:
3265         echo line 1
3266         echo line 2
3267         echo line 3
3268         echo line 4
3269         echo line 5
3270         fc -l
3271 expected-stdout:
3272         line 1
3273         line 2
3274         line 3
3275         line 4
3276         line 5
3277         4       echo line 4
3278         5       echo line 5
3279 expected-stderr-pattern:
3280         /^X*$/
3281 ---
3282 name: history-list-7
3283 description:
3284         fc allows too old/new errors in range specification
3285 need-ctty: yes
3286 arguments: !-i!
3287 env-setup: !ENV=./Env!HISTFILE=hist.file!HISTSIZE=3!
3288 file-setup: file 644 "Env"
3289         PS1=X
3290 stdin:
3291         echo line 1
3292         echo line 2
3293         echo line 3
3294         echo line 4
3295         echo line 5
3296         fc -l 1 30
3297 expected-stdout:
3298         line 1
3299         line 2
3300         line 3
3301         line 4
3302         line 5
3303         4       echo line 4
3304         5       echo line 5
3305         6       fc -l 1 30
3306 expected-stderr-pattern:
3307         /^X*$/
3308 ---
3309 name: history-list-r-1
3310 description:
3311         test -r flag in history
3312 need-ctty: yes
3313 arguments: !-i!
3314 env-setup: !ENV=./Env!HISTFILE=hist.file!
3315 file-setup: file 644 "Env"
3316         PS1=X
3317 stdin:
3318         echo line 1
3319         echo line 2
3320         echo line 3
3321         echo line 4
3322         echo line 5
3323         fc -l -r 2 4
3324 expected-stdout:
3325         line 1
3326         line 2
3327         line 3
3328         line 4
3329         line 5
3330         4       echo line 4
3331         3       echo line 3
3332         2       echo line 2
3333 expected-stderr-pattern:
3334         /^X*$/
3335 ---
3336 name: history-list-r-2
3337 description:
3338         If first is newer than last, -r is implied.
3339 need-ctty: yes
3340 arguments: !-i!
3341 env-setup: !ENV=./Env!HISTFILE=hist.file!
3342 file-setup: file 644 "Env"
3343         PS1=X
3344 stdin:
3345         echo line 1
3346         echo line 2
3347         echo line 3
3348         echo line 4
3349         echo line 5
3350         fc -l 4 2
3351 expected-stdout:
3352         line 1
3353         line 2
3354         line 3
3355         line 4
3356         line 5
3357         4       echo line 4
3358         3       echo line 3
3359         2       echo line 2
3360 expected-stderr-pattern:
3361         /^X*$/
3362 ---
3363 name: history-list-r-3
3364 description:
3365         If first is newer than last, -r is cancelled.
3366 need-ctty: yes
3367 arguments: !-i!
3368 env-setup: !ENV=./Env!HISTFILE=hist.file!
3369 file-setup: file 644 "Env"
3370         PS1=X
3371 stdin:
3372         echo line 1
3373         echo line 2
3374         echo line 3
3375         echo line 4
3376         echo line 5
3377         fc -l -r 4 2
3378 expected-stdout:
3379         line 1
3380         line 2
3381         line 3
3382         line 4
3383         line 5
3384         2       echo line 2
3385         3       echo line 3
3386         4       echo line 4
3387 expected-stderr-pattern:
3388         /^X*$/
3389 ---
3390 name: history-subst-1
3391 description:
3392         Basic substitution
3393 need-ctty: yes
3394 arguments: !-i!
3395 env-setup: !ENV=./Env!HISTFILE=hist.file!
3396 file-setup: file 644 "Env"
3397         PS1=X
3398 stdin:
3399         echo abc def
3400         echo ghi jkl
3401         fc -e - abc=AB 'echo a'
3402 expected-stdout:
3403         abc def
3404         ghi jkl
3405         AB def
3406 expected-stderr-pattern:
3407         /^X*echo AB def\nX*$/
3408 ---
3409 name: history-subst-2
3410 description:
3411         Does subst find previous command?
3412 need-ctty: yes
3413 arguments: !-i!
3414 env-setup: !ENV=./Env!HISTFILE=hist.file!
3415 file-setup: file 644 "Env"
3416         PS1=X
3417 stdin:
3418         echo abc def
3419         echo ghi jkl
3420         fc -e - jkl=XYZQRT 'echo g'
3421 expected-stdout:
3422         abc def
3423         ghi jkl
3424         ghi XYZQRT
3425 expected-stderr-pattern:
3426         /^X*echo ghi XYZQRT\nX*$/
3427 ---
3428 name: history-subst-3
3429 description:
3430         Does subst find previous command when no arguments given
3431 need-ctty: yes
3432 arguments: !-i!
3433 env-setup: !ENV=./Env!HISTFILE=hist.file!
3434 file-setup: file 644 "Env"
3435         PS1=X
3436 stdin:
3437         echo abc def
3438         echo ghi jkl
3439         fc -e - jkl=XYZQRT
3440 expected-stdout:
3441         abc def
3442         ghi jkl
3443         ghi XYZQRT
3444 expected-stderr-pattern:
3445         /^X*echo ghi XYZQRT\nX*$/
3446 ---
3447 name: history-subst-4
3448 description:
3449         Global substitutions work
3450         (ksh88 and ksh93 do not have -g option)
3451 need-ctty: yes
3452 arguments: !-i!
3453 env-setup: !ENV=./Env!HISTFILE=hist.file!
3454 file-setup: file 644 "Env"
3455         PS1=X
3456 stdin:
3457         echo abc def asjj sadjhasdjh asdjhasd
3458         fc -e - -g a=FooBAR
3459 expected-stdout:
3460         abc def asjj sadjhasdjh asdjhasd
3461         FooBARbc def FooBARsjj sFooBARdjhFooBARsdjh FooBARsdjhFooBARsd
3462 expected-stderr-pattern:
3463         /^X*echo FooBARbc def FooBARsjj sFooBARdjhFooBARsdjh FooBARsdjhFooBARsd\nX*$/
3464 ---
3465 name: history-subst-5
3466 description:
3467         Make sure searches don't find current (fc) command
3468         (ksh88/ksh93 don't have the ? prefix thing so they fail this test)
3469 need-ctty: yes
3470 arguments: !-i!
3471 env-setup: !ENV=./Env!HISTFILE=hist.file!
3472 file-setup: file 644 "Env"
3473         PS1=X
3474 stdin:
3475         echo abc def
3476         echo ghi jkl
3477         fc -e - abc=AB \?abc
3478 expected-stdout:
3479         abc def
3480         ghi jkl
3481         AB def
3482 expected-stderr-pattern:
3483         /^X*echo AB def\nX*$/
3484 ---
3485 name: history-ed-1-old
3486 description:
3487         Basic (ed) editing works (assumes you have generic ed editor
3488         that prints no prompts). This is for oldish ed(1) which write
3489         the character count to stdout.
3490 category: stdout-ed
3491 need-ctty: yes
3492 need-pass: no
3493 arguments: !-i!
3494 env-setup: !ENV=./Env!HISTFILE=hist.file!
3495 file-setup: file 644 "Env"
3496         PS1=X
3497 stdin:
3498         echo abc def
3499         fc echo
3500         s/abc/FOOBAR/
3501         w
3502         q
3503 expected-stdout:
3504         abc def
3505         13
3506         16
3507         FOOBAR def
3508 expected-stderr-pattern:
3509         /^X*echo FOOBAR def\nX*$/
3510 ---
3511 name: history-ed-2-old
3512 description:
3513         Correct command is edited when number given
3514 category: stdout-ed
3515 need-ctty: yes
3516 need-pass: no
3517 arguments: !-i!
3518 env-setup: !ENV=./Env!HISTFILE=hist.file!
3519 file-setup: file 644 "Env"
3520         PS1=X
3521 stdin:
3522         echo line 1
3523         echo line 2 is here
3524         echo line 3
3525         echo line 4
3526         fc 2
3527         s/is here/is changed/
3528         w
3529         q
3530 expected-stdout:
3531         line 1
3532         line 2 is here
3533         line 3
3534         line 4
3535         20
3536         23
3537         line 2 is changed
3538 expected-stderr-pattern:
3539         /^X*echo line 2 is changed\nX*$/
3540 ---
3541 name: history-ed-3-old
3542 description:
3543         Newly created multi line commands show up as single command
3544         in history.
3545         (NOTE: adjusted for COMPLEX HISTORY compile time option)
3546         (ksh88 fails 'cause it lists the fc command)
3547 category: stdout-ed
3548 need-ctty: yes
3549 need-pass: no
3550 arguments: !-i!
3551 env-setup: !ENV=./Env!HISTFILE=hist.file!
3552 file-setup: file 644 "Env"
3553         PS1=X
3554 stdin:
3555         echo abc def
3556         fc echo
3557         s/abc/FOOBAR/
3558         $a
3559         echo a new line
3560         .
3561         w
3562         q
3563         fc -l
3564 expected-stdout:
3565         abc def
3566         13
3567         32
3568         FOOBAR def
3569         a new line
3570         1       echo abc def
3571         2       echo FOOBAR def
3572         3       echo a new line
3573 expected-stderr-pattern:
3574         /^X*echo FOOBAR def\necho a new line\nX*$/
3575 ---
3576 name: history-ed-1
3577 description:
3578         Basic (ed) editing works (assumes you have generic ed editor
3579         that prints no prompts). This is for newish ed(1) and stderr.
3580 category: !no-stderr-ed
3581 need-ctty: yes
3582 need-pass: no
3583 arguments: !-i!
3584 env-setup: !ENV=./Env!HISTFILE=hist.file!
3585 file-setup: file 644 "Env"
3586         PS1=X
3587 stdin:
3588         echo abc def
3589         fc echo
3590         s/abc/FOOBAR/
3591         w
3592         q
3593 expected-stdout:
3594         abc def
3595         FOOBAR def
3596 expected-stderr-pattern:
3597         /^X*13\n16\necho FOOBAR def\nX*$/
3598 ---
3599 name: history-ed-2
3600 description:
3601         Correct command is edited when number given
3602 category: !no-stderr-ed
3603 need-ctty: yes
3604 need-pass: no
3605 arguments: !-i!
3606 env-setup: !ENV=./Env!HISTFILE=hist.file!
3607 file-setup: file 644 "Env"
3608         PS1=X
3609 stdin:
3610         echo line 1
3611         echo line 2 is here
3612         echo line 3
3613         echo line 4
3614         fc 2
3615         s/is here/is changed/
3616         w
3617         q
3618 expected-stdout:
3619         line 1
3620         line 2 is here
3621         line 3
3622         line 4
3623         line 2 is changed
3624 expected-stderr-pattern:
3625         /^X*20\n23\necho line 2 is changed\nX*$/
3626 ---
3627 name: history-ed-3
3628 description:
3629         Newly created multi line commands show up as single command
3630         in history.
3631 category: !no-stderr-ed
3632 need-ctty: yes
3633 need-pass: no
3634 arguments: !-i!
3635 env-setup: !ENV=./Env!HISTFILE=hist.file!
3636 file-setup: file 644 "Env"
3637         PS1=X
3638 stdin:
3639         echo abc def
3640         fc echo
3641         s/abc/FOOBAR/
3642         $a
3643         echo a new line
3644         .
3645         w
3646         q
3647         fc -l
3648 expected-stdout:
3649         abc def
3650         FOOBAR def
3651         a new line
3652         1       echo abc def
3653         2       echo FOOBAR def
3654         3       echo a new line
3655 expected-stderr-pattern:
3656         /^X*13\n32\necho FOOBAR def\necho a new line\nX*$/
3657 ---
3658 name: IFS-space-1
3659 description:
3660         Simple test, default IFS
3661 stdin:
3662         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3663         set -- A B C
3664         showargs 1 $*
3665         showargs 2 "$*"
3666         showargs 3 $@
3667         showargs 4 "$@"
3668 expected-stdout:
3669         <1> <A> <B> <C> .
3670         <2> <A B C> .
3671         <3> <A> <B> <C> .
3672         <4> <A> <B> <C> .
3673 ---
3674 name: IFS-colon-1
3675 description:
3676         Simple test, IFS=:
3677 stdin:
3678         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3679         IFS=:
3680         set -- A B C
3681         showargs 1 $*
3682         showargs 2 "$*"
3683         showargs 3 $@
3684         showargs 4 "$@"
3685 expected-stdout:
3686         <1> <A> <B> <C> .
3687         <2> <A:B:C> .
3688         <3> <A> <B> <C> .
3689         <4> <A> <B> <C> .
3690 ---
3691 name: IFS-null-1
3692 description:
3693         Simple test, IFS=""
3694 stdin:
3695         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3696         IFS=""
3697         set -- A B C
3698         showargs 1 $*
3699         showargs 2 "$*"
3700         showargs 3 $@
3701         showargs 4 "$@"
3702 expected-stdout:
3703         <1> <A> <B> <C> .
3704         <2> <ABC> .
3705         <3> <A> <B> <C> .
3706         <4> <A> <B> <C> .
3707 ---
3708 name: IFS-space-colon-1
3709 description:
3710         Simple test, IFS=<white-space>:
3711 stdin:
3712         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3713         IFS="$IFS:"
3714         set --
3715         showargs 1 $*
3716         showargs 2 "$*"
3717         showargs 3 $@
3718         showargs 4 "$@"
3719         showargs 5 : "$@"
3720 expected-stdout:
3721         <1> .
3722         <2> <> .
3723         <3> .
3724         <4> .
3725         <5> <:> .
3726 ---
3727 name: IFS-space-colon-2
3728 description:
3729         Simple test, IFS=<white-space>:
3730         AT&T ksh fails this, POSIX says the test is correct.
3731 stdin:
3732         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3733         IFS="$IFS:"
3734         set --
3735         showargs :"$@"
3736 expected-stdout:
3737         <:> .
3738 ---
3739 name: IFS-space-colon-4
3740 description:
3741         Simple test, IFS=<white-space>:
3742 stdin:
3743         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3744         IFS="$IFS:"
3745         set --
3746         showargs "$@$@"
3747 expected-stdout:
3748         .
3749 ---
3750 name: IFS-space-colon-5
3751 description:
3752         Simple test, IFS=<white-space>:
3753         Don't know what POSIX thinks of this.  AT&T ksh does not do this.
3754 stdin:
3755         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3756         IFS="$IFS:"
3757         set --
3758         showargs "${@:-}"
3759 expected-stdout:
3760         <> .
3761 ---
3762 name: IFS-subst-1
3763 description:
3764         Simple test, IFS=<white-space>:
3765 stdin:
3766         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3767         IFS="$IFS:"
3768         x=":b: :"
3769         echo -n '1:'; for i in $x ; do echo -n " [$i]" ; done ; echo
3770         echo -n '2:'; for i in :b:: ; do echo -n " [$i]" ; done ; echo
3771         showargs 3 $x
3772         showargs 4 :b::
3773         x="a:b:"
3774         echo -n '5:'; for i in $x ; do echo -n " [$i]" ; done ; echo
3775         showargs 6 $x
3776         x="a::c"
3777         echo -n '7:'; for i in $x ; do echo -n " [$i]" ; done ; echo
3778         showargs 8 $x
3779         echo -n '9:'; for i in ${FOO-`echo -n h:i`th:ere} ; do echo -n " [$i]" ; done ; echo
3780         showargs 10 ${FOO-`echo -n h:i`th:ere}
3781         showargs 11 "${FOO-`echo -n h:i`th:ere}"
3782         x=" A :  B::D"
3783         echo -n '12:'; for i in $x ; do echo -n " [$i]" ; done ; echo
3784         showargs 13 $x
3785 expected-stdout:
3786         1: [] [b] []
3787         2: [:b::]
3788         <3> <> <b> <> .
3789         <4> <:b::> .
3790         5: [a] [b]
3791         <6> <a> <b> .
3792         7: [a] [] [c]
3793         <8> <a> <> <c> .
3794         9: [h] [ith] [ere]
3795         <10> <h> <ith> <ere> .
3796         <11> <h:ith:ere> .
3797         12: [A] [B] [] [D]
3798         <13> <A> <B> <> <D> .
3799 ---
3800 name: IFS-subst-2
3801 description:
3802         Check leading whitespace after trim does not make a field
3803 stdin:
3804         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3805         x="X 1 2"
3806         showargs 1 shift ${x#X}
3807 expected-stdout:
3808         <1> <shift> <1> <2> .
3809 ---
3810 name: IFS-subst-3-arr
3811 description:
3812         Check leading IFS non-whitespace after trim does make a field
3813         but leading IFS whitespace does not, nor empty replacements
3814 stdin:
3815         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3816         showargs 0 ${-+}
3817         IFS=:
3818         showargs 1 ${-+:foo:bar}
3819         IFS=' '
3820         showargs 2 ${-+ foo bar}
3821 expected-stdout:
3822         <0> .
3823         <1> <> <foo> <bar> .
3824         <2> <foo> <bar> .
3825 ---
3826 name: IFS-subst-3-ass
3827 description:
3828         Check non-field semantics
3829 stdin:
3830         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
3831         showargs 0 x=${-+}
3832         IFS=:
3833         showargs 1 x=${-+:foo:bar}
3834         IFS=' '
3835         showargs 2 x=${-+ foo bar}
3836 expected-stdout:
3837         <0> <x=> .
3838         <1> <x=> <foo> <bar> .
3839         <2> <x=> <foo> <bar> .
3840 ---
3841 name: IFS-subst-3-lcl
3842 description:
3843         Check non-field semantics, smaller corner case (LP#1381965)
3844 stdin:
3845         set -x
3846         local regex=${2:-}
3847         exit 1
3848 expected-exit: e != 0
3849 expected-stderr-pattern:
3850         /regex=/
3851 ---
3852 name: IFS-subst-4-1
3853 description:
3854         reported by mikeserv
3855 stdin:
3856         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
3857         a='space divded  argument
3858         here'
3859         IFS=\  ; set -- $a
3860         IFS= ; q="$*" ; nq=$*
3861         pfn "$*" $* "$q" "$nq"
3862         [ "$q" = "$nq" ] && echo =true || echo =false
3863 expected-stdout:
3864         <spacedivdedargument
3865         here>
3866         <space>
3867         <divded>
3868         <argument
3869         here>
3870         <spacedivdedargument
3871         here>
3872         <spacedivdedargument
3873         here>
3874         =true
3875 ---
3876 name: IFS-subst-4-2
3877 description:
3878         extended testsuite based on problem by mikeserv
3879 stdin:
3880         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
3881         a='space divded  argument
3882         here'
3883         IFS=\  ; set -- $a
3884         IFS= ; q="$@" ; nq=$@
3885         pfn "$*" $* "$q" "$nq"
3886         [ "$q" = "$nq" ] && echo =true || echo =false
3887 expected-stdout:
3888         <spacedivdedargument
3889         here>
3890         <space>
3891         <divded>
3892         <argument
3893         here>
3894         <space divded argument
3895         here>
3896         <space divded argument
3897         here>
3898         =true
3899 ---
3900 name: IFS-subst-4-3
3901 description:
3902         extended testsuite based on problem by mikeserv
3903 stdin:
3904         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
3905         a='space divded  argument
3906         here'
3907         IFS=\ ; set -- $a; IFS=
3908         qs="$*"
3909         nqs=$*
3910         qk="$@"
3911         nqk=$@
3912         print -nr -- '= qs '; pfn "$qs"
3913         print -nr -- '=nqs '; pfn "$nqs"
3914         print -nr -- '= qk '; pfn "$qk"
3915         print -nr -- '=nqk '; pfn "$nqk"
3916         print -nr -- '~ qs '; pfn "$*"
3917         print -nr -- '~nqs '; pfn $*
3918         print -nr -- '~ qk '; pfn "$@"
3919         print -nr -- '~nqk '; pfn $@
3920 expected-stdout:
3921         = qs <spacedivdedargument
3922         here>
3923         =nqs <spacedivdedargument
3924         here>
3925         = qk <space divded argument
3926         here>
3927         =nqk <space divded argument
3928         here>
3929         ~ qs <spacedivdedargument
3930         here>
3931         ~nqs <space>
3932         <divded>
3933         <argument
3934         here>
3935         ~ qk <space>
3936         <divded>
3937         <argument
3938         here>
3939         ~nqk <space>
3940         <divded>
3941         <argument
3942         here>
3943 ---
3944 name: IFS-subst-4-4
3945 description:
3946         extended testsuite based on problem by mikeserv
3947 stdin:
3948         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
3949         a='space divded  argument
3950         here'
3951         IFS=\ ; set -- $a; IFS=
3952         qs="$*"
3953         print -nr -- '= qs '; pfn "$qs"
3954         print -nr -- '~ qs '; pfn "$*"
3955         nqs=$*
3956         print -nr -- '=nqs '; pfn "$nqs"
3957         print -nr -- '~nqs '; pfn $*
3958         qk="$@"
3959         print -nr -- '= qk '; pfn "$qk"
3960         print -nr -- '~ qk '; pfn "$@"
3961         nqk=$@
3962         print -nr -- '=nqk '; pfn "$nqk"
3963         print -nr -- '~nqk '; pfn $@
3964 expected-stdout:
3965         = qs <spacedivdedargument
3966         here>
3967         ~ qs <spacedivdedargument
3968         here>
3969         =nqs <spacedivdedargument
3970         here>
3971         ~nqs <space>
3972         <divded>
3973         <argument
3974         here>
3975         = qk <space divded argument
3976         here>
3977         ~ qk <space>
3978         <divded>
3979         <argument
3980         here>
3981         =nqk <space divded argument
3982         here>
3983         ~nqk <space>
3984         <divded>
3985         <argument
3986         here>
3987 ---
3988 name: IFS-subst-4-4p
3989 description:
3990         extended testsuite based on problem by mikeserv
3991 stdin:
3992         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
3993         a='space divded  argument
3994         here'
3995         IFS=\ ; set -- $a; IFS=
3996         unset v
3997         qs=${v:-"$*"}
3998         print -nr -- '= qs '; pfn "$qs"
3999         print -nr -- '~ qs '; pfn ${v:-"$*"}
4000         nqs=${v:-$*}
4001         print -nr -- '=nqs '; pfn "$nqs"
4002         print -nr -- '~nqs '; pfn ${v:-$*}
4003         qk=${v:-"$@"}
4004         print -nr -- '= qk '; pfn "$qk"
4005         print -nr -- '~ qk '; pfn ${v:-"$@"}
4006         nqk=${v:-$@}
4007         print -nr -- '=nqk '; pfn "$nqk"
4008         print -nr -- '~nqk '; pfn ${v:-$@}
4009 expected-stdout:
4010         = qs <spacedivdedargument
4011         here>
4012         ~ qs <spacedivdedargument
4013         here>
4014         =nqs <spacedivdedargument
4015         here>
4016         ~nqs <space>
4017         <divded>
4018         <argument
4019         here>
4020         = qk <space divded argument
4021         here>
4022         ~ qk <space>
4023         <divded>
4024         <argument
4025         here>
4026         =nqk <space divded argument
4027         here>
4028         ~nqk <space>
4029         <divded>
4030         <argument
4031         here>
4032 ---
4033 name: IFS-subst-4-5
4034 description:
4035         extended testsuite based on problem by mikeserv
4036 stdin:
4037         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4038         a='space divded  argument
4039         here'
4040         IFS=\ ; set -- $a; IFS=,
4041         qs="$*"
4042         print -nr -- '= qs '; pfn "$qs"
4043         print -nr -- '~ qs '; pfn "$*"
4044         nqs=$*
4045         print -nr -- '=nqs '; pfn "$nqs"
4046         print -nr -- '~nqs '; pfn $*
4047         qk="$@"
4048         print -nr -- '= qk '; pfn "$qk"
4049         print -nr -- '~ qk '; pfn "$@"
4050         nqk=$@
4051         print -nr -- '=nqk '; pfn "$nqk"
4052         print -nr -- '~nqk '; pfn $@
4053 expected-stdout:
4054         = qs <space,divded,argument
4055         here>
4056         ~ qs <space,divded,argument
4057         here>
4058         =nqs <space,divded,argument
4059         here>
4060         ~nqs <space>
4061         <divded>
4062         <argument
4063         here>
4064         = qk <space divded argument
4065         here>
4066         ~ qk <space>
4067         <divded>
4068         <argument
4069         here>
4070         =nqk <space divded argument
4071         here>
4072         ~nqk <space>
4073         <divded>
4074         <argument
4075         here>
4076 ---
4077 name: IFS-subst-4-5p
4078 description:
4079         extended testsuite based on problem by mikeserv
4080 stdin:
4081         pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
4082         a='space divded  argument
4083         here'
4084         IFS=\ ; set -- $a; IFS=,
4085         unset v
4086         qs=${v:-"$*"}
4087         print -nr -- '= qs '; pfn "$qs"
4088         print -nr -- '~ qs '; pfn ${v:-"$*"}
4089         nqs=${v:-$*}
4090         print -nr -- '=nqs '; pfn "$nqs"
4091         print -nr -- '~nqs '; pfn ${v:-$*}
4092         qk=${v:-"$@"}
4093         print -nr -- '= qk '; pfn "$qk"
4094         print -nr -- '~ qk '; pfn ${v:-"$@"}
4095         nqk=${v:-$@}
4096         print -nr -- '=nqk '; pfn "$nqk"
4097         print -nr -- '~nqk '; pfn ${v:-$@}
4098 expected-stdout:
4099         = qs <space,divded,argument
4100         here>
4101         ~ qs <space,divded,argument
4102         here>
4103         =nqs <space,divded,argument
4104         here>
4105         ~nqs <space>
4106         <divded>
4107         <argument
4108         here>
4109         = qk <space divded argument
4110         here>
4111         ~ qk <space>
4112         <divded>
4113         <argument
4114         here>
4115         =nqk <space divded argument
4116         here>
4117         ~nqk <space>
4118         <divded>
4119         <argument
4120         here>
4121 ---
4122 name: IFS-subst-5
4123 description:
4124         extended testsuite based on IFS-subst-3
4125         differs slightly from ksh93:
4126         - omit trailing field in a3zna, a7ina (unquoted $@ expansion)
4127         - has extra middle fields in b5ins, b7ina (IFS_NWS unquoted expansion)
4128         differs slightly from bash:
4129         - omit leading field in a5ins, a7ina (IFS_NWS unquoted expansion)
4130         differs slightly from zsh:
4131         - differs in assignment, not expansion; probably zsh bug
4132         - has extra middle fields in b5ins, b7ina (IFS_NWS unquoted expansion)
4133         'emulate sh' zsh has extra fields in
4134         - a5ins (IFS_NWS unquoted $*)
4135         - b5ins, matching mksh’s
4136         !!WARNING!! more to come: http://austingroupbugs.net/view.php?id=888
4137 stdin:
4138         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4139                 IFS=; set -- "" 2 ""; pfb $*; x=$*; pfn "$x"'
4140         echo '=a1zns'
4141         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4142                 IFS=; set -- "" 2 ""; pfb "$*"; x="$*"; pfn "$x"'
4143         echo '=a2zqs'
4144         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4145                 IFS=; set -- "" 2 ""; pfb $@; x=$@; pfn "$x"'
4146         echo '=a3zna'
4147         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4148                 IFS=; set -- "" 2 ""; pfb "$@"; x="$@"; pfn "$x"'
4149         echo '=a4zqa'
4150         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4151                 IFS=,; set -- "" 2 ""; pfb $*; x=$*; pfn "$x"'
4152         echo '=a5ins'
4153         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4154                 IFS=,; set -- "" 2 ""; pfb "$*"; x="$*"; pfn "$x"'
4155         echo '=a6iqs'
4156         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4157                 IFS=,; set -- "" 2 ""; pfb $@; x=$@; pfn "$x"'
4158         echo '=a7ina'
4159         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4160                 IFS=,; set -- "" 2 ""; pfb "$@"; x="$@"; pfn "$x"'
4161         echo '=a8iqa'
4162         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4163                 IFS=; set -- A B "" "" C; pfb $*; x=$*; pfn "$x"'
4164         echo '=b1zns'
4165         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4166                 IFS=; set -- A B "" "" C; pfb "$*"; x="$*"; pfn "$x"'
4167         echo '=b2zqs'
4168         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4169                 IFS=; set -- A B "" "" C; pfb $@; x=$@; pfn "$x"'
4170         echo '=b3zna'
4171         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4172                 IFS=; set -- A B "" "" C; pfb "$@"; x="$@"; pfn "$x"'
4173         echo '=b4zqa'
4174         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4175                 IFS=,; set -- A B "" "" C; pfb $*; x=$*; pfn "$x"'
4176         echo '=b5ins'
4177         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4178                 IFS=,; set -- A B "" "" C; pfb "$*"; x="$*"; pfn "$x"'
4179         echo '=b6iqs'
4180         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4181                 IFS=,; set -- A B "" "" C; pfb $@; x=$@; pfn "$x"'
4182         echo '=b7ina'
4183         "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4184                 IFS=,; set -- A B "" "" C; pfb "$@"; x="$@"; pfn "$x"'
4185         echo '=b8iqa'
4186 expected-stdout:
4187         [2]
4188         <2>
4189         =a1zns
4190         [2]
4191         <2>
4192         =a2zqs
4193         [2]
4194         < 2 >
4195         =a3zna
4196         []
4197         [2]
4198         []
4199         < 2 >
4200         =a4zqa
4201         [2]
4202         <,2,>
4203         =a5ins
4204         [,2,]
4205         <,2,>
4206         =a6iqs
4207         [2]
4208         < 2 >
4209         =a7ina
4210         []
4211         [2]
4212         []
4213         < 2 >
4214         =a8iqa
4215         [A]
4216         [B]
4217         [C]
4218         <ABC>
4219         =b1zns
4220         [ABC]
4221         <ABC>
4222         =b2zqs
4223         [A]
4224         [B]
4225         [C]
4226         <A B   C>
4227         =b3zna
4228         [A]
4229         [B]
4230         []
4231         []
4232         [C]
4233         <A B   C>
4234         =b4zqa
4235         [A]
4236         [B]
4237         []
4238         []
4239         [C]
4240         <A,B,,,C>
4241         =b5ins
4242         [A,B,,,C]
4243         <A,B,,,C>
4244         =b6iqs
4245         [A]
4246         [B]
4247         []
4248         []
4249         [C]
4250         <A B   C>
4251         =b7ina
4252         [A]
4253         [B]
4254         []
4255         []
4256         [C]
4257         <A B   C>
4258         =b8iqa
4259 ---
4260 name: IFS-subst-6
4261 description:
4262         Regression wrt. vector expansion in trim
4263 stdin:
4264         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4265         IFS=
4266         x=abc
4267         set -- a b
4268         showargs ${x#$*}
4269 expected-stdout:
4270         <c> .
4271 ---
4272 name: IFS-subst-7
4273 description:
4274         ksh93 bug wrt. vector expansion in trim
4275 stdin:
4276         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4277         IFS="*"
4278         a=abcd
4279         set -- '' c
4280         showargs "$*" ${a##"$*"}
4281 expected-stdout:
4282         <*c> <abcd> .
4283 ---
4284 name: IFS-subst-8
4285 description:
4286         http://austingroupbugs.net/view.php?id=221
4287 stdin:
4288         n() { echo "$#"; }; n "${foo-$@}"
4289 expected-stdout:
4290         1
4291 ---
4292 name: IFS-subst-9
4293 description:
4294         Scalar context for $*/$@ in [[ and case
4295 stdin:
4296         "$__progname" -c 'IFS=; set a b; [[ $* = "$1$2" ]]; echo 1 $?' sh a b
4297         "$__progname" -c 'IFS=; [[ $* = ab ]]; echo 2 "$?"' sh a b
4298         "$__progname" -c 'IFS=; [[ "$*" = ab ]]; echo 3 "$?"' sh a b
4299         "$__progname" -c 'IFS=; [[ $* = a ]]; echo 4 "$?"' sh a b
4300         "$__progname" -c 'IFS=; [[ "$*" = a ]]; echo 5 "$?"' sh a b
4301         "$__progname" -c 'IFS=; [[ "$@" = a ]]; echo 6 "$?"' sh a b
4302         "$__progname" -c 'IFS=; case "$@" in a) echo 7 a;; ab) echo 7 b;; a\ b) echo 7 ok;; esac' sh a b
4303         "$__progname" -c 'IFS=; case $* in a) echo 8 a;; ab) echo 8 ok;; esac' sh a b
4304         "$__progname" -c 'pfsp() { for s_arg in "$@"; do print -nr -- "<$s_arg> "; done; print .; }; IFS=; star=$* at="$@"; pfsp 9 "$star" "$at"' sh a b
4305 expected-stdout:
4306         1 0
4307         2 0
4308         3 0
4309         4 1
4310         5 1
4311         6 1
4312         7 ok
4313         8 ok
4314         <9> <ab> <a b> .
4315 ---
4316 name: IFS-arith-1
4317 description:
4318         http://austingroupbugs.net/view.php?id=832
4319 stdin:
4320         ${ZSH_VERSION+false} || emulate sh
4321         ${BASH_VERSION+set -o posix}
4322         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4323         IFS=0
4324         showargs $((1230456))
4325 expected-stdout:
4326         <123> <456> .
4327 ---
4328 name: integer-base-err-1
4329 description:
4330         Can't have 0 base (causes shell to exit)
4331 expected-exit: e != 0
4332 stdin:
4333         typeset -i i
4334         i=3
4335         i=0#4
4336         echo $i
4337 expected-stderr-pattern:
4338         /^.*:.*0#4.*\n$/
4339 ---
4340 name: integer-base-err-2
4341 description:
4342         Can't have multiple bases in a 'constant' (causes shell to exit)
4343         (ksh88 fails this test)
4344 expected-exit: e != 0
4345 stdin:
4346         typeset -i i
4347         i=3
4348         i=2#110#11
4349         echo $i
4350 expected-stderr-pattern:
4351         /^.*:.*2#110#11.*\n$/
4352 ---
4353 name: integer-base-err-3
4354 description:
4355         Syntax errors in expressions and effects on bases
4356         (interactive so errors don't cause exits)
4357         (ksh88 fails this test - shell exits, even with -i)
4358 need-ctty: yes
4359 arguments: !-i!
4360 stdin:
4361         PS1= # minimise prompt hassles
4362         typeset -i4 a=10
4363         typeset -i a=2+
4364         echo $a
4365         typeset -i4 a=10
4366         typeset -i2 a=2+
4367         echo $a
4368 expected-stderr-pattern:
4369         /^([#\$] )?.*:.*2+.*\n.*:.*2+.*\n$/
4370 expected-stdout:
4371         4#22
4372         4#22
4373 ---
4374 name: integer-base-err-4
4375 description:
4376         Are invalid digits (according to base) errors?
4377         (ksh93 fails this test)
4378 expected-exit: e != 0
4379 stdin:
4380         typeset -i i;
4381         i=3#4
4382 expected-stderr-pattern:
4383         /^([#\$] )?.*:.*3#4.*\n$/
4384 ---
4385 name: integer-base-1
4386 description:
4387         Missing number after base is treated as 0.
4388 stdin:
4389         typeset -i i
4390         i=3
4391         i=2#
4392         echo $i
4393 expected-stdout:
4394         0
4395 ---
4396 name: integer-base-2
4397 description:
4398         Check 'stickyness' of base in various situations
4399 stdin:
4400         typeset -i i=8
4401         echo $i
4402         echo ---------- A
4403         typeset -i4 j=8
4404         echo $j
4405         echo ---------- B
4406         typeset -i k=8
4407         typeset -i4 k=8
4408         echo $k
4409         echo ---------- C
4410         typeset -i4 l
4411         l=3#10
4412         echo $l
4413         echo ---------- D
4414         typeset -i m
4415         m=3#10
4416         echo $m
4417         echo ---------- E
4418         n=2#11
4419         typeset -i n
4420         echo $n
4421         n=10
4422         echo $n
4423         echo ---------- F
4424         typeset -i8 o=12
4425         typeset -i4 o
4426         echo $o
4427         echo ---------- G
4428         typeset -i p
4429         let p=8#12
4430         echo $p
4431 expected-stdout:
4432         8
4433         ---------- A
4434         4#20
4435         ---------- B
4436         4#20
4437         ---------- C
4438         4#3
4439         ---------- D
4440         3#10
4441         ---------- E
4442         2#11
4443         2#1010
4444         ---------- F
4445         4#30
4446         ---------- G
4447         8#12
4448 ---
4449 name: integer-base-3
4450 description:
4451         More base parsing (hmm doesn't test much..)
4452 stdin:
4453         typeset -i aa
4454         aa=1+12#10+2
4455         echo $aa
4456         typeset -i bb
4457         bb=1+$aa
4458         echo $bb
4459         typeset -i bb
4460         bb=$aa
4461         echo $bb
4462         typeset -i cc
4463         cc=$aa
4464         echo $cc
4465 expected-stdout:
4466         15
4467         16
4468         15
4469         15
4470 ---
4471 name: integer-base-4
4472 description:
4473         Check that things not declared as integers are not made integers,
4474         also, check if base is not reset by -i with no arguments.
4475         (ksh93 fails - prints 10#20 - go figure)
4476 stdin:
4477         xx=20
4478         let xx=10
4479         typeset -i | grep '^xx='
4480         typeset -i4 a=10
4481         typeset -i a=20
4482         echo $a
4483 expected-stdout:
4484         4#110
4485 ---
4486 name: integer-base-5
4487 description:
4488         More base stuff
4489 stdin:
4490         typeset -i4 a=3#10
4491         echo $a
4492         echo --
4493         typeset -i j=3
4494         j='~3'
4495         echo $j
4496         echo --
4497         typeset -i k=1
4498         x[k=k+1]=3
4499         echo $k
4500         echo --
4501         typeset -i l
4502         for l in 1 2+3 4; do echo $l; done
4503 expected-stdout:
4504         4#3
4505         --
4506         -4
4507         --
4508         2
4509         --
4510         1
4511         5
4512         4
4513 ---
4514 name: integer-base-6
4515 description:
4516         Even more base stuff
4517         (ksh93 fails this test - prints 0)
4518 stdin:
4519         typeset -i7 i
4520         i=
4521         echo $i
4522 expected-stdout:
4523         7#0
4524 ---
4525 name: integer-base-7
4526 description:
4527         Check that non-integer parameters don't get bases assigned
4528 stdin:
4529         echo $(( zz = 8#100 ))
4530         echo $zz
4531 expected-stdout:
4532         64
4533         64
4534 ---
4535 name: integer-base-check-flat
4536 description:
4537         Check behaviour does not match POSuX (except if set -o posix),
4538         because a not type-safe scripting language has *no* business
4539         interpreting the string "010" as octal numer eight (dangerous).
4540 stdin:
4541         echo 1 "$("$__progname" -c 'echo :$((10))/$((010)),$((0x10)):')" .
4542         echo 2 "$("$__progname" -o posix -c 'echo :$((10))/$((010)),$((0x10)):')" .
4543         echo 3 "$("$__progname" -o sh -c 'echo :$((10))/$((010)),$((0x10)):')" .
4544 expected-stdout:
4545         1 :10/10,16: .
4546         2 :10/8,16: .
4547         3 :10/10,16: .
4548 ---
4549 name: integer-base-check-numeric-from
4550 description:
4551         Check behaviour for base one to 36, and that 37 errors out
4552 stdin:
4553         echo 1:$((1#1))0.
4554         i=1
4555         while (( ++i <= 36 )); do
4556                 eval 'echo '$i':$(('$i'#10)).'
4557         done
4558         echo 37:$($__progname -c 'echo $((37#10))').$?:
4559 expected-stdout:
4560         1:490.
4561         2:2.
4562         3:3.
4563         4:4.
4564         5:5.
4565         6:6.
4566         7:7.
4567         8:8.
4568         9:9.
4569         10:10.
4570         11:11.
4571         12:12.
4572         13:13.
4573         14:14.
4574         15:15.
4575         16:16.
4576         17:17.
4577         18:18.
4578         19:19.
4579         20:20.
4580         21:21.
4581         22:22.
4582         23:23.
4583         24:24.
4584         25:25.
4585         26:26.
4586         27:27.
4587         28:28.
4588         29:29.
4589         30:30.
4590         31:31.
4591         32:32.
4592         33:33.
4593         34:34.
4594         35:35.
4595         36:36.
4596         37:.0:
4597 expected-stderr-pattern:
4598         /.*bad number '37#10'/
4599 ---
4600 name: integer-base-check-numeric-to
4601 description:
4602         Check behaviour for base one to 36, and that 37 errors out
4603 stdin:
4604         i=0
4605         while (( ++i <= 37 )); do
4606                 typeset -Uui$i x=0x40
4607                 eval "typeset -i10 y=$x"
4608                 print $i:$x.$y.
4609         done
4610 expected-stdout:
4611         1:1#@.64.
4612         2:2#1000000.64.
4613         3:3#2101.64.
4614         4:4#1000.64.
4615         5:5#224.64.
4616         6:6#144.64.
4617         7:7#121.64.
4618         8:8#100.64.
4619         9:9#71.64.
4620         10:64.64.
4621         11:11#59.64.
4622         12:12#54.64.
4623         13:13#4C.64.
4624         14:14#48.64.
4625         15:15#44.64.
4626         16:16#40.64.
4627         17:17#3D.64.
4628         18:18#3A.64.
4629         19:19#37.64.
4630         20:20#34.64.
4631         21:21#31.64.
4632         22:22#2K.64.
4633         23:23#2I.64.
4634         24:24#2G.64.
4635         25:25#2E.64.
4636         26:26#2C.64.
4637         27:27#2A.64.
4638         28:28#28.64.
4639         29:29#26.64.
4640         30:30#24.64.
4641         31:31#22.64.
4642         32:32#20.64.
4643         33:33#1V.64.
4644         34:34#1U.64.
4645         35:35#1T.64.
4646         36:36#1S.64.
4647         37:36#1S.64.
4648 expected-stderr-pattern:
4649         /.*bad integer base: 37/
4650 ---
4651 name: integer-arithmetic-span
4652 description:
4653         Check wraparound and size that is defined in mksh
4654 category: int:32
4655 stdin:
4656         echo s:$((2147483647+1)).$(((2147483647*2)+1)).$(((2147483647*2)+2)).
4657         echo u:$((#2147483647+1)).$((#(2147483647*2)+1)).$((#(2147483647*2)+2)).
4658 expected-stdout:
4659         s:-2147483648.-1.0.
4660         u:2147483648.4294967295.0.
4661 ---
4662 name: integer-arithmetic-span-64
4663 description:
4664         Check wraparound and size that is defined in mksh
4665 category: int:64
4666 stdin:
4667         echo s:$((9223372036854775807+1)).$(((9223372036854775807*2)+1)).$(((9223372036854775807*2)+2)).
4668         echo u:$((#9223372036854775807+1)).$((#(9223372036854775807*2)+1)).$((#(9223372036854775807*2)+2)).
4669 expected-stdout:
4670         s:-9223372036854775808.-1.0.
4671         u:9223372036854775808.18446744073709551615.0.
4672 ---
4673 name: integer-size-FAIL-to-detect
4674 description:
4675         Notify the user that their ints are not 32 or 64 bit
4676 category: int:u
4677 stdin:
4678         :
4679 ---
4680 name: lineno-stdin
4681 description:
4682         See if $LINENO is updated and can be modified.
4683 stdin:
4684         echo A $LINENO
4685         echo B $LINENO
4686         LINENO=20
4687         echo C $LINENO
4688 expected-stdout:
4689         A 1
4690         B 2
4691         C 20
4692 ---
4693 name: lineno-inc
4694 description:
4695         See if $LINENO is set for .'d files.
4696 file-setup: file 644 "dotfile"
4697         echo dot A $LINENO
4698         echo dot B $LINENO
4699         LINENO=20
4700         echo dot C $LINENO
4701 stdin:
4702         echo A $LINENO
4703         echo B $LINENO
4704         . ./dotfile
4705 expected-stdout:
4706         A 1
4707         B 2
4708         dot A 1
4709         dot B 2
4710         dot C 20
4711 ---
4712 name: lineno-func
4713 description:
4714         See if $LINENO is set for commands in a function.
4715 stdin:
4716         echo A $LINENO
4717         echo B $LINENO
4718         bar() {
4719             echo func A $LINENO
4720             echo func B $LINENO
4721         }
4722         bar
4723         echo C $LINENO
4724 expected-stdout:
4725         A 1
4726         B 2
4727         func A 4
4728         func B 5
4729         C 8
4730 ---
4731 name: lineno-unset
4732 description:
4733         See if unsetting LINENO makes it non-magic.
4734 file-setup: file 644 "dotfile"
4735         echo dot A $LINENO
4736         echo dot B $LINENO
4737 stdin:
4738         unset LINENO
4739         echo A $LINENO
4740         echo B $LINENO
4741         bar() {
4742             echo func A $LINENO
4743             echo func B $LINENO
4744         }
4745         bar
4746         . ./dotfile
4747         echo C $LINENO
4748 expected-stdout:
4749         A
4750         B
4751         func A
4752         func B
4753         dot A
4754         dot B
4755         C
4756 ---
4757 name: lineno-unset-use
4758 description:
4759         See if unsetting LINENO makes it non-magic even
4760         when it is re-used.
4761 file-setup: file 644 "dotfile"
4762         echo dot A $LINENO
4763         echo dot B $LINENO
4764 stdin:
4765         unset LINENO
4766         LINENO=3
4767         echo A $LINENO
4768         echo B $LINENO
4769         bar() {
4770             echo func A $LINENO
4771             echo func B $LINENO
4772         }
4773         bar
4774         . ./dotfile
4775         echo C $LINENO
4776 expected-stdout:
4777         A 3
4778         B 3
4779         func A 3
4780         func B 3
4781         dot A 3
4782         dot B 3
4783         C 3
4784 ---
4785 name: lineno-trap
4786 description:
4787         Check if LINENO is tracked in traps
4788 stdin:
4789         fail() {
4790                 echo "line <$1>"
4791                 exit 1
4792         }
4793         trap 'fail $LINENO' INT ERR
4794         false
4795 expected-stdout:
4796         line <6>
4797 expected-exit: 1
4798 ---
4799 name: unknown-trap
4800 description:
4801         Ensure unknown traps are not a syntax error
4802 stdin:
4803         (
4804         trap "echo trap 1 executed" UNKNOWNSIGNAL || echo "foo"
4805         echo =1
4806         trap "echo trap 2 executed" UNKNOWNSIGNAL EXIT 999999 FNORD
4807         echo = $?
4808         ) 2>&1 | sed "s\ 1^${__progname%.exe}\.*e*x*e*: <stdin>\[[0-9]*]\ 1PROG\ 1"
4809 expected-stdout:
4810         PROG: trap: bad signal 'UNKNOWNSIGNAL'
4811         foo
4812         =1
4813         PROG: trap: bad signal 'UNKNOWNSIGNAL'
4814         PROG: trap: bad signal '999999'
4815         PROG: trap: bad signal 'FNORD'
4816         = 3
4817         trap 2 executed
4818 ---
4819 name: read-IFS-1
4820 description:
4821         Simple test, default IFS
4822 stdin:
4823         echo "A B " > IN
4824         unset x y z
4825         read x y z < IN
4826         echo 1: "x[$x] y[$y] z[$z]"
4827         echo 1a: ${z-z not set}
4828         read x < IN
4829         echo 2: "x[$x]"
4830 expected-stdout:
4831         1: x[A] y[B] z[]
4832         1a:
4833         2: x[A B]
4834 ---
4835 name: read-ksh-1
4836 description:
4837         If no var specified, REPLY is used
4838 stdin:
4839         echo "abc" > IN
4840         read < IN
4841         echo "[$REPLY]";
4842 expected-stdout:
4843         [abc]
4844 ---
4845 name: read-regress-1
4846 description:
4847         Check a regression of read
4848 file-setup: file 644 "foo"
4849         foo bar
4850         baz
4851         blah
4852 stdin:
4853         while read a b c; do
4854                 read d
4855                 break
4856         done <foo
4857         echo "<$a|$b|$c><$d>"
4858 expected-stdout:
4859         <foo|bar|><baz>
4860 ---
4861 name: read-delim-1
4862 description:
4863         Check read with delimiters
4864 stdin:
4865         emit() {
4866                 print -n 'foo bar\tbaz\nblah \0blub\tblech\nmyok meck \0'
4867         }
4868         emit | while IFS= read -d "" foo; do print -r -- "<$foo>"; done
4869         emit | while read -d "" foo; do print -r -- "<$foo>"; done
4870         emit | while read -d "eh?" foo; do print -r -- "<$foo>"; done
4871 expected-stdout:
4872         <foo bar        baz
4873         blah >
4874         <blub   blech
4875         myok meck >
4876         <foo bar        baz
4877         blah>
4878         <blub   blech
4879         myok meck>
4880         <foo bar        baz
4881         blah blub       bl>
4882         <ch
4883         myok m>
4884 ---
4885 name: read-ext-1
4886 description:
4887         Check read with number of bytes specified, and -A
4888 stdin:
4889         print 'foo\nbar' >x1
4890         print -n x >x2
4891         print 'foo\\ bar baz' >x3
4892         x1a=u; read x1a <x1
4893         x1b=u; read -N-1 x1b <x1
4894         x2a=u; read x2a <x2; r2a=$?
4895         x2b=u; read -N2 x2c <x2; r2b=$?
4896         x2c=u; read -n2 x2c <x2; r2c=$?
4897         x3a=u; read -A x3a <x3
4898         print -r "x1a=<$x1a>"
4899         print -r "x1b=<$x1b>"
4900         print -r "x2a=$r2a<$x2a>"
4901         print -r "x2b=$r2b<$x2b>"
4902         print -r "x2c=$r2c<$x2c>"
4903         print -r "x3a=<${x3a[0]}|${x3a[1]}|${x3a[2]}>"
4904 expected-stdout:
4905         x1a=<foo>
4906         x1b=<foo
4907         bar>
4908         x2a=1<x>
4909         x2b=1<u>
4910         x2c=0<x>
4911         x3a=<foo bar|baz|>
4912 ---
4913 name: regression-1
4914 description:
4915         Lex array code had problems with this.
4916 stdin:
4917         echo foo[
4918         n=bar
4919         echo "hi[ $n ]=1"
4920 expected-stdout:
4921         foo[
4922         hi[ bar ]=1
4923 ---
4924 name: regression-2
4925 description:
4926         When PATH is set before running a command, the new path is
4927         not used in doing the path search
4928                 $ echo echo hi > /tmp/q ; chmod a+rx /tmp/q
4929                 $ PATH=/tmp q
4930                 q: not found
4931                 $
4932         in comexec() the two lines
4933                 while (*vp != NULL)
4934                         (void) typeset(*vp++, xxx, 0);
4935         need to be moved out of the switch to before findcom() is
4936         called - I don't know what this will break.
4937 stdin:
4938         : ${PWD:-`pwd 2> /dev/null`}
4939         : ${PWD:?"PWD not set - can't do test"}
4940         mkdir Y
4941         cat > Y/xxxscript << EOF
4942         #!/bin/sh
4943         # Need to restore path so echo can be found (some shells don't have
4944         # it as a built-in)
4945         PATH=\$OLDPATH
4946         echo hi
4947         exit 0
4948         EOF
4949         chmod a+rx Y/xxxscript
4950         export OLDPATH="$PATH"
4951         PATH=$PWD/Y xxxscript
4952         exit $?
4953 expected-stdout:
4954         hi
4955 ---
4956 name: regression-6
4957 description:
4958         Parsing of $(..) expressions is non-optimal.  It is
4959         impossible to have any parentheses inside the expression.
4960         I.e.,
4961                 $ ksh -c 'echo $(echo \( )'
4962                 no closing quote
4963                 $ ksh -c 'echo $(echo "(" )'
4964                 no closing quote
4965                 $
4966         The solution is to hack the parsing clode in lex.c, the
4967         question is how to hack it: should any parentheses be
4968         escaped by a backslash, or should recursive parsing be done
4969         (so quotes could also be used to hide hem).  The former is
4970         easier, the later better...
4971 stdin:
4972         echo $(echo \( )
4973         echo $(echo "(" )
4974 expected-stdout:
4975         (
4976         (
4977 ---
4978 name: regression-9
4979 description:
4980         Continue in a for loop does not work right:
4981                 for i in a b c ; do
4982                         if [ $i = b ] ; then
4983                                 continue
4984                         fi
4985                         echo $i
4986                 done
4987         Prints a forever...
4988 stdin:
4989         first=yes
4990         for i in a b c ; do
4991                 if [ $i = b ] ; then
4992                         if [ $first = no ] ; then
4993                                 echo 'continue in for loop broken'
4994                                 break   # hope break isn't broken too :-)
4995                         fi
4996                         first=no
4997                         continue
4998                 fi
4999         done
5000         echo bye
5001 expected-stdout:
5002         bye
5003 ---
5004 name: regression-10
5005 description:
5006         The following:
5007                 set -- `false`
5008                 echo $?
5009         should print 0 according to POSIX (dash, bash, ksh93, posh)
5010         but not 0 according to the getopt(1) manual page, ksh88, and
5011         Bourne sh (such as /bin/sh on Solaris).
5012         We honour POSIX except when -o sh is set.
5013 category: shell:legacy-no
5014 stdin:
5015         showf() {
5016                 [[ -o posix ]]; FPOSIX=$((1-$?))
5017                 [[ -o sh ]]; FSH=$((1-$?))
5018                 echo -n "FPOSIX=$FPOSIX FSH=$FSH "
5019         }
5020         set +o posix +o sh
5021         showf
5022         set -- `false`
5023         echo rv=$?
5024         set -o sh
5025         showf
5026         set -- `false`
5027         echo rv=$?
5028         set -o posix
5029         showf
5030         set -- `false`
5031         echo rv=$?
5032         set -o posix -o sh
5033         showf
5034         set -- `false`
5035         echo rv=$?
5036 expected-stdout:
5037         FPOSIX=0 FSH=0 rv=0
5038         FPOSIX=0 FSH=1 rv=1
5039         FPOSIX=1 FSH=0 rv=0
5040         FPOSIX=1 FSH=1 rv=0
5041 ---
5042 name: regression-10-legacy
5043 description:
5044         The following:
5045                 set -- `false`
5046                 echo $?
5047         should print 0 according to POSIX (dash, bash, ksh93, posh)
5048         but not 0 according to the getopt(1) manual page, ksh88, and
5049         Bourne sh (such as /bin/sh on Solaris).
5050 category: shell:legacy-yes
5051 stdin:
5052         showf() {
5053                 [[ -o posix ]]; FPOSIX=$((1-$?))
5054                 [[ -o sh ]]; FSH=$((1-$?))
5055                 echo -n "FPOSIX=$FPOSIX FSH=$FSH "
5056         }
5057         set +o posix +o sh
5058         showf
5059         set -- `false`
5060         echo rv=$?
5061         set -o sh
5062         showf
5063         set -- `false`
5064         echo rv=$?
5065         set -o posix
5066         showf
5067         set -- `false`
5068         echo rv=$?
5069         set -o posix -o sh
5070         showf
5071         set -- `false`
5072         echo rv=$?
5073 expected-stdout:
5074         FPOSIX=0 FSH=0 rv=1
5075         FPOSIX=0 FSH=1 rv=1
5076         FPOSIX=1 FSH=0 rv=0
5077         FPOSIX=1 FSH=1 rv=0
5078 ---
5079 name: regression-11
5080 description:
5081         The following:
5082                 x=/foo/bar/blah
5083                 echo ${x##*/}
5084         should echo blah but on some machines echos /foo/bar/blah.
5085 stdin:
5086         x=/foo/bar/blah
5087         echo ${x##*/}
5088 expected-stdout:
5089         blah
5090 ---
5091 name: regression-12
5092 description:
5093         Both of the following echos produce the same output under sh/ksh.att:
5094                 #!/bin/sh
5095                 x="foo  bar"
5096                 echo "`echo \"$x\"`"
5097                 echo "`echo "$x"`"
5098         pdksh produces different output for the former (foo instead of foo\tbar)
5099 stdin:
5100         x="foo  bar"
5101         echo "`echo \"$x\"`"
5102         echo "`echo "$x"`"
5103 expected-stdout:
5104         foo     bar
5105         foo     bar
5106 ---
5107 name: regression-13
5108 description:
5109         The following command hangs forever:
5110                 $ (: ; cat /etc/termcap) | sleep 2
5111         This is because the shell forks a shell to run the (..) command
5112         and this shell has the pipe open.  When the sleep dies, the cat
5113         doesn't get a SIGPIPE 'cause a process (ie, the second shell)
5114         still has the pipe open.
5115         
5116         NOTE: this test provokes a bizarre bug in ksh93 (shell starts reading
5117               commands from /etc/termcap..)
5118 time-limit: 10
5119 stdin:
5120         echo A line of text that will be duplicated quite a number of times.> t1
5121         cat t1 t1 t1 t1  t1 t1 t1 t1  t1 t1 t1 t1  t1 t1 t1 t1  > t2
5122         cat t2 t2 t2 t2  t2 t2 t2 t2  t2 t2 t2 t2  t2 t2 t2 t2  > t1
5123         cat t1 t1 t1 t1 > t2
5124         (: ; cat t2 2>/dev/null) | sleep 1
5125 ---
5126 name: regression-14
5127 description:
5128         The command
5129                 $ (foobar) 2> /dev/null
5130         generates no output under /bin/sh, but pdksh produces the error
5131                 foobar: not found
5132         Also, the command
5133                 $ foobar 2> /dev/null
5134         generates an error under /bin/sh and pdksh, but AT&T ksh88 produces
5135         no error (redirected to /dev/null).
5136 stdin:
5137         (you/should/not/see/this/error/1) 2> /dev/null
5138         you/should/not/see/this/error/2 2> /dev/null
5139         true
5140 ---
5141 name: regression-15
5142 description:
5143         The command
5144                 $ whence foobar
5145         generates a blank line under pdksh and sets the exit status to 0.
5146         AT&T ksh88 generates no output and sets the exit status to 1.  Also,
5147         the command
5148                 $ whence foobar cat
5149         generates no output under AT&T ksh88 (pdksh generates a blank line
5150         and /bin/cat).
5151 stdin:
5152         whence does/not/exist > /dev/null
5153         echo 1: $?
5154         echo 2: $(whence does/not/exist | wc -l)
5155         echo 3: $(whence does/not/exist cat | wc -l)
5156 expected-stdout:
5157         1: 1
5158         2: 0
5159         3: 0
5160 ---
5161 name: regression-16
5162 description:
5163         ${var%%expr} seems to be broken in many places.  On the mips
5164         the commands
5165                 $ read line < /etc/passwd
5166                 $ echo $line
5167                 root:0:1:...
5168                 $ echo ${line%%:*}
5169                 root
5170                 $ echo $line
5171                 root
5172                 $
5173         change the value of line.  On sun4s & pas, the echo ${line%%:*} doesn't
5174         work.  Haven't checked elsewhere...
5175 script:
5176         read x
5177         y=$x
5178         echo ${x%%:*}
5179         echo $x
5180 stdin:
5181         root:asdjhasdasjhs:0:1:Root:/:/bin/sh
5182 expected-stdout:
5183         root
5184         root:asdjhasdasjhs:0:1:Root:/:/bin/sh
5185 ---
5186 name: regression-17
5187 description:
5188         The command
5189                 . /foo/bar
5190         should set the exit status to non-zero (sh and AT&T ksh88 do).
5191         XXX doting a non existent file is a fatal error for a script
5192 stdin:
5193         . does/not/exist
5194 expected-exit: e != 0
5195 expected-stderr-pattern: /.?/
5196 ---
5197 name: regression-19
5198 description:
5199         Both of the following echos should produce the same thing, but don't:
5200                 $ x=foo/bar
5201                 $ echo ${x%/*}
5202                 foo
5203                 $ echo "${x%/*}"
5204                 foo/bar
5205 stdin:
5206         x=foo/bar
5207         echo "${x%/*}"
5208 expected-stdout:
5209         foo
5210 ---
5211 name: regression-21
5212 description:
5213         backslash does not work as expected in case labels:
5214         $ x='-x'
5215         $ case $x in
5216         -\?) echo hi
5217         esac
5218         hi
5219         $ x='-?'
5220         $ case $x in
5221         -\\?) echo hi
5222         esac
5223         hi
5224         $
5225 stdin:
5226         case -x in
5227         -\?)    echo fail
5228         esac
5229 ---
5230 name: regression-22
5231 description:
5232         Quoting backquotes inside backquotes doesn't work:
5233         $ echo `echo hi \`echo there\` folks`
5234         asks for more info.  sh and AT&T ksh88 both echo
5235         hi there folks
5236 stdin:
5237         echo `echo hi \`echo there\` folks`
5238 expected-stdout:
5239         hi there folks
5240 ---
5241 name: regression-23
5242 description:
5243         )) is not treated `correctly':
5244             $ (echo hi ; (echo there ; echo folks))
5245             missing ((
5246             $
5247         instead of (as sh and ksh.att)
5248             $ (echo hi ; (echo there ; echo folks))
5249             hi
5250             there
5251             folks
5252             $
5253 stdin:
5254         ( : ; ( : ; echo hi))
5255 expected-stdout:
5256         hi
5257 ---
5258 name: regression-25
5259 description:
5260         Check reading stdin in a while loop.  The read should only read
5261         a single line, not a whole stdio buffer; the cat should get
5262         the rest.
5263 stdin:
5264         (echo a; echo b) | while read x ; do
5265             echo $x
5266             cat > /dev/null
5267         done
5268 expected-stdout:
5269         a
5270 ---
5271 name: regression-26
5272 description:
5273         Check reading stdin in a while loop.  The read should read both
5274         lines, not just the first.
5275 script:
5276         a=
5277         while [ "$a" != xxx ] ; do
5278             last=$x
5279             read x
5280             cat /dev/null | sed 's/x/y/'
5281             a=x$a
5282         done
5283         echo $last
5284 stdin:
5285         a
5286         b
5287 expected-stdout:
5288         b
5289 ---
5290 name: regression-27
5291 description:
5292         The command
5293                 . /does/not/exist
5294         should cause a script to exit.
5295 stdin:
5296         . does/not/exist
5297         echo hi
5298 expected-exit: e != 0
5299 expected-stderr-pattern: /does\/not\/exist/
5300 ---
5301 name: regression-28
5302 description:
5303         variable assignements not detected well
5304 stdin:
5305         a.x=1 echo hi
5306 expected-exit: e != 0
5307 expected-stderr-pattern: /a\.x=1/
5308 ---
5309 name: regression-29
5310 description:
5311         alias expansion different from AT&T ksh88
5312 stdin:
5313         alias a='for ' b='i in'
5314         a b hi ; do echo $i ; done
5315 expected-stdout:
5316         hi
5317 ---
5318 name: regression-30
5319 description:
5320         strange characters allowed inside ${...}
5321 stdin:
5322         echo ${a{b}}
5323 expected-exit: e != 0
5324 expected-stderr-pattern: /.?/
5325 ---
5326 name: regression-31
5327 description:
5328         Does read handle partial lines correctly
5329 script:
5330         a= ret=
5331         while [ "$a" != xxx ] ; do
5332             read x y z
5333             ret=$?
5334             a=x$a
5335         done
5336         echo "[$x]"
5337         echo $ret
5338 stdin: !
5339         a A aA
5340         b B Bb
5341         c
5342 expected-stdout:
5343         [c]
5344         1
5345 ---
5346 name: regression-32
5347 description:
5348         Does read set variables to null at eof?
5349 script:
5350         a=
5351         while [ "$a" != xxx ] ; do
5352             read x y z
5353             a=x$a
5354         done
5355         echo 1: ${x-x not set} ${y-y not set} ${z-z not set}
5356         echo 2: ${x:+x not null} ${y:+y not null} ${z:+z not null}
5357 stdin:
5358         a A Aa
5359         b B Bb
5360 expected-stdout:
5361         1:
5362         2:
5363 ---
5364 name: regression-33
5365 description:
5366         Does umask print a leading 0 when umask is 3 digits?
5367 stdin:
5368         # on MiNT, the first umask call seems to fail
5369         umask 022
5370         # now, the test proper
5371         umask 222
5372         umask
5373 expected-stdout:
5374         0222
5375 ---
5376 name: regression-35
5377 description:
5378         Tempory files used for here-docs in functions get trashed after
5379         the function is parsed (before it is executed)
5380 stdin:
5381         f1() {
5382                 cat <<- EOF
5383                         F1
5384                 EOF
5385                 f2() {
5386                         cat <<- EOF
5387                                 F2
5388                         EOF
5389                 }
5390         }
5391         f1
5392         f2
5393         unset -f f1
5394         f2
5395 expected-stdout:
5396         F1
5397         F2
5398         F2
5399 ---
5400 name: regression-36
5401 description:
5402         Command substitution breaks reading in while loop
5403         (test from <sjg@void.zen.oz.au>)
5404 stdin:
5405         (echo abcdef; echo; echo 123) |
5406             while read line
5407             do
5408               # the following line breaks it
5409               c=`echo $line | wc -c`
5410               echo $c
5411             done
5412 expected-stdout:
5413         7
5414         1
5415         4
5416 ---
5417 name: regression-37
5418 description:
5419         Machines with broken times() (reported by <sjg@void.zen.oz.au>)
5420         time does not report correct real time
5421 stdin:
5422         time sleep 1
5423 expected-stderr-pattern: !/^\s*0\.0[\s\d]+real|^\s*real[\s]+0+\.0/
5424 ---
5425 name: regression-38
5426 description:
5427         set -e doesn't ignore exit codes for if/while/until/&&/||/!.
5428 arguments: !-e!
5429 stdin:
5430         if false; then echo hi ; fi
5431         false || true
5432         false && true
5433         while false; do echo hi; done
5434         echo ok
5435 expected-stdout:
5436         ok
5437 ---
5438 name: regression-39
5439 description:
5440         Only posh and oksh(2013-07) say “hi” below; FreeBSD sh,
5441         GNU bash in POSIX mode, dash, ksh93, mksh don’t. All of
5442         them exit 0. The POSIX behaviour is needed by BSD make.
5443 stdin:
5444         set -e
5445         echo `false; echo hi` $(<this-file-does-not-exist)
5446         echo $?
5447 expected-stdout:
5448         
5449         0
5450 expected-stderr-pattern: /this-file-does-not-exist/
5451 ---
5452 name: regression-40
5453 description:
5454         This used to cause a core dump
5455 env-setup: !RANDOM=12!
5456 stdin:
5457         echo hi
5458 expected-stdout:
5459         hi
5460 ---
5461 name: regression-41
5462 description:
5463         foo should be set to bar (should not be empty)
5464 stdin:
5465         foo=`
5466         echo bar`
5467         echo "($foo)"
5468 expected-stdout:
5469         (bar)
5470 ---
5471 name: regression-42
5472 description:
5473         Can't use command line assignments to assign readonly parameters.
5474 stdin:
5475         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
5476             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
5477             done >env; chmod +x env; PATH=.:$PATH
5478         foo=bar
5479         readonly foo
5480         foo=stuff env | grep '^foo'
5481 expected-exit: e != 0
5482 expected-stderr-pattern:
5483         /read-only/
5484 ---
5485 name: regression-43
5486 description:
5487         Can subshells be prefixed by redirections (historical shells allow
5488         this)
5489 stdin:
5490         < /dev/null (sed 's/^/X/')
5491 ---
5492 name: regression-45
5493 description:
5494         Parameter assignments with [] recognised correctly
5495 stdin:
5496         FOO=*[12]
5497         BAR=abc[
5498         MORE=[abc]
5499         JUNK=a[bc
5500         echo "<$FOO>"
5501         echo "<$BAR>"
5502         echo "<$MORE>"
5503         echo "<$JUNK>"
5504 expected-stdout:
5505         <*[12]>
5506         <abc[>
5507         <[abc]>
5508         <a[bc>
5509 ---
5510 name: regression-46
5511 description:
5512         Check that alias expansion works in command substitutions and
5513         at the end of file.
5514 stdin:
5515         alias x='echo hi'
5516         FOO="`x` "
5517         echo "[$FOO]"
5518         x
5519 expected-stdout:
5520         [hi ]
5521         hi
5522 ---
5523 name: regression-47
5524 description:
5525         Check that aliases are fully read.
5526 stdin:
5527         alias x='echo hi;
5528         echo there'
5529         x
5530         echo done
5531 expected-stdout:
5532         hi
5533         there
5534         done
5535 ---
5536 name: regression-48
5537 description:
5538         Check that (here doc) temp files are not left behind after an exec.
5539 stdin:
5540         mkdir foo || exit 1
5541         TMPDIR=$PWD/foo "$__progname" <<- 'EOF'
5542                 x() {
5543                         sed 's/^/X /' << E_O_F
5544                         hi
5545                         there
5546                         folks
5547                         E_O_F
5548                         echo "done ($?)"
5549                 }
5550                 echo=echo; [ -x /bin/echo ] && echo=/bin/echo
5551                 exec $echo subtest-1 hi
5552         EOF
5553         echo subtest-1 foo/*
5554         TMPDIR=$PWD/foo "$__progname" <<- 'EOF'
5555                 echo=echo; [ -x /bin/echo ] && echo=/bin/echo
5556                 sed 's/^/X /' << E_O_F; exec $echo subtest-2 hi
5557                 a
5558                 few
5559                 lines
5560                 E_O_F
5561         EOF
5562         echo subtest-2 foo/*
5563 expected-stdout:
5564         subtest-1 hi
5565         subtest-1 foo/*
5566         X a
5567         X few
5568         X lines
5569         subtest-2 hi
5570         subtest-2 foo/*
5571 ---
5572 name: regression-49
5573 description:
5574         Check that unset params with attributes are reported by set, those
5575         sans attributes are not.
5576 stdin:
5577         unset FOO BAR
5578         echo X$FOO
5579         export BAR
5580         typeset -i BLAH
5581         set | grep FOO
5582         set | grep BAR
5583         set | grep BLAH
5584 expected-stdout:
5585         X
5586         BAR
5587         BLAH
5588 ---
5589 name: regression-50
5590 description:
5591         Check that aliases do not use continuation prompt after trailing
5592         semi-colon.
5593 file-setup: file 644 "envf"
5594         PS1=Y
5595         PS2=X
5596 env-setup: !ENV=./envf!
5597 need-ctty: yes
5598 arguments: !-i!
5599 stdin:
5600         alias foo='echo hi ; '
5601         foo
5602         foo echo there
5603 expected-stdout:
5604         hi
5605         hi
5606         there
5607 expected-stderr: !
5608         YYYY
5609 ---
5610 name: regression-51
5611 description:
5612         Check that set allows both +o and -o options on same command line.
5613 stdin:
5614         set a b c
5615         set -o noglob +o allexport
5616         echo A: $*, *
5617 expected-stdout:
5618         A: a b c, *
5619 ---
5620 name: regression-52
5621 description:
5622         Check that globbing works in pipelined commands
5623 file-setup: file 644 "envf"
5624         PS1=P
5625 file-setup: file 644 "abc"
5626         stuff
5627 env-setup: !ENV=./envf!
5628 need-ctty: yes
5629 arguments: !-i!
5630 stdin:
5631         sed 's/^/X /' < ab*
5632         echo mark 1
5633         sed 's/^/X /' < ab* | sed 's/^/Y /'
5634         echo mark 2
5635 expected-stdout:
5636         X stuff
5637         mark 1
5638         Y X stuff
5639         mark 2
5640 expected-stderr: !
5641         PPPPP
5642 ---
5643 name: regression-53
5644 description:
5645         Check that getopts works in functions
5646 stdin:
5647         bfunc() {
5648             echo bfunc: enter "(args: $*; OPTIND=$OPTIND)"
5649             while getopts B oc; do
5650                 case $oc in
5651                   (B)
5652                     echo bfunc: B option
5653                     ;;
5654                   (*)
5655                     echo bfunc: odd option "($oc)"
5656                     ;;
5657                 esac
5658             done
5659             echo bfunc: leave
5660         }
5661         
5662         function kfunc {
5663             echo kfunc: enter "(args: $*; OPTIND=$OPTIND)"
5664             while getopts K oc; do
5665                 case $oc in
5666                   (K)
5667                     echo kfunc: K option
5668                     ;;
5669                   (*)
5670                     echo bfunc: odd option "($oc)"
5671                     ;;
5672                 esac
5673             done
5674             echo kfunc: leave
5675         }
5676         
5677         set -- -f -b -k -l
5678         echo "line 1: OPTIND=$OPTIND"
5679         getopts kbfl optc
5680         echo "line 2: ret=$?, optc=$optc, OPTIND=$OPTIND"
5681         bfunc -BBB blah
5682         echo "line 3: OPTIND=$OPTIND"
5683         getopts kbfl optc
5684         echo "line 4: ret=$?, optc=$optc, OPTIND=$OPTIND"
5685         kfunc -KKK blah
5686         echo "line 5: OPTIND=$OPTIND"
5687         getopts kbfl optc
5688         echo "line 6: ret=$?, optc=$optc, OPTIND=$OPTIND"
5689         echo
5690         
5691         OPTIND=1
5692         set -- -fbkl
5693         echo "line 10: OPTIND=$OPTIND"
5694         getopts kbfl optc
5695         echo "line 20: ret=$?, optc=$optc, OPTIND=$OPTIND"
5696         bfunc -BBB blah
5697         echo "line 30: OPTIND=$OPTIND"
5698         getopts kbfl optc
5699         echo "line 40: ret=$?, optc=$optc, OPTIND=$OPTIND"
5700         kfunc -KKK blah
5701         echo "line 50: OPTIND=$OPTIND"
5702         getopts kbfl optc
5703         echo "line 60: ret=$?, optc=$optc, OPTIND=$OPTIND"
5704 expected-stdout:
5705         line 1: OPTIND=1
5706         line 2: ret=0, optc=f, OPTIND=2
5707         bfunc: enter (args: -BBB blah; OPTIND=2)
5708         bfunc: B option
5709         bfunc: B option
5710         bfunc: leave
5711         line 3: OPTIND=2
5712         line 4: ret=0, optc=b, OPTIND=3
5713         kfunc: enter (args: -KKK blah; OPTIND=1)
5714         kfunc: K option
5715         kfunc: K option
5716         kfunc: K option
5717         kfunc: leave
5718         line 5: OPTIND=3
5719         line 6: ret=0, optc=k, OPTIND=4
5720         
5721         line 10: OPTIND=1
5722         line 20: ret=0, optc=f, OPTIND=2
5723         bfunc: enter (args: -BBB blah; OPTIND=2)
5724         bfunc: B option
5725         bfunc: B option
5726         bfunc: leave
5727         line 30: OPTIND=2
5728         line 40: ret=1, optc=?, OPTIND=2
5729         kfunc: enter (args: -KKK blah; OPTIND=1)
5730         kfunc: K option
5731         kfunc: K option
5732         kfunc: K option
5733         kfunc: leave
5734         line 50: OPTIND=2
5735         line 60: ret=1, optc=?, OPTIND=2
5736 ---
5737 name: regression-54
5738 description:
5739         Check that ; is not required before the then in if (( ... )) then ...
5740 stdin:
5741         if (( 1 )) then
5742             echo ok dparen
5743         fi
5744         if [[ -n 1 ]] then
5745             echo ok dbrackets
5746         fi
5747 expected-stdout:
5748         ok dparen
5749         ok dbrackets
5750 ---
5751 name: regression-55
5752 description:
5753         Check ${foo:%bar} is allowed (ksh88 allows it...)
5754 stdin:
5755         x=fooXbarXblah
5756         echo 1 ${x%X*}
5757         echo 2 ${x:%X*}
5758         echo 3 ${x%%X*}
5759         echo 4 ${x:%%X*}
5760         echo 5 ${x#*X}
5761         echo 6 ${x:#*X}
5762         echo 7 ${x##*X}
5763         echo 8 ${x:##*X}
5764 expected-stdout:
5765         1 fooXbar
5766         2 fooXbar
5767         3 foo
5768         4 foo
5769         5 barXblah
5770         6 barXblah
5771         7 blah
5772         8 blah
5773 ---
5774 name: regression-57
5775 description:
5776         Check if typeset output is correct for
5777         uninitialised array elements.
5778 stdin:
5779         typeset -i xxx[4]
5780         echo A
5781         typeset -i | grep xxx | sed 's/^/    /'
5782         echo B
5783         typeset | grep xxx | sed 's/^/    /'
5784         
5785         xxx[1]=2+5
5786         echo M
5787         typeset -i | grep xxx | sed 's/^/    /'
5788         echo N
5789         typeset | grep xxx | sed 's/^/    /'
5790 expected-stdout:
5791         A
5792             xxx
5793         B
5794             typeset -i xxx
5795         M
5796             xxx[1]=7
5797         N
5798             set -A xxx
5799             typeset -i xxx[1]
5800 ---
5801 name: regression-58
5802 description:
5803         Check if trap exit is ok (exit not mistaken for signal name)
5804 stdin:
5805         trap 'echo hi' exit
5806         trap exit 1
5807 expected-stdout:
5808         hi
5809 ---
5810 name: regression-59
5811 description:
5812         Check if ${#array[*]} is calculated correctly.
5813 stdin:
5814         a[12]=hi
5815         a[8]=there
5816         echo ${#a[*]}
5817 expected-stdout:
5818         2
5819 ---
5820 name: regression-60
5821 description:
5822         Check if default exit status is previous command
5823 stdin:
5824         (true; exit)
5825         echo A $?
5826         (false; exit)
5827         echo B $?
5828         ( (exit 103) ; exit)
5829         echo C $?
5830 expected-stdout:
5831         A 0
5832         B 1
5833         C 103
5834 ---
5835 name: regression-61
5836 description:
5837         Check if EXIT trap is executed for sub shells.
5838 stdin:
5839         trap 'echo parent exit' EXIT
5840         echo start
5841         (echo A; echo A last)
5842         echo B
5843         (echo C; trap 'echo sub exit' EXIT; echo C last)
5844         echo parent last
5845 expected-stdout:
5846         start
5847         A
5848         A last
5849         B
5850         C
5851         C last
5852         sub exit
5853         parent last
5854         parent exit
5855 ---
5856 name: regression-62
5857 description:
5858         Check if test -nt/-ot succeeds if second(first) file is missing.
5859 stdin:
5860         touch a
5861         test a -nt b && echo nt OK || echo nt BAD
5862         test b -ot a && echo ot OK || echo ot BAD
5863 expected-stdout:
5864         nt OK
5865         ot OK
5866 ---
5867 name: regression-63
5868 description:
5869         Check if typeset, export, and readonly work
5870 stdin:
5871         {
5872                 echo FNORD-0
5873                 FNORD_A=1
5874                 FNORD_B=2
5875                 FNORD_C=3
5876                 FNORD_D=4
5877                 FNORD_E=5
5878                 FNORD_F=6
5879                 FNORD_G=7
5880                 FNORD_H=8
5881                 integer FNORD_E FNORD_F FNORD_G FNORD_H
5882                 export FNORD_C FNORD_D FNORD_G FNORD_H
5883                 readonly FNORD_B FNORD_D FNORD_F FNORD_H
5884                 echo FNORD-1
5885                 export
5886                 echo FNORD-2
5887                 export -p
5888                 echo FNORD-3
5889                 readonly
5890                 echo FNORD-4
5891                 readonly -p
5892                 echo FNORD-5
5893                 typeset
5894                 echo FNORD-6
5895                 typeset -p
5896                 echo FNORD-7
5897                 typeset -
5898                 echo FNORD-8
5899         } | fgrep FNORD
5900         fnord=(42 23)
5901         typeset -p fnord
5902         echo FNORD-9
5903 expected-stdout:
5904         FNORD-0
5905         FNORD-1
5906         FNORD_C
5907         FNORD_D
5908         FNORD_G
5909         FNORD_H
5910         FNORD-2
5911         export FNORD_C=3
5912         export FNORD_D=4
5913         export FNORD_G=7
5914         export FNORD_H=8
5915         FNORD-3
5916         FNORD_B
5917         FNORD_D
5918         FNORD_F
5919         FNORD_H
5920         FNORD-4
5921         readonly FNORD_B=2
5922         readonly FNORD_D=4
5923         readonly FNORD_F=6
5924         readonly FNORD_H=8
5925         FNORD-5
5926         typeset FNORD_A
5927         typeset -r FNORD_B
5928         typeset -x FNORD_C
5929         typeset -x -r FNORD_D
5930         typeset -i FNORD_E
5931         typeset -i -r FNORD_F
5932         typeset -i -x FNORD_G
5933         typeset -i -x -r FNORD_H
5934         FNORD-6
5935         typeset FNORD_A=1
5936         typeset -r FNORD_B=2
5937         typeset -x FNORD_C=3
5938         typeset -x -r FNORD_D=4
5939         typeset -i FNORD_E=5
5940         typeset -i -r FNORD_F=6
5941         typeset -i -x FNORD_G=7
5942         typeset -i -x -r FNORD_H=8
5943         FNORD-7
5944         FNORD_A=1
5945         FNORD_B=2
5946         FNORD_C=3
5947         FNORD_D=4
5948         FNORD_E=5
5949         FNORD_F=6
5950         FNORD_G=7
5951         FNORD_H=8
5952         FNORD-8
5953         set -A fnord
5954         typeset fnord[0]=42
5955         typeset fnord[1]=23
5956         FNORD-9
5957 ---
5958 name: regression-64
5959 description:
5960         Check that we can redefine functions calling time builtin
5961 stdin:
5962         t() {
5963                 time >/dev/null
5964         }
5965         t 2>/dev/null
5966         t() {
5967                 time
5968         }
5969 ---
5970 name: regression-65
5971 description:
5972         check for a regression with sleep builtin and signal mask
5973 category: !nojsig
5974 time-limit: 3
5975 stdin:
5976         sleep 1
5977         echo blub |&
5978         while read -p line; do :; done
5979         echo ok
5980 expected-stdout:
5981         ok
5982 ---
5983 name: regression-66
5984 description:
5985         Check that quoting is sane
5986 category: !nojsig
5987 stdin:
5988         ac_space=' '
5989         ac_newline='
5990         '
5991         set | grep ^ac_ |&
5992         set -A lines
5993         while IFS= read -pr line; do
5994                 if [[ $line = *space* ]]; then
5995                         lines[0]=$line
5996                 else
5997                         lines[1]=$line
5998                 fi
5999         done
6000         for line in "${lines[@]}"; do
6001                 print -r -- "$line"
6002         done
6003 expected-stdout:
6004         ac_space=' '
6005         ac_newline=$'\n'
6006 ---
6007 name: readonly-0
6008 description:
6009         Ensure readonly is honoured for assignments and unset
6010 stdin:
6011         "$__progname" -c 'u=x; echo $? $u .' || echo aborted, $?
6012         echo =
6013         "$__progname" -c 'readonly u; u=x; echo $? $u .' || echo aborted, $?
6014         echo =
6015         "$__progname" -c 'u=x; readonly u; unset u; echo $? $u .' || echo aborted, $?
6016 expected-stdout:
6017         0 x .
6018         =
6019         aborted, 2
6020         =
6021         1 x .
6022 expected-stderr-pattern:
6023         /read-only/
6024 ---
6025 name: readonly-1
6026 description:
6027         http://austingroupbugs.net/view.php?id=367 for export
6028 stdin:
6029         "$__progname" -c 'readonly foo; export foo=a; echo $?' || echo aborted, $?
6030 expected-stdout:
6031         aborted, 2
6032 expected-stderr-pattern:
6033         /read-only/
6034 ---
6035 name: readonly-2a
6036 description:
6037         Check that getopts works as intended, for readonly-2b to be valid
6038 stdin:
6039         "$__progname" -c 'set -- -a b; getopts a c; echo $? $c .; getopts a c; echo $? $c .' || echo aborted, $?
6040 expected-stdout:
6041         0 a .
6042         1 ? .
6043 ---
6044 name: readonly-2b
6045 description:
6046         http://austingroupbugs.net/view.php?id=367 for getopts
6047 stdin:
6048         "$__progname" -c 'readonly c; set -- -a b; getopts a c; echo $? $c .' || echo aborted, $?
6049 expected-stdout:
6050         2 .
6051 expected-stderr-pattern:
6052         /read-only/
6053 ---
6054 name: readonly-3
6055 description:
6056         http://austingroupbugs.net/view.php?id=367 for read
6057 stdin:
6058         echo x | "$__progname" -c 'read s; echo $? $s .' || echo aborted, $?
6059         echo y | "$__progname" -c 'readonly s; read s; echo $? $s .' || echo aborted, $?
6060 expected-stdout:
6061         0 x .
6062         2 .
6063 expected-stderr-pattern:
6064         /read-only/
6065 ---
6066 name: readonly-4
6067 description:
6068         Do not permit bypassing readonly for first array item
6069 stdin:
6070         set -A arr -- foo bar
6071         readonly arr
6072         arr=baz
6073         print -r -- "${arr[@]}"
6074 expected-exit: e != 0
6075 expected-stderr-pattern:
6076         /read[ -]?only/
6077 ---
6078 name: syntax-1
6079 description:
6080         Check that lone ampersand is a syntax error
6081 stdin:
6082          &
6083 expected-exit: e != 0
6084 expected-stderr-pattern:
6085         /syntax error/
6086 ---
6087 name: xxx-quoted-newline-1
6088 description:
6089         Check that \<newline> works inside of ${}
6090 stdin:
6091         abc=2
6092         echo ${ab\
6093         c}
6094 expected-stdout:
6095         2
6096 ---
6097 name: xxx-quoted-newline-2
6098 description:
6099         Check that \<newline> works at the start of a here document
6100 stdin:
6101         cat << EO\
6102         F
6103         hi
6104         EOF
6105 expected-stdout:
6106         hi
6107 ---
6108 name: xxx-quoted-newline-3
6109 description:
6110         Check that \<newline> works at the end of a here document
6111 stdin:
6112         cat << EOF
6113         hi
6114         EO\
6115         F
6116 expected-stdout:
6117         hi
6118 ---
6119 name: xxx-multi-assignment-cmd
6120 description:
6121         Check that assignments in a command affect subsequent assignments
6122         in the same command
6123 stdin:
6124         FOO=abc
6125         FOO=123 BAR=$FOO
6126         echo $BAR
6127 expected-stdout:
6128         123
6129 ---
6130 name: xxx-multi-assignment-posix-cmd
6131 description:
6132         Check that the behaviour for multiple assignments with a
6133         command name matches POSIX. See:
6134         http://thread.gmane.org/gmane.comp.standards.posix.austin.general/1925
6135 stdin:
6136         X=a Y=b; X=$Y Y=$X "$__progname" -c 'echo 1 $X $Y .'; echo 2 $X $Y .
6137         unset X Y Z
6138         X=a Y=${X=b} Z=$X "$__progname" -c 'echo 3 $Z .'
6139         unset X Y Z
6140         X=a Y=${X=b} Z=$X; echo 4 $Z .
6141 expected-stdout:
6142         1 b a .
6143         2 a b .
6144         3 b .
6145         4 a .
6146 ---
6147 name: xxx-multi-assignment-posix-nocmd
6148 description:
6149         Check that the behaviour for multiple assignments with no
6150         command name matches POSIX (Debian #334182). See:
6151         http://thread.gmane.org/gmane.comp.standards.posix.austin.general/1925
6152 stdin:
6153         X=a Y=b; X=$Y Y=$X; echo 1 $X $Y .
6154 expected-stdout:
6155         1 b b .
6156 ---
6157 name: xxx-multi-assignment-posix-subassign
6158 description:
6159         Check that the behaviour for multiple assignments matches POSIX:
6160         - The assignment words shall be expanded in the current execution
6161           environment.
6162         - The assignments happen in the temporary execution environment.
6163 stdin:
6164         unset X Y Z
6165         Z=a Y=${X:=b} sh -c 'echo +$X+ +$Y+ +$Z+'
6166         echo /$X/
6167         # Now for the special case:
6168         unset X Y Z
6169         X= Y=${X:=b} sh -c 'echo +$X+ +$Y+'
6170         echo /$X/
6171 expected-stdout:
6172         ++ +b+ +a+
6173         /b/
6174         ++ +b+
6175         /b/
6176 ---
6177 name: xxx-exec-environment-1
6178 description:
6179         Check to see if exec sets it's environment correctly
6180 stdin:
6181         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
6182             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
6183             done >env; chmod +x env; PATH=.:$PATH
6184         FOO=bar exec env
6185 expected-stdout-pattern:
6186         /(^|.*\n)FOO=bar\n/
6187 ---
6188 name: xxx-exec-environment-2
6189 description:
6190         Check to make sure exec doesn't change environment if a program
6191         isn't exec-ed
6192 stdin:
6193         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
6194             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
6195             done >env; chmod +x env; PATH=.:$PATH
6196         env >bar1
6197         FOO=bar exec; env >bar2
6198         cmp -s bar1 bar2
6199 ---
6200 name: exec-function-environment-1
6201 description:
6202         Check assignments in function calls and whether they affect
6203         the current execution environment (ksh93, SUSv4)
6204 stdin:
6205         f() { a=2; }; g() { b=3; echo y$c-; }; a=1 f; b=2; c=1 g
6206         echo x$a-$b- z$c-
6207 expected-stdout:
6208         y1-
6209         x2-3- z1-
6210 ---
6211 name: xxx-what-do-you-call-this-1
6212 stdin:
6213         echo "${foo:-"a"}*"
6214 expected-stdout:
6215         a*
6216 ---
6217 name: xxx-prefix-strip-1
6218 stdin:
6219         foo='a cdef'
6220         echo ${foo#a c}
6221 expected-stdout:
6222         def
6223 ---
6224 name: xxx-prefix-strip-2
6225 stdin:
6226         set a c
6227         x='a cdef'
6228         echo ${x#$*}
6229 expected-stdout:
6230         def
6231 ---
6232 name: xxx-variable-syntax-1
6233 stdin:
6234         echo ${:}
6235 expected-stderr-pattern:
6236         /bad substitution/
6237 expected-exit: 1
6238 ---
6239 name: xxx-variable-syntax-2
6240 stdin:
6241         set 0
6242         echo ${*:0}
6243 expected-stderr-pattern:
6244         /bad substitution/
6245 expected-exit: 1
6246 ---
6247 name: xxx-variable-syntax-3
6248 stdin:
6249         set -A foo 0
6250         echo ${foo[*]:0}
6251 expected-stderr-pattern:
6252         /bad substitution/
6253 expected-exit: 1
6254 ---
6255 name: xxx-substitution-eval-order
6256 description:
6257         Check order of evaluation of expressions
6258 stdin:
6259         i=1 x= y=
6260         set -A A abc def GHI j G k
6261         echo ${A[x=(i+=1)]#${A[y=(i+=2)]}}
6262         echo $x $y
6263 expected-stdout:
6264         HI
6265         2 4
6266 ---
6267 name: xxx-set-option-1
6268 description:
6269         Check option parsing in set
6270 stdin:
6271         set -vsA foo -- A 1 3 2
6272         echo ${foo[*]}
6273 expected-stderr:
6274         echo ${foo[*]}
6275 expected-stdout:
6276         1 2 3 A
6277 ---
6278 name: xxx-exec-1
6279 description:
6280         Check that exec exits for built-ins
6281 need-ctty: yes
6282 arguments: !-i!
6283 stdin:
6284         exec echo hi
6285         echo still herre
6286 expected-stdout:
6287         hi
6288 expected-stderr-pattern: /.*/
6289 ---
6290 name: xxx-while-1
6291 description:
6292         Check the return value of while loops
6293         XXX need to do same for for/select/until loops
6294 stdin:
6295         i=x
6296         while [ $i != xxx ] ; do
6297             i=x$i
6298             if [ $i = xxx ] ; then
6299                 false
6300                 continue
6301             fi
6302         done
6303         echo loop1=$?
6304         
6305         i=x
6306         while [ $i != xxx ] ; do
6307             i=x$i
6308             if [ $i = xxx ] ; then
6309                 false
6310                 break
6311             fi
6312         done
6313         echo loop2=$?
6314         
6315         i=x
6316         while [ $i != xxx ] ; do
6317             i=x$i
6318             false
6319         done
6320         echo loop3=$?
6321 expected-stdout:
6322         loop1=0
6323         loop2=0
6324         loop3=1
6325 ---
6326 name: xxx-status-1
6327 description:
6328         Check that blank lines don't clear $?
6329 need-ctty: yes
6330 arguments: !-i!
6331 stdin:
6332         (exit 1)
6333         echo $?
6334         (exit 1)
6335         
6336         echo $?
6337         true
6338 expected-stdout:
6339         1
6340         1
6341 expected-stderr-pattern: /.*/
6342 ---
6343 name: xxx-status-2
6344 description:
6345         Check that $? is preserved in subshells, includes, traps.
6346 stdin:
6347         (exit 1)
6348         
6349         echo blank: $?
6350         
6351         (exit 2)
6352         (echo subshell: $?)
6353         
6354         echo 'echo include: $?' > foo
6355         (exit 3)
6356         . ./foo
6357         
6358         trap 'echo trap: $?' ERR
6359         (exit 4)
6360         echo exit: $?
6361 expected-stdout:
6362         blank: 1
6363         subshell: 2
6364         include: 3
6365         trap: 4
6366         exit: 4
6367 ---
6368 name: xxx-clean-chars-1
6369 description:
6370         Check MAGIC character is stuffed correctly
6371 stdin:
6372         echo `echo [£`
6373 expected-stdout:
6374         [£
6375 ---
6376 name: xxx-param-subst-qmark-1
6377 description:
6378         Check suppresion of error message with null string.  According to
6379         POSIX, it shouldn't print the error as 'word' isn't ommitted.
6380         ksh88/93, Solaris /bin/sh and /usr/xpg4/bin/sh all print the error,
6381         that's why the condition is reversed.
6382 stdin:
6383         unset foo
6384         x=
6385         echo x${foo?$x}
6386 expected-exit: 1
6387 # POSIX
6388 #expected-fail: yes
6389 #expected-stderr-pattern: !/not set/
6390 # common use
6391 expected-stderr-pattern: /parameter null or not set/
6392 ---
6393 name: xxx-param-_-1
6394 # fails due to weirdness of execv stuff
6395 category: !os:uwin-nt
6396 description:
6397         Check c flag is set.
6398 arguments: !-c!echo "[$-]"!
6399 expected-stdout-pattern: /^\[.*c.*\]$/
6400 ---
6401 name: tilde-expand-1
6402 description:
6403         Check tilde expansion after equal signs
6404 env-setup: !HOME=/sweet!
6405 stdin:
6406         echo ${A=a=}~ b=~ c=d~ ~
6407         set +o braceexpand
6408         unset A
6409         echo ${A=a=}~ b=~ c=d~ ~
6410 expected-stdout:
6411         a=/sweet b=/sweet c=d~ /sweet
6412         a=~ b=~ c=d~ /sweet
6413 ---
6414 name: tilde-expand-2
6415 description:
6416         Check tilde expansion works
6417 env-setup: !HOME=/sweet!
6418 stdin:
6419         wd=$PWD
6420         cd /
6421         plus=$(print -r -- ~+)
6422         minus=$(print -r -- ~-)
6423         nix=$(print -r -- ~)
6424         [[ $plus = / ]]; echo one $? .
6425         [[ $minus = "$wd" ]]; echo two $? .
6426         [[ $nix = /sweet ]]; echo nix $? .
6427 expected-stdout:
6428         one 0 .
6429         two 0 .
6430         nix 0 .
6431 ---
6432 name: exit-err-1
6433 description:
6434         Check some "exit on error" conditions
6435 stdin:
6436         print '#!'"$__progname"'\nexec "$1"' >env
6437         print '#!'"$__progname"'\nexit 1' >false
6438         chmod +x env false
6439         PATH=.:$PATH
6440         set -ex
6441         env false && echo something
6442         echo END
6443 expected-stdout:
6444         END
6445 expected-stderr:
6446         + env false
6447         + echo END
6448 ---
6449 name: exit-err-2
6450 description:
6451         Check some "exit on error" edge conditions (POSIXly)
6452 stdin:
6453         print '#!'"$__progname"'\nexec "$1"' >env
6454         print '#!'"$__progname"'\nexit 1' >false
6455         print '#!'"$__progname"'\nexit 0' >true
6456         chmod +x env false
6457         PATH=.:$PATH
6458         set -ex
6459         if env true; then
6460                 env false && echo something
6461         fi
6462         echo END
6463 expected-stdout:
6464         END
6465 expected-stderr:
6466         + env true
6467         + env false
6468         + echo END
6469 ---
6470 name: exit-err-3
6471 description:
6472         pdksh regression which AT&T ksh does right
6473         TFM says: [set] -e | errexit
6474                 Exit (after executing the ERR trap) ...
6475 stdin:
6476         trap 'echo EXIT' EXIT
6477         trap 'echo ERR' ERR
6478         set -e
6479         cd /XXXXX 2>/dev/null
6480         echo DONE
6481         exit 0
6482 expected-stdout:
6483         ERR
6484         EXIT
6485 expected-exit: e != 0
6486 ---
6487 name: exit-err-4
6488 description:
6489         "set -e" test suite (POSIX)
6490 stdin:
6491         set -e
6492         echo pre
6493         if true ; then
6494                 false && echo foo
6495         fi
6496         echo bar
6497 expected-stdout:
6498         pre
6499         bar
6500 ---
6501 name: exit-err-5
6502 description:
6503         "set -e" test suite (POSIX)
6504 stdin:
6505         set -e
6506         foo() {
6507                 while [ "$1" ]; do
6508                         for E in $x; do
6509                                 [ "$1" = "$E" ] && { shift ; continue 2 ; }
6510                         done
6511                         x="$x $1"
6512                         shift
6513                 done
6514                 echo $x
6515         }
6516         echo pre
6517         foo a b b c
6518         echo post
6519 expected-stdout:
6520         pre
6521         a b c
6522         post
6523 ---
6524 name: exit-err-6
6525 description:
6526         "set -e" test suite (BSD make)
6527 category: os:mirbsd
6528 stdin:
6529         mkdir zd zd/a zd/b
6530         print 'all:\n\t@echo eins\n\t@exit 42\n' >zd/a/Makefile
6531         print 'all:\n\t@echo zwei\n' >zd/b/Makefile
6532         wd=$(pwd)
6533         set -e
6534         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"
6535 expected-stdout:
6536         ===> a
6537         eins
6538         *** Error code 42
6539         
6540         Stop in WD/zd/a (line 2 of Makefile).
6541 ---
6542 name: exit-err-7
6543 description:
6544         "set -e" regression (LP#1104543)
6545 stdin:
6546         set -e
6547         bla() {
6548                 [ -x $PWD/nonexistant ] && $PWD/nonexistant
6549         }
6550         echo x
6551         bla
6552         echo y$?
6553 expected-stdout:
6554         x
6555 expected-exit: 1
6556 ---
6557 name: exit-err-8
6558 description:
6559         "set -e" regression (Debian #700526)
6560 stdin:
6561         set -e
6562         _db_cmd() { return $1; }
6563         db_input() { _db_cmd 30; }
6564         db_go() { _db_cmd 0; }
6565         db_input || :
6566         db_go
6567         exit 0
6568 ---
6569 name: exit-enoent-1
6570 description:
6571         SUSv4 says that the shell should exit with 126/127 in some situations
6572 stdin:
6573         i=0
6574         (echo; echo :) >x
6575         "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
6576         "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
6577         echo exit 42 >x
6578         "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
6579         "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
6580         rm -f x
6581         "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
6582         "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
6583 expected-stdout:
6584         0 0 .
6585         1 126 .
6586         2 42 .
6587         3 126 .
6588         4 127 .
6589         5 127 .
6590 ---
6591 name: exit-eval-1
6592 description:
6593         Check eval vs substitution exit codes (ksh93 alike)
6594 stdin:
6595         (exit 12)
6596         eval $(false)
6597         echo A $?
6598         (exit 12)
6599         eval ' $(false)'
6600         echo B $?
6601         (exit 12)
6602         eval " $(false)"
6603         echo C $?
6604         (exit 12)
6605         eval "eval $(false)"
6606         echo D $?
6607         (exit 12)
6608         eval 'eval '"$(false)"
6609         echo E $?
6610         IFS="$IFS:"
6611         (exit 12)
6612         eval $(echo :; false)
6613         echo F $?
6614         echo -n "G "
6615         (exit 12)
6616         eval 'echo $?'
6617         echo H $?
6618 expected-stdout:
6619         A 0
6620         B 1
6621         C 0
6622         D 0
6623         E 0
6624         F 0
6625         G 12
6626         H 0
6627 ---
6628 name: exit-trap-1
6629 description:
6630         Check that "exit" with no arguments behaves SUSv4 conformant.
6631 stdin:
6632         trap 'echo hi; exit' EXIT
6633         exit 9
6634 expected-stdout:
6635         hi
6636 expected-exit: 9
6637 ---
6638 name: exit-trap-2
6639 description:
6640         Check that ERR and EXIT traps are run just like ksh93 does.
6641         GNU bash does not run ERtrap in ±e eval-undef but runs it
6642         twice (bug?) in +e eval-false, so does ksh93 (bug?), which
6643         also has a bug to continue execution (echoing "and out" and
6644         returning 0) in +e eval-undef.
6645 file-setup: file 644 "x"
6646         v=; unset v
6647         trap 'echo EXtrap' EXIT
6648         trap 'echo ERtrap' ERR
6649         set $1
6650         echo "and run $2"
6651         eval $2
6652         echo and out
6653 file-setup: file 644 "xt"
6654         v=; unset v
6655         trap 'echo EXtrap' EXIT
6656         trap 'echo ERtrap' ERR
6657         set $1
6658         echo 'and run true'
6659         true
6660         echo and out
6661 file-setup: file 644 "xf"
6662         v=; unset v
6663         trap 'echo EXtrap' EXIT
6664         trap 'echo ERtrap' ERR
6665         set $1
6666         echo 'and run false'
6667         false
6668         echo and out
6669 file-setup: file 644 "xu"
6670         v=; unset v
6671         trap 'echo EXtrap' EXIT
6672         trap 'echo ERtrap' ERR
6673         set $1
6674         echo 'and run ${v?}'
6675         ${v?}
6676         echo and out
6677 stdin:
6678         runtest() {
6679                 rm -f rc
6680                 (
6681                         "$__progname" "$@"
6682                         echo $? >rc
6683                 ) 2>&1 | sed \
6684                     -e 's/parameter not set/parameter null or not set/' \
6685                     -e 's/[[]6]//' -e 's/: eval: line 1//' -e 's/: line 6//' \
6686                     -e "s\ 1^${__progname%.exe}\.*e*x*e*: <stdin>\[[0-9]*]\ 1PROG\ 1"
6687         }
6688         xe=-e
6689         echo : $xe
6690         runtest x $xe true
6691         echo = eval-true $(<rc) .
6692         runtest x $xe false
6693         echo = eval-false $(<rc) .
6694         runtest x $xe '${v?}'
6695         echo = eval-undef $(<rc) .
6696         runtest xt $xe
6697         echo = noeval-true $(<rc) .
6698         runtest xf $xe
6699         echo = noeval-false $(<rc) .
6700         runtest xu $xe
6701         echo = noeval-undef $(<rc) .
6702         xe=+e
6703         echo : $xe
6704         runtest x $xe true
6705         echo = eval-true $(<rc) .
6706         runtest x $xe false
6707         echo = eval-false $(<rc) .
6708         runtest x $xe '${v?}'
6709         echo = eval-undef $(<rc) .
6710         runtest xt $xe
6711         echo = noeval-true $(<rc) .
6712         runtest xf $xe
6713         echo = noeval-false $(<rc) .
6714         runtest xu $xe
6715         echo = noeval-undef $(<rc) .
6716 expected-stdout:
6717         : -e
6718         and run true
6719         and out
6720         EXtrap
6721         = eval-true 0 .
6722         and run false
6723         ERtrap
6724         EXtrap
6725         = eval-false 1 .
6726         and run ${v?}
6727         x: v: parameter null or not set
6728         ERtrap
6729         EXtrap
6730         = eval-undef 1 .
6731         and run true
6732         and out
6733         EXtrap
6734         = noeval-true 0 .
6735         and run false
6736         ERtrap
6737         EXtrap
6738         = noeval-false 1 .
6739         and run ${v?}
6740         xu: v: parameter null or not set
6741         EXtrap
6742         = noeval-undef 1 .
6743         : +e
6744         and run true
6745         and out
6746         EXtrap
6747         = eval-true 0 .
6748         and run false
6749         ERtrap
6750         and out
6751         EXtrap
6752         = eval-false 0 .
6753         and run ${v?}
6754         x: v: parameter null or not set
6755         ERtrap
6756         EXtrap
6757         = eval-undef 1 .
6758         and run true
6759         and out
6760         EXtrap
6761         = noeval-true 0 .
6762         and run false
6763         ERtrap
6764         and out
6765         EXtrap
6766         = noeval-false 0 .
6767         and run ${v?}
6768         xu: v: parameter null or not set
6769         EXtrap
6770         = noeval-undef 1 .
6771 ---
6772 name: exit-trap-interactive
6773 description:
6774         Check that interactive shell doesn't exit via EXIT trap on syntax error
6775 arguments: !-i!
6776 stdin:
6777         trap -- EXIT
6778         echo Syntax error <
6779         echo 'After error 1'
6780         trap 'echo Exit trap' EXIT
6781         echo Syntax error <
6782         echo 'After error 2'
6783         trap 'echo Exit trap' EXIT
6784         exit
6785         echo 'After exit'
6786 expected-stdout:
6787         After error 1
6788         After error 2
6789         Exit trap
6790 expected-stderr-pattern:
6791         /syntax error: 'newline' unexpected/
6792 ---
6793 name: test-stlt-1
6794 description:
6795         Check that test also can handle string1 < string2 etc.
6796 stdin:
6797         test 2005/10/08 '<' 2005/08/21 && echo ja || echo nein
6798         test 2005/08/21 \< 2005/10/08 && echo ja || echo nein
6799         test 2005/10/08 '>' 2005/08/21 && echo ja || echo nein
6800         test 2005/08/21 \> 2005/10/08 && echo ja || echo nein
6801 expected-stdout:
6802         nein
6803         ja
6804         ja
6805         nein
6806 expected-stderr-pattern: !/unexpected op/
6807 ---
6808 name: test-precedence-1
6809 description:
6810         Check a weird precedence case (and POSIX echo)
6811 stdin:
6812         test \( -f = -f \)
6813         rv=$?
6814         echo $rv
6815 expected-stdout:
6816         0
6817 ---
6818 name: test-option-1
6819 description:
6820         Test the test -o operator
6821 stdin:
6822         runtest() {
6823                 test -o $1; echo $?
6824                 [ -o $1 ]; echo $?
6825                 [[ -o $1 ]]; echo $?
6826         }
6827         if_test() {
6828                 test -o $1 -o -o !$1; echo $?
6829                 [ -o $1 -o -o !$1 ]; echo $?
6830                 [[ -o $1 || -o !$1 ]]; echo $?
6831                 test -o ?$1; echo $?
6832         }
6833         echo 0y $(if_test utf8-mode) =
6834         echo 0n $(if_test utf8-hack) =
6835         echo 1= $(runtest utf8-hack) =
6836         echo 2= $(runtest !utf8-hack) =
6837         echo 3= $(runtest ?utf8-hack) =
6838         set +U
6839         echo 1+ $(runtest utf8-mode) =
6840         echo 2+ $(runtest !utf8-mode) =
6841         echo 3+ $(runtest ?utf8-mode) =
6842         set -U
6843         echo 1- $(runtest utf8-mode) =
6844         echo 2- $(runtest !utf8-mode) =
6845         echo 3- $(runtest ?utf8-mode) =
6846         echo = short flags =
6847         echo 0y $(if_test -U) =
6848         echo 0y $(if_test +U) =
6849         echo 0n $(if_test -_) =
6850         echo 0n $(if_test -U-) =
6851         echo 1= $(runtest -_) =
6852         echo 2= $(runtest !-_) =
6853         echo 3= $(runtest ?-_) =
6854         set +U
6855         echo 1+ $(runtest -U) =
6856         echo 2+ $(runtest !-U) =
6857         echo 3+ $(runtest ?-U) =
6858         echo 1+ $(runtest +U) =
6859         echo 2+ $(runtest !+U) =
6860         echo 3+ $(runtest ?+U) =
6861         set -U
6862         echo 1- $(runtest -U) =
6863         echo 2- $(runtest !-U) =
6864         echo 3- $(runtest ?-U) =
6865         echo 1- $(runtest +U) =
6866         echo 2- $(runtest !+U) =
6867         echo 3- $(runtest ?+U) =
6868 expected-stdout:
6869         0y 0 0 0 0 =
6870         0n 1 1 1 1 =
6871         1= 1 1 1 =
6872         2= 1 1 1 =
6873         3= 1 1 1 =
6874         1+ 1 1 1 =
6875         2+ 0 0 0 =
6876         3+ 0 0 0 =
6877         1- 0 0 0 =
6878         2- 1 1 1 =
6879         3- 0 0 0 =
6880         = short flags =
6881         0y 0 0 0 0 =
6882         0y 0 0 0 0 =
6883         0n 1 1 1 1 =
6884         0n 1 1 1 1 =
6885         1= 1 1 1 =
6886         2= 1 1 1 =
6887         3= 1 1 1 =
6888         1+ 1 1 1 =
6889         2+ 0 0 0 =
6890         3+ 0 0 0 =
6891         1+ 1 1 1 =
6892         2+ 0 0 0 =
6893         3+ 0 0 0 =
6894         1- 0 0 0 =
6895         2- 1 1 1 =
6896         3- 0 0 0 =
6897         1- 0 0 0 =
6898         2- 1 1 1 =
6899         3- 0 0 0 =
6900 ---
6901 name: mkshrc-1
6902 description:
6903         Check that ~/.mkshrc works correctly.
6904         Part 1: verify user environment is not read (internal)
6905 stdin:
6906         echo x $FNORD
6907 expected-stdout:
6908         x
6909 ---
6910 name: mkshrc-2a
6911 description:
6912         Check that ~/.mkshrc works correctly.
6913         Part 2: verify mkshrc is not read (non-interactive shells)
6914 file-setup: file 644 ".mkshrc"
6915         FNORD=42
6916 env-setup: !HOME=.!ENV=!
6917 stdin:
6918         echo x $FNORD
6919 expected-stdout:
6920         x
6921 ---
6922 name: mkshrc-2b
6923 description:
6924         Check that ~/.mkshrc works correctly.
6925         Part 2: verify mkshrc can be read (interactive shells)
6926 file-setup: file 644 ".mkshrc"
6927         FNORD=42
6928 need-ctty: yes
6929 arguments: !-i!
6930 env-setup: !HOME=.!ENV=!PS1=!
6931 stdin:
6932         echo x $FNORD
6933 expected-stdout:
6934         x 42
6935 expected-stderr-pattern:
6936         /(# )*/
6937 ---
6938 name: mkshrc-3
6939 description:
6940         Check that ~/.mkshrc works correctly.
6941         Part 3: verify mkshrc can be turned off
6942 file-setup: file 644 ".mkshrc"
6943         FNORD=42
6944 env-setup: !HOME=.!ENV=nonexistant!
6945 stdin:
6946         echo x $FNORD
6947 expected-stdout:
6948         x
6949 ---
6950 name: sh-mode-1
6951 description:
6952         Check that sh mode turns braceexpand off
6953         and that that works correctly
6954 stdin:
6955         set -o braceexpand
6956         set +o sh
6957         [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
6958         [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
6959         echo {a,b,c}
6960         set +o braceexpand
6961         echo {a,b,c}
6962         set -o braceexpand
6963         echo {a,b,c}
6964         set -o sh
6965         echo {a,b,c}
6966         [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
6967         [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
6968         set -o braceexpand
6969         echo {a,b,c}
6970         [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
6971         [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
6972 expected-stdout:
6973         nosh
6974         brex
6975         a b c
6976         {a,b,c}
6977         a b c
6978         {a,b,c}
6979         sh
6980         nobrex
6981         a b c
6982         sh
6983         brex
6984 ---
6985 name: sh-mode-2a
6986 description:
6987         Check that posix or sh mode is *not* automatically turned on
6988 category: !binsh
6989 stdin:
6990         ln -s "$__progname" ksh || cp "$__progname" ksh
6991         ln -s "$__progname" sh || cp "$__progname" sh
6992         ln -s "$__progname" ./-ksh || cp "$__progname" ./-ksh
6993         ln -s "$__progname" ./-sh || cp "$__progname" ./-sh
6994         for shell in {,-}{,k}sh; do
6995                 print -- $shell $(./$shell +l -c \
6996                     '[[ $(set +o) == *"-o "@(sh|posix)@(| *) ]] && echo sh || echo nosh')
6997         done
6998 expected-stdout:
6999         sh nosh
7000         ksh nosh
7001         -sh nosh
7002         -ksh nosh
7003 ---
7004 name: sh-mode-2b
7005 description:
7006         Check that posix or sh mode *is* automatically turned on
7007 category: binsh
7008 stdin:
7009         ln -s "$__progname" ksh || cp "$__progname" ksh
7010         ln -s "$__progname" sh || cp "$__progname" sh
7011         ln -s "$__progname" ./-ksh || cp "$__progname" ./-ksh
7012         ln -s "$__progname" ./-sh || cp "$__progname" ./-sh
7013         for shell in {,-}{,k}sh; do
7014                 print -- $shell $(./$shell +l -c \
7015                     '[[ $(set +o) == *"-o "@(sh|posix)@(| *) ]] && echo sh || echo nosh')
7016         done
7017 expected-stdout:
7018         sh sh
7019         ksh nosh
7020         -sh sh
7021         -ksh nosh
7022 ---
7023 name: pipeline-1
7024 description:
7025         pdksh bug: last command of a pipeline is executed in a
7026         subshell - make sure it still is, scripts depend on it
7027 file-setup: file 644 "abcx"
7028 file-setup: file 644 "abcy"
7029 stdin:
7030         echo *
7031         echo a | while read d; do
7032                 echo $d
7033                 echo $d*
7034                 echo *
7035                 set -o noglob
7036                 echo $d*
7037                 echo *
7038         done
7039         echo *
7040 expected-stdout:
7041         abcx abcy
7042         a
7043         abcx abcy
7044         abcx abcy
7045         a*
7046         *
7047         abcx abcy
7048 ---
7049 name: pipeline-2
7050 description:
7051         check that co-processes work with TCOMs, TPIPEs and TPARENs
7052 category: !nojsig
7053 stdin:
7054         "$__progname" -c 'i=100; echo hi |& while read -p line; do echo "$((i++)) $line"; done'
7055         "$__progname" -c 'i=200; echo hi | cat |& while read -p line; do echo "$((i++)) $line"; done'
7056         "$__progname" -c 'i=300; (echo hi | cat) |& while read -p line; do echo "$((i++)) $line"; done'
7057 expected-stdout:
7058         100 hi
7059         200 hi
7060         300 hi
7061 ---
7062 name: pipeline-3
7063 description:
7064         Check that PIPESTATUS does what it's supposed to
7065 stdin:
7066         echo 1 $PIPESTATUS .
7067         echo 2 ${PIPESTATUS[0]} .
7068         echo 3 ${PIPESTATUS[1]} .
7069         (echo x; exit 12) | (cat; exit 23) | (cat; exit 42)
7070         echo 5 $? , $PIPESTATUS , ${PIPESTATUS[0]} , ${PIPESTATUS[1]} , ${PIPESTATUS[2]} , ${PIPESTATUS[3]} .
7071         echo 6 ${PIPESTATUS[0]} .
7072         set | fgrep PIPESTATUS
7073         echo 8 $(set | fgrep PIPESTATUS) .
7074 expected-stdout:
7075         1 0 .
7076         2 0 .
7077         3 .
7078         x
7079         5 42 , 12 , 12 , 23 , 42 , .
7080         6 0 .
7081         PIPESTATUS[0]=0
7082         8 PIPESTATUS[0]=0 PIPESTATUS[1]=0 .
7083 ---
7084 name: pipeline-4
7085 description:
7086         Check that "set -o pipefail" does what it's supposed to
7087 stdin:
7088         echo 1 "$("$__progname" -c '(exit 12) | (exit 23) | (exit 42); echo $?')" .
7089         echo 2 "$("$__progname" -c '! (exit 12) | (exit 23) | (exit 42); echo $?')" .
7090         echo 3 "$("$__progname" -o pipefail -c '(exit 12) | (exit 23) | (exit 42); echo $?')" .
7091         echo 4 "$("$__progname" -o pipefail -c '! (exit 12) | (exit 23) | (exit 42); echo $?')" .
7092         echo 5 "$("$__progname" -c '(exit 23) | (exit 42) | :; echo $?')" .
7093         echo 6 "$("$__progname" -c '! (exit 23) | (exit 42) | :; echo $?')" .
7094         echo 7 "$("$__progname" -o pipefail -c '(exit 23) | (exit 42) | :; echo $?')" .
7095         echo 8 "$("$__progname" -o pipefail -c '! (exit 23) | (exit 42) | :; echo $?')" .
7096         echo 9 "$("$__progname" -o pipefail -c 'x=$( (exit 23) | (exit 42) | :); echo $?')" .
7097 expected-stdout:
7098         1 42 .
7099         2 0 .
7100         3 42 .
7101         4 0 .
7102         5 0 .
7103         6 1 .
7104         7 42 .
7105         8 0 .
7106         9 42 .
7107 ---
7108 name: persist-history-1
7109 description:
7110         Check if persistent history saving works
7111 category: !no-histfile
7112 need-ctty: yes
7113 arguments: !-i!
7114 env-setup: !ENV=./Env!HISTFILE=hist.file!
7115 file-setup: file 644 "Env"
7116         PS1=X
7117 stdin:
7118         cat hist.file
7119 expected-stdout-pattern:
7120         /cat hist.file/
7121 expected-stderr-pattern:
7122         /^X*$/
7123 ---
7124 name: typeset-1
7125 description:
7126         Check that global does what typeset is supposed to do
7127 stdin:
7128         set -A arrfoo 65
7129         foo() {
7130                 global -Uui16 arrfoo[*]
7131         }
7132         echo before ${arrfoo[0]} .
7133         foo
7134         echo after ${arrfoo[0]} .
7135         set -A arrbar 65
7136         bar() {
7137                 echo inside before ${arrbar[0]} .
7138                 arrbar[0]=97
7139                 echo inside changed ${arrbar[0]} .
7140                 global -Uui16 arrbar[*]
7141                 echo inside typeset ${arrbar[0]} .
7142                 arrbar[0]=48
7143                 echo inside changed ${arrbar[0]} .
7144         }
7145         echo before ${arrbar[0]} .
7146         bar
7147         echo after ${arrbar[0]} .
7148 expected-stdout:
7149         before 65 .
7150         after 16#41 .
7151         before 65 .
7152         inside before 65 .
7153         inside changed 97 .
7154         inside typeset 16#61 .
7155         inside changed 16#30 .
7156         after 16#30 .
7157 ---
7158 name: typeset-padding-1
7159 description:
7160         Check if left/right justification works as per TFM
7161 stdin:
7162         typeset -L10 ln=0hall0
7163         typeset -R10 rn=0hall0
7164         typeset -ZL10 lz=0hall0
7165         typeset -ZR10 rz=0hall0
7166         typeset -Z10 rx=" hallo "
7167         echo "<$ln> <$rn> <$lz> <$rz> <$rx>"
7168 expected-stdout:
7169         <0hall0    > <    0hall0> <hall0     > <00000hall0> <0000 hallo>
7170 ---
7171 name: typeset-padding-2
7172 description:
7173         Check if base-!10 integers are padded right
7174 stdin:
7175         typeset -Uui16 -L9 ln=16#1
7176         typeset -Uui16 -R9 rn=16#1
7177         typeset -Uui16 -Z9 zn=16#1
7178         typeset -L9 ls=16#1
7179         typeset -R9 rs=16#1
7180         typeset -Z9 zs=16#1
7181         echo "<$ln> <$rn> <$zn> <$ls> <$rs> <$zs>"
7182 expected-stdout:
7183         <16#1     > <     16#1> <16#000001> <16#1     > <     16#1> <0000016#1>
7184 ---
7185 name: utf8bom-1
7186 description:
7187         Check that the UTF-8 Byte Order Mark is ignored as the first
7188         multibyte character of the shell input (with -c, from standard
7189         input, as file, or as eval argument), but nowhere else
7190 # breaks on Mac OSX (HFS+ non-standard Unicode canonical decomposition)
7191 category: !os:darwin
7192 stdin:
7193         mkdir foo
7194         print '#!/bin/sh\necho ohne' >foo/fnord
7195         print '#!/bin/sh\necho mit' >foo/fnord
7196         print 'fnord\nfnord\nfnord\nfnord' >foo/bar
7197         print eval \''fnord\nfnord\nfnord\nfnord'\' >foo/zoo
7198         set -A anzahl -- foo/*
7199         echo got ${#anzahl[*]} files
7200         chmod +x foo/*
7201         export PATH=$(pwd)/foo:$PATH
7202         "$__progname" -c 'fnord'
7203         echo =
7204         "$__progname" -c 'fnord; fnord; fnord; fnord'
7205         echo =
7206         "$__progname" foo/bar
7207         echo =
7208         "$__progname" <foo/bar
7209         echo =
7210         "$__progname" foo/zoo
7211         echo =
7212         "$__progname" -c 'echo : $(fnord)'
7213         rm -rf foo
7214 expected-stdout:
7215         got 4 files
7216         ohne
7217         =
7218         ohne
7219         ohne
7220         mit
7221         ohne
7222         =
7223         ohne
7224         ohne
7225         mit
7226         ohne
7227         =
7228         ohne
7229         ohne
7230         mit
7231         ohne
7232         =
7233         ohne
7234         ohne
7235         mit
7236         ohne
7237         =
7238         : ohne
7239 ---
7240 name: utf8bom-2
7241 description:
7242         Check that we can execute BOM-shebangs (failures not fatal)
7243         XXX if the OS can already execute them, we lose
7244         note: cygwin execve(2) doesn't return to us with ENOEXEC, we lose
7245         note: Ultrix perl5 t4 returns 65280 (exit-code 255) and no text
7246         XXX fails when LD_PRELOAD is set with -e and Perl chokes it (ASan)
7247 need-pass: no
7248 category: !os:cygwin,!os:msys,!os:ultrix,!os:uwin-nt,!smksh
7249 env-setup: !FOO=BAR!
7250 stdin:
7251         print '#!'"$__progname"'\nprint "1 a=$ENV{FOO}";' >t1
7252         print '#!'"$__progname"'\nprint "2 a=$ENV{FOO}";' >t2
7253         print '#!'"$__perlname"'\nprint "3 a=$ENV{FOO}\n";' >t3
7254         print '#!'"$__perlname"'\nprint "4 a=$ENV{FOO}\n";' >t4
7255         chmod +x t?
7256         ./t1
7257         ./t2
7258         ./t3
7259         ./t4
7260 expected-stdout:
7261         1 a=/nonexistant{FOO}
7262         2 a=/nonexistant{FOO}
7263         3 a=BAR
7264         4 a=BAR
7265 expected-stderr-pattern:
7266         /(Unrecognized character .... ignored at \..t4 line 1)*/
7267 ---
7268 name: utf8opt-1a
7269 description:
7270         Check that the utf8-mode flag is not set at non-interactive startup
7271 category: !os:hpux
7272 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.UTF-8!
7273 stdin:
7274         if [[ $- = *U* ]]; then
7275                 echo is set
7276         else
7277                 echo is not set
7278         fi
7279 expected-stdout:
7280         is not set
7281 ---
7282 name: utf8opt-1b
7283 description:
7284         Check that the utf8-mode flag is not set at non-interactive startup
7285 category: os:hpux
7286 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.utf8!
7287 stdin:
7288         if [[ $- = *U* ]]; then
7289                 echo is set
7290         else
7291                 echo is not set
7292         fi
7293 expected-stdout:
7294         is not set
7295 ---
7296 name: utf8opt-2a
7297 description:
7298         Check that the utf8-mode flag is set at interactive startup.
7299         -DMKSH_ASSUME_UTF8=0 => expected failure, please ignore
7300         -DMKSH_ASSUME_UTF8=1 => not expected, please investigate
7301         -UMKSH_ASSUME_UTF8 => not expected, but if your OS is old,
7302          try passing HAVE_SETLOCALE_CTYPE=0 to Build.sh
7303 need-pass: no
7304 category: !os:hpux,!os:msys
7305 need-ctty: yes
7306 arguments: !-i!
7307 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.UTF-8!
7308 stdin:
7309         if [[ $- = *U* ]]; then
7310                 echo is set
7311         else
7312                 echo is not set
7313         fi
7314 expected-stdout:
7315         is set
7316 expected-stderr-pattern:
7317         /(# )*/
7318 ---
7319 name: utf8opt-2b
7320 description:
7321         Check that the utf8-mode flag is set at interactive startup
7322         Expected failure if -DMKSH_ASSUME_UTF8=0
7323 category: os:hpux
7324 need-ctty: yes
7325 arguments: !-i!
7326 env-setup: !PS1=!PS2=!LC_CTYPE=en_US.utf8!
7327 stdin:
7328         if [[ $- = *U* ]]; then
7329                 echo is set
7330         else
7331                 echo is not set
7332         fi
7333 expected-stdout:
7334         is set
7335 expected-stderr-pattern:
7336         /(# )*/
7337 ---
7338 name: utf8opt-3a
7339 description:
7340         Ensure ±U on the command line is honoured
7341         (these two tests may pass falsely depending on CPPFLAGS)
7342 stdin:
7343         export i=0
7344         code='if [[ $- = *U* ]]; then echo $i on; else echo $i off; fi'
7345         let i++; "$__progname" -U -c "$code"
7346         let i++; "$__progname" +U -c "$code"
7347         echo $((++i)) done
7348 expected-stdout:
7349         1 on
7350         2 off
7351         3 done
7352 ---
7353 name: utf8opt-3b
7354 description:
7355         Ensure ±U on the command line is honoured, interactive shells
7356 need-ctty: yes
7357 stdin:
7358         export i=0
7359         code='if [[ $- = *U* ]]; then echo $i on; else echo $i off; fi'
7360         let i++; "$__progname" -U -ic "$code"
7361         let i++; "$__progname" +U -ic "$code"
7362         echo $((++i)) done
7363 expected-stdout:
7364         1 on
7365         2 off
7366         3 done
7367 ---
7368 name: aliases-1
7369 description:
7370         Check if built-in shell aliases are okay
7371 category: !android,!arge
7372 stdin:
7373         alias
7374         typeset -f
7375 expected-stdout:
7376         autoload='typeset -fu'
7377         functions='typeset -f'
7378         hash='alias -t'
7379         history='fc -l'
7380         integer='typeset -i'
7381         local=typeset
7382         login='exec login'
7383         nameref='typeset -n'
7384         nohup='nohup '
7385         r='fc -e -'
7386         source='PATH=$PATH:. command .'
7387         stop='kill -STOP'
7388         type='whence -v'
7389 ---
7390 name: aliases-1-hartz4
7391 description:
7392         Check if built-in shell aliases are okay
7393 category: android,arge
7394 stdin:
7395         alias
7396         typeset -f
7397 expected-stdout:
7398         autoload='typeset -fu'
7399         functions='typeset -f'
7400         hash='alias -t'
7401         history='fc -l'
7402         integer='typeset -i'
7403         local=typeset
7404         login='exec login'
7405         nameref='typeset -n'
7406         nohup='nohup '
7407         r='fc -e -'
7408         source='PATH=$PATH:. command .'
7409         type='whence -v'
7410 ---
7411 name: aliases-2a
7412 description:
7413         Check if “set -o sh” disables built-in aliases (except a few)
7414 category: disabled
7415 arguments: !-o!sh!
7416 stdin:
7417         alias
7418         typeset -f
7419 expected-stdout:
7420         integer='typeset -i'
7421         local=typeset
7422 ---
7423 name: aliases-3a
7424 description:
7425         Check if running as sh disables built-in aliases (except a few)
7426 category: disabled
7427 stdin:
7428         cp "$__progname" sh
7429         ./sh -c 'alias; typeset -f'
7430         rm -f sh
7431 expected-stdout:
7432         integer='typeset -i'
7433         local=typeset
7434 ---
7435 name: aliases-2b
7436 description:
7437         Check if “set -o sh” does not influence built-in aliases
7438 category: !android,!arge
7439 arguments: !-o!sh!
7440 stdin:
7441         alias
7442         typeset -f
7443 expected-stdout:
7444         autoload='typeset -fu'
7445         functions='typeset -f'
7446         hash='alias -t'
7447         history='fc -l'
7448         integer='typeset -i'
7449         local=typeset
7450         login='exec login'
7451         nameref='typeset -n'
7452         nohup='nohup '
7453         r='fc -e -'
7454         source='PATH=$PATH:. command .'
7455         stop='kill -STOP'
7456         type='whence -v'
7457 ---
7458 name: aliases-3b
7459 description:
7460         Check if running as sh does not influence built-in aliases
7461 category: !android,!arge
7462 stdin:
7463         cp "$__progname" sh
7464         ./sh -c 'alias; typeset -f'
7465         rm -f sh
7466 expected-stdout:
7467         autoload='typeset -fu'
7468         functions='typeset -f'
7469         hash='alias -t'
7470         history='fc -l'
7471         integer='typeset -i'
7472         local=typeset
7473         login='exec login'
7474         nameref='typeset -n'
7475         nohup='nohup '
7476         r='fc -e -'
7477         source='PATH=$PATH:. command .'
7478         stop='kill -STOP'
7479         type='whence -v'
7480 ---
7481 name: aliases-2b-hartz4
7482 description:
7483         Check if “set -o sh” does not influence built-in aliases
7484 category: android,arge
7485 arguments: !-o!sh!
7486 stdin:
7487         alias
7488         typeset -f
7489 expected-stdout:
7490         autoload='typeset -fu'
7491         functions='typeset -f'
7492         hash='alias -t'
7493         history='fc -l'
7494         integer='typeset -i'
7495         local=typeset
7496         login='exec login'
7497         nameref='typeset -n'
7498         nohup='nohup '
7499         r='fc -e -'
7500         source='PATH=$PATH:. command .'
7501         type='whence -v'
7502 ---
7503 name: aliases-3b-hartz4
7504 description:
7505         Check if running as sh does not influence built-in aliases
7506 category: android,arge
7507 stdin:
7508         cp "$__progname" sh
7509         ./sh -c 'alias; typeset -f'
7510         rm -f sh
7511 expected-stdout:
7512         autoload='typeset -fu'
7513         functions='typeset -f'
7514         hash='alias -t'
7515         history='fc -l'
7516         integer='typeset -i'
7517         local=typeset
7518         login='exec login'
7519         nameref='typeset -n'
7520         nohup='nohup '
7521         r='fc -e -'
7522         source='PATH=$PATH:. command .'
7523         type='whence -v'
7524 ---
7525 name: aliases-cmdline
7526 description:
7527         Check that aliases work from the command line (Debian #517009)
7528         Note that due to the nature of the lexing process, defining
7529         aliases in COMSUBs then immediately using them, and things
7530         like 'alias foo=bar && foo', still fail.
7531 stdin:
7532         "$__progname" -c $'alias a="echo OK"\na'
7533 expected-stdout:
7534         OK
7535 ---
7536 name: aliases-funcdef-1
7537 description:
7538         Check if POSIX functions take precedences over aliases
7539 stdin:
7540         alias foo='echo makro'
7541         foo() {
7542                 echo funktion
7543         }
7544         foo
7545 expected-stdout:
7546         funktion
7547 ---
7548 name: aliases-funcdef-2
7549 description:
7550         Check if POSIX functions take precedences over aliases
7551 stdin:
7552         alias foo='echo makro'
7553         foo () {
7554                 echo funktion
7555         }
7556         foo
7557 expected-stdout:
7558         funktion
7559 ---
7560 name: aliases-funcdef-3
7561 description:
7562         Check if aliases take precedences over Korn functions
7563 stdin:
7564         alias foo='echo makro'
7565         function foo {
7566                 echo funktion
7567         }
7568         foo
7569 expected-stdout:
7570         makro
7571 ---
7572 name: aliases-funcdef-4
7573 description:
7574         Functions should only take over if actually being defined
7575 stdin:
7576         alias local
7577         :|| local() { :; }
7578         alias local
7579 expected-stdout:
7580         local=typeset
7581         local=typeset
7582 ---
7583 name: arrays-1
7584 description:
7585         Check if Korn Shell arrays work as expected
7586 stdin:
7587         v="c d"
7588         set -A foo -- a \$v "$v" '$v' b
7589         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|"
7590 expected-stdout:
7591         5|a|$v|c d|$v|b|
7592 ---
7593 name: arrays-2a
7594 description:
7595         Check if bash-style arrays work as expected
7596 stdin:
7597         v="c d"
7598         foo=(a \$v "$v" '$v' b)
7599         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|"
7600 expected-stdout:
7601         5|a|$v|c d|$v|b|
7602 ---
7603 name: arrays-2b
7604 description:
7605         Check if bash-style arrays work as expected, with newlines
7606 stdin:
7607         print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "$x|"; done' >pfp
7608         chmod +x pfp
7609         test -n "$ZSH_VERSION" && setopt KSH_ARRAYS
7610         v="e f"
7611         foo=(a
7612                 bc
7613                 d \$v "$v" '$v' g
7614         )
7615         ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
7616         foo=(a\
7617                 bc
7618                 d \$v "$v" '$v' g
7619         )
7620         ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
7621         foo=(a\
7622         bc\\
7623                 d \$v "$v" '$v'
7624         g)
7625         ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
7626 expected-stdout:
7627         7|a|bc|d|$v|e f|$v|g|
7628         7|a|bc|d|$v|e f|$v|g|
7629         6|abc\|d|$v|e f|$v|g||
7630 ---
7631 name: arrays-3
7632 description:
7633         Check if array bounds are uint32_t
7634 stdin:
7635         set -A foo a b c
7636         foo[4097]=d
7637         foo[2147483637]=e
7638         echo ${foo[*]}
7639         foo[-1]=f
7640         echo ${foo[4294967295]} g ${foo[*]}
7641 expected-stdout:
7642         a b c d e
7643         f g a b c d e f
7644 ---
7645 name: arrays-4
7646 description:
7647         Check if Korn Shell arrays with specified indices work as expected
7648 stdin:
7649         v="c d"
7650         set -A foo -- [1]=\$v [2]="$v" [4]='$v' [0]=a [5]=b
7651         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|${foo[5]}|"
7652         # we don't want this at all:
7653         #       5|a|$v|c d||$v|b|
7654         set -A arr "[5]=meh"
7655         echo "<${arr[0]}><${arr[5]}>"
7656 expected-stdout:
7657         5|[1]=$v|[2]=c d|[4]=$v|[0]=a|[5]=b||
7658         <[5]=meh><>
7659 ---
7660 name: arrays-5
7661 description:
7662         Check if bash-style arrays with specified indices work as expected
7663         (taken out temporarily to fix arrays-4; see also arrays-9a comment)
7664 category: disabled
7665 stdin:
7666         v="c d"
7667         foo=([1]=\$v [2]="$v" [4]='$v' [0]=a [5]=b)
7668         echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|${foo[5]}|"
7669         x=([128]=foo bar baz)
7670         echo k= ${!x[*]} .
7671         echo v= ${x[*]} .
7672         # Check that we do not break this by globbing
7673         :>b=blah
7674         bleh=5
7675         typeset -a arr
7676         arr+=([bleh]=blah)
7677         echo "<${arr[0]}><${arr[5]}>"
7678 expected-stdout:
7679         5|a|$v|c d||$v|b|
7680         k= 128 129 130 .
7681         v= foo bar baz .
7682         <><blah>
7683 ---
7684 name: arrays-6
7685 description:
7686         Check if we can get the array keys (indices) for indexed arrays,
7687         Korn shell style
7688 stdin:
7689         of() {
7690                 i=0
7691                 for x in "$@"; do
7692                         echo -n "$((i++))<$x>"
7693                 done
7694                 echo
7695         }
7696         foo[1]=eins
7697         set | grep '^foo'
7698         echo =
7699         foo[0]=zwei
7700         foo[4]=drei
7701         set | grep '^foo'
7702         echo =
7703         echo a $(of ${foo[*]}) = $(of ${bar[*]}) a
7704         echo b $(of "${foo[*]}") = $(of "${bar[*]}") b
7705         echo c $(of ${foo[@]}) = $(of ${bar[@]}) c
7706         echo d $(of "${foo[@]}") = $(of "${bar[@]}") d
7707         echo e $(of ${!foo[*]}) = $(of ${!bar[*]}) e
7708         echo f $(of "${!foo[*]}") = $(of "${!bar[*]}") f
7709         echo g $(of ${!foo[@]}) = $(of ${!bar[@]}) g
7710         echo h $(of "${!foo[@]}") = $(of "${!bar[@]}") h
7711 expected-stdout:
7712         foo[1]=eins
7713         =
7714         foo[0]=zwei
7715         foo[1]=eins
7716         foo[4]=drei
7717         =
7718         a 0<zwei>1<eins>2<drei> = a
7719         b 0<zwei eins drei> = 0<> b
7720         c 0<zwei>1<eins>2<drei> = c
7721         d 0<zwei>1<eins>2<drei> = d
7722         e 0<0>1<1>2<4> = e
7723         f 0<0 1 4> = 0<> f
7724         g 0<0>1<1>2<4> = g
7725         h 0<0>1<1>2<4> = h
7726 ---
7727 name: arrays-7
7728 description:
7729         Check if we can get the array keys (indices) for indexed arrays,
7730         Korn shell style, in some corner cases
7731 stdin:
7732         echo !arz: ${!arz}
7733         echo !arz[0]: ${!arz[0]}
7734         echo !arz[1]: ${!arz[1]}
7735         arz=foo
7736         echo !arz: ${!arz}
7737         echo !arz[0]: ${!arz[0]}
7738         echo !arz[1]: ${!arz[1]}
7739         unset arz
7740         echo !arz: ${!arz}
7741         echo !arz[0]: ${!arz[0]}
7742         echo !arz[1]: ${!arz[1]}
7743 expected-stdout:
7744         !arz: arz
7745         !arz[0]: arz[0]
7746         !arz[1]: arz[1]
7747         !arz: arz
7748         !arz[0]: arz[0]
7749         !arz[1]: arz[1]
7750         !arz: arz
7751         !arz[0]: arz[0]
7752         !arz[1]: arz[1]
7753 ---
7754 name: arrays-8
7755 description:
7756         Check some behavioural rules for arrays.
7757 stdin:
7758         fna() {
7759                 set -A aa 9
7760         }
7761         fnb() {
7762                 typeset ab
7763                 set -A ab 9
7764         }
7765         fnc() {
7766                 typeset ac
7767                 set -A ac 91
7768                 unset ac
7769                 set -A ac 92
7770         }
7771         fnd() {
7772                 set +A ad 9
7773         }
7774         fne() {
7775                 unset ae
7776                 set +A ae 9
7777         }
7778         fnf() {
7779                 unset af[0]
7780                 set +A af 9
7781         }
7782         fng() {
7783                 unset ag[*]
7784                 set +A ag 9
7785         }
7786         set -A aa 1 2
7787         set -A ab 1 2
7788         set -A ac 1 2
7789         set -A ad 1 2
7790         set -A ae 1 2
7791         set -A af 1 2
7792         set -A ag 1 2
7793         set -A ah 1 2
7794         typeset -Z3 aa ab ac ad ae af ag
7795         print 1a ${aa[*]} .
7796         print 1b ${ab[*]} .
7797         print 1c ${ac[*]} .
7798         print 1d ${ad[*]} .
7799         print 1e ${ae[*]} .
7800         print 1f ${af[*]} .
7801         print 1g ${ag[*]} .
7802         print 1h ${ah[*]} .
7803         fna
7804         fnb
7805         fnc
7806         fnd
7807         fne
7808         fnf
7809         fng
7810         typeset -Z5 ah[*]
7811         print 2a ${aa[*]} .
7812         print 2b ${ab[*]} .
7813         print 2c ${ac[*]} .
7814         print 2d ${ad[*]} .
7815         print 2e ${ae[*]} .
7816         print 2f ${af[*]} .
7817         print 2g ${ag[*]} .
7818         print 2h ${ah[*]} .
7819 expected-stdout:
7820         1a 001 002 .
7821         1b 001 002 .
7822         1c 001 002 .
7823         1d 001 002 .
7824         1e 001 002 .
7825         1f 001 002 .
7826         1g 001 002 .
7827         1h 1 2 .
7828         2a 9 .
7829         2b 001 002 .
7830         2c 92 .
7831         2d 009 002 .
7832         2e 9 .
7833         2f 9 002 .
7834         2g 009 .
7835         2h 00001 00002 .
7836 ---
7837 name: arrays-9a
7838 description:
7839         Check that we can concatenate arrays
7840 stdin:
7841         unset foo; foo=(bar); foo+=(baz); echo 1 ${!foo[*]} : ${foo[*]} .
7842         unset foo; foo=(foo bar); foo+=(baz); echo 2 ${!foo[*]} : ${foo[*]} .
7843 #       unset foo; foo=([2]=foo [0]=bar); foo+=(baz [5]=quux); echo 3 ${!foo[*]} : ${foo[*]} .
7844 expected-stdout:
7845         1 0 1 : bar baz .
7846         2 0 1 2 : foo bar baz .
7847 #       3 0 2 3 5 : bar foo baz quux .
7848 ---
7849 name: arrays-9b
7850 description:
7851         Check that we can concatenate parameters too
7852 stdin:
7853         unset foo; foo=bar; foo+=baz; echo 1 $foo .
7854         unset foo; typeset -i16 foo=10; foo+=20; echo 2 $foo .
7855 expected-stdout:
7856         1 barbaz .
7857         2 16#a20 .
7858 ---
7859 name: arrassign-basic
7860 description:
7861         Check basic whitespace conserving properties of wdarrassign
7862 stdin:
7863         a=($(echo a  b))
7864         b=($(echo "a  b"))
7865         c=("$(echo "a  b")")
7866         d=("$(echo a  b)")
7867         a+=($(echo c  d))
7868         b+=($(echo "c  d"))
7869         c+=("$(echo "c  d")")
7870         d+=("$(echo c  d)")
7871         echo ".a:${a[0]}.${a[1]}.${a[2]}.${a[3]}:"
7872         echo ".b:${b[0]}.${b[1]}.${b[2]}.${b[3]}:"
7873         echo ".c:${c[0]}.${c[1]}.${c[2]}.${c[3]}:"
7874         echo ".d:${d[0]}.${d[1]}.${d[2]}.${d[3]}:"
7875 expected-stdout:
7876         .a:a.b.c.d:
7877         .b:a.b.c.d:
7878         .c:a  b.c  d..:
7879         .d:a b.c d..:
7880 ---
7881 name: arrassign-fnc-none
7882 description:
7883         Check locality of array access inside a function
7884 stdin:
7885         function fn {
7886                 x+=(f)
7887                 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
7888         }
7889         function rfn {
7890                 if [[ -n $BASH_VERSION ]]; then
7891                         y=()
7892                 else
7893                         set -A y
7894                 fi
7895                 y+=(f)
7896                 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
7897         }
7898         x=(m m)
7899         y=(m m)
7900         echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
7901         fn
7902         echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
7903         fn
7904         echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
7905         echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
7906         rfn
7907         echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
7908         rfn
7909         echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
7910 expected-stdout:
7911         .f0:m.m..:
7912         .fn:m.m.f.:
7913         .f1:m.m.f.:
7914         .fn:m.m.f.f:
7915         .f2:m.m.f.f:
7916         .rf0:m.m..:
7917         .rfn:f...:
7918         .rf1:f...:
7919         .rfn:f...:
7920         .rf2:f...:
7921 ---
7922 name: arrassign-fnc-local
7923 description:
7924         Check locality of array access inside a function
7925         with the bash/mksh/ksh93 local/typeset keyword
7926         (note: ksh93 has no local; typeset works only in FKSH)
7927 stdin:
7928         function fn {
7929                 typeset x
7930                 x+=(f)
7931                 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
7932         }
7933         function rfn {
7934                 if [[ -n $BASH_VERSION ]]; then
7935                         y=()
7936                 else
7937                         set -A y
7938                 fi
7939                 typeset y
7940                 y+=(f)
7941                 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
7942         }
7943         function fnr {
7944                 typeset z
7945                 if [[ -n $BASH_VERSION ]]; then
7946                         z=()
7947                 else
7948                         set -A z
7949                 fi
7950                 z+=(f)
7951                 echo ".fnr:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
7952         }
7953         x=(m m)
7954         y=(m m)
7955         z=(m m)
7956         echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
7957         fn
7958         echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
7959         fn
7960         echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
7961         echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
7962         rfn
7963         echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
7964         rfn
7965         echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
7966         echo ".f0r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
7967         fnr
7968         echo ".f1r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
7969         fnr
7970         echo ".f2r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
7971 expected-stdout:
7972         .f0:m.m..:
7973         .fn:f...:
7974         .f1:m.m..:
7975         .fn:f...:
7976         .f2:m.m..:
7977         .rf0:m.m..:
7978         .rfn:f...:
7979         .rf1:...:
7980         .rfn:f...:
7981         .rf2:...:
7982         .f0r:m.m..:
7983         .fnr:f...:
7984         .f1r:m.m..:
7985         .fnr:f...:
7986         .f2r:m.m..:
7987 ---
7988 name: arrassign-fnc-global
7989 description:
7990         Check locality of array access inside a function
7991         with the mksh-specific global keyword
7992 stdin:
7993         function fn {
7994                 global x
7995                 x+=(f)
7996                 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
7997         }
7998         function rfn {
7999                 set -A y
8000                 global y
8001                 y+=(f)
8002                 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8003         }
8004         function fnr {
8005                 global z
8006                 set -A z
8007                 z+=(f)
8008                 echo ".fnr:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8009         }
8010         x=(m m)
8011         y=(m m)
8012         z=(m m)
8013         echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8014         fn
8015         echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8016         fn
8017         echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8018         echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8019         rfn
8020         echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8021         rfn
8022         echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8023         echo ".f0r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8024         fnr
8025         echo ".f1r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8026         fnr
8027         echo ".f2r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8028 expected-stdout:
8029         .f0:m.m..:
8030         .fn:m.m.f.:
8031         .f1:m.m.f.:
8032         .fn:m.m.f.f:
8033         .f2:m.m.f.f:
8034         .rf0:m.m..:
8035         .rfn:f...:
8036         .rf1:f...:
8037         .rfn:f...:
8038         .rf2:f...:
8039         .f0r:m.m..:
8040         .fnr:f...:
8041         .f1r:f...:
8042         .fnr:f...:
8043         .f2r:f...:
8044 ---
8045 name: strassign-fnc-none
8046 description:
8047         Check locality of string access inside a function
8048 stdin:
8049         function fn {
8050                 x+=f
8051                 echo ".fn:$x:"
8052         }
8053         function rfn {
8054                 y=
8055                 y+=f
8056                 echo ".rfn:$y:"
8057         }
8058         x=m
8059         y=m
8060         echo ".f0:$x:"
8061         fn
8062         echo ".f1:$x:"
8063         fn
8064         echo ".f2:$x:"
8065         echo ".rf0:$y:"
8066         rfn
8067         echo ".rf1:$y:"
8068         rfn
8069         echo ".rf2:$y:"
8070 expected-stdout:
8071         .f0:m:
8072         .fn:mf:
8073         .f1:mf:
8074         .fn:mff:
8075         .f2:mff:
8076         .rf0:m:
8077         .rfn:f:
8078         .rf1:f:
8079         .rfn:f:
8080         .rf2:f:
8081 ---
8082 name: strassign-fnc-local
8083 description:
8084         Check locality of string access inside a function
8085         with the bash/mksh/ksh93 local/typeset keyword
8086         (note: ksh93 has no local; typeset works only in FKSH)
8087 stdin:
8088         function fn {
8089                 typeset x
8090                 x+=f
8091                 echo ".fn:$x:"
8092         }
8093         function rfn {
8094                 y=
8095                 typeset y
8096                 y+=f
8097                 echo ".rfn:$y:"
8098         }
8099         function fnr {
8100                 typeset z
8101                 z=
8102                 z+=f
8103                 echo ".fnr:$z:"
8104         }
8105         x=m
8106         y=m
8107         z=m
8108         echo ".f0:$x:"
8109         fn
8110         echo ".f1:$x:"
8111         fn
8112         echo ".f2:$x:"
8113         echo ".rf0:$y:"
8114         rfn
8115         echo ".rf1:$y:"
8116         rfn
8117         echo ".rf2:$y:"
8118         echo ".f0r:$z:"
8119         fnr
8120         echo ".f1r:$z:"
8121         fnr
8122         echo ".f2r:$z:"
8123 expected-stdout:
8124         .f0:m:
8125         .fn:f:
8126         .f1:m:
8127         .fn:f:
8128         .f2:m:
8129         .rf0:m:
8130         .rfn:f:
8131         .rf1::
8132         .rfn:f:
8133         .rf2::
8134         .f0r:m:
8135         .fnr:f:
8136         .f1r:m:
8137         .fnr:f:
8138         .f2r:m:
8139 ---
8140 name: strassign-fnc-global
8141 description:
8142         Check locality of string access inside a function
8143         with the mksh-specific global keyword
8144 stdin:
8145         function fn {
8146                 global x
8147                 x+=f
8148                 echo ".fn:$x:"
8149         }
8150         function rfn {
8151                 y=
8152                 global y
8153                 y+=f
8154                 echo ".rfn:$y:"
8155         }
8156         function fnr {
8157                 global z
8158                 z=
8159                 z+=f
8160                 echo ".fnr:$z:"
8161         }
8162         x=m
8163         y=m
8164         z=m
8165         echo ".f0:$x:"
8166         fn
8167         echo ".f1:$x:"
8168         fn
8169         echo ".f2:$x:"
8170         echo ".rf0:$y:"
8171         rfn
8172         echo ".rf1:$y:"
8173         rfn
8174         echo ".rf2:$y:"
8175         echo ".f0r:$z:"
8176         fnr
8177         echo ".f1r:$z:"
8178         fnr
8179         echo ".f2r:$z:"
8180 expected-stdout:
8181         .f0:m:
8182         .fn:mf:
8183         .f1:mf:
8184         .fn:mff:
8185         .f2:mff:
8186         .rf0:m:
8187         .rfn:f:
8188         .rf1:f:
8189         .rfn:f:
8190         .rf2:f:
8191         .f0r:m:
8192         .fnr:f:
8193         .f1r:f:
8194         .fnr:f:
8195         .f2r:f:
8196 ---
8197 name: unset-fnc-local-ksh
8198 description:
8199         Check that “unset” removes a previous “local”
8200         (ksh93 syntax compatible version); apparently,
8201         there are shells which fail this?
8202 stdin:
8203         function f {
8204                 echo f0: $x
8205                 typeset x
8206                 echo f1: $x
8207                 x=fa
8208                 echo f2: $x
8209                 unset x
8210                 echo f3: $x
8211                 x=fb
8212                 echo f4: $x
8213         }
8214         x=o
8215         echo before: $x
8216         f
8217         echo after: $x
8218 expected-stdout:
8219         before: o
8220         f0: o
8221         f1:
8222         f2: fa
8223         f3: o
8224         f4: fb
8225         after: fb
8226 ---
8227 name: unset-fnc-local-sh
8228 description:
8229         Check that “unset” removes a previous “local”
8230         (Debian Policy §10.4 sh version); apparently,
8231         there are shells which fail this?
8232 stdin:
8233         f() {
8234                 echo f0: $x
8235                 local x
8236                 echo f1: $x
8237                 x=fa
8238                 echo f2: $x
8239                 unset x
8240                 echo f3: $x
8241                 x=fb
8242                 echo f4: $x
8243         }
8244         x=o
8245         echo before: $x
8246         f
8247         echo after: $x
8248 expected-stdout:
8249         before: o
8250         f0: o
8251         f1:
8252         f2: fa
8253         f3: o
8254         f4: fb
8255         after: fb
8256 ---
8257 name: varexpand-substr-1
8258 description:
8259         Check if bash-style substring expansion works
8260         when using positive numerics
8261 stdin:
8262         x=abcdefghi
8263         typeset -i y=123456789
8264         typeset -i 16 z=123456789       # 16#75bcd15
8265         echo a t${x:2:2} ${y:2:3} ${z:2:3} a
8266         echo b ${x::3} ${y::3} ${z::3} b
8267         echo c ${x:2:} ${y:2:} ${z:2:} c
8268         echo d ${x:2} ${y:2} ${z:2} d
8269         echo e ${x:2:6} ${y:2:6} ${z:2:7} e
8270         echo f ${x:2:7} ${y:2:7} ${z:2:8} f
8271         echo g ${x:2:8} ${y:2:8} ${z:2:9} g
8272 expected-stdout:
8273         a tcd 345 #75 a
8274         b abc 123 16# b
8275         c c
8276         d cdefghi 3456789 #75bcd15 d
8277         e cdefgh 345678 #75bcd1 e
8278         f cdefghi 3456789 #75bcd15 f
8279         g cdefghi 3456789 #75bcd15 g
8280 ---
8281 name: varexpand-substr-2
8282 description:
8283         Check if bash-style substring expansion works
8284         when using negative numerics or expressions
8285 stdin:
8286         x=abcdefghi
8287         typeset -i y=123456789
8288         typeset -i 16 z=123456789       # 16#75bcd15
8289         n=2
8290         echo a ${x:$n:3} ${y:$n:3} ${z:$n:3} a
8291         echo b ${x:(n):3} ${y:(n):3} ${z:(n):3} b
8292         echo c ${x:(-2):1} ${y:(-2):1} ${z:(-2):1} c
8293         echo d t${x: n:2} ${y: n:3} ${z: n:3} d
8294 expected-stdout:
8295         a cde 345 #75 a
8296         b cde 345 #75 b
8297         c h 8 1 c
8298         d tcd 345 #75 d
8299 ---
8300 name: varexpand-substr-3
8301 description:
8302         Check that some things that work in bash fail.
8303         This is by design. And that some things fail in both.
8304 stdin:
8305         export x=abcdefghi n=2
8306         "$__progname" -c 'echo v${x:(n)}x'
8307         "$__progname" -c 'echo w${x: n}x'
8308         "$__progname" -c 'echo x${x:n}x'
8309         "$__progname" -c 'echo y${x:}x'
8310         "$__progname" -c 'echo z${x}x'
8311         "$__progname" -c 'x=abcdef;y=123;echo ${x:${y:2:1}:2}' >/dev/null 2>&1; echo $?
8312 expected-stdout:
8313         vcdefghix
8314         wcdefghix
8315         zabcdefghix
8316         1
8317 expected-stderr-pattern:
8318         /x:n.*bad substitution.*\n.*bad substitution/
8319 ---
8320 name: varexpand-substr-4
8321 description:
8322         Check corner cases for substring expansion
8323 stdin:
8324         x=abcdefghi
8325         integer y=2
8326         echo a ${x:(y == 1 ? 2 : 3):4} a
8327 expected-stdout:
8328         a defg a
8329 ---
8330 name: varexpand-substr-5A
8331 description:
8332         Check that substring expansions work on characters
8333 stdin:
8334         set +U
8335         x=mäh
8336         echo a ${x::1} ${x: -1} a
8337         echo b ${x::3} ${x: -3} b
8338         echo c ${x:1:2} ${x: -3:2} c
8339         echo d ${#x} d
8340 expected-stdout:
8341         a m h a
8342         b mä äh b
8343         c ä ä c
8344         d 4 d
8345 ---
8346 name: varexpand-substr-5W
8347 description:
8348         Check that substring expansions work on characters
8349 stdin:
8350         set -U
8351         x=mäh
8352         echo a ${x::1} ${x: -1} a
8353         echo b ${x::2} ${x: -2} b
8354         echo c ${x:1:1} ${x: -2:1} c
8355         echo d ${#x} d
8356 expected-stdout:
8357         a m h a
8358         b mä äh b
8359         c ä ä c
8360         d 3 d
8361 ---
8362 name: varexpand-substr-6
8363 description:
8364         Check that string substitution works correctly
8365 stdin:
8366         foo=1
8367         bar=2
8368         baz=qwertyuiop
8369         echo a ${baz: foo: bar}
8370         echo b ${baz: foo: $bar}
8371         echo c ${baz: $foo: bar}
8372         echo d ${baz: $foo: $bar}
8373 expected-stdout:
8374         a we
8375         b we
8376         c we
8377         d we
8378 ---
8379 name: varexpand-special-hash
8380 description:
8381         Check special ${var@x} expansion for x=hash
8382 stdin:
8383         typeset -i8 foo=10
8384         bar=baz
8385         unset baz
8386         print ${foo@#} ${bar@#} ${baz@#} .
8387 expected-stdout:
8388         9B15FBFB CFBDD32B 00000000 .
8389 ---
8390 name: varexpand-special-quote
8391 description:
8392         Check special ${var@Q} expansion for quoted strings
8393 stdin:
8394         set +U
8395         i=x
8396         j=a\ b
8397         k=$'c
8398         d\xA0''e€f'
8399         print -r -- "<i=$i j=$j k=$k>"
8400         s="u=${i@Q} v=${j@Q} w=${k@Q}"
8401         print -r -- "s=\"$s\""
8402         eval "$s"
8403         typeset -p u v w
8404 expected-stdout:
8405         <i=x j=a b k=c
8406         d eâ\82¬f>
8407         s="u=x v='a b' w=$'c\nd\240e\u20ACf'"
8408         typeset u=x
8409         typeset v='a b'
8410         typeset w=$'c\nd\240e\u20ACf'
8411 ---
8412 name: varexpand-null-1
8413 description:
8414         Ensure empty strings expand emptily
8415 stdin:
8416         print s ${a} . ${b} S
8417         print t ${a#?} . ${b%?} T
8418         print r ${a=} . ${b/c/d} R
8419         print q
8420         print s "${a}" . "${b}" S
8421         print t "${a#?}" . "${b%?}" T
8422         print r "${a=}" . "${b/c/d}" R
8423 expected-stdout:
8424         s . S
8425         t . T
8426         r . R
8427         q
8428         s  .  S
8429         t  .  T
8430         r  .  R
8431 ---
8432 name: varexpand-null-2
8433 description:
8434         Ensure empty strings, when quoted, are expanded as empty strings
8435 stdin:
8436         print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "<$x> "; done' >pfs
8437         chmod +x pfs
8438         ./pfs 1 "${a}" 2 "${a#?}" + "${b%?}" 3 "${a=}" + "${b/c/d}"
8439         echo .
8440 expected-stdout:
8441         <1> <> <2> <> <+> <> <3> <> <+> <> .
8442 ---
8443 name: varexpand-null-3
8444 description:
8445         Ensure concatenating behaviour matches other shells
8446 stdin:
8447         showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
8448         x=; showargs 1 "$x"$@
8449         set A; showargs 2 "${@:+}"
8450         n() { echo "$#"; }
8451         unset e
8452         set -- a b
8453         n """$@"
8454         n "$@"
8455         n "$@"""
8456         n "$e""$@"
8457         n "$@"
8458         n "$@""$e"
8459         set --
8460         n """$@"
8461         n "$@"
8462         n "$@"""
8463         n "$e""$@"
8464         n "$@"
8465         n "$@""$e"
8466 expected-stdout:
8467         <1> <> .
8468         <2> <> .
8469         2
8470         2
8471         2
8472         2
8473         2
8474         2
8475         1
8476         0
8477         1
8478         1
8479         0
8480         1
8481 ---
8482 name: print-funny-chars
8483 description:
8484         Check print builtin's capability to output designated characters
8485 stdin:
8486         print '<\0144\0344\xDB\u00DB\u20AC\uDB\x40>'
8487 expected-stdout:
8488         <däÛÃ\9bâ\82¬Ã\9b@>
8489 ---
8490 name: print-bksl-c
8491 description:
8492         Check print builtin's \c escape
8493 stdin:
8494         print '\ca'; print b
8495 expected-stdout:
8496         ab
8497 ---
8498 name: print-cr
8499 description:
8500         Check that CR+LF is not collapsed into LF as some MSYS shells wrongly do
8501 stdin:
8502         echo '#!'"$__progname" >foo
8503         cat >>foo <<-'EOF'
8504                 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'
8505                 print \?\r
8506         EOF
8507         chmod +x foo
8508         echo "[$(./foo)]"
8509         ./foo | while IFS= read -r line; do
8510                 print -r -- "{$line}"
8511         done
8512 expected-stdout:
8513         [220-blau.mirbsd.org ESMTP ready at Thu, 25 Jul 2013 15:57:57 GMT\r
8514         220->> Bitte keine Werbung einwerfen! <<\r\r
8515         220 Who do you wanna pretend to be today?\r]
8516         {220-blau.mirbsd.org ESMTP ready at Thu, 25 Jul 2013 15:57:57 GMT\r}
8517         {220->> Bitte keine Werbung einwerfen! <<\r\r}
8518         {220 Who do you wanna pretend to be today?\r}
8519 ---
8520 name: print-nul-chars
8521 description:
8522         Check handling of NUL characters for print and COMSUB
8523 stdin:
8524         x=$(print '<\0>')
8525         print $(($(print '<\0>' | wc -c))) $(($(print "$x" | wc -c))) \
8526             ${#x} "$x" '<\0>'
8527 expected-stdout-pattern:
8528         /^4 3 2 <> <\0>$/
8529 ---
8530 name: print-escapes
8531 description:
8532         Check backslash expansion by the print builtin
8533 stdin:
8534         print '\ \!\"\#\$\%\&'\\\''\(\)\*\+\,\-\.\/\0\1\2\3\4\5\6\7\8' \
8535             '\9\:\;\<\=\>\?\@\A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T' \
8536             '\U\V\W\X\Y\Z\[\\\]\^\_\`\a\b  \d\e\f\g\h\i\j\k\l\m\n\o\p' \
8537             '\q\r\s\t\u\v\w\x\y\z\{\|\}\~' '\u20acd' '\U20acd' '\x123' \
8538             '\0x' '\0123' '\01234' | {
8539                 # integer-base-one-3As
8540                 typeset -Uui16 -Z11 pos=0
8541                 typeset -Uui16 -Z5 hv=2147483647
8542                 typeset -i1 wc=0x0A
8543                 dasc=
8544                 nl=${wc#1#}
8545                 while IFS= read -r line; do
8546                         line=$line$nl
8547                         while [[ -n $line ]]; do
8548                                 hv=1#${line::1}
8549                                 if (( (pos & 15) == 0 )); then
8550                                         (( pos )) && print "$dasc|"
8551                                         print -n "${pos#16#}  "
8552                                         dasc=' |'
8553                                 fi
8554                                 print -n "${hv#16#} "
8555                                 if (( (hv < 32) || (hv > 126) )); then
8556                                         dasc=$dasc.
8557                                 else
8558                                         dasc=$dasc${line::1}
8559                                 fi
8560                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
8561                                 line=${line:1}
8562                         done
8563                 done
8564                 while (( pos & 15 )); do
8565                         print -n '   '
8566                         (( (pos++ & 15) == 7 )) && print -n -- '- '
8567                 done
8568                 (( hv == 2147483647 )) || print "$dasc|"
8569         }
8570 expected-stdout:
8571         00000000  5C 20 5C 21 5C 22 5C 23 - 5C 24 5C 25 5C 26 5C 27  |\ \!\"\#\$\%\&\'|
8572         00000010  5C 28 5C 29 5C 2A 5C 2B - 5C 2C 5C 2D 5C 2E 5C 2F  |\(\)\*\+\,\-\.\/|
8573         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|
8574         00000030  20 5C 39 5C 3A 5C 3B 5C - 3C 5C 3D 5C 3E 5C 3F 5C  | \9\:\;\<\=\>\?\|
8575         00000040  40 5C 41 5C 42 5C 43 5C - 44 1B 5C 46 5C 47 5C 48  |@\A\B\C\D.\F\G\H|
8576         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|
8577         00000060  5C 51 5C 52 5C 53 5C 54 - 20 5C 56 5C 57 5C 58 5C  |\Q\R\S\T \V\W\X\|
8578         00000070  59 5C 5A 5C 5B 5C 5C 5D - 5C 5E 5C 5F 5C 60 07 08  |Y\Z\[\]\^\_\`..|
8579         00000080  20 20 5C 64 1B 0C 5C 67 - 5C 68 5C 69 5C 6A 5C 6B  |  \d..\g\h\i\j\k|
8580         00000090  5C 6C 5C 6D 0A 5C 6F 5C - 70 20 5C 71 0D 5C 73 09  |\l\m.\o\p \q.\s.|
8581         000000A0  0B 5C 77 5C 79 5C 7A 5C - 7B 5C 7C 5C 7D 5C 7E 20  |.\w\y\z\{\|\}\~ |
8582         000000B0  E2 82 AC 64 20 EF BF BD - 20 12 33 20 78 20 53 20  |...d ... .3 x S |
8583         000000C0  53 34 0A                -                          |S4.|
8584 ---
8585 name: dollar-doublequoted-strings
8586 description:
8587         Check that a $ preceding "…" is ignored
8588 stdin:
8589         echo $"Localise me!"
8590         cat <<<$"Me too!"
8591         V=X
8592         aol=aol
8593         cat <<-$"aol"
8594                 I do not take a $V for a V!
8595         aol
8596 expected-stdout:
8597         Localise me!
8598         Me too!
8599         I do not take a $V for a V!
8600 ---
8601 name: dollar-quoted-strings
8602 description:
8603         Check backslash expansion by $'…' strings
8604 stdin:
8605         print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
8606         chmod +x pfn
8607         ./pfn $'\ \!\"\#\$\%\&\'\(\)\*\+\,\-\.\/ \1\2\3\4\5\6' \
8608             $'a\0b' $'a\01b' $'\7\8\9\:\;\<\=\>\?\@\A\B\C\D\E\F\G\H\I' \
8609             $'\J\K\L\M\N\O\P\Q\R\S\T\U1\V\W\X\Y\Z\[\\\]\^\_\`\a\b\d\e' \
8610             $'\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u1\v\w\x1\y\z\{\|\}\~ $x' \
8611             $'\u20acd' $'\U20acd' $'\x123' $'fn\x0rd' $'\0234' $'\234' \
8612             $'\2345' $'\ca' $'\c!' $'\c?' $'\c€' $'a\
8613         b' | {
8614                 # integer-base-one-3As
8615                 typeset -Uui16 -Z11 pos=0
8616                 typeset -Uui16 -Z5 hv=2147483647
8617                 typeset -i1 wc=0x0A
8618                 dasc=
8619                 nl=${wc#1#}
8620                 while IFS= read -r line; do
8621                         line=$line$nl
8622                         while [[ -n $line ]]; do
8623                                 hv=1#${line::1}
8624                                 if (( (pos & 15) == 0 )); then
8625                                         (( pos )) && print "$dasc|"
8626                                         print -n "${pos#16#}  "
8627                                         dasc=' |'
8628                                 fi
8629                                 print -n "${hv#16#} "
8630                                 if (( (hv < 32) || (hv > 126) )); then
8631                                         dasc=$dasc.
8632                                 else
8633                                         dasc=$dasc${line::1}
8634                                 fi
8635                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
8636                                 line=${line:1}
8637                         done
8638                 done
8639                 while (( pos & 15 )); do
8640                         print -n '   '
8641                         (( (pos++ & 15) == 7 )) && print -n -- '- '
8642                 done
8643                 (( hv == 2147483647 )) || print "$dasc|"
8644         }
8645 expected-stdout:
8646         00000000  20 21 22 23 24 25 26 27 - 28 29 2A 2B 2C 2D 2E 2F  | !"#$%&'()*+,-./|
8647         00000010  20 01 02 03 04 05 06 0A - 61 0A 61 01 62 0A 07 38  | .......a.a.b..8|
8648         00000020  39 3A 3B 3C 3D 3E 3F 40 - 41 42 43 44 1B 46 47 48  |9:;<=>?@ABCD.FGH|
8649         00000030  49 0A 4A 4B 4C 4D 4E 4F - 50 51 52 53 54 01 56 57  |I.JKLMNOPQRST.VW|
8650         00000040  58 59 5A 5B 5C 5D 5E 5F - 60 07 08 64 1B 0A 0C 67  |XYZ[\]^_`..d...g|
8651         00000050  68 69 6A 6B 6C 6D 0A 6F - 70 71 0D 73 09 01 0B 77  |hijklm.opq.s...w|
8652         00000060  01 79 7A 7B 7C 7D 7E 20 - 24 78 0A E2 82 AC 64 0A  |.yz{|}~ $x....d.|
8653         00000070  EF BF BD 0A C4 A3 0A 66 - 6E 0A 13 34 0A 9C 0A 9C  |.......fn..4....|
8654         00000080  35 0A 01 0A 01 0A 7F 0A - 02 82 AC 0A 61 0A 62 0A  |5...........a.b.|
8655 ---
8656 name: dollar-quotes-in-heredocs-strings
8657 description:
8658         They are, however, not parsed in here documents, here strings
8659         (outside of string delimiters) or regular strings, but in
8660         parameter substitutions.
8661 stdin:
8662         cat <<EOF
8663                 dollar = strchr(s, '$');        /* ' */
8664                 foo " bar \" baz
8665         EOF
8666         cat <<$'a\tb'
8667         a\tb
8668         a       b
8669         cat <<<"dollar = strchr(s, '$');        /* ' */"
8670         cat <<<'dollar = strchr(s, '\''$'\'');  /* '\'' */'
8671         x="dollar = strchr(s, '$');     /* ' */"
8672         cat <<<"$x"
8673         cat <<<$'a\E[0m\tb'
8674         unset nl; print -r -- "x${nl:=$'\n'}y"
8675         echo "1 foo\"bar"
8676         # cf & HEREDOC
8677         cat <<EOF
8678         2 foo\"bar
8679         EOF
8680         # probably never reached for here strings?
8681         cat <<<"3 foo\"bar"
8682         cat <<<"4 foo\\\"bar"
8683         cat <<<'5 foo\"bar'
8684         # old scripts use this (e.g. ncurses)
8685         echo "^$"
8686         # make sure this works, outside of quotes
8687         cat <<<'7'$'\t''.'
8688 expected-stdout:
8689                 dollar = strchr(s, '$');        /* ' */
8690                 foo " bar \" baz
8691         a\tb
8692         dollar = strchr(s, '$');        /* ' */
8693         dollar = strchr(s, '$');        /* ' */
8694         dollar = strchr(s, '$');        /* ' */
8695         a\e[0m   b
8696         x
8697         y
8698         1 foo"bar
8699         2 foo\"bar
8700         3 foo"bar
8701         4 foo\"bar
8702         5 foo\"bar
8703         ^$
8704         7       .
8705 ---
8706 name: dot-needs-argument
8707 description:
8708         check Debian #415167 solution: '.' without arguments should fail
8709 stdin:
8710         "$__progname" -c .
8711         "$__progname" -c source
8712 expected-exit: e != 0
8713 expected-stderr-pattern:
8714         /\.: missing argument.*\n.*\.: missing argument/
8715 ---
8716 name: alias-function-no-conflict
8717 description:
8718         make aliases not conflict with functions
8719         note: for ksh-like functions, the order of preference is
8720         different; bash outputs baz instead of bar in line 2 below
8721 stdin:
8722         alias foo='echo bar'
8723         foo() {
8724                 echo baz
8725         }
8726         alias korn='echo bar'
8727         function korn {
8728                 echo baz
8729         }
8730         foo
8731         korn
8732         unset -f foo
8733         foo 2>/dev/null || echo rab
8734 expected-stdout:
8735         baz
8736         bar
8737         rab
8738 ---
8739 name: bash-function-parens
8740 description:
8741         ensure the keyword function is ignored when preceding
8742         POSIX style function declarations (bashism)
8743 stdin:
8744         mk() {
8745                 echo '#!'"$__progname"
8746                 echo "$1 {"
8747                 echo '  echo "bar='\''$0'\'\"
8748                 echo '}'
8749                 echo ${2:-foo}
8750         }
8751         mk 'function foo' >f-korn
8752         mk 'foo ()' >f-dash
8753         mk 'function foo ()' >f-bash
8754         mk 'function stop ()' stop >f-stop
8755         print '#!'"$__progname"'\nprint -r -- "${0%/f-argh}"' >f-argh
8756         chmod +x f-*
8757         u=$(./f-argh)
8758         x="korn: $(./f-korn)"; echo "${x/@("$u")/.}"
8759         x="dash: $(./f-dash)"; echo "${x/@("$u")/.}"
8760         x="bash: $(./f-bash)"; echo "${x/@("$u")/.}"
8761         x="stop: $(./f-stop)"; echo "${x/@("$u")/.}"
8762 expected-stdout:
8763         korn: bar='foo'
8764         dash: bar='./f-dash'
8765         bash: bar='./f-bash'
8766         stop: bar='./f-stop'
8767 ---
8768 name: integer-base-one-1
8769 description:
8770         check if the use of fake integer base 1 works
8771 stdin:
8772         set -U
8773         typeset -Uui16 i0=1#ï i1=1#â\82¬
8774         typeset -i1 o0a=64
8775         typeset -i1 o1a=0x263A
8776         typeset -Uui1 o0b=0x7E
8777         typeset -Uui1 o1b=0xFDD0
8778         integer px=0xCAFE 'p0=1# ' p1=1#… pl=1#f
8779         echo "in <$i0> <$i1>"
8780         echo "out <${o0a#1#}|${o0b#1#}> <${o1a#1#}|${o1b#1#}>"
8781         typeset -Uui1 i0 i1
8782         echo "pass <$px> <$p0> <$p1> <$pl> <${i0#1#}|${i1#1#}>"
8783         typeset -Uui16 tv1=1#~ tv2=1#\7f tv3=1#\80 tv4=1#\81 tv5=1#À tv6=1#Á tv7=1#  tv8=1#Â\80
8784         echo "specX <${tv1#16#}> <${tv2#16#}> <${tv3#16#}> <${tv4#16#}> <${tv5#16#}> <${tv6#16#}> <${tv7#16#}> <${tv8#16#}>"
8785         typeset -i1 tv1 tv2 tv3 tv4 tv5 tv6 tv7 tv8
8786         echo "specW <${tv1#1#}> <${tv2#1#}> <${tv3#1#}> <${tv4#1#}> <${tv5#1#}> <${tv6#1#}> <${tv7#1#}> <${tv8#1#}>"
8787         typeset -i1 xs1=0xEF7F xs2=0xEF80 xs3=0xFDD0
8788         echo "specU <${xs1#1#}> <${xs2#1#}> <${xs3#1#}>"
8789 expected-stdout:
8790         in <16#EFEF> <16#20AC>
8791         out <@|~> <☺|﷐>
8792         pass <16#cafe> <1# > <1#â\80¦> <1#f> <ï|â\82¬>
8793         specX <7E> <7F> <EF80> <EF81> <EFC0> <EFC1> <A0> <80>
8794         specW <~> <\7f> <\80> <\81> <À> <Á> < > <Â\80>
8795         specU <> <\80> <ï·\90>
8796 ---
8797 name: integer-base-one-2a
8798 description:
8799         check if the use of fake integer base 1 stops at correct characters
8800 stdin:
8801         set -U
8802         integer x=1#foo
8803         echo /$x/
8804 expected-stderr-pattern:
8805         /1#foo: unexpected 'oo'/
8806 expected-exit: e != 0
8807 ---
8808 name: integer-base-one-2b
8809 description:
8810         check if the use of fake integer base 1 stops at correct characters
8811 stdin:
8812         set -U
8813         integer x=1#À\80
8814         echo /$x/
8815 expected-stderr-pattern:
8816         /1#À\80: unexpected '\80'/
8817 expected-exit: e != 0
8818 ---
8819 name: integer-base-one-2c1
8820 description:
8821         check if the use of fake integer base 1 stops at correct characters
8822 stdin:
8823         set -U
8824         integer x=1#…
8825         echo /$x/
8826 expected-stdout:
8827         /1#…/
8828 ---
8829 name: integer-base-one-2c2
8830 description:
8831         check if the use of fake integer base 1 stops at correct characters
8832 stdin:
8833         set +U
8834         integer x=1#…
8835         echo /$x/
8836 expected-stderr-pattern:
8837         /1#â\80¦: unexpected '\80'/
8838 expected-exit: e != 0
8839 ---
8840 name: integer-base-one-2d1
8841 description:
8842         check if the use of fake integer base 1 handles octets okay
8843 stdin:
8844         set -U
8845         typeset -i16 x=1#ÿ
8846         echo /$x/       # invalid utf-8
8847 expected-stdout:
8848         /16#efff/
8849 ---
8850 name: integer-base-one-2d2
8851 description:
8852         check if the use of fake integer base 1 handles octets
8853 stdin:
8854         set -U
8855         typeset -i16 x=1#Â
8856         echo /$x/       # invalid 2-byte
8857 expected-stdout:
8858         /16#efc2/
8859 ---
8860 name: integer-base-one-2d3
8861 description:
8862         check if the use of fake integer base 1 handles octets
8863 stdin:
8864         set -U
8865         typeset -i16 x=1#ï
8866         echo /$x/       # invalid 2-byte
8867 expected-stdout:
8868         /16#efef/
8869 ---
8870 name: integer-base-one-2d4
8871 description:
8872         check if the use of fake integer base 1 stops at invalid input
8873 stdin:
8874         set -U
8875         typeset -i16 x=1#ï¿À
8876         echo /$x/       # invalid 3-byte
8877 expected-stderr-pattern:
8878         /1#ï¿À: unexpected '¿'/
8879 expected-exit: e != 0
8880 ---
8881 name: integer-base-one-2d5
8882 description:
8883         check if the use of fake integer base 1 stops at invalid input
8884 stdin:
8885         set -U
8886         typeset -i16 x=1#À\80
8887         echo /$x/       # non-minimalistic
8888 expected-stderr-pattern:
8889         /1#À\80: unexpected '\80'/
8890 expected-exit: e != 0
8891 ---
8892 name: integer-base-one-2d6
8893 description:
8894         check if the use of fake integer base 1 stops at invalid input
8895 stdin:
8896         set -U
8897         typeset -i16 x=1#à\80\80
8898         echo /$x/       # non-minimalistic
8899 expected-stderr-pattern:
8900         /1#à\80\80: unexpected '\80'/
8901 expected-exit: e != 0
8902 ---
8903 name: integer-base-one-3As
8904 description:
8905         some sample code for hexdumping
8906         not NUL safe; input lines must be NL terminated
8907 stdin:
8908         {
8909                 print 'Hello, World!\\\nこんにちは!'
8910                 typeset -Uui16 i=0x100
8911                 # change that to 0xFF once we can handle embedded
8912                 # NUL characters in strings / here documents
8913                 while (( i++ < 0x1FF )); do
8914                         print -n "\x${i#16#1}"
8915                 done
8916                 print '\0z'
8917         } | {
8918                 # integer-base-one-3As
8919                 typeset -Uui16 -Z11 pos=0
8920                 typeset -Uui16 -Z5 hv=2147483647
8921                 typeset -i1 wc=0x0A
8922                 dasc=
8923                 nl=${wc#1#}
8924                 while IFS= read -r line; do
8925                         line=$line$nl
8926                         while [[ -n $line ]]; do
8927                                 hv=1#${line::1}
8928                                 if (( (pos & 15) == 0 )); then
8929                                         (( pos )) && print "$dasc|"
8930                                         print -n "${pos#16#}  "
8931                                         dasc=' |'
8932                                 fi
8933                                 print -n "${hv#16#} "
8934                                 if (( (hv < 32) || (hv > 126) )); then
8935                                         dasc=$dasc.
8936                                 else
8937                                         dasc=$dasc${line::1}
8938                                 fi
8939                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
8940                                 line=${line:1}
8941                         done
8942                 done
8943                 while (( pos & 15 )); do
8944                         print -n '   '
8945                         (( (pos++ & 15) == 7 )) && print -n -- '- '
8946                 done
8947                 (( hv == 2147483647 )) || print "$dasc|"
8948         }
8949 expected-stdout:
8950         00000000  48 65 6C 6C 6F 2C 20 57 - 6F 72 6C 64 21 5C 0A E3  |Hello, World!\..|
8951         00000010  81 93 E3 82 93 E3 81 AB - E3 81 A1 E3 81 AF EF BC  |................|
8952         00000020  81 0A 01 02 03 04 05 06 - 07 08 09 0A 0B 0C 0D 0E  |................|
8953         00000030  0F 10 11 12 13 14 15 16 - 17 18 19 1A 1B 1C 1D 1E  |................|
8954         00000040  1F 20 21 22 23 24 25 26 - 27 28 29 2A 2B 2C 2D 2E  |. !"#$%&'()*+,-.|
8955         00000050  2F 30 31 32 33 34 35 36 - 37 38 39 3A 3B 3C 3D 3E  |/0123456789:;<=>|
8956         00000060  3F 40 41 42 43 44 45 46 - 47 48 49 4A 4B 4C 4D 4E  |?@ABCDEFGHIJKLMN|
8957         00000070  4F 50 51 52 53 54 55 56 - 57 58 59 5A 5B 5C 5D 5E  |OPQRSTUVWXYZ[\]^|
8958         00000080  5F 60 61 62 63 64 65 66 - 67 68 69 6A 6B 6C 6D 6E  |_`abcdefghijklmn|
8959         00000090  6F 70 71 72 73 74 75 76 - 77 78 79 7A 7B 7C 7D 7E  |opqrstuvwxyz{|}~|
8960         000000A0  7F 80 81 82 83 84 85 86 - 87 88 89 8A 8B 8C 8D 8E  |................|
8961         000000B0  8F 90 91 92 93 94 95 96 - 97 98 99 9A 9B 9C 9D 9E  |................|
8962         000000C0  9F A0 A1 A2 A3 A4 A5 A6 - A7 A8 A9 AA AB AC AD AE  |................|
8963         000000D0  AF B0 B1 B2 B3 B4 B5 B6 - B7 B8 B9 BA BB BC BD BE  |................|
8964         000000E0  BF C0 C1 C2 C3 C4 C5 C6 - C7 C8 C9 CA CB CC CD CE  |................|
8965         000000F0  CF D0 D1 D2 D3 D4 D5 D6 - D7 D8 D9 DA DB DC DD DE  |................|
8966         00000100  DF E0 E1 E2 E3 E4 E5 E6 - E7 E8 E9 EA EB EC ED EE  |................|
8967         00000110  EF F0 F1 F2 F3 F4 F5 F6 - F7 F8 F9 FA FB FC FD FE  |................|
8968         00000120  FF 7A 0A                -                          |.z.|
8969 ---
8970 name: integer-base-one-3Ws
8971 description:
8972         some sample code for hexdumping Unicode
8973         not NUL safe; input lines must be NL terminated
8974 stdin:
8975         set -U
8976         {
8977                 print 'Hello, World!\\\nこんにちは!'
8978                 typeset -Uui16 i=0x100
8979                 # change that to 0xFF once we can handle embedded
8980                 # NUL characters in strings / here documents
8981                 while (( i++ < 0x1FF )); do
8982                         print -n "\u${i#16#1}"
8983                 done
8984                 print
8985                 print \\xff             # invalid utf-8
8986                 print \\xc2             # invalid 2-byte
8987                 print \\xef\\xbf\\xc0   # invalid 3-byte
8988                 print \\xc0\\x80        # non-minimalistic
8989                 print \\xe0\\x80\\x80   # non-minimalistic
8990                 print '�￾￿'       # end of range
8991                 print '\0z'             # embedded NUL
8992         } | {
8993                 # integer-base-one-3Ws
8994                 typeset -Uui16 -Z11 pos=0
8995                 typeset -Uui16 -Z7 hv
8996                 typeset -i1 wc=0x0A
8997                 typeset -i lpos
8998                 dasc=
8999                 nl=${wc#1#}
9000                 while IFS= read -r line; do
9001                         line=$line$nl
9002                         lpos=0
9003                         while (( lpos < ${#line} )); do
9004                                 wc=1#${line:(lpos++):1}
9005                                 if (( (wc < 32) || \
9006                                     ((wc > 126) && (wc < 160)) )); then
9007                                         dch=.
9008                                 elif (( (wc & 0xFF80) == 0xEF80 )); then
9009                                         dch=�
9010                                 else
9011                                         dch=${wc#1#}
9012                                 fi
9013                                 if (( (pos & 7) == 7 )); then
9014                                         dasc=$dasc$dch
9015                                         dch=
9016                                 elif (( (pos & 7) == 0 )); then
9017                                         (( pos )) && print "$dasc|"
9018                                         print -n "${pos#16#}  "
9019                                         dasc=' |'
9020                                 fi
9021                                 let hv=wc
9022                                 print -n "${hv#16#} "
9023                                 (( (pos++ & 7) == 3 )) && \
9024                                     print -n -- '- '
9025                                 dasc=$dasc$dch
9026                         done
9027                 done
9028                 while (( pos & 7 )); do
9029                         print -n '     '
9030                         (( (pos++ & 7) == 3 )) && print -n -- '- '
9031                 done
9032                 (( hv == 2147483647 )) || print "$dasc|"
9033         }
9034 expected-stdout:
9035         00000000  0048 0065 006C 006C - 006F 002C 0020 0057  |Hello, W|
9036         00000008  006F 0072 006C 0064 - 0021 005C 000A 3053  |orld!\.こ|
9037         00000010  3093 306B 3061 306F - FF01 000A 0001 0002  |んにちは!...|
9038         00000018  0003 0004 0005 0006 - 0007 0008 0009 000A  |........|
9039         00000020  000B 000C 000D 000E - 000F 0010 0011 0012  |........|
9040         00000028  0013 0014 0015 0016 - 0017 0018 0019 001A  |........|
9041         00000030  001B 001C 001D 001E - 001F 0020 0021 0022  |..... !"|
9042         00000038  0023 0024 0025 0026 - 0027 0028 0029 002A  |#$%&'()*|
9043         00000040  002B 002C 002D 002E - 002F 0030 0031 0032  |+,-./012|
9044         00000048  0033 0034 0035 0036 - 0037 0038 0039 003A  |3456789:|
9045         00000050  003B 003C 003D 003E - 003F 0040 0041 0042  |;<=>?@AB|
9046         00000058  0043 0044 0045 0046 - 0047 0048 0049 004A  |CDEFGHIJ|
9047         00000060  004B 004C 004D 004E - 004F 0050 0051 0052  |KLMNOPQR|
9048         00000068  0053 0054 0055 0056 - 0057 0058 0059 005A  |STUVWXYZ|
9049         00000070  005B 005C 005D 005E - 005F 0060 0061 0062  |[\]^_`ab|
9050         00000078  0063 0064 0065 0066 - 0067 0068 0069 006A  |cdefghij|
9051         00000080  006B 006C 006D 006E - 006F 0070 0071 0072  |klmnopqr|
9052         00000088  0073 0074 0075 0076 - 0077 0078 0079 007A  |stuvwxyz|
9053         00000090  007B 007C 007D 007E - 007F 0080 0081 0082  |{|}~....|
9054         00000098  0083 0084 0085 0086 - 0087 0088 0089 008A  |........|
9055         000000A0  008B 008C 008D 008E - 008F 0090 0091 0092  |........|
9056         000000A8  0093 0094 0095 0096 - 0097 0098 0099 009A  |........|
9057         000000B0  009B 009C 009D 009E - 009F 00A0 00A1 00A2  |..... ¡¢|
9058         000000B8  00A3 00A4 00A5 00A6 - 00A7 00A8 00A9 00AA  |£¤¥¦§¨©ª|
9059         000000C0  00AB 00AC 00AD 00AE - 00AF 00B0 00B1 00B2  |«¬­®¯°±²|
9060         000000C8  00B3 00B4 00B5 00B6 - 00B7 00B8 00B9 00BA  |³´µ¶·¸¹º|
9061         000000D0  00BB 00BC 00BD 00BE - 00BF 00C0 00C1 00C2  |»¼½¾¿ÀÁÂ|
9062         000000D8  00C3 00C4 00C5 00C6 - 00C7 00C8 00C9 00CA  |ÃÄÅÆÇÈÉÊ|
9063         000000E0  00CB 00CC 00CD 00CE - 00CF 00D0 00D1 00D2  |ËÌÍÎÏÐÑÒ|
9064         000000E8  00D3 00D4 00D5 00D6 - 00D7 00D8 00D9 00DA  |ÓÔÕÖ×ØÙÚ|
9065         000000F0  00DB 00DC 00DD 00DE - 00DF 00E0 00E1 00E2  |ÛÜÝÞßàáâ|
9066         000000F8  00E3 00E4 00E5 00E6 - 00E7 00E8 00E9 00EA  |ãäåæçèéê|
9067         00000100  00EB 00EC 00ED 00EE - 00EF 00F0 00F1 00F2  |ëìíîïðñò|
9068         00000108  00F3 00F4 00F5 00F6 - 00F7 00F8 00F9 00FA  |óôõö÷øùú|
9069         00000110  00FB 00FC 00FD 00FE - 00FF 000A EFFF 000A  |ûüýþÿ.�.|
9070         00000118  EFC2 000A EFEF EFBF - EFC0 000A EFC0 EF80  |�.���.��|
9071         00000120  000A EFE0 EF80 EF80 - 000A FFFD EFEF EFBF  |.���.���|
9072         00000128  EFBE EFEF EFBF EFBF - 000A 007A 000A       |����.z.|
9073 ---
9074 name: integer-base-one-3Ar
9075 description:
9076         some sample code for hexdumping; NUL and binary safe
9077 stdin:
9078         {
9079                 print 'Hello, World!\\\nこんにちは!'
9080                 typeset -Uui16 i=0x100
9081                 # change that to 0xFF once we can handle embedded
9082                 # NUL characters in strings / here documents
9083                 while (( i++ < 0x1FF )); do
9084                         print -n "\x${i#16#1}"
9085                 done
9086                 print '\0z'
9087         } | {
9088                 # integer-base-one-3Ar
9089                 typeset -Uui16 -Z11 pos=0
9090                 typeset -Uui16 -Z5 hv=2147483647
9091                 dasc=
9092                 if read -arN -1 line; then
9093                         typeset -i1 line
9094                         i=0
9095                         while (( i < ${#line[*]} )); do
9096                                 hv=${line[i++]}
9097                                 if (( (pos & 15) == 0 )); then
9098                                         (( pos )) && print "$dasc|"
9099                                         print -n "${pos#16#}  "
9100                                         dasc=' |'
9101                                 fi
9102                                 print -n "${hv#16#} "
9103                                 if (( (hv < 32) || (hv > 126) )); then
9104                                         dasc=$dasc.
9105                                 else
9106                                         dasc=$dasc${line[i-1]#1#}
9107                                 fi
9108                                 (( (pos++ & 15) == 7 )) && print -n -- '- '
9109                         done
9110                 fi
9111                 while (( pos & 15 )); do
9112                         print -n '   '
9113                         (( (pos++ & 15) == 7 )) && print -n -- '- '
9114                 done
9115                 (( hv == 2147483647 )) || print "$dasc|"
9116         }
9117 expected-stdout:
9118         00000000  48 65 6C 6C 6F 2C 20 57 - 6F 72 6C 64 21 5C 0A E3  |Hello, World!\..|
9119         00000010  81 93 E3 82 93 E3 81 AB - E3 81 A1 E3 81 AF EF BC  |................|
9120         00000020  81 0A 01 02 03 04 05 06 - 07 08 09 0A 0B 0C 0D 0E  |................|
9121         00000030  0F 10 11 12 13 14 15 16 - 17 18 19 1A 1B 1C 1D 1E  |................|
9122         00000040  1F 20 21 22 23 24 25 26 - 27 28 29 2A 2B 2C 2D 2E  |. !"#$%&'()*+,-.|
9123         00000050  2F 30 31 32 33 34 35 36 - 37 38 39 3A 3B 3C 3D 3E  |/0123456789:;<=>|
9124         00000060  3F 40 41 42 43 44 45 46 - 47 48 49 4A 4B 4C 4D 4E  |?@ABCDEFGHIJKLMN|
9125         00000070  4F 50 51 52 53 54 55 56 - 57 58 59 5A 5B 5C 5D 5E  |OPQRSTUVWXYZ[\]^|
9126         00000080  5F 60 61 62 63 64 65 66 - 67 68 69 6A 6B 6C 6D 6E  |_`abcdefghijklmn|
9127         00000090  6F 70 71 72 73 74 75 76 - 77 78 79 7A 7B 7C 7D 7E  |opqrstuvwxyz{|}~|
9128         000000A0  7F 80 81 82 83 84 85 86 - 87 88 89 8A 8B 8C 8D 8E  |................|
9129         000000B0  8F 90 91 92 93 94 95 96 - 97 98 99 9A 9B 9C 9D 9E  |................|
9130         000000C0  9F A0 A1 A2 A3 A4 A5 A6 - A7 A8 A9 AA AB AC AD AE  |................|
9131         000000D0  AF B0 B1 B2 B3 B4 B5 B6 - B7 B8 B9 BA BB BC BD BE  |................|
9132         000000E0  BF C0 C1 C2 C3 C4 C5 C6 - C7 C8 C9 CA CB CC CD CE  |................|
9133         000000F0  CF D0 D1 D2 D3 D4 D5 D6 - D7 D8 D9 DA DB DC DD DE  |................|
9134         00000100  DF E0 E1 E2 E3 E4 E5 E6 - E7 E8 E9 EA EB EC ED EE  |................|
9135         00000110  EF F0 F1 F2 F3 F4 F5 F6 - F7 F8 F9 FA FB FC FD FE  |................|
9136         00000120  FF 00 7A 0A             -                          |..z.|
9137 ---
9138 name: integer-base-one-3Wr
9139 description:
9140         some sample code for hexdumping Unicode; NUL and binary safe
9141 stdin:
9142         set -U
9143         {
9144                 print 'Hello, World!\\\nこんにちは!'
9145                 typeset -Uui16 i=0x100
9146                 # change that to 0xFF once we can handle embedded
9147                 # NUL characters in strings / here documents
9148                 while (( i++ < 0x1FF )); do
9149                         print -n "\u${i#16#1}"
9150                 done
9151                 print
9152                 print \\xff             # invalid utf-8
9153                 print \\xc2             # invalid 2-byte
9154                 print \\xef\\xbf\\xc0   # invalid 3-byte
9155                 print \\xc0\\x80        # non-minimalistic
9156                 print \\xe0\\x80\\x80   # non-minimalistic
9157                 print '�￾￿'       # end of range
9158                 print '\0z'             # embedded NUL
9159         } | {
9160                 # integer-base-one-3Wr
9161                 typeset -Uui16 -Z11 pos=0
9162                 typeset -Uui16 -Z7 hv=2147483647
9163                 dasc=
9164                 if read -arN -1 line; then
9165                         typeset -i1 line
9166                         i=0
9167                         while (( i < ${#line[*]} )); do
9168                                 hv=${line[i++]}
9169                                 if (( (hv < 32) || \
9170                                     ((hv > 126) && (hv < 160)) )); then
9171                                         dch=.
9172                                 elif (( (hv & 0xFF80) == 0xEF80 )); then
9173                                         dch=�
9174                                 else
9175                                         dch=${line[i-1]#1#}
9176                                 fi
9177                                 if (( (pos & 7) == 7 )); then
9178                                         dasc=$dasc$dch
9179                                         dch=
9180                                 elif (( (pos & 7) == 0 )); then
9181                                         (( pos )) && print "$dasc|"
9182                                         print -n "${pos#16#}  "
9183                                         dasc=' |'
9184                                 fi
9185                                 print -n "${hv#16#} "
9186                                 (( (pos++ & 7) == 3 )) && \
9187                                     print -n -- '- '
9188                                 dasc=$dasc$dch
9189                         done
9190                 fi
9191                 while (( pos & 7 )); do
9192                         print -n '     '
9193                         (( (pos++ & 7) == 3 )) && print -n -- '- '
9194                 done
9195                 (( hv == 2147483647 )) || print "$dasc|"
9196         }
9197 expected-stdout:
9198         00000000  0048 0065 006C 006C - 006F 002C 0020 0057  |Hello, W|
9199         00000008  006F 0072 006C 0064 - 0021 005C 000A 3053  |orld!\.こ|
9200         00000010  3093 306B 3061 306F - FF01 000A 0001 0002  |んにちは!...|
9201         00000018  0003 0004 0005 0006 - 0007 0008 0009 000A  |........|
9202         00000020  000B 000C 000D 000E - 000F 0010 0011 0012  |........|
9203         00000028  0013 0014 0015 0016 - 0017 0018 0019 001A  |........|
9204         00000030  001B 001C 001D 001E - 001F 0020 0021 0022  |..... !"|
9205         00000038  0023 0024 0025 0026 - 0027 0028 0029 002A  |#$%&'()*|
9206         00000040  002B 002C 002D 002E - 002F 0030 0031 0032  |+,-./012|
9207         00000048  0033 0034 0035 0036 - 0037 0038 0039 003A  |3456789:|
9208         00000050  003B 003C 003D 003E - 003F 0040 0041 0042  |;<=>?@AB|
9209         00000058  0043 0044 0045 0046 - 0047 0048 0049 004A  |CDEFGHIJ|
9210         00000060  004B 004C 004D 004E - 004F 0050 0051 0052  |KLMNOPQR|
9211         00000068  0053 0054 0055 0056 - 0057 0058 0059 005A  |STUVWXYZ|
9212         00000070  005B 005C 005D 005E - 005F 0060 0061 0062  |[\]^_`ab|
9213         00000078  0063 0064 0065 0066 - 0067 0068 0069 006A  |cdefghij|
9214         00000080  006B 006C 006D 006E - 006F 0070 0071 0072  |klmnopqr|
9215         00000088  0073 0074 0075 0076 - 0077 0078 0079 007A  |stuvwxyz|
9216         00000090  007B 007C 007D 007E - 007F 0080 0081 0082  |{|}~....|
9217         00000098  0083 0084 0085 0086 - 0087 0088 0089 008A  |........|
9218         000000A0  008B 008C 008D 008E - 008F 0090 0091 0092  |........|
9219         000000A8  0093 0094 0095 0096 - 0097 0098 0099 009A  |........|
9220         000000B0  009B 009C 009D 009E - 009F 00A0 00A1 00A2  |..... ¡¢|
9221         000000B8  00A3 00A4 00A5 00A6 - 00A7 00A8 00A9 00AA  |£¤¥¦§¨©ª|
9222         000000C0  00AB 00AC 00AD 00AE - 00AF 00B0 00B1 00B2  |«¬­®¯°±²|
9223         000000C8  00B3 00B4 00B5 00B6 - 00B7 00B8 00B9 00BA  |³´µ¶·¸¹º|
9224         000000D0  00BB 00BC 00BD 00BE - 00BF 00C0 00C1 00C2  |»¼½¾¿ÀÁÂ|
9225         000000D8  00C3 00C4 00C5 00C6 - 00C7 00C8 00C9 00CA  |ÃÄÅÆÇÈÉÊ|
9226         000000E0  00CB 00CC 00CD 00CE - 00CF 00D0 00D1 00D2  |ËÌÍÎÏÐÑÒ|
9227         000000E8  00D3 00D4 00D5 00D6 - 00D7 00D8 00D9 00DA  |ÓÔÕÖ×ØÙÚ|
9228         000000F0  00DB 00DC 00DD 00DE - 00DF 00E0 00E1 00E2  |ÛÜÝÞßàáâ|
9229         000000F8  00E3 00E4 00E5 00E6 - 00E7 00E8 00E9 00EA  |ãäåæçèéê|
9230         00000100  00EB 00EC 00ED 00EE - 00EF 00F0 00F1 00F2  |ëìíîïðñò|
9231         00000108  00F3 00F4 00F5 00F6 - 00F7 00F8 00F9 00FA  |óôõö÷øùú|
9232         00000110  00FB 00FC 00FD 00FE - 00FF 000A EFFF 000A  |ûüýþÿ.�.|
9233         00000118  EFC2 000A EFEF EFBF - EFC0 000A EFC0 EF80  |�.���.��|
9234         00000120  000A EFE0 EF80 EF80 - 000A FFFD EFEF EFBF  |.���.���|
9235         00000128  EFBE EFEF EFBF EFBF - 000A 0000 007A 000A  |����..z.|
9236 ---
9237 name: integer-base-one-4
9238 description:
9239         Check if ksh93-style base-one integers work
9240 category: !smksh
9241 stdin:
9242         set -U
9243         echo 1 $(('a'))
9244         (echo 2f $(('aa'))) 2>&1 | sed "s/^[^']*'/2p '/"
9245         echo 3 $(('…'))
9246         x="'a'"
9247         echo "4 <$x>"
9248         echo 5 $(($x))
9249         echo 6 $((x))
9250 expected-stdout:
9251         1 97
9252         2p 'aa': multi-character character constant
9253         3 8230
9254         4 <'a'>
9255         5 97
9256         6 97
9257 ---
9258 name: integer-base-one-5A
9259 description:
9260         Check to see that we’re NUL and Unicode safe
9261 stdin:
9262         set +U
9263         print 'a\0b\xfdz' >x
9264         read -a y <x
9265         set -U
9266         typeset -Uui16 y
9267         print ${y[*]} .
9268 expected-stdout:
9269         16#61 16#0 16#62 16#FD 16#7A .
9270 ---
9271 name: integer-base-one-5W
9272 description:
9273         Check to see that we’re NUL and Unicode safe
9274 stdin:
9275         set -U
9276         print 'a\0b€c' >x
9277         read -a y <x
9278         set +U
9279         typeset -Uui16 y
9280         print ${y[*]} .
9281 expected-stdout:
9282         16#61 16#0 16#62 16#20AC 16#63 .
9283 ---
9284 name: ulimit-1
9285 description:
9286         Check if we can use a specific syntax idiom for ulimit
9287 category: !os:syllable
9288 stdin:
9289         if ! x=$(ulimit -d) || [[ $x = unknown ]]; then
9290                 #echo expected to fail on this OS
9291                 echo okay
9292         else
9293                 ulimit -dS $x && echo okay
9294         fi
9295 expected-stdout:
9296         okay
9297 ---
9298 name: redir-1
9299 description:
9300         Check some of the most basic invariants of I/O redirection
9301 stdin:
9302         i=0
9303         function d {
9304                 print o$i.
9305                 print -u2 e$((i++)).
9306         }
9307         d >a 2>b
9308         echo =1=
9309         cat a
9310         echo =2=
9311         cat b
9312         echo =3=
9313         d 2>&1 >c
9314         echo =4=
9315         cat c
9316         echo =5=
9317 expected-stdout:
9318         =1=
9319         o0.
9320         =2=
9321         e0.
9322         =3=
9323         e1.
9324         =4=
9325         o1.
9326         =5=
9327 ---
9328 name: bashiop-1
9329 description:
9330         Check if GNU bash-like I/O redirection works
9331         Part 1: this is also supported by GNU bash
9332 category: shell:legacy-no
9333 stdin:
9334         exec 3>&1
9335         function threeout {
9336                 echo ras
9337                 echo dwa >&2
9338                 echo tri >&3
9339         }
9340         threeout &>foo
9341         echo ===
9342         cat foo
9343 expected-stdout:
9344         tri
9345         ===
9346         ras
9347         dwa
9348 ---
9349 name: bashiop-2a
9350 description:
9351         Check if GNU bash-like I/O redirection works
9352         Part 2: this is *not* supported by GNU bash
9353 category: shell:legacy-no
9354 stdin:
9355         exec 3>&1
9356         function threeout {
9357                 echo ras
9358                 echo dwa >&2
9359                 echo tri >&3
9360         }
9361         threeout 3&>foo
9362         echo ===
9363         cat foo
9364 expected-stdout:
9365         ras
9366         ===
9367         dwa
9368         tri
9369 ---
9370 name: bashiop-2b
9371 description:
9372         Check if GNU bash-like I/O redirection works
9373         Part 2: this is *not* supported by GNU bash
9374 category: shell:legacy-no
9375 stdin:
9376         exec 3>&1
9377         function threeout {
9378                 echo ras
9379                 echo dwa >&2
9380                 echo tri >&3
9381         }
9382         threeout 3>foo &>&3
9383         echo ===
9384         cat foo
9385 expected-stdout:
9386         ===
9387         ras
9388         dwa
9389         tri
9390 ---
9391 name: bashiop-2c
9392 description:
9393         Check if GNU bash-like I/O redirection works
9394         Part 2: this is supported by GNU bash 4 only
9395 category: shell:legacy-no
9396 stdin:
9397         echo mir >foo
9398         set -o noclobber
9399         exec 3>&1
9400         function threeout {
9401                 echo ras
9402                 echo dwa >&2
9403                 echo tri >&3
9404         }
9405         threeout &>>foo
9406         echo ===
9407         cat foo
9408 expected-stdout:
9409         tri
9410         ===
9411         mir
9412         ras
9413         dwa
9414 ---
9415 name: bashiop-3a
9416 description:
9417         Check if GNU bash-like I/O redirection fails correctly
9418         Part 1: this is also supported by GNU bash
9419 category: shell:legacy-no
9420 stdin:
9421         echo mir >foo
9422         set -o noclobber
9423         exec 3>&1
9424         function threeout {
9425                 echo ras
9426                 echo dwa >&2
9427                 echo tri >&3
9428         }
9429         threeout &>foo
9430         echo ===
9431         cat foo
9432 expected-stdout:
9433         ===
9434         mir
9435 expected-stderr-pattern: /.*: can't (create|overwrite) .*/
9436 ---
9437 name: bashiop-3b
9438 description:
9439         Check if GNU bash-like I/O redirection fails correctly
9440         Part 2: this is *not* supported by GNU bash
9441 category: shell:legacy-no
9442 stdin:
9443         echo mir >foo
9444         set -o noclobber
9445         exec 3>&1
9446         function threeout {
9447                 echo ras
9448                 echo dwa >&2
9449                 echo tri >&3
9450         }
9451         threeout &>|foo
9452         echo ===
9453         cat foo
9454 expected-stdout:
9455         tri
9456         ===
9457         ras
9458         dwa
9459 ---
9460 name: bashiop-4
9461 description:
9462         Check if GNU bash-like I/O redirection works
9463         Part 4: this is also supported by GNU bash,
9464         but failed in some mksh versions
9465 category: shell:legacy-no
9466 stdin:
9467         exec 3>&1
9468         function threeout {
9469                 echo ras
9470                 echo dwa >&2
9471                 echo tri >&3
9472         }
9473         function blubb {
9474                 [[ -e bar ]] && threeout "$bf" &>foo
9475         }
9476         blubb
9477         echo -n >bar
9478         blubb
9479         echo ===
9480         cat foo
9481 expected-stdout:
9482         tri
9483         ===
9484         ras
9485         dwa
9486 ---
9487 name: bashiop-5-normal
9488 description:
9489         Check if GNU bash-like I/O redirection is only supported
9490         in !POSIX !sh mode as it breaks existing scripts' syntax
9491 category: shell:legacy-no
9492 stdin:
9493         :>x; echo 1 "$("$__progname" -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
9494         :>x; echo 2 "$("$__progname" -o posix -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
9495         :>x; echo 3 "$("$__progname" -o sh -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
9496 expected-stdout:
9497         1  = foo echo bar .
9498         2  = bar .
9499         3  = bar .
9500 ---
9501 name: bashiop-5-legacy
9502 description:
9503         Check if GNU bash-like I/O redirection is not parsed
9504         in lksh as it breaks existing scripts' syntax
9505 category: shell:legacy-yes
9506 stdin:
9507         :>x; echo 1 "$("$__progname" -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
9508         :>x; echo 2 "$("$__progname" -o posix -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
9509         :>x; echo 3 "$("$__progname" -o sh -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
9510 expected-stdout:
9511         1  = bar .
9512         2  = bar .
9513         3  = bar .
9514 ---
9515 name: mkshiop-1
9516 description:
9517         Check for support of more than 9 file descriptors
9518 category: !convfds
9519 stdin:
9520         read -u10 foo 10<<< bar
9521         echo x$foo
9522 expected-stdout:
9523         xbar
9524 ---
9525 name: mkshiop-2
9526 description:
9527         Check for support of more than 9 file descriptors
9528 category: !convfds
9529 stdin:
9530         exec 12>foo
9531         print -u12 bar
9532         echo baz >&12
9533         cat foo
9534 expected-stdout:
9535         bar
9536         baz
9537 ---
9538 name: oksh-eval
9539 description:
9540         Check expansions.
9541 stdin:
9542         a=
9543         for n in ${a#*=}; do echo 1hu ${n} .; done
9544         for n in "${a#*=}"; do echo 1hq ${n} .; done
9545         for n in ${a##*=}; do echo 2hu ${n} .; done
9546         for n in "${a##*=}"; do echo 2hq ${n} .; done
9547         for n in ${a%=*}; do echo 1pu ${n} .; done
9548         for n in "${a%=*}"; do echo 1pq ${n} .; done
9549         for n in ${a%%=*}; do echo 2pu ${n} .; done
9550         for n in "${a%%=*}"; do echo 2pq ${n} .; done
9551 expected-stdout:
9552         1hq .
9553         2hq .
9554         1pq .
9555         2pq .
9556 ---
9557 name: oksh-and-list-error-1
9558 description:
9559         Test exit status of rightmost element in 2 element && list in -e mode
9560 stdin:
9561         true && false
9562         echo "should not print"
9563 arguments: !-e!
9564 expected-exit: e != 0
9565 ---
9566 name: oksh-and-list-error-2
9567 description:
9568         Test exit status of rightmost element in 3 element && list in -e mode
9569 stdin:
9570         true && true && false
9571         echo "should not print"
9572 arguments: !-e!
9573 expected-exit: e != 0
9574 ---
9575 name: oksh-or-list-error-1
9576 description:
9577         Test exit status of || list in -e mode
9578 stdin:
9579         false || false
9580         echo "should not print"
9581 arguments: !-e!
9582 expected-exit: e != 0
9583 ---
9584 name: oksh-longline-crash
9585 description:
9586         This used to cause a core dump
9587 stdin:
9588         ulimit -c 0
9589         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"
9590         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"
9591         for deplib in $deplibs; do
9592                 case $deplib in
9593                 -L*)
9594                         new_libs="$deplib $new_libs"
9595                         ;;
9596                 *)
9597                         case " $specialdeplibs " in
9598                         *" $deplib "*)
9599                                 new_libs="$deplib $new_libs";;
9600                         esac
9601                         ;;
9602                 esac
9603         done
9604 ---
9605 name: oksh-seterror-1
9606 description:
9607         The -e flag should be ignored when executing a compound list
9608         followed by an if statement.
9609 stdin:
9610         if true; then false && false; fi
9611         true
9612 arguments: !-e!
9613 expected-exit: e == 0
9614 ---
9615 name: oksh-seterror-2
9616 description:
9617         The -e flag should be ignored when executing a compound list
9618         followed by an if statement.
9619 stdin:
9620         if true; then if true; then false && false; fi; fi
9621         true
9622 arguments: !-e!
9623 expected-exit: e == 0
9624 ---
9625 name: oksh-seterror-3
9626 description:
9627         The -e flag should be ignored when executing a compound list
9628         followed by an elif statement.
9629 stdin:
9630         if true; then :; elif true; then false && false; fi
9631 arguments: !-e!
9632 expected-exit: e == 0
9633 ---
9634 name: oksh-seterror-4
9635 description:
9636         The -e flag should be ignored when executing a pipeline
9637         beginning with '!'
9638 stdin:
9639         for i in 1 2 3
9640         do
9641                 false && false
9642                 true || false
9643         done
9644 arguments: !-e!
9645 expected-exit: e == 0
9646 ---
9647 name: oksh-seterror-5
9648 description:
9649         The -e flag should be ignored when executing a pipeline
9650         beginning with '!'
9651 stdin:
9652         ! true | false
9653         true
9654 arguments: !-e!
9655 expected-exit: e == 0
9656 ---
9657 name: oksh-seterror-6
9658 description:
9659         When trapping ERR and EXIT, both traps should run in -e mode
9660         when an error occurs.
9661 stdin:
9662         trap 'echo EXIT' EXIT
9663         trap 'echo ERR' ERR
9664         set -e
9665         false
9666         echo DONE
9667         exit 0
9668 arguments: !-e!
9669 expected-exit: e != 0
9670 expected-stdout:
9671         ERR
9672         EXIT
9673 ---
9674 name: oksh-seterror-7
9675 description:
9676         The -e flag within a command substitution should be honored
9677 stdin:
9678         echo $( set -e; false; echo foo )
9679 arguments: !-e!
9680 expected-stdout:
9681         
9682 ---
9683 name: oksh-input-comsub
9684 description:
9685         A command substitution using input redirection should exit with
9686         failure if the input file does not exist.
9687 stdin:
9688         var=$(< non-existent)
9689 expected-exit: e != 0
9690 expected-stderr-pattern: /non-existent/
9691 ---
9692 name: oksh-empty-for-list
9693 description:
9694         A for list which expands to zero items should not execute the body.
9695 stdin:
9696         set foo bar baz ; for out in ; do echo $out ; done
9697 ---
9698 name: oksh-varfunction-mod1
9699 description:
9700         (Inspired by PR 2450 on OpenBSD.) Calling
9701                 FOO=bar f
9702         where f is a ksh style function, should not set FOO in the current
9703         env. If f is a Bourne style function, FOO should be set. Furthermore,
9704         the function should receive a correct value of FOO. However, differing
9705         from oksh, setting FOO in the function itself must change the value in
9706         setting FOO in the function itself should not change the value in
9707         global environment.
9708 stdin:
9709         print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
9710             'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
9711             done >env; chmod +x env; PATH=.:$PATH
9712         function k {
9713                 if [ x$FOO != xbar ]; then
9714                         echo 1
9715                         return 1
9716                 fi
9717                 x=$(env | grep FOO)
9718                 if [ "x$x" != "xFOO=bar" ]; then
9719                         echo 2
9720                         return 1;
9721                 fi
9722                 FOO=foo
9723                 return 0
9724         }
9725         b () {
9726                 if [ x$FOO != xbar ]; then
9727                         echo 3
9728                         return 1
9729                 fi
9730                 x=$(env | grep FOO)
9731                 if [ "x$x" != "xFOO=bar" ]; then
9732                         echo 4
9733                         return 1;
9734                 fi
9735                 FOO=foo
9736                 return 0
9737         }
9738         FOO=bar k
9739         if [ $? != 0 ]; then
9740                 exit 1
9741         fi
9742         if [ x$FOO != x ]; then
9743                 exit 1
9744         fi
9745         FOO=bar b
9746         if [ $? != 0 ]; then
9747                 exit 1
9748         fi
9749         if [ x$FOO != xfoo ]; then
9750                 exit 1
9751         fi
9752         FOO=barbar
9753         FOO=bar k
9754         if [ $? != 0 ]; then
9755                 exit 1
9756         fi
9757         if [ x$FOO != xbarbar ]; then
9758                 exit 1
9759         fi
9760         FOO=bar b
9761         if [ $? != 0 ]; then
9762                 exit 1
9763         fi
9764         if [ x$FOO != xfoo ]; then
9765                 exit 1
9766         fi
9767 ---
9768 name: fd-cloexec-1
9769 description:
9770         Verify that file descriptors > 2 are private for Korn shells
9771         AT&T ksh93 does this still, which means we must keep it as well
9772 category: shell:legacy-no
9773 file-setup: file 644 "test.sh"
9774         echo >&3 Fowl
9775 stdin:
9776         exec 3>&1
9777         "$__progname" test.sh
9778 expected-exit: e != 0
9779 expected-stderr-pattern:
9780         /bad file descriptor/
9781 ---
9782 name: fd-cloexec-2
9783 description:
9784         Verify that file descriptors > 2 are not private for POSIX shells
9785         See Debian Bug #154540, Closes: #499139
9786 file-setup: file 644 "test.sh"
9787         echo >&3 Fowl
9788 stdin:
9789         test -n "$POSH_VERSION" || set -o sh
9790         exec 3>&1
9791         "$__progname" test.sh
9792 expected-stdout:
9793         Fowl
9794 ---
9795 name: fd-cloexec-3
9796 description:
9797         Verify that file descriptors > 2 are not private for LEGACY KSH
9798 category: shell:legacy-yes
9799 file-setup: file 644 "test.sh"
9800         echo >&3 Fowl
9801 stdin:
9802         exec 3>&1
9803         "$__progname" test.sh
9804 expected-stdout:
9805         Fowl
9806 ---
9807 name: comsub-1a
9808 description:
9809         COMSUB are now parsed recursively, so this works
9810         see also regression-6: matching parenthesēs bug
9811         Fails on: pdksh bash2 bash3 zsh
9812         Passes on: bash4 ksh93 mksh(20110313+)
9813 stdin:
9814         echo 1 $(case 1 in (1) echo yes;; (2) echo no;; esac) .
9815         echo 2 $(case 1 in 1) echo yes;; 2) echo no;; esac) .
9816         TEST=1234; echo 3 ${TEST: $(case 1 in (1) echo 1;; (*) echo 2;; esac)} .
9817         TEST=5678; echo 4 ${TEST: $(case 1 in 1) echo 1;; *) echo 2;; esac)} .
9818         a=($(case 1 in (1) echo 1;; (*) echo 2;; esac)); echo 5 ${a[0]} .
9819         a=($(case 1 in 1) echo 1;; *) echo 2;; esac)); echo 6 ${a[0]} .
9820 expected-stdout:
9821         1 yes .
9822         2 yes .
9823         3 234 .
9824         4 678 .
9825         5 1 .
9826         6 1 .
9827 ---
9828 name: comsub-1b
9829 description:
9830         COMSUB are now parsed recursively, so this works
9831         Fails on: pdksh bash2 bash3 bash4 zsh
9832         Passes on: ksh93 mksh(20110313+)
9833 stdin:
9834         echo 1 $(($(case 1 in (1) echo 1;; (*) echo 2;; esac)+10)) .
9835         echo 2 $(($(case 1 in 1) echo 1;; *) echo 2;; esac)+20)) .
9836         (( a = $(case 1 in (1) echo 1;; (*) echo 2;; esac) )); echo 3 $a .
9837         (( a = $(case 1 in 1) echo 1;; *) echo 2;; esac) )); echo 4 $a .
9838         a=($(($(case 1 in (1) echo 1;; (*) echo 2;; esac)+10))); echo 5 ${a[0]} .
9839         a=($(($(case 1 in 1) echo 1;; *) echo 2;; esac)+20))); echo 6 ${a[0]} .
9840 expected-stdout:
9841         1 11 .
9842         2 21 .
9843         3 1 .
9844         4 1 .
9845         5 11 .
9846         6 21 .
9847 ---
9848 name: comsub-2
9849 description:
9850         RedHat BZ#496791 – another case of missing recursion
9851         in parsing COMSUB expressions
9852         Fails on: pdksh bash2 bash3¹ bash4¹ zsh
9853         Passes on: ksh93 mksh(20110305+)
9854         ① bash[34] seem to choke on comment ending with backslash-newline
9855 stdin:
9856         # a comment with " ' \
9857         x=$(
9858         echo yes
9859         # a comment with " ' \
9860         )
9861         echo $x
9862 expected-stdout:
9863         yes
9864 ---
9865 name: comsub-3
9866 description:
9867         Extended test for COMSUB explaining why a recursive parser
9868         is a must (a non-recursive parser cannot pass all three of
9869         these test cases, especially the ‘#’ is difficult)
9870 stdin:
9871         print '#!'"$__progname"'\necho 1234' >id; chmod +x id; PATH=.:$PATH
9872         echo $(typeset -i10 x=16#20; echo $x)
9873         echo $(typeset -Uui16 x=16#$(id -u)
9874         ) .
9875         echo $(c=1; d=1
9876         typeset -Uui16 a=36#foo; c=2
9877         typeset -Uui16 b=36 #foo; d=2
9878         echo $a $b $c $d)
9879 expected-stdout:
9880         32
9881         .
9882         16#4F68 16#24 2 1
9883 ---
9884 name: comsub-4
9885 description:
9886         Check the tree dump functions for !MKSH_SMALL functionality
9887 category: !smksh
9888 stdin:
9889         x() { case $1 in u) echo x ;;& *) echo $1 ;; esac; }
9890         typeset -f x
9891 expected-stdout:
9892         x() {
9893                 case $1 in
9894                 (u)
9895                         echo x 
9896                         ;|
9897                 (*)
9898                         echo $1 
9899                         ;;
9900                 esac 
9901         } 
9902 ---
9903 name: comsub-5
9904 description:
9905         Check COMSUB works with aliases (does not expand them twice)
9906 stdin:
9907         print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
9908         chmod +x pfn
9909         alias echo='echo a'
9910         foo() {
9911                 ./pfn "$(echo foo)"
9912         }
9913         ./pfn "$(echo b)"
9914         typeset -f foo
9915 expected-stdout:
9916         a b
9917         foo() {
9918                 ./pfn "$(echo foo )" 
9919         } 
9920 ---
9921 name: comsub-torture
9922 description:
9923         Check the tree dump functions work correctly
9924 stdin:
9925         if [[ -z $__progname ]]; then echo >&2 call me with __progname; exit 1; fi
9926         while IFS= read -r line; do
9927                 if [[ $line = '#1' ]]; then
9928                         lastf=0
9929                         continue
9930                 elif [[ $line = EOFN* ]]; then
9931                         fbody=$fbody$'\n'$line
9932                         continue
9933                 elif [[ $line != '#'* ]]; then
9934                         fbody=$fbody$'\n\t'$line
9935                         continue
9936                 fi
9937                 if (( lastf )); then
9938                         x="inline_${nextf}() {"$fbody$'\n}\n'
9939                         print -nr -- "$x"
9940                         print -r -- "${x}typeset -f inline_$nextf" | "$__progname"
9941                         x="function comsub_$nextf { x=\$("$fbody$'\n); }\n'
9942                         print -nr -- "$x"
9943                         print -r -- "${x}typeset -f comsub_$nextf" | "$__progname"
9944                         x="function reread_$nextf { x=\$(("$fbody$'\n)|tr u x); }\n'
9945                         print -nr -- "$x"
9946                         print -r -- "${x}typeset -f reread_$nextf" | "$__progname"
9947                 fi
9948                 lastf=1
9949                 fbody=
9950                 nextf=${line#?}
9951         done <<'EOD'
9952         #1
9953         #TCOM
9954         vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
9955         #TPAREN_TPIPE_TLIST
9956         (echo $foo  |  tr -dc 0-9; echo)
9957         #TAND_TOR
9958         cmd  &&  echo ja  ||  echo nein
9959         #TSELECT
9960         select  file  in  *;  do  echo  "<$file>" ;  break ;  done
9961         #TFOR_TTIME
9962         time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
9963         #TCASE
9964         case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
9965         #TIF_TBANG_TDBRACKET_TELIF
9966         if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
9967         #TWHILE
9968         i=1; while (( i < 10 )); do echo $i; let ++i; done
9969         #TUNTIL
9970         i=10; until  (( !--i )) ; do echo $i; done
9971         #TCOPROC
9972         cat  *  |&  ls
9973         #TFUNCT_TBRACE_TASYNC
9974         function  korn  {  echo eins; echo zwei ;  }
9975         bourne  ()  {  logger *  &  }
9976         #IOREAD_IOCAT
9977         tr  x  u  0<foo  >>bar
9978         #IOWRITE_IOCLOB_IOHERE_noIOSKIP
9979         cat  >|bar  <<'EOFN'
9980         foo
9981         EOFN
9982         #IOWRITE_noIOCLOB_IOHERE_IOSKIP
9983         cat  1>bar  <<-EOFI
9984         foo
9985         EOFI
9986         #IORDWR_IODUP
9987         sh  1<>/dev/console  0<&1  2>&1
9988         #COMSUB_EXPRSUB_FUNSUB_VALSUB
9989         echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
9990         #QCHAR_OQUOTE_CQUOTE
9991         echo fo\ob\"a\`r\'b\$az
9992         echo "fo\ob\"a\`r\'b\$az"
9993         echo 'fo\ob\"a\`r'\''b\$az'
9994         #OSUBST_CSUBST_OPAT_SPAT_CPAT
9995         [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
9996         #heredoc_closed
9997         x=$(cat <<EOFN
9998         note there must be no space between EOFN and )
9999         EOFN); echo $x
10000         #heredoc_space
10001         x=$(cat <<EOFN\ 
10002         note the space between EOFN and ) is actually part of the here document marker
10003         EOFN ); echo $x
10004         #patch_motd
10005         x=$(sysctl -n kern.version | sed 1q)
10006         [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
10007             ed -s /etc/motd 2>&1 <<-EOF
10008                 1,/^\$/d
10009                 0a
10010                         $x
10011         
10012                 .
10013                 wq
10014         EOF)" = @(?) ]] && rm -f /etc/motd
10015         if [[ ! -s /etc/motd ]]; then
10016                 install -c -o root -g wheel -m 664 /dev/null /etc/motd
10017                 print -- "$x\n" >/etc/motd
10018         fi
10019         #wdarrassign
10020         case x in
10021         x) a+=b; c+=(d e)
10022         esac
10023         #0
10024         EOD
10025 expected-stdout:
10026         inline_TCOM() {
10027                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
10028         }
10029         inline_TCOM() {
10030                 vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" 
10031         } 
10032         function comsub_TCOM { x=$(
10033                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
10034         ); }
10035         function comsub_TCOM {
10036                 x=$(vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" ) 
10037         } 
10038         function reread_TCOM { x=$((
10039                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4"
10040         )|tr u x); }
10041         function reread_TCOM {
10042                 x=$(( vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" ) | tr u x ) 
10043         } 
10044         inline_TPAREN_TPIPE_TLIST() {
10045                 (echo $foo  |  tr -dc 0-9; echo)
10046         }
10047         inline_TPAREN_TPIPE_TLIST() {
10048                 ( echo $foo | tr -dc 0-9 
10049                   echo ) 
10050         } 
10051         function comsub_TPAREN_TPIPE_TLIST { x=$(
10052                 (echo $foo  |  tr -dc 0-9; echo)
10053         ); }
10054         function comsub_TPAREN_TPIPE_TLIST {
10055                 x=$(( echo $foo | tr -dc 0-9 ; echo ) ) 
10056         } 
10057         function reread_TPAREN_TPIPE_TLIST { x=$((
10058                 (echo $foo  |  tr -dc 0-9; echo)
10059         )|tr u x); }
10060         function reread_TPAREN_TPIPE_TLIST {
10061                 x=$(( ( echo $foo | tr -dc 0-9 ; echo ) ) | tr u x ) 
10062         } 
10063         inline_TAND_TOR() {
10064                 cmd  &&  echo ja  ||  echo nein
10065         }
10066         inline_TAND_TOR() {
10067                 cmd && echo ja || echo nein 
10068         } 
10069         function comsub_TAND_TOR { x=$(
10070                 cmd  &&  echo ja  ||  echo nein
10071         ); }
10072         function comsub_TAND_TOR {
10073                 x=$(cmd && echo ja || echo nein ) 
10074         } 
10075         function reread_TAND_TOR { x=$((
10076                 cmd  &&  echo ja  ||  echo nein
10077         )|tr u x); }
10078         function reread_TAND_TOR {
10079                 x=$(( cmd && echo ja || echo nein ) | tr u x ) 
10080         } 
10081         inline_TSELECT() {
10082                 select  file  in  *;  do  echo  "<$file>" ;  break ;  done
10083         }
10084         inline_TSELECT() {
10085                 select file in * 
10086                 do
10087                         echo "<$file>" 
10088                         break 
10089                 done 
10090         } 
10091         function comsub_TSELECT { x=$(
10092                 select  file  in  *;  do  echo  "<$file>" ;  break ;  done
10093         ); }
10094         function comsub_TSELECT {
10095                 x=$(select file in * ; do echo "<$file>" ; break ; done ) 
10096         } 
10097         function reread_TSELECT { x=$((
10098                 select  file  in  *;  do  echo  "<$file>" ;  break ;  done
10099         )|tr u x); }
10100         function reread_TSELECT {
10101                 x=$(( select file in * ; do echo "<$file>" ; break ; done ) | tr u x ) 
10102         } 
10103         inline_TFOR_TTIME() {
10104                 time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
10105         }
10106         inline_TFOR_TTIME() {
10107                 time for i in {1,2,3} 
10108                 do
10109                         echo $i 
10110                 done 
10111         } 
10112         function comsub_TFOR_TTIME { x=$(
10113                 time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
10114         ); }
10115         function comsub_TFOR_TTIME {
10116                 x=$(time for i in {1,2,3} ; do echo $i ; done ) 
10117         } 
10118         function reread_TFOR_TTIME { x=$((
10119                 time  for  i  in  {1,2,3}  ;  do  echo  $i ;  done
10120         )|tr u x); }
10121         function reread_TFOR_TTIME {
10122                 x=$(( time for i in {1,2,3} ; do echo $i ; done ) | tr u x ) 
10123         } 
10124         inline_TCASE() {
10125                 case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
10126         }
10127         inline_TCASE() {
10128                 case $foo in
10129                 (1)
10130                         echo eins 
10131                         ;&
10132                 (2)
10133                         echo zwei 
10134                         ;|
10135                 (*)
10136                         echo kann net bis drei zählen 
10137                         ;;
10138                 esac 
10139         } 
10140         function comsub_TCASE { x=$(
10141                 case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
10142         ); }
10143         function comsub_TCASE {
10144                 x=$(case $foo in (1) echo eins  ;& (2) echo zwei  ;| (*) echo kann net bis drei zählen  ;; esac ) 
10145         } 
10146         function reread_TCASE { x=$((
10147                 case  $foo  in  1)  echo eins;& 2) echo zwei  ;| *) echo kann net bis drei zählen;;  esac
10148         )|tr u x); }
10149         function reread_TCASE {
10150                 x=$(( case $foo in (1) echo eins  ;& (2) echo zwei  ;| (*) echo kann net bis drei zählen  ;; esac ) | tr u x ) 
10151         } 
10152         inline_TIF_TBANG_TDBRACKET_TELIF() {
10153                 if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
10154         }
10155         inline_TIF_TBANG_TDBRACKET_TELIF() {
10156                 if ! [[ 1 = 1 ]] 
10157                 then
10158                         echo eins 
10159                 elif [[ 1 = 2 ]] 
10160                 then
10161                         echo zwei 
10162                 else
10163                         echo drei 
10164                 fi 
10165         } 
10166         function comsub_TIF_TBANG_TDBRACKET_TELIF { x=$(
10167                 if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
10168         ); }
10169         function comsub_TIF_TBANG_TDBRACKET_TELIF {
10170                 x=$(if ! [[ 1 = 1 ]] ; then echo eins ; elif [[ 1 = 2 ]] ; then echo zwei ; else echo drei ; fi ) 
10171         } 
10172         function reread_TIF_TBANG_TDBRACKET_TELIF { x=$((
10173                 if  !  [[  1  =  1  ]]  ;  then  echo eins;  elif [[ 1 = 2 ]]; then echo zwei  ;else echo drei; fi
10174         )|tr u x); }
10175         function reread_TIF_TBANG_TDBRACKET_TELIF {
10176                 x=$(( if ! [[ 1 = 1 ]] ; then echo eins ; elif [[ 1 = 2 ]] ; then echo zwei ; else echo drei ; fi ) | tr u x ) 
10177         } 
10178         inline_TWHILE() {
10179                 i=1; while (( i < 10 )); do echo $i; let ++i; done
10180         }
10181         inline_TWHILE() {
10182                 i=1 
10183                 while let] " i < 10 " 
10184                 do
10185                         echo $i 
10186                         let ++i 
10187                 done 
10188         } 
10189         function comsub_TWHILE { x=$(
10190                 i=1; while (( i < 10 )); do echo $i; let ++i; done
10191         ); }
10192         function comsub_TWHILE {
10193                 x=$(i=1 ; while let] " i < 10 " ; do echo $i ; let ++i ; done ) 
10194         } 
10195         function reread_TWHILE { x=$((
10196                 i=1; while (( i < 10 )); do echo $i; let ++i; done
10197         )|tr u x); }
10198         function reread_TWHILE {
10199                 x=$(( i=1 ; while let] " i < 10 " ; do echo $i ; let ++i ; done ) | tr u x ) 
10200         } 
10201         inline_TUNTIL() {
10202                 i=10; until  (( !--i )) ; do echo $i; done
10203         }
10204         inline_TUNTIL() {
10205                 i=10 
10206                 until let] " !--i " 
10207                 do
10208                         echo $i 
10209                 done 
10210         } 
10211         function comsub_TUNTIL { x=$(
10212                 i=10; until  (( !--i )) ; do echo $i; done
10213         ); }
10214         function comsub_TUNTIL {
10215                 x=$(i=10 ; until let] " !--i " ; do echo $i ; done ) 
10216         } 
10217         function reread_TUNTIL { x=$((
10218                 i=10; until  (( !--i )) ; do echo $i; done
10219         )|tr u x); }
10220         function reread_TUNTIL {
10221                 x=$(( i=10 ; until let] " !--i " ; do echo $i ; done ) | tr u x ) 
10222         } 
10223         inline_TCOPROC() {
10224                 cat  *  |&  ls
10225         }
10226         inline_TCOPROC() {
10227                 cat * |& 
10228                 ls 
10229         } 
10230         function comsub_TCOPROC { x=$(
10231                 cat  *  |&  ls
10232         ); }
10233         function comsub_TCOPROC {
10234                 x=$(cat * |&  ls ) 
10235         } 
10236         function reread_TCOPROC { x=$((
10237                 cat  *  |&  ls
10238         )|tr u x); }
10239         function reread_TCOPROC {
10240                 x=$(( cat * |&  ls ) | tr u x ) 
10241         } 
10242         inline_TFUNCT_TBRACE_TASYNC() {
10243                 function  korn  {  echo eins; echo zwei ;  }
10244                 bourne  ()  {  logger *  &  }
10245         }
10246         inline_TFUNCT_TBRACE_TASYNC() {
10247                 function korn {
10248                         echo eins 
10249                         echo zwei 
10250                 } 
10251                 bourne() {
10252                         logger * & 
10253                 } 
10254         } 
10255         function comsub_TFUNCT_TBRACE_TASYNC { x=$(
10256                 function  korn  {  echo eins; echo zwei ;  }
10257                 bourne  ()  {  logger *  &  }
10258         ); }
10259         function comsub_TFUNCT_TBRACE_TASYNC {
10260                 x=$(function korn { echo eins ; echo zwei ; } ; bourne() { logger * &  } ) 
10261         } 
10262         function reread_TFUNCT_TBRACE_TASYNC { x=$((
10263                 function  korn  {  echo eins; echo zwei ;  }
10264                 bourne  ()  {  logger *  &  }
10265         )|tr u x); }
10266         function reread_TFUNCT_TBRACE_TASYNC {
10267                 x=$(( function korn { echo eins ; echo zwei ; } ; bourne() { logger * &  } ) | tr u x ) 
10268         } 
10269         inline_IOREAD_IOCAT() {
10270                 tr  x  u  0<foo  >>bar
10271         }
10272         inline_IOREAD_IOCAT() {
10273                 tr x u <foo >>bar 
10274         } 
10275         function comsub_IOREAD_IOCAT { x=$(
10276                 tr  x  u  0<foo  >>bar
10277         ); }
10278         function comsub_IOREAD_IOCAT {
10279                 x=$(tr x u <foo >>bar ) 
10280         } 
10281         function reread_IOREAD_IOCAT { x=$((
10282                 tr  x  u  0<foo  >>bar
10283         )|tr u x); }
10284         function reread_IOREAD_IOCAT {
10285                 x=$(( tr x u <foo >>bar ) | tr u x ) 
10286         } 
10287         inline_IOWRITE_IOCLOB_IOHERE_noIOSKIP() {
10288                 cat  >|bar  <<'EOFN'
10289                 foo
10290         EOFN
10291         }
10292         inline_IOWRITE_IOCLOB_IOHERE_noIOSKIP() {
10293                 cat >|bar <<"EOFN"
10294                 foo
10295         EOFN
10296         
10297         } 
10298         function comsub_IOWRITE_IOCLOB_IOHERE_noIOSKIP { x=$(
10299                 cat  >|bar  <<'EOFN'
10300                 foo
10301         EOFN
10302         ); }
10303         function comsub_IOWRITE_IOCLOB_IOHERE_noIOSKIP {
10304                 x=$(cat >|bar <<"EOFN"
10305                 foo
10306         EOFN
10307         ) 
10308         } 
10309         function reread_IOWRITE_IOCLOB_IOHERE_noIOSKIP { x=$((
10310                 cat  >|bar  <<'EOFN'
10311                 foo
10312         EOFN
10313         )|tr u x); }
10314         function reread_IOWRITE_IOCLOB_IOHERE_noIOSKIP {
10315                 x=$(( cat >|bar <<"EOFN"
10316                 foo
10317         EOFN
10318         ) | tr u x ) 
10319         } 
10320         inline_IOWRITE_noIOCLOB_IOHERE_IOSKIP() {
10321                 cat  1>bar  <<-EOFI
10322                 foo
10323                 EOFI
10324         }
10325         inline_IOWRITE_noIOCLOB_IOHERE_IOSKIP() {
10326                 cat >bar <<-EOFI
10327         foo
10328         EOFI
10329         
10330         } 
10331         function comsub_IOWRITE_noIOCLOB_IOHERE_IOSKIP { x=$(
10332                 cat  1>bar  <<-EOFI
10333                 foo
10334                 EOFI
10335         ); }
10336         function comsub_IOWRITE_noIOCLOB_IOHERE_IOSKIP {
10337                 x=$(cat >bar <<-EOFI
10338         foo
10339         EOFI
10340         ) 
10341         } 
10342         function reread_IOWRITE_noIOCLOB_IOHERE_IOSKIP { x=$((
10343                 cat  1>bar  <<-EOFI
10344                 foo
10345                 EOFI
10346         )|tr u x); }
10347         function reread_IOWRITE_noIOCLOB_IOHERE_IOSKIP {
10348                 x=$(( cat >bar <<-EOFI
10349         foo
10350         EOFI
10351         ) | tr u x ) 
10352         } 
10353         inline_IORDWR_IODUP() {
10354                 sh  1<>/dev/console  0<&1  2>&1
10355         }
10356         inline_IORDWR_IODUP() {
10357                 sh 1<>/dev/console <&1 2>&1 
10358         } 
10359         function comsub_IORDWR_IODUP { x=$(
10360                 sh  1<>/dev/console  0<&1  2>&1
10361         ); }
10362         function comsub_IORDWR_IODUP {
10363                 x=$(sh 1<>/dev/console <&1 2>&1 ) 
10364         } 
10365         function reread_IORDWR_IODUP { x=$((
10366                 sh  1<>/dev/console  0<&1  2>&1
10367         )|tr u x); }
10368         function reread_IORDWR_IODUP {
10369                 x=$(( sh 1<>/dev/console <&1 2>&1 ) | tr u x ) 
10370         } 
10371         inline_COMSUB_EXPRSUB_FUNSUB_VALSUB() {
10372                 echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
10373         }
10374         inline_COMSUB_EXPRSUB_FUNSUB_VALSUB() {
10375                 echo $(true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} 
10376         } 
10377         function comsub_COMSUB_EXPRSUB_FUNSUB_VALSUB { x=$(
10378                 echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
10379         ); }
10380         function comsub_COMSUB_EXPRSUB_FUNSUB_VALSUB {
10381                 x=$(echo $(true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} ) 
10382         } 
10383         function reread_COMSUB_EXPRSUB_FUNSUB_VALSUB { x=$((
10384                 echo $(true) $((1+ 2)) ${  :;} ${| REPLY=x;}
10385         )|tr u x); }
10386         function reread_COMSUB_EXPRSUB_FUNSUB_VALSUB {
10387                 x=$(( echo $(true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} ) | tr u x ) 
10388         } 
10389         inline_QCHAR_OQUOTE_CQUOTE() {
10390                 echo fo\ob\"a\`r\'b\$az
10391                 echo "fo\ob\"a\`r\'b\$az"
10392                 echo 'fo\ob\"a\`r'\''b\$az'
10393         }
10394         inline_QCHAR_OQUOTE_CQUOTE() {
10395                 echo fo\ob\"a\`r\'b\$az 
10396                 echo "fo\ob\"a\`r\'b\$az" 
10397                 echo "fo\\ob\\\"a\\\`r"\'"b\\\$az" 
10398         } 
10399         function comsub_QCHAR_OQUOTE_CQUOTE { x=$(
10400                 echo fo\ob\"a\`r\'b\$az
10401                 echo "fo\ob\"a\`r\'b\$az"
10402                 echo 'fo\ob\"a\`r'\''b\$az'
10403         ); }
10404         function comsub_QCHAR_OQUOTE_CQUOTE {
10405                 x=$(echo fo\ob\"a\`r\'b\$az ; echo "fo\ob\"a\`r\'b\$az" ; echo "fo\\ob\\\"a\\\`r"\'"b\\\$az" ) 
10406         } 
10407         function reread_QCHAR_OQUOTE_CQUOTE { x=$((
10408                 echo fo\ob\"a\`r\'b\$az
10409                 echo "fo\ob\"a\`r\'b\$az"
10410                 echo 'fo\ob\"a\`r'\''b\$az'
10411         )|tr u x); }
10412         function reread_QCHAR_OQUOTE_CQUOTE {
10413                 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 ) 
10414         } 
10415         inline_OSUBST_CSUBST_OPAT_SPAT_CPAT() {
10416                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
10417         }
10418         inline_OSUBST_CSUBST_OPAT_SPAT_CPAT() {
10419                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]] 
10420         } 
10421         function comsub_OSUBST_CSUBST_OPAT_SPAT_CPAT { x=$(
10422                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
10423         ); }
10424         function comsub_OSUBST_CSUBST_OPAT_SPAT_CPAT {
10425                 x=$([[ ${foo#bl\(u\)b} = @(bar|baz) ]] ) 
10426         } 
10427         function reread_OSUBST_CSUBST_OPAT_SPAT_CPAT { x=$((
10428                 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
10429         )|tr u x); }
10430         function reread_OSUBST_CSUBST_OPAT_SPAT_CPAT {
10431                 x=$(( [[ ${foo#bl\(u\)b} = @(bar|baz) ]] ) | tr u x ) 
10432         } 
10433         inline_heredoc_closed() {
10434                 x=$(cat <<EOFN
10435                 note there must be no space between EOFN and )
10436         EOFN); echo $x
10437         }
10438         inline_heredoc_closed() {
10439                 x=$(cat <<EOFN
10440                 note there must be no space between EOFN and )
10441         EOFN
10442         ) 
10443                 echo $x 
10444         } 
10445         function comsub_heredoc_closed { x=$(
10446                 x=$(cat <<EOFN
10447                 note there must be no space between EOFN and )
10448         EOFN); echo $x
10449         ); }
10450         function comsub_heredoc_closed {
10451                 x=$(x=$(cat <<EOFN
10452                 note there must be no space between EOFN and )
10453         EOFN
10454         ) ; echo $x ) 
10455         } 
10456         function reread_heredoc_closed { x=$((
10457                 x=$(cat <<EOFN
10458                 note there must be no space between EOFN and )
10459         EOFN); echo $x
10460         )|tr u x); }
10461         function reread_heredoc_closed {
10462                 x=$(( x=$(cat <<EOFN
10463                 note there must be no space between EOFN and )
10464         EOFN
10465         ) ; echo $x ) | tr u x ) 
10466         } 
10467         inline_heredoc_space() {
10468                 x=$(cat <<EOFN\ 
10469                 note the space between EOFN and ) is actually part of the here document marker
10470         EOFN ); echo $x
10471         }
10472         inline_heredoc_space() {
10473                 x=$(cat <<EOFN\ 
10474                 note the space between EOFN and ) is actually part of the here document marker
10475         EOFN 
10476         ) 
10477                 echo $x 
10478         } 
10479         function comsub_heredoc_space { x=$(
10480                 x=$(cat <<EOFN\ 
10481                 note the space between EOFN and ) is actually part of the here document marker
10482         EOFN ); echo $x
10483         ); }
10484         function comsub_heredoc_space {
10485                 x=$(x=$(cat <<EOFN\ 
10486                 note the space between EOFN and ) is actually part of the here document marker
10487         EOFN 
10488         ) ; echo $x ) 
10489         } 
10490         function reread_heredoc_space { x=$((
10491                 x=$(cat <<EOFN\ 
10492                 note the space between EOFN and ) is actually part of the here document marker
10493         EOFN ); echo $x
10494         )|tr u x); }
10495         function reread_heredoc_space {
10496                 x=$(( x=$(cat <<EOFN\ 
10497                 note the space between EOFN and ) is actually part of the here document marker
10498         EOFN 
10499         ) ; echo $x ) | tr u x ) 
10500         } 
10501         inline_patch_motd() {
10502                 x=$(sysctl -n kern.version | sed 1q)
10503                 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
10504                     ed -s /etc/motd 2>&1 <<-EOF
10505                         1,/^\$/d
10506                         0a
10507                                 $x
10508                 
10509                         .
10510                         wq
10511                 EOF)" = @(?) ]] && rm -f /etc/motd
10512                 if [[ ! -s /etc/motd ]]; then
10513                         install -c -o root -g wheel -m 664 /dev/null /etc/motd
10514                         print -- "$x\n" >/etc/motd
10515                 fi
10516         }
10517         inline_patch_motd() {
10518                 x=$(sysctl -n kern.version | sed 1q ) 
10519                 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd )" != $x ]] && ed -s /etc/motd 2>&1 <<-EOF
10520         1,/^\$/d
10521         0a
10522         $x
10523         
10524         .
10525         wq
10526         EOF
10527         )" = @(?) ]] && rm -f /etc/motd 
10528                 if [[ ! -s /etc/motd ]] 
10529                 then
10530                         install -c -o root -g wheel -m 664 /dev/null /etc/motd 
10531                         print -- "$x\n" >/etc/motd 
10532                 fi 
10533         } 
10534         function comsub_patch_motd { x=$(
10535                 x=$(sysctl -n kern.version | sed 1q)
10536                 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
10537                     ed -s /etc/motd 2>&1 <<-EOF
10538                         1,/^\$/d
10539                         0a
10540                                 $x
10541                 
10542                         .
10543                         wq
10544                 EOF)" = @(?) ]] && rm -f /etc/motd
10545                 if [[ ! -s /etc/motd ]]; then
10546                         install -c -o root -g wheel -m 664 /dev/null /etc/motd
10547                         print -- "$x\n" >/etc/motd
10548                 fi
10549         ); }
10550         function comsub_patch_motd {
10551                 x=$(x=$(sysctl -n kern.version | sed 1q ) ; [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd )" != $x ]] && ed -s /etc/motd 2>&1 <<-EOF
10552         1,/^\$/d
10553         0a
10554         $x
10555         
10556         .
10557         wq
10558         EOF
10559         )" = @(?) ]] && 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 ) 
10560         } 
10561         function reread_patch_motd { x=$((
10562                 x=$(sysctl -n kern.version | sed 1q)
10563                 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
10564                     ed -s /etc/motd 2>&1 <<-EOF
10565                         1,/^\$/d
10566                         0a
10567                                 $x
10568                 
10569                         .
10570                         wq
10571                 EOF)" = @(?) ]] && rm -f /etc/motd
10572                 if [[ ! -s /etc/motd ]]; then
10573                         install -c -o root -g wheel -m 664 /dev/null /etc/motd
10574                         print -- "$x\n" >/etc/motd
10575                 fi
10576         )|tr u x); }
10577         function reread_patch_motd {
10578                 x=$(( x=$(sysctl -n kern.version | sed 1q ) ; [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd )" != $x ]] && ed -s /etc/motd 2>&1 <<-EOF
10579         1,/^\$/d
10580         0a
10581         $x
10582         
10583         .
10584         wq
10585         EOF
10586         )" = @(?) ]] && 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 ) 
10587         } 
10588         inline_wdarrassign() {
10589                 case x in
10590                 x) a+=b; c+=(d e)
10591                 esac
10592         }
10593         inline_wdarrassign() {
10594                 case x in
10595                 (x)
10596                         a+=b 
10597                         set -A c+ -- d e 
10598                         ;;
10599                 esac 
10600         } 
10601         function comsub_wdarrassign { x=$(
10602                 case x in
10603                 x) a+=b; c+=(d e)
10604                 esac
10605         ); }
10606         function comsub_wdarrassign {
10607                 x=$(case x in (x) a+=b ; set -A c+ -- d e  ;; esac ) 
10608         } 
10609         function reread_wdarrassign { x=$((
10610                 case x in
10611                 x) a+=b; c+=(d e)
10612                 esac
10613         )|tr u x); }
10614         function reread_wdarrassign {
10615                 x=$(( case x in (x) a+=b ; set -A c+ -- d e  ;; esac ) | tr u x ) 
10616         } 
10617 ---
10618 name: comsub-torture-io
10619 description:
10620         Check the tree dump functions work correctly with I/O redirection
10621 stdin:
10622         if [[ -z $__progname ]]; then echo >&2 call me with __progname; exit 1; fi
10623         while IFS= read -r line; do
10624                 if [[ $line = '#1' ]]; then
10625                         lastf=0
10626                         continue
10627                 elif [[ $line = EOFN* ]]; then
10628                         fbody=$fbody$'\n'$line
10629                         continue
10630                 elif [[ $line != '#'* ]]; then
10631                         fbody=$fbody$'\n\t'$line
10632                         continue
10633                 fi
10634                 if (( lastf )); then
10635                         x="inline_${nextf}() {"$fbody$'\n}\n'
10636                         print -nr -- "$x"
10637                         print -r -- "${x}typeset -f inline_$nextf" | "$__progname"
10638                         x="function comsub_$nextf { x=\$("$fbody$'\n); }\n'
10639                         print -nr -- "$x"
10640                         print -r -- "${x}typeset -f comsub_$nextf" | "$__progname"
10641                         x="function reread_$nextf { x=\$(("$fbody$'\n)|tr u x); }\n'
10642                         print -nr -- "$x"
10643                         print -r -- "${x}typeset -f reread_$nextf" | "$__progname"
10644                 fi
10645                 lastf=1
10646                 fbody=
10647                 nextf=${line#?}
10648         done <<'EOD'
10649         #1
10650         #TCOM
10651         vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
10652         #TPAREN_TPIPE_TLIST
10653         (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
10654         #TAND_TOR
10655         cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
10656         #TSELECT
10657         select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
10658         #TFOR_TTIME
10659         for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
10660         #TCASE
10661         case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
10662         #TIF_TBANG_TDBRACKET_TELIF
10663         if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
10664         #TWHILE
10665         i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
10666         #TUNTIL
10667         i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
10668         #TCOPROC
10669         cat  *  >&3 |&  >&3 ls
10670         #TFUNCT_TBRACE_TASYNC
10671         function  korn  {  echo eins; echo >&3 zwei ;  }
10672         bourne  ()  {  logger *  >&3 &  }
10673         #COMSUB_EXPRSUB
10674         echo $(true >&3) $((1+ 2))
10675         #0
10676         EOD
10677 expected-stdout:
10678         inline_TCOM() {
10679                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
10680         }
10681         inline_TCOM() {
10682                 vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" >&3 
10683         } 
10684         function comsub_TCOM { x=$(
10685                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
10686         ); }
10687         function comsub_TCOM {
10688                 x=$(vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" >&3 ) 
10689         } 
10690         function reread_TCOM { x=$((
10691                 vara=1  varb='2  3'  cmd  arg1  $arg2  "$arg3  4" >&3
10692         )|tr u x); }
10693         function reread_TCOM {
10694                 x=$(( vara=1 varb="2  3" cmd arg1 $arg2 "$arg3  4" >&3 ) | tr u x ) 
10695         } 
10696         inline_TPAREN_TPIPE_TLIST() {
10697                 (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
10698         }
10699         inline_TPAREN_TPIPE_TLIST() {
10700                 ( echo $foo | tr -dc 0-9 >&3 
10701                   echo >&3 ) >&3 
10702         } 
10703         function comsub_TPAREN_TPIPE_TLIST { x=$(
10704                 (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
10705         ); }
10706         function comsub_TPAREN_TPIPE_TLIST {
10707                 x=$(( echo $foo | tr -dc 0-9 >&3 ; echo >&3 ) >&3 ) 
10708         } 
10709         function reread_TPAREN_TPIPE_TLIST { x=$((
10710                 (echo $foo  |  tr -dc 0-9 >&3; echo >&3) >&3
10711         )|tr u x); }
10712         function reread_TPAREN_TPIPE_TLIST {
10713                 x=$(( ( echo $foo | tr -dc 0-9 >&3 ; echo >&3 ) >&3 ) | tr u x ) 
10714         } 
10715         inline_TAND_TOR() {
10716                 cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
10717         }
10718         inline_TAND_TOR() {
10719                 cmd >&3 && echo ja >&3 || echo nein >&3 
10720         } 
10721         function comsub_TAND_TOR { x=$(
10722                 cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
10723         ); }
10724         function comsub_TAND_TOR {
10725                 x=$(cmd >&3 && echo ja >&3 || echo nein >&3 ) 
10726         } 
10727         function reread_TAND_TOR { x=$((
10728                 cmd  >&3 &&  >&3 echo ja  ||  echo >&3 nein
10729         )|tr u x); }
10730         function reread_TAND_TOR {
10731                 x=$(( cmd >&3 && echo ja >&3 || echo nein >&3 ) | tr u x ) 
10732         } 
10733         inline_TSELECT() {
10734                 select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
10735         }
10736         inline_TSELECT() {
10737                 select file in * 
10738                 do
10739                         echo "<$file>" 
10740                         break >&3 
10741                 done >&3 
10742         } 
10743         function comsub_TSELECT { x=$(
10744                 select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
10745         ); }
10746         function comsub_TSELECT {
10747                 x=$(select file in * ; do echo "<$file>" ; break >&3 ; done >&3 ) 
10748         } 
10749         function reread_TSELECT { x=$((
10750                 select  file  in  *;  do  echo  "<$file>" ;  break >&3 ;  done >&3
10751         )|tr u x); }
10752         function reread_TSELECT {
10753                 x=$(( select file in * ; do echo "<$file>" ; break >&3 ; done >&3 ) | tr u x ) 
10754         } 
10755         inline_TFOR_TTIME() {
10756                 for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
10757         }
10758         inline_TFOR_TTIME() {
10759                 for i in {1,2,3} 
10760                 do
10761                         time echo $i >&3 
10762                 done >&3 
10763         } 
10764         function comsub_TFOR_TTIME { x=$(
10765                 for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
10766         ); }
10767         function comsub_TFOR_TTIME {
10768                 x=$(for i in {1,2,3} ; do time echo $i >&3 ; done >&3 ) 
10769         } 
10770         function reread_TFOR_TTIME { x=$((
10771                 for  i  in  {1,2,3}  ;  do  time  >&3 echo  $i ;  done >&3
10772         )|tr u x); }
10773         function reread_TFOR_TTIME {
10774                 x=$(( for i in {1,2,3} ; do time echo $i >&3 ; done >&3 ) | tr u x ) 
10775         } 
10776         inline_TCASE() {
10777                 case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
10778         }
10779         inline_TCASE() {
10780                 case $foo in
10781                 (1)
10782                         echo eins >&3 
10783                         ;&
10784                 (2)
10785                         echo zwei >&3 
10786                         ;|
10787                 (*)
10788                         echo kann net bis drei zählen >&3 
10789                         ;;
10790                 esac >&3 
10791         } 
10792         function comsub_TCASE { x=$(
10793                 case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
10794         ); }
10795         function comsub_TCASE {
10796                 x=$(case $foo in (1) echo eins >&3  ;& (2) echo zwei >&3  ;| (*) echo kann net bis drei zählen >&3  ;; esac >&3 ) 
10797         } 
10798         function reread_TCASE { x=$((
10799                 case  $foo  in  1)  echo eins >&3;& 2) echo zwei >&3  ;| *) echo kann net bis drei zählen >&3;;  esac >&3
10800         )|tr u x); }
10801         function reread_TCASE {
10802                 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 ) 
10803         } 
10804         inline_TIF_TBANG_TDBRACKET_TELIF() {
10805                 if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
10806         }
10807         inline_TIF_TBANG_TDBRACKET_TELIF() {
10808                 if ! [[ 1 = 1 ]] >&3 
10809                 then
10810                         echo eins 
10811                 elif [[ 1 = 2 ]] >&3 
10812                 then
10813                         echo zwei 
10814                 else
10815                         echo drei 
10816                 fi >&3 
10817         } 
10818         function comsub_TIF_TBANG_TDBRACKET_TELIF { x=$(
10819                 if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
10820         ); }
10821         function comsub_TIF_TBANG_TDBRACKET_TELIF {
10822                 x=$(if ! [[ 1 = 1 ]] >&3 ; then echo eins ; elif [[ 1 = 2 ]] >&3 ; then echo zwei ; else echo drei ; fi >&3 ) 
10823         } 
10824         function reread_TIF_TBANG_TDBRACKET_TELIF { x=$((
10825                 if  !  [[  1  =  1  ]]  >&3 ;  then  echo eins;  elif [[ 1 = 2 ]] >&3; then echo zwei  ;else echo drei; fi >&3
10826         )|tr u x); }
10827         function reread_TIF_TBANG_TDBRACKET_TELIF {
10828                 x=$(( if ! [[ 1 = 1 ]] >&3 ; then echo eins ; elif [[ 1 = 2 ]] >&3 ; then echo zwei ; else echo drei ; fi >&3 ) | tr u x ) 
10829         } 
10830         inline_TWHILE() {
10831                 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
10832         }
10833         inline_TWHILE() {
10834                 i=1 
10835                 while let] " i < 10 " >&3 
10836                 do
10837                         echo $i 
10838                         let ++i 
10839                 done >&3 
10840         } 
10841         function comsub_TWHILE { x=$(
10842                 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
10843         ); }
10844         function comsub_TWHILE {
10845                 x=$(i=1 ; while let] " i < 10 " >&3 ; do echo $i ; let ++i ; done >&3 ) 
10846         } 
10847         function reread_TWHILE { x=$((
10848                 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
10849         )|tr u x); }
10850         function reread_TWHILE {
10851                 x=$(( i=1 ; while let] " i < 10 " >&3 ; do echo $i ; let ++i ; done >&3 ) | tr u x ) 
10852         } 
10853         inline_TUNTIL() {
10854                 i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
10855         }
10856         inline_TUNTIL() {
10857                 i=10 
10858                 until let] " !--i " >&3 
10859                 do
10860                         echo $i 
10861                 done >&3 
10862         } 
10863         function comsub_TUNTIL { x=$(
10864                 i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
10865         ); }
10866         function comsub_TUNTIL {
10867                 x=$(i=10 ; until let] " !--i " >&3 ; do echo $i ; done >&3 ) 
10868         } 
10869         function reread_TUNTIL { x=$((
10870                 i=10; until  (( !--i )) >&3 ; do echo $i; done >&3
10871         )|tr u x); }
10872         function reread_TUNTIL {
10873                 x=$(( i=10 ; until let] " !--i " >&3 ; do echo $i ; done >&3 ) | tr u x ) 
10874         } 
10875         inline_TCOPROC() {
10876                 cat  *  >&3 |&  >&3 ls
10877         }
10878         inline_TCOPROC() {
10879                 cat * >&3 |& 
10880                 ls >&3 
10881         } 
10882         function comsub_TCOPROC { x=$(
10883                 cat  *  >&3 |&  >&3 ls
10884         ); }
10885         function comsub_TCOPROC {
10886                 x=$(cat * >&3 |&  ls >&3 ) 
10887         } 
10888         function reread_TCOPROC { x=$((
10889                 cat  *  >&3 |&  >&3 ls
10890         )|tr u x); }
10891         function reread_TCOPROC {
10892                 x=$(( cat * >&3 |&  ls >&3 ) | tr u x ) 
10893         } 
10894         inline_TFUNCT_TBRACE_TASYNC() {
10895                 function  korn  {  echo eins; echo >&3 zwei ;  }
10896                 bourne  ()  {  logger *  >&3 &  }
10897         }
10898         inline_TFUNCT_TBRACE_TASYNC() {
10899                 function korn {
10900                         echo eins 
10901                         echo zwei >&3 
10902                 } 
10903                 bourne() {
10904                         logger * >&3 & 
10905                 } 
10906         } 
10907         function comsub_TFUNCT_TBRACE_TASYNC { x=$(
10908                 function  korn  {  echo eins; echo >&3 zwei ;  }
10909                 bourne  ()  {  logger *  >&3 &  }
10910         ); }
10911         function comsub_TFUNCT_TBRACE_TASYNC {
10912                 x=$(function korn { echo eins ; echo zwei >&3 ; } ; bourne() { logger * >&3 &  } ) 
10913         } 
10914         function reread_TFUNCT_TBRACE_TASYNC { x=$((
10915                 function  korn  {  echo eins; echo >&3 zwei ;  }
10916                 bourne  ()  {  logger *  >&3 &  }
10917         )|tr u x); }
10918         function reread_TFUNCT_TBRACE_TASYNC {
10919                 x=$(( function korn { echo eins ; echo zwei >&3 ; } ; bourne() { logger * >&3 &  } ) | tr u x ) 
10920         } 
10921         inline_COMSUB_EXPRSUB() {
10922                 echo $(true >&3) $((1+ 2))
10923         }
10924         inline_COMSUB_EXPRSUB() {
10925                 echo $(true >&3 ) $((1+ 2)) 
10926         } 
10927         function comsub_COMSUB_EXPRSUB { x=$(
10928                 echo $(true >&3) $((1+ 2))
10929         ); }
10930         function comsub_COMSUB_EXPRSUB {
10931                 x=$(echo $(true >&3 ) $((1+ 2)) ) 
10932         } 
10933         function reread_COMSUB_EXPRSUB { x=$((
10934                 echo $(true >&3) $((1+ 2))
10935         )|tr u x); }
10936         function reread_COMSUB_EXPRSUB {
10937                 x=$(( echo $(true >&3 ) $((1+ 2)) ) | tr u x ) 
10938         } 
10939 ---
10940 name: funsub-1
10941 description:
10942         Check that non-subenvironment command substitution works
10943 stdin:
10944         set -e
10945         foo=bar
10946         echo "ob $foo ."
10947         echo "${
10948                 echo "ib $foo :"
10949                 foo=baz
10950                 echo "ia $foo :"
10951                 false
10952         }" .
10953         echo "oa $foo ."
10954 expected-stdout:
10955         ob bar .
10956         ib bar :
10957         ia baz : .
10958         oa baz .
10959 ---
10960 name: funsub-2
10961 description:
10962         You can now reliably use local and return in funsubs
10963         (not exit though)
10964 stdin:
10965         x=q; e=1; x=${ echo a; e=2; echo x$e;}; echo 1:y$x,$e,$?.
10966         x=q; e=1; x=${ echo a; typeset e=2; echo x$e;}; echo 2:y$x,$e,$?.
10967         x=q; e=1; x=${ echo a; typeset e=2; return 3; echo x$e;}; echo 3:y$x,$e,$?.
10968 expected-stdout:
10969         1:ya x2,2,0.
10970         2:ya x2,1,0.
10971         3:ya,1,3.
10972 ---
10973 name: valsub-1
10974 description:
10975         Check that "value substitutions" work as advertised
10976 stdin:
10977         x=1
10978         y=2
10979         z=3
10980         REPLY=4
10981         echo "before:   x<$x> y<$y> z<$z> R<$REPLY>"
10982         x=${|
10983                 local y
10984                 echo "begin:    x<$x> y<$y> z<$z> R<$REPLY>"
10985                 x=5
10986                 y=6
10987                 z=7
10988                 REPLY=8
10989                 echo "end:      x<$x> y<$y> z<$z> R<$REPLY>"
10990         }
10991         echo "after:    x<$x> y<$y> z<$z> R<$REPLY>"
10992         # ensure trailing newlines are kept
10993         t=${|REPLY=$'foo\n\n';}
10994         typeset -p t
10995         echo -n this used to segfault
10996         echo ${|true;}$(true).
10997 expected-stdout:
10998         before: x<1> y<2> z<3> R<4>
10999         begin:  x<1> y<> z<3> R<>
11000         end:    x<5> y<6> z<7> R<8>
11001         after:  x<8> y<2> z<7> R<4>
11002         typeset t=$'foo\n\n'
11003         this used to segfault.
11004 ---
11005 name: test-stnze-1
11006 description:
11007         Check that the short form [ $x ] works
11008 stdin:
11009         i=0
11010         [ -n $x ]
11011         rv=$?; echo $((++i)) $rv
11012         [ $x ]
11013         rv=$?; echo $((++i)) $rv
11014         [ -n "$x" ]
11015         rv=$?; echo $((++i)) $rv
11016         [ "$x" ]
11017         rv=$?; echo $((++i)) $rv
11018         x=0
11019         [ -n $x ]
11020         rv=$?; echo $((++i)) $rv
11021         [ $x ]
11022         rv=$?; echo $((++i)) $rv
11023         [ -n "$x" ]
11024         rv=$?; echo $((++i)) $rv
11025         [ "$x" ]
11026         rv=$?; echo $((++i)) $rv
11027         x='1 -a 1 = 2'
11028         [ -n $x ]
11029         rv=$?; echo $((++i)) $rv
11030         [ $x ]
11031         rv=$?; echo $((++i)) $rv
11032         [ -n "$x" ]
11033         rv=$?; echo $((++i)) $rv
11034         [ "$x" ]
11035         rv=$?; echo $((++i)) $rv
11036 expected-stdout:
11037         1 0
11038         2 1
11039         3 1
11040         4 1
11041         5 0
11042         6 0
11043         7 0
11044         8 0
11045         9 1
11046         10 1
11047         11 0
11048         12 0
11049 ---
11050 name: test-stnze-2
11051 description:
11052         Check that the short form [[ $x ]] works (ksh93 extension)
11053 stdin:
11054         i=0
11055         [[ -n $x ]]
11056         rv=$?; echo $((++i)) $rv
11057         [[ $x ]]
11058         rv=$?; echo $((++i)) $rv
11059         [[ -n "$x" ]]
11060         rv=$?; echo $((++i)) $rv
11061         [[ "$x" ]]
11062         rv=$?; echo $((++i)) $rv
11063         x=0
11064         [[ -n $x ]]
11065         rv=$?; echo $((++i)) $rv
11066         [[ $x ]]
11067         rv=$?; echo $((++i)) $rv
11068         [[ -n "$x" ]]
11069         rv=$?; echo $((++i)) $rv
11070         [[ "$x" ]]
11071         rv=$?; echo $((++i)) $rv
11072         x='1 -a 1 = 2'
11073         [[ -n $x ]]
11074         rv=$?; echo $((++i)) $rv
11075         [[ $x ]]
11076         rv=$?; echo $((++i)) $rv
11077         [[ -n "$x" ]]
11078         rv=$?; echo $((++i)) $rv
11079         [[ "$x" ]]
11080         rv=$?; echo $((++i)) $rv
11081 expected-stdout:
11082         1 1
11083         2 1
11084         3 1
11085         4 1
11086         5 0
11087         6 0
11088         7 0
11089         8 0
11090         9 0
11091         10 0
11092         11 0
11093         12 0
11094 ---
11095 name: event-subst-3
11096 description:
11097         Check that '!' substitution in noninteractive mode is ignored
11098 file-setup: file 755 "falsetto"
11099         #! /bin/sh
11100         echo molto bene
11101         exit 42
11102 file-setup: file 755 "!false"
11103         #! /bin/sh
11104         echo si
11105 stdin:
11106         export PATH=.:$PATH
11107         falsetto
11108         echo yeap
11109         !false
11110         echo meow
11111         ! false
11112         echo = $?
11113         if
11114         ! false; then echo foo; else echo bar; fi
11115 expected-stdout:
11116         molto bene
11117         yeap
11118         si
11119         meow
11120         = 0
11121         foo
11122 ---
11123 name: event-subst-0
11124 description:
11125         Check that '!' substitution in interactive mode is ignored
11126 need-ctty: yes
11127 arguments: !-i!
11128 file-setup: file 755 "falsetto"
11129         #! /bin/sh
11130         echo molto bene
11131         exit 42
11132 file-setup: file 755 "!false"
11133         #! /bin/sh
11134         echo si
11135 stdin:
11136         export PATH=.:$PATH
11137         falsetto
11138         echo yeap
11139         !false
11140         echo meow
11141         ! false
11142         echo = $?
11143         if
11144         ! false; then echo foo; else echo bar; fi
11145 expected-stdout:
11146         molto bene
11147         yeap
11148         si
11149         meow
11150         = 0
11151         foo
11152 expected-stderr-pattern:
11153         /.*/
11154 ---
11155 name: nounset-1
11156 description:
11157         Check that "set -u" matches (future) SUSv4 requirement
11158 stdin:
11159         (set -u
11160         try() {
11161                 local v
11162                 eval v=\$$1
11163                 if [[ -n $v ]]; then
11164                         echo $1=nz
11165                 else
11166                         echo $1=zf
11167                 fi
11168         }
11169         x=y
11170         (echo $x)
11171         echo =1
11172         (echo $y)
11173         echo =2
11174         (try x)
11175         echo =3
11176         (try y)
11177         echo =4
11178         (try 0)
11179         echo =5
11180         (try 2)
11181         echo =6
11182         (try)
11183         echo =7
11184         (echo at=$@)
11185         echo =8
11186         (echo asterisk=$*)
11187         echo =9
11188         (echo $?)
11189         echo =10
11190         (echo $!)
11191         echo =11
11192         (echo $-)
11193         echo =12
11194         #(echo $_)
11195         #echo =13
11196         (echo $#)
11197         echo =14
11198         (mypid=$$; try mypid)
11199         echo =15
11200         ) 2>&1 | sed -e 's/^[^]]*]//' -e 's/^[^:]*: *//'
11201         exit ${PIPESTATUS[0]}
11202 expected-stdout:
11203         y
11204         =1
11205         y: parameter not set
11206         =2
11207         x=nz
11208         =3
11209         y: parameter not set
11210         =4
11211         0=nz
11212         =5
11213         2: parameter not set
11214         =6
11215         1: parameter not set
11216         =7
11217         at=
11218         =8
11219         asterisk=
11220         =9
11221         0
11222         =10
11223         !: parameter not set
11224         =11
11225         ush
11226         =12
11227         0
11228         =14
11229         mypid=nz
11230         =15
11231 ---
11232 name: nameref-1
11233 description:
11234         Testsuite for nameref (bound variables)
11235 stdin:
11236         bar=global
11237         typeset -n ir2=bar
11238         typeset -n ind=ir2
11239         echo !ind: ${!ind}
11240         echo ind: $ind
11241         echo !ir2: ${!ir2}
11242         echo ir2: $ir2
11243         typeset +n ind
11244         echo !ind: ${!ind}
11245         echo ind: $ind
11246         typeset -n ir2=ind
11247         echo !ir2: ${!ir2}
11248         echo ir2: $ir2
11249         set|grep ^ir2|sed 's/^/s1: /'
11250         typeset|grep ' ir2'|sed -e 's/^/s2: /' -e 's/nameref/typeset -n/'
11251         set -A blub -- e1 e2 e3
11252         typeset -n ind=blub
11253         typeset -n ir2=blub[2]
11254         echo !ind[1]: ${!ind[1]}
11255         echo !ir2: $!ir2
11256         echo ind[1]: ${ind[1]}
11257         echo ir2: $ir2
11258 expected-stdout:
11259         !ind: bar
11260         ind: global
11261         !ir2: bar
11262         ir2: global
11263         !ind: ind
11264         ind: ir2
11265         !ir2: ind
11266         ir2: ir2
11267         s1: ir2=ind
11268         s2: typeset -n ir2
11269         !ind[1]: blub[1]
11270         !ir2: ir2
11271         ind[1]: e2
11272         ir2: e3
11273 ---
11274 name: nameref-2da
11275 description:
11276         Testsuite for nameref (bound variables)
11277         Functions, argument given directly, after local
11278 stdin:
11279         function foo {
11280                 typeset bar=lokal baz=auch
11281                 typeset -n v=bar
11282                 echo entering
11283                 echo !v: ${!v}
11284                 echo !bar: ${!bar}
11285                 echo !baz: ${!baz}
11286                 echo bar: $bar
11287                 echo v: $v
11288                 v=123
11289                 echo bar: $bar
11290                 echo v: $v
11291                 echo exiting
11292         }
11293         bar=global
11294         echo bar: $bar
11295         foo bar
11296         echo bar: $bar
11297 expected-stdout:
11298         bar: global
11299         entering
11300         !v: bar
11301         !bar: bar
11302         !baz: baz
11303         bar: lokal
11304         v: lokal
11305         bar: 123
11306         v: 123
11307         exiting
11308         bar: global
11309 ---
11310 name: nameref-3
11311 description:
11312         Advanced testsuite for bound variables (ksh93 fails this)
11313 stdin:
11314         typeset -n foo=bar[i]
11315         set -A bar -- b c a
11316         for i in 0 1 2 3; do
11317                 print $i $foo .
11318         done
11319 expected-stdout:
11320         0 b .
11321         1 c .
11322         2 a .
11323         3 .
11324 ---
11325 name: nameref-4
11326 description:
11327         Ensure we don't run in an infinite loop
11328 time-limit: 3
11329 stdin:
11330         baz() {
11331                 typeset -n foo=fnord fnord=foo
11332                 foo[0]=bar
11333         }
11334         set -A foo bad
11335         echo sind $foo .
11336         baz
11337         echo blah $foo .
11338 expected-stdout:
11339         sind bad .
11340         blah bad .
11341 expected-stderr-pattern:
11342         /fnord: expression recurses on parameter/
11343 ---
11344 name: better-parens-1a
11345 description:
11346         Check support for ((…)) and $((…)) vs (…) and $(…)
11347 stdin:
11348         if ( (echo fubar)|tr u x); then
11349                 echo ja
11350         else
11351                 echo nein
11352         fi
11353 expected-stdout:
11354         fxbar
11355         ja
11356 ---
11357 name: better-parens-1b
11358 description:
11359         Check support for ((…)) and $((…)) vs (…) and $(…)
11360 stdin:
11361         echo $( (echo fubar)|tr u x) $?
11362 expected-stdout:
11363         fxbar 0
11364 ---
11365 name: better-parens-1c
11366 description:
11367         Check support for ((…)) and $((…)) vs (…) and $(…)
11368 stdin:
11369         x=$( (echo fubar)|tr u x); echo $x $?
11370 expected-stdout:
11371         fxbar 0
11372 ---
11373 name: better-parens-2a
11374 description:
11375         Check support for ((…)) and $((…)) vs (…) and $(…)
11376 stdin:
11377         if ((echo fubar)|tr u x); then
11378                 echo ja
11379         else
11380                 echo nein
11381         fi
11382 expected-stdout:
11383         fxbar
11384         ja
11385 ---
11386 name: better-parens-2b
11387 description:
11388         Check support for ((…)) and $((…)) vs (…) and $(…)
11389 stdin:
11390         echo $((echo fubar)|tr u x) $?
11391 expected-stdout:
11392         fxbar 0
11393 ---
11394 name: better-parens-2c
11395 description:
11396         Check support for ((…)) and $((…)) vs (…) and $(…)
11397 stdin:
11398         x=$((echo fubar)|tr u x); echo $x $?
11399 expected-stdout:
11400         fxbar 0
11401 ---
11402 name: better-parens-3a
11403 description:
11404         Check support for ((…)) and $((…)) vs (…) and $(…)
11405 stdin:
11406         if ( (echo fubar)|(tr u x)); then
11407                 echo ja
11408         else
11409                 echo nein
11410         fi
11411 expected-stdout:
11412         fxbar
11413         ja
11414 ---
11415 name: better-parens-3b
11416 description:
11417         Check support for ((…)) and $((…)) vs (…) and $(…)
11418 stdin:
11419         echo $( (echo fubar)|(tr u x)) $?
11420 expected-stdout:
11421         fxbar 0
11422 ---
11423 name: better-parens-3c
11424 description:
11425         Check support for ((…)) and $((…)) vs (…) and $(…)
11426 stdin:
11427         x=$( (echo fubar)|(tr u x)); echo $x $?
11428 expected-stdout:
11429         fxbar 0
11430 ---
11431 name: better-parens-4a
11432 description:
11433         Check support for ((…)) and $((…)) vs (…) and $(…)
11434 stdin:
11435         if ((echo fubar)|(tr u x)); then
11436                 echo ja
11437         else
11438                 echo nein
11439         fi
11440 expected-stdout:
11441         fxbar
11442         ja
11443 ---
11444 name: better-parens-4b
11445 description:
11446         Check support for ((…)) and $((…)) vs (…) and $(…)
11447 stdin:
11448         echo $((echo fubar)|(tr u x)) $?
11449 expected-stdout:
11450         fxbar 0
11451 ---
11452 name: better-parens-4c
11453 description:
11454         Check support for ((…)) and $((…)) vs (…) and $(…)
11455 stdin:
11456         x=$((echo fubar)|(tr u x)); echo $x $?
11457 expected-stdout:
11458         fxbar 0
11459 ---
11460 name: echo-test-1
11461 description:
11462         Test what the echo builtin does (mksh)
11463 stdin:
11464         echo -n 'foo\x40bar'
11465         echo -e '\tbaz'
11466 expected-stdout:
11467         foo@bar baz
11468 ---
11469 name: echo-test-2
11470 description:
11471         Test what the echo builtin does (POSIX)
11472         Note: this follows Debian Policy 10.4 which mandates
11473         that -n shall be treated as an option, not XSI which
11474         mandates it shall be treated as string but escapes
11475         shall be expanded.
11476 stdin:
11477         test -n "$POSH_VERSION" || set -o posix
11478         echo -n 'foo\x40bar'
11479         echo -e '\tbaz'
11480 expected-stdout:
11481         foo\x40bar-e \tbaz
11482 ---
11483 name: echo-test-3-mnbsd
11484 description:
11485         Test what the echo builtin does, and test a compatibility flag.
11486 category: mnbsdash
11487 stdin:
11488         "$__progname" -c 'echo -n 1=\\x40$1; echo -e \\x2E' -- foo bar
11489         "$__progname" -o posix -c 'echo -n 2=\\x40$1; echo -e \\x2E' -- foo bar
11490         "$__progname" -o sh -c 'echo -n 3=\\x40$1; echo -e \\x2E' -- foo bar
11491 expected-stdout:
11492         1=@foo.
11493         2=\x40foo-e \x2E
11494         3=\x40bar.
11495 ---
11496 name: echo-test-3-normal
11497 description:
11498         Test what the echo builtin does, and test a compatibility flag.
11499 category: !mnbsdash
11500 stdin:
11501         "$__progname" -c 'echo -n 1=\\x40$1; echo -e \\x2E' -- foo bar
11502         "$__progname" -o posix -c 'echo -n 2=\\x40$1; echo -e \\x2E' -- foo bar
11503         "$__progname" -o sh -c 'echo -n 3=\\x40$1; echo -e \\x2E' -- foo bar
11504 expected-stdout:
11505         1=@foo.
11506         2=\x40foo-e \x2E
11507         3=\x40foo-e \x2E
11508 ---
11509 name: utilities-getopts-1
11510 description:
11511         getopts sets OPTIND correctly for unparsed option
11512 stdin:
11513         set -- -a -a -x
11514         while getopts :a optc; do
11515             echo "OPTARG=$OPTARG, OPTIND=$OPTIND, optc=$optc."
11516         done
11517         echo done
11518 expected-stdout:
11519         OPTARG=, OPTIND=2, optc=a.
11520         OPTARG=, OPTIND=3, optc=a.
11521         OPTARG=x, OPTIND=4, optc=?.
11522         done
11523 ---
11524 name: utilities-getopts-2
11525 description:
11526         Check OPTARG
11527 stdin:
11528         set -- -a Mary -x
11529         while getopts a: optc; do
11530             echo "OPTARG=$OPTARG, OPTIND=$OPTIND, optc=$optc."
11531         done
11532         echo done
11533 expected-stdout:
11534         OPTARG=Mary, OPTIND=3, optc=a.
11535         OPTARG=, OPTIND=4, optc=?.
11536         done
11537 expected-stderr-pattern: /.*-x.*option/
11538 ---
11539 name: wcswidth-1
11540 description:
11541         Check the new wcswidth feature
11542 stdin:
11543         s=何
11544         set +U
11545         print octets: ${#s} .
11546         print 8-bit width: ${%s} .
11547         set -U
11548         print characters: ${#s} .
11549         print columns: ${%s} .
11550         s=�
11551         set +U
11552         print octets: ${#s} .
11553         print 8-bit width: ${%s} .
11554         set -U
11555         print characters: ${#s} .
11556         print columns: ${%s} .
11557 expected-stdout:
11558         octets: 3 .
11559         8-bit width: -1 .
11560         characters: 1 .
11561         columns: 2 .
11562         octets: 3 .
11563         8-bit width: 3 .
11564         characters: 1 .
11565         columns: 1 .
11566 ---
11567 name: wcswidth-2
11568 description:
11569         Check some corner cases
11570 stdin:
11571         print % $% .
11572         set -U
11573         x='a    b'
11574         print c ${%x} .
11575         set +U
11576         x='a    b'
11577         print d ${%x} .
11578 expected-stdout:
11579         % $% .
11580         c -1 .
11581         d -1 .
11582 ---
11583 name: wcswidth-3
11584 description:
11585         Check some corner cases
11586 stdin:
11587         print ${%} .
11588 expected-stderr-pattern:
11589         /bad substitution/
11590 expected-exit: 1
11591 ---
11592 name: wcswidth-4a
11593 description:
11594         Check some corner cases
11595 stdin:
11596         print ${%*} .
11597 expected-stderr-pattern:
11598         /bad substitution/
11599 expected-exit: 1
11600 ---
11601 name: wcswidth-4b
11602 description:
11603         Check some corner cases
11604 stdin:
11605         print ${%@} .
11606 expected-stderr-pattern:
11607         /bad substitution/
11608 expected-exit: 1
11609 ---
11610 name: wcswidth-4c
11611 description:
11612         Check some corner cases
11613 stdin:
11614         :
11615         print ${%?} .
11616 expected-stdout:
11617         1 .
11618 ---
11619 name: realpath-1
11620 description:
11621         Check proper return values for realpath
11622 category: os:mirbsd
11623 stdin:
11624         wd=$(realpath .)
11625         mkdir dir
11626         :>file
11627         :>dir/file
11628         ln -s dir lndir
11629         ln -s file lnfile
11630         ln -s nix lnnix
11631         ln -s . lnself
11632         i=0
11633         chk() {
11634                 typeset x y
11635                 x=$(realpath "$wd/$1" 2>&1); y=$?
11636                 print $((++i)) "?$1" =${x##*$wd/} !$y
11637         }
11638         chk dir
11639         chk dir/
11640         chk dir/file
11641         chk dir/nix
11642         chk file
11643         chk file/
11644         chk file/file
11645         chk file/nix
11646         chk nix
11647         chk nix/
11648         chk nix/file
11649         chk nix/nix
11650         chk lndir
11651         chk lndir/
11652         chk lndir/file
11653         chk lndir/nix
11654         chk lnfile
11655         chk lnfile/
11656         chk lnfile/file
11657         chk lnfile/nix
11658         chk lnnix
11659         chk lnnix/
11660         chk lnnix/file
11661         chk lnnix/nix
11662         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
11663         rm lnself
11664 expected-stdout:
11665         1 ?dir =dir !0
11666         2 ?dir/ =dir !0
11667         3 ?dir/file =dir/file !0
11668         4 ?dir/nix =dir/nix !0
11669         5 ?file =file !0
11670         6 ?file/ =file/: Not a directory !20
11671         7 ?file/file =file/file: Not a directory !20
11672         8 ?file/nix =file/nix: Not a directory !20
11673         9 ?nix =nix !0
11674         10 ?nix/ =nix !0
11675         11 ?nix/file =nix/file: No such file or directory !2
11676         12 ?nix/nix =nix/nix: No such file or directory !2
11677         13 ?lndir =dir !0
11678         14 ?lndir/ =dir !0
11679         15 ?lndir/file =dir/file !0
11680         16 ?lndir/nix =dir/nix !0
11681         17 ?lnfile =file !0
11682         18 ?lnfile/ =lnfile/: Not a directory !20
11683         19 ?lnfile/file =lnfile/file: Not a directory !20
11684         20 ?lnfile/nix =lnfile/nix: Not a directory !20
11685         21 ?lnnix =nix !0
11686         22 ?lnnix/ =nix !0
11687         23 ?lnnix/file =lnnix/file: No such file or directory !2
11688         24 ?lnnix/nix =lnnix/nix: No such file or directory !2
11689         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
11690 ---
11691 name: realpath-2
11692 description:
11693         Ensure that exactly two leading slashes are not collapsed
11694         POSIX guarantees this exception, e.g. for UNC paths on Cygwin
11695 category: os:mirbsd
11696 stdin:
11697         ln -s /bin t1
11698         ln -s //bin t2
11699         ln -s ///bin t3
11700         realpath /bin
11701         realpath //bin
11702         realpath ///bin
11703         realpath /usr/bin
11704         realpath /usr//bin
11705         realpath /usr///bin
11706         realpath t1
11707         realpath t2
11708         realpath t3
11709         rm -f t1 t2 t3
11710         cd //usr/bin
11711         pwd
11712         cd ../lib
11713         pwd
11714         realpath //usr/include/../bin
11715 expected-stdout:
11716         /bin
11717         //bin
11718         /bin
11719         /usr/bin
11720         /usr/bin
11721         /usr/bin
11722         /bin
11723         //bin
11724         /bin
11725         //usr/bin
11726         //usr/lib
11727         //usr/bin
11728 ---
11729 name: crash-1
11730 description:
11731         Crashed during March 2011, fixed on vernal equinōx ☺
11732 category: os:mirbsd,os:openbsd
11733 stdin:
11734         export MALLOC_OPTIONS=FGJPRSX
11735         "$__progname" -c 'x=$(tr z r <<<baz); echo $x'
11736 expected-stdout:
11737         bar
11738 ---
11739 name: debian-117-1
11740 description:
11741         Check test - bug#465250
11742 stdin:
11743         test \( ! -e \) ; echo $?
11744 expected-stdout:
11745         1
11746 ---
11747 name: debian-117-2
11748 description:
11749         Check test - bug#465250
11750 stdin:
11751         test \(  -e \) ; echo $?
11752 expected-stdout:
11753         0
11754 ---
11755 name: debian-117-3
11756 description:
11757         Check test - bug#465250
11758 stdin:
11759         test ! -e  ; echo $?
11760 expected-stdout:
11761         1
11762 ---
11763 name: debian-117-4
11764 description:
11765         Check test - bug#465250
11766 stdin:
11767         test  -e  ; echo $?
11768 expected-stdout:
11769         0
11770 ---
11771 name: case-zsh
11772 description:
11773         Check that zsh case variants work
11774 stdin:
11775         case 'b' in
11776           a) echo a ;;
11777           b) echo b ;;
11778           c) echo c ;;
11779           *) echo x ;;
11780         esac
11781         echo =
11782         case 'b' in
11783           a) echo a ;&
11784           b) echo b ;&
11785           c) echo c ;&
11786           *) echo x ;&
11787         esac
11788         echo =
11789         case 'b' in
11790           a) echo a ;|
11791           b) echo b ;|
11792           c) echo c ;|
11793           *) echo x ;|
11794         esac
11795 expected-stdout:
11796         b
11797         =
11798         b
11799         c
11800         x
11801         =
11802         b
11803         x
11804 ---
11805 name: case-braces
11806 description:
11807         Check that case end tokens are not mixed up (Debian #220272)
11808 stdin:
11809         i=0
11810         for value in 'x' '}' 'esac'; do
11811                 print -n "$((++i))($value)bourne "
11812                 case $value in
11813                 }) echo brace ;;
11814                 *) echo no ;;
11815                 esac
11816                 print -n "$((++i))($value)korn "
11817                 case $value {
11818                 esac) echo esac ;;
11819                 *) echo no ;;
11820                 }
11821         done
11822 expected-stdout:
11823         1(x)bourne no
11824         2(x)korn no
11825         3(})bourne brace
11826         4(})korn no
11827         5(esac)bourne no
11828         6(esac)korn esac
11829 ---
11830 name: command-shift
11831 description:
11832         Check that 'command shift' works
11833 stdin:
11834         function snc {
11835                 echo "before    0='$0' 1='$1' 2='$2'"
11836                 shift
11837                 echo "after     0='$0' 1='$1' 2='$2'"
11838         }
11839         function swc {
11840                 echo "before    0='$0' 1='$1' 2='$2'"
11841                 command shift
11842                 echo "after     0='$0' 1='$1' 2='$2'"
11843         }
11844         echo = without command
11845         snc 一 二
11846         echo = with command
11847         swc 一 二
11848         echo = done
11849 expected-stdout:
11850         = without command
11851         before  0='snc' 1='一' 2='二'
11852         after   0='snc' 1='二' 2=''
11853         = with command
11854         before  0='swc' 1='一' 2='二'
11855         after   0='swc' 1='二' 2=''
11856         = done
11857 ---
11858 name: duffs-device
11859 description:
11860         Check that the compiler did not optimise-break them
11861         (lex.c has got a similar one in SHEREDELIM)
11862 stdin:
11863         set +U
11864         s=
11865         typeset -i1 i=0
11866         while (( ++i < 256 )); do
11867                 s+=${i#1#}
11868         done
11869         s+=$'\xC2\xA0\xE2\x82\xAC\xEF\xBF\xBD\xEF\xBF\xBE\xEF\xBF\xBF\xF0\x90\x80\x80.'
11870         typeset -p s
11871 expected-stdout:
11872         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.'
11873 ---
11874 name: stateptr-underflow
11875 description:
11876         This check overflows an Xrestpos stored in a short in R40
11877 category: fastbox
11878 stdin:
11879         function Lb64decode {
11880                 [[ -o utf8-mode ]]; local u=$?
11881                 set +U
11882                 local c s="$*" t=
11883                 [[ -n $s ]] || { s=$(cat;print x); s=${s%x}; }
11884                 local -i i=0 n=${#s} p=0 v x
11885                 local -i16 o
11886         
11887                 while (( i < n )); do
11888                         c=${s:(i++):1}
11889                         case $c {
11890                         (=)     break ;;
11891                         ([A-Z]) (( v = 1#$c - 65 )) ;;
11892                         ([a-z]) (( v = 1#$c - 71 )) ;;
11893                         ([0-9]) (( v = 1#$c + 4 )) ;;
11894                         (+)     v=62 ;;
11895                         (/)     v=63 ;;
11896                         (*)     continue ;;
11897                         }
11898                         (( x = (x << 6) | v ))
11899                         case $((p++)) {
11900                         (0)     continue ;;
11901                         (1)     (( o = (x >> 4) & 255 )) ;;
11902                         (2)     (( o = (x >> 2) & 255 )) ;;
11903                         (3)     (( o = x & 255 ))
11904                                 p=0
11905                                 ;;
11906                         }
11907                         t=$t\\x${o#16#}
11908                 done
11909                 print -n $t
11910                 (( u )) || set -U
11911         }
11912         
11913         i=-1
11914         s=
11915         while (( ++i < 12120 )); do
11916                 s+=a
11917         done
11918         Lb64decode $s >/dev/null
11919 ---
11920 name: xtrace-1
11921 description:
11922         Check that "set -x" doesn't redirect too quickly
11923 stdin:
11924         print '#!'"$__progname" >bash
11925         cat >>bash <<'EOF'
11926         echo 'GNU bash, version 2.05b.0(1)-release (i386-ecce-mirbsd10)
11927         Copyright (C) 2002 Free Software Foundation, Inc.'
11928         EOF
11929         chmod +x bash
11930         "$__progname" -xc 'foo=$(./bash --version 2>&1 | head -1); echo "=$foo="'
11931 expected-stdout:
11932         =GNU bash, version 2.05b.0(1)-release (i386-ecce-mirbsd10)=
11933 expected-stderr-pattern:
11934         /.*/
11935 ---
11936 name: xtrace-2
11937 description:
11938         Check that "set -x" is off during PS4 expansion
11939 stdin:
11940         f() {
11941                 print -n "(f1:$-)"
11942                 set -x
11943                 print -n "(f2:$-)"
11944         }
11945         PS4='[(p:$-)$(f)] '
11946         print "(o0:$-)"
11947         set -x -o inherit-xtrace
11948         print "(o1:$-)"
11949         set +x
11950         print "(o2:$-)"
11951 expected-stdout:
11952         (o0:sh)
11953         (o1:shx)
11954         (o2:sh)
11955 expected-stderr:
11956         [(p:sh)(f1:sh)(f2:sh)] print '(o1:shx)'
11957         [(p:sh)(f1:sh)(f2:sh)] set +x
11958 ---