blob: 93c614f5e168e151fd78e618a84d72401384b75c [file] [log] [blame]
Elliott Hughesa3c3f962017-04-12 16:52:30 -07001# $MirOS: src/bin/mksh/check.t,v 1.775 2017/04/12 17:38:41 tg Exp $
Elliott Hughes50012062015-03-10 22:22:24 -07002# -*- mode: sh -*-
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003#-
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00004# Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
Elliott Hughesa3c3f962017-04-12 16:52:30 -07005# 2011, 2012, 2013, 2014, 2015, 2016, 2017
Elliott Hughesfc0307d2016-02-02 15:26:47 -08006# mirabilos <m@mirbsd.org>
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007#
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
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000025#
26# More testsuites at:
Elliott Hughes50012062015-03-10 22:22:24 -070027# http://svnweb.freebsd.org/base/head/bin/test/tests/legacy_test.sh?view=co&content-type=text%2Fplain
28#
29# Integrated testsuites from:
Elliott Hughes77740fc2016-08-12 15:06:53 -070030# (2013/12/02 20:39:44) http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070031
32expected-stdout:
Elliott Hughesa3c3f962017-04-12 16:52:30 -070033 @(#)MIRBSD KSH R55 2017/04/12
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070034description:
35 Check version of shell.
36stdin:
37 echo $KSH_VERSION
38name: KSH_VERSION
Elliott Hughesa3c3f962017-04-12 16:52:30 -070039category: !shell:legacy-yes,!shell:textmode-yes
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000040---
41expected-stdout:
Elliott Hughesa3c3f962017-04-12 16:52:30 -070042 @(#)LEGACY KSH R55 2017/04/12
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000043description:
44 Check version of legacy shell.
45stdin:
46 echo $KSH_VERSION
47name: KSH_VERSION-legacy
Elliott Hughesa3c3f962017-04-12 16:52:30 -070048category: !shell:legacy-no,!shell:textmode-yes
49---
50expected-stdout:
51 @(#)MIRBSD KSH R55 2017/04/12 +TEXTMODE
52description:
53 Check version of shell.
54stdin:
55 echo $KSH_VERSION
56name: KSH_VERSION-textmode
57category: !shell:legacy-yes,!shell:textmode-no
58---
59expected-stdout:
60 @(#)LEGACY KSH R55 2017/04/12 +TEXTMODE
61description:
62 Check version of legacy shell.
63stdin:
64 echo $KSH_VERSION
65name: KSH_VERSION-legacy-textmode
66category: !shell:legacy-no,!shell:textmode-no
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070067---
68name: selftest-1
69description:
70 Regression test self-testing
71stdin:
72 echo ${foo:-baz}
73expected-stdout:
74 baz
75---
76name: selftest-2
77description:
78 Regression test self-testing
79env-setup: !foo=bar!
80stdin:
81 echo ${foo:-baz}
82expected-stdout:
83 bar
84---
85name: selftest-3
86description:
87 Regression test self-testing
88env-setup: !ENV=fnord!
89stdin:
90 echo "<$ENV>"
91expected-stdout:
92 <fnord>
93---
Elliott Hughes737fdce2014-08-07 12:59:26 -070094name: selftest-exec
95description:
96 Ensure that the test run directory (default /tmp but can be changed
97 with check.pl flag -T or test.sh $TMPDIR) is not mounted noexec, as
98 we execute scripts from the scratch directory during several tests.
99stdin:
100 print '#!'"$__progname"'\necho tf' >lq
101 chmod +x lq
102 ./lq
103expected-stdout:
104 tf
105---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700106name: selftest-env
107description:
108 Just output the environment variables set (always fails)
109category: disabled
110stdin:
111 set
112---
Geremy Condra03ebf062011-10-12 18:17:24 -0700113name: selftest-direct-builtin-call
114description:
115 Check that direct builtin calls work
116stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000117 ln -s "$__progname" cat || cp "$__progname" cat
118 ln -s "$__progname" echo || cp "$__progname" echo
Geremy Condra03ebf062011-10-12 18:17:24 -0700119 ./echo -c 'echo foo' | ./cat -u
120expected-stdout:
121 -c echo foo
122---
Elliott Hughesa3c3f962017-04-12 16:52:30 -0700123name: selftest-pathsep-unix
124description:
125 Check that $PATHSEP is set correctly.
126category: !os:os2
127stdin:
128 PATHSEP=.; export PATHSEP
129 "$__progname" -c 'print -r -- $PATHSEP'
130expected-stdout:
131 :
132---
133name: selftest-pathsep-dospath
134description:
135 Check that $PATHSEP is set correctly.
136category: os:os2
137stdin:
138 PATHSEP=.; export PATHSEP
139 "$__progname" -c 'print -r -- $PATHSEP'
140expected-stdout:
141 ;
142---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700143name: alias-1
144description:
145 Check that recursion is detected/avoided in aliases.
146stdin:
147 alias fooBar=fooBar
148 fooBar
149 exit 0
150expected-stderr-pattern:
151 /fooBar.*not found.*/
152---
153name: alias-2
154description:
155 Check that recursion is detected/avoided in aliases.
156stdin:
157 alias fooBar=barFoo
158 alias barFoo=fooBar
159 fooBar
160 barFoo
161 exit 0
162expected-stderr-pattern:
163 /fooBar.*not found.*\n.*barFoo.*not found/
164---
165name: alias-3
166description:
167 Check that recursion is detected/avoided in aliases.
168stdin:
169 alias Echo='echo '
170 alias fooBar=barFoo
171 alias barFoo=fooBar
172 Echo fooBar
173 unalias barFoo
174 Echo fooBar
175expected-stdout:
176 fooBar
177 barFoo
178---
179name: alias-4
180description:
181 Check that alias expansion isn't done on keywords (in keyword
182 postitions).
183stdin:
184 alias Echo='echo '
185 alias while=While
186 while false; do echo hi ; done
187 Echo while
188expected-stdout:
189 While
190---
191name: alias-5
192description:
193 Check that alias expansion done after alias with trailing space.
194stdin:
195 alias Echo='echo '
196 alias foo='bar stuff '
197 alias bar='Bar1 Bar2 '
198 alias stuff='Stuff'
199 alias blah='Blah'
200 Echo foo blah
201expected-stdout:
202 Bar1 Bar2 Stuff Blah
203---
204name: alias-6
205description:
206 Check that alias expansion done after alias with trailing space.
207stdin:
208 alias Echo='echo '
209 alias foo='bar bar'
210 alias bar='Bar '
211 alias blah=Blah
212 Echo foo blah
213expected-stdout:
214 Bar Bar Blah
215---
216name: alias-7
217description:
218 Check that alias expansion done after alias with trailing space
219 after a keyword.
220stdin:
221 alias X='case '
222 alias Y=Z
Elliott Hughes77740fc2016-08-12 15:06:53 -0700223 X Y in 'Y') echo is y ;; Z) echo is z ;; esac
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700224expected-stdout:
225 is z
226---
227name: alias-8
228description:
229 Check that newlines in an alias don't cause the command to be lost.
230stdin:
231 alias foo='
232
233
234 echo hi
235
236
237
238 echo there
239
240
241 '
242 foo
243expected-stdout:
244 hi
245 there
246---
247name: alias-9
248description:
249 Check that recursion is detected/avoided in aliases.
250 This check fails for slow machines or Cygwin, raise
251 the time-limit clause (e.g. to 7) if this occurs.
252time-limit: 3
253stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000254 print '#!'"$__progname"'\necho tf' >lq
255 chmod +x lq
Elliott Hughes96b43632015-07-17 11:39:41 -0700256 PATH=$PWD$PATHSEP$PATH
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000257 alias lq=lq
258 lq
259 echo = now
260 i=`lq`
261 print -r -- $i
262 echo = out
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700263 exit 0
264expected-stdout:
265 tf
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000266 = now
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700267 tf
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000268 = out
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700269---
270name: alias-10
271description:
272 Check that recursion is detected/avoided in aliases.
273 Regression, introduced during an old bugfix.
274stdin:
275 alias foo='print hello '
276 alias bar='foo world'
277 echo $(bar)
278expected-stdout:
279 hello world
280---
Elliott Hughesb27ce952015-04-21 13:39:18 -0700281name: alias-11
282description:
283 Check that special argument handling still applies with escaped aliases
284stdin:
Elliott Hughesa3c3f962017-04-12 16:52:30 -0700285 alias local1='\typeset'
286 alias local2='\\builtin typeset'
287 function fooa {
288 local1 x=$1 y=z
Elliott Hughesb27ce952015-04-21 13:39:18 -0700289 print -r -- "$x,$y"
290 }
Elliott Hughesa3c3f962017-04-12 16:52:30 -0700291 function foob {
292 local2 x=$1 y=z
293 print -r -- "$x,$y"
294 }
295 x=1 y=2; fooa 'bar - baz'
296 x=1 y=2; foob 'bar - baz'
Elliott Hughesb27ce952015-04-21 13:39:18 -0700297expected-stdout:
298 bar - baz,z
Elliott Hughesa3c3f962017-04-12 16:52:30 -0700299 bar - baz,z
300---
301name: alias-12
302description:
303 Something weird from Martijn Dekker
304stdin:
305 alias echo=print
306 x() { echo a; (echo b); x=$(echo c); }
307 typeset -f x
308 alias OPEN='{' CLOSE='};'
309 { OPEN echo hi1; CLOSE }
310 var=`{ OPEN echo hi2; CLOSE }` && echo "$var"
311 var=$({ OPEN echo hi3; CLOSE }) && echo "$var"
312expected-stdout:
313 x() {
314 \print a
315 ( \print b )
316 x=$(\print c )
317 }
318 hi1
319 hi2
320 hi3
Elliott Hughesb27ce952015-04-21 13:39:18 -0700321---
Elliott Hughesfc0307d2016-02-02 15:26:47 -0800322name: arith-compound
323description:
324 Check that arithmetic expressions are compound constructs
325stdin:
326 { ! (( 0$(cat >&2) )) <<<1; } <<<2
327expected-stderr:
328 1
329---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700330name: arith-lazy-1
331description:
332 Check that only one side of ternary operator is evaluated
333stdin:
334 x=i+=2
335 y=j+=2
336 typeset -i i=1 j=1
337 echo $((1 ? 20 : (x+=2)))
338 echo $i,$x
339 echo $((0 ? (y+=2) : 30))
340 echo $j,$y
341expected-stdout:
342 20
343 1,i+=2
344 30
345 1,j+=2
346---
347name: arith-lazy-2
348description:
349 Check that assignments not done on non-evaluated side of ternary
350 operator
351stdin:
352 x=i+=2
353 y=j+=2
354 typeset -i i=1 j=1
355 echo $((1 ? 20 : (x+=2)))
356 echo $i,$x
357 echo $((0 ? (y+=2) : 30))
358 echo $i,$y
359expected-stdout:
360 20
361 1,i+=2
362 30
363 1,j+=2
364---
365name: arith-lazy-3
366description:
367 Check that assignments not done on non-evaluated side of ternary
368 operator and this construct is parsed correctly (Debian #445651)
369stdin:
370 x=4
371 y=$((0 ? x=1 : 2))
372 echo = $x $y =
373expected-stdout:
374 = 4 2 =
375---
Thorsten Glaser811a5752013-07-25 14:24:45 +0000376name: arith-lazy-4
377description:
378 Check that preun/postun not done on non-evaluated side of ternary
379 operator
380stdin:
381 (( m = n = 0, 1 ? n++ : m++ ? 2 : 3 ))
382 echo "($n, $m)"
383 m=0; echo $(( 0 ? ++m : 2 )); echo $m
384 m=0; echo $(( 0 ? m++ : 2 )); echo $m
385expected-stdout:
386 (1, 0)
387 2
388 0
389 2
390 0
391---
Elliott Hughes966dd552016-12-08 15:56:04 -0800392name: arith-lazy-5-arr-n
393description: Check lazy evaluation with side effects
394stdin:
395 a=0; echo "$((0&&b[a++],a))"
396expected-stdout:
397 0
398---
399name: arith-lazy-5-arr-p
400description: Check lazy evaluation with side effects
401stdin:
402 a=0; echo "$((0&&(b[a++]),a))"
403expected-stdout:
404 0
405---
406name: arith-lazy-5-str-n
407description: Check lazy evaluation with side effects
408stdin:
409 a=0 b=a++; ((0&&b)); echo $a
410expected-stdout:
411 0
412---
413name: arith-lazy-5-str-p
414description: Check lazy evaluation with side effects
415stdin:
416 a=0 b=a++; ((0&&(b))); echo $a
417expected-stdout:
418 0
419---
420name: arith-lazy-5-tern-l-n
421description: Check lazy evaluation with side effects
422stdin:
423 a=0; echo "$((0?b[a++]:999,a))"
424expected-stdout:
425 0
426---
427name: arith-lazy-5-tern-l-p
428description: Check lazy evaluation with side effects
429stdin:
430 a=0; echo "$((0?(b[a++]):999,a))"
431expected-stdout:
432 0
433---
434name: arith-lazy-5-tern-r-n
435description: Check lazy evaluation with side effects
436stdin:
437 a=0; echo "$((1?999:b[a++],a))"
438expected-stdout:
439 0
440---
441name: arith-lazy-5-tern-r-p
442description: Check lazy evaluation with side effects
443stdin:
444 a=0; echo "$((1?999:(b[a++]),a))"
445expected-stdout:
446 0
447---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700448name: arith-ternary-prec-1
449description:
450 Check precedence of ternary operator vs assignment
451stdin:
452 typeset -i x=2
453 y=$((1 ? 20 : x+=2))
454expected-exit: e != 0
455expected-stderr-pattern:
456 /.*:.*1 \? 20 : x\+=2.*lvalue.*\n$/
457---
458name: arith-ternary-prec-2
459description:
460 Check precedence of ternary operator vs assignment
461stdin:
462 typeset -i x=2
463 echo $((0 ? x+=2 : 20))
464expected-stdout:
465 20
466---
Elliott Hughes77740fc2016-08-12 15:06:53 -0700467name: arith-prec-1
468description:
469 Prove arithmetic expressions with embedded parameter
470 substitutions cannot be parsed ahead of time
471stdin:
472 a='3 + 4'
473 print 1 $((2 * a)) .
474 print 2 $((2 * $a)) .
475expected-stdout:
476 1 14 .
477 2 10 .
478---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700479name: arith-div-assoc-1
480description:
481 Check associativity of division operator
482stdin:
483 echo $((20 / 2 / 2))
484expected-stdout:
485 5
486---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000487name: arith-div-byzero
488description:
489 Check division by zero errors out
490stdin:
491 x=$(echo $((1 / 0)))
492 echo =$?:$x.
493expected-stdout:
494 =1:.
495expected-stderr-pattern:
496 /.*divisor/
497---
498name: arith-div-intmin-by-minusone
499description:
500 Check division overflow wraps around silently
501category: int:32
502stdin:
503 echo signed:$((-2147483648 / -1))r$((-2147483648 % -1)).
504 echo unsigned:$((# -2147483648 / -1))r$((# -2147483648 % -1)).
505expected-stdout:
506 signed:-2147483648r0.
507 unsigned:0r2147483648.
508---
509name: arith-div-intmin-by-minusone-64
510description:
511 Check division overflow wraps around silently
512category: int:64
513stdin:
514 echo signed:$((-9223372036854775808 / -1))r$((-9223372036854775808 % -1)).
515 echo unsigned:$((# -9223372036854775808 / -1))r$((# -9223372036854775808 % -1)).
516expected-stdout:
517 signed:-9223372036854775808r0.
518 unsigned:0r9223372036854775808.
519---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700520name: arith-assop-assoc-1
521description:
522 Check associativity of assignment-operator operator
523stdin:
524 typeset -i i=1 j=2 k=3
525 echo $((i += j += k))
526 echo $i,$j,$k
527expected-stdout:
528 6
529 6,5,3
530---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000531name: arith-mandatory
532description:
Thorsten Glaser811a5752013-07-25 14:24:45 +0000533 Passing of this test is *mandatory* for a valid mksh executable!
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000534category: shell:legacy-no
535stdin:
536 typeset -i sari=0
537 typeset -Ui uari=0
538 typeset -i x=0
Thorsten Glaser811a5752013-07-25 14:24:45 +0000539 print -r -- $((x++)):$sari=$uari. #0
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000540 let --sari --uari
Thorsten Glaser811a5752013-07-25 14:24:45 +0000541 print -r -- $((x++)):$sari=$uari. #1
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000542 sari=2147483647 uari=2147483647
Thorsten Glaser811a5752013-07-25 14:24:45 +0000543 print -r -- $((x++)):$sari=$uari. #2
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000544 let ++sari ++uari
Thorsten Glaser811a5752013-07-25 14:24:45 +0000545 print -r -- $((x++)):$sari=$uari. #3
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000546 let --sari --uari
547 let 'sari *= 2' 'uari *= 2'
548 let ++sari ++uari
Thorsten Glaser811a5752013-07-25 14:24:45 +0000549 print -r -- $((x++)):$sari=$uari. #4
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000550 let ++sari ++uari
Thorsten Glaser811a5752013-07-25 14:24:45 +0000551 print -r -- $((x++)):$sari=$uari. #5
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000552 sari=-2147483648 uari=-2147483648
Thorsten Glaser811a5752013-07-25 14:24:45 +0000553 print -r -- $((x++)):$sari=$uari. #6
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000554 let --sari --uari
Thorsten Glaser811a5752013-07-25 14:24:45 +0000555 print -r -- $((x++)):$sari=$uari. #7
556 (( sari = -5 >> 1 ))
557 ((# uari = -5 >> 1 ))
558 print -r -- $((x++)):$sari=$uari. #8
559 (( sari = -2 ))
560 ((# uari = sari ))
561 print -r -- $((x++)):$sari=$uari. #9
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000562expected-stdout:
563 0:0=0.
564 1:-1=4294967295.
565 2:2147483647=2147483647.
566 3:-2147483648=2147483648.
567 4:-1=4294967295.
568 5:0=0.
569 6:-2147483648=2147483648.
570 7:2147483647=2147483647.
Thorsten Glaser811a5752013-07-25 14:24:45 +0000571 8:-3=2147483645.
572 9:-2=4294967294.
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000573---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700574name: arith-unsigned-1
575description:
576 Check if unsigned arithmetics work
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000577category: int:32
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700578stdin:
579 # signed vs unsigned
580 echo x1 $((-1)) $((#-1))
581 # calculating
582 typeset -i vs
583 typeset -Ui vu
584 vs=4123456789; vu=4123456789
585 echo x2 $vs $vu
586 (( vs %= 2147483647 ))
587 (( vu %= 2147483647 ))
588 echo x3 $vs $vu
589 vs=4123456789; vu=4123456789
590 (( # vs %= 2147483647 ))
591 (( # vu %= 2147483647 ))
592 echo x4 $vs $vu
593 # make sure the calculation does not change unsigned flag
594 vs=4123456789; vu=4123456789
595 echo x5 $vs $vu
596 # short form
597 echo x6 $((# vs % 2147483647)) $((# vu % 2147483647))
598 # array refs
599 set -A va
600 va[1975973142]=right
601 va[4123456789]=wrong
602 echo x7 ${va[#4123456789%2147483647]}
Elliott Hughesfc0307d2016-02-02 15:26:47 -0800603 # make sure multiple calculations don't interfere with each other
604 let '# mca = -4 % -2' ' mcb = -4 % -2'
605 echo x8 $mca $mcb
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700606expected-stdout:
607 x1 -1 4294967295
608 x2 -171510507 4123456789
609 x3 -171510507 4123456789
610 x4 1975973142 1975973142
611 x5 -171510507 4123456789
612 x6 1975973142 1975973142
613 x7 right
Elliott Hughesfc0307d2016-02-02 15:26:47 -0800614 x8 -4 0
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700615---
616name: arith-limit32-1
617description:
618 Check if arithmetics are 32 bit
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000619category: int:32
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700620stdin:
621 # signed vs unsigned
622 echo x1 $((-1)) $((#-1))
623 # calculating
624 typeset -i vs
625 typeset -Ui vu
626 vs=2147483647; vu=2147483647
627 echo x2 $vs $vu
628 let vs++ vu++
629 echo x3 $vs $vu
630 vs=4294967295; vu=4294967295
631 echo x4 $vs $vu
632 let vs++ vu++
633 echo x5 $vs $vu
634 let vs++ vu++
635 echo x6 $vs $vu
636expected-stdout:
637 x1 -1 4294967295
638 x2 2147483647 2147483647
639 x3 -2147483648 2147483648
640 x4 -1 4294967295
641 x5 0 0
642 x6 1 1
643---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +0000644name: arith-limit64-1
645description:
646 Check if arithmetics are 64 bit
647category: int:64
648stdin:
649 # signed vs unsigned
650 echo x1 $((-1)) $((#-1))
651 # calculating
652 typeset -i vs
653 typeset -Ui vu
654 vs=9223372036854775807; vu=9223372036854775807
655 echo x2 $vs $vu
656 let vs++ vu++
657 echo x3 $vs $vu
658 vs=18446744073709551615; vu=18446744073709551615
659 echo x4 $vs $vu
660 let vs++ vu++
661 echo x5 $vs $vu
662 let vs++ vu++
663 echo x6 $vs $vu
664expected-stdout:
665 x1 -1 18446744073709551615
666 x2 9223372036854775807 9223372036854775807
667 x3 -9223372036854775808 9223372036854775808
668 x4 -1 18446744073709551615
669 x5 0 0
670 x6 1 1
671---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700672name: bksl-nl-ign-1
673description:
Geremy Condra03ebf062011-10-12 18:17:24 -0700674 Check that \newline is not collapsed after #
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700675stdin:
676 echo hi #there \
677 echo folks
678expected-stdout:
679 hi
680 folks
681---
682name: bksl-nl-ign-2
683description:
Geremy Condra03ebf062011-10-12 18:17:24 -0700684 Check that \newline is not collapsed inside single quotes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700685stdin:
686 echo 'hi \
687 there'
688 echo folks
689expected-stdout:
690 hi \
691 there
692 folks
693---
694name: bksl-nl-ign-3
695description:
Geremy Condra03ebf062011-10-12 18:17:24 -0700696 Check that \newline is not collapsed inside single quotes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700697stdin:
698 cat << \EOF
699 hi \
700 there
701 EOF
702expected-stdout:
703 hi \
704 there
705---
706name: bksl-nl-ign-4
707description:
708 Check interaction of aliases, single quotes and here-documents
709 with backslash-newline
710 (don't know what POSIX has to say about this)
711stdin:
712 a=2
713 alias x='echo hi
714 cat << "EOF"
715 foo\
716 bar
717 some'
718 x
719 more\
720 stuff$a
721 EOF
722expected-stdout:
723 hi
724 foo\
725 bar
726 some
727 more\
728 stuff$a
729---
730name: bksl-nl-ign-5
731description:
732 Check what happens with backslash at end of input
733 (the old Bourne shell trashes them; so do we)
734stdin: !
735 echo `echo foo\\`bar
736 echo hi\
737expected-stdout:
738 foobar
739 hi
740---
741#
742# Places \newline should be collapsed
743#
744name: bksl-nl-1
745description:
Geremy Condra03ebf062011-10-12 18:17:24 -0700746 Check that \newline is collapsed before, in the middle of, and
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700747 after words
748stdin:
749 \
750 echo hi\
751 There, \
752 folks
753expected-stdout:
754 hiThere, folks
755---
756name: bksl-nl-2
757description:
Geremy Condra03ebf062011-10-12 18:17:24 -0700758 Check that \newline is collapsed in $ sequences
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700759 (ksh93 fails this)
760stdin:
761 a=12
762 ab=19
763 echo $\
764 a
765 echo $a\
766 b
767 echo $\
768 {a}
769 echo ${a\
770 b}
771 echo ${ab\
772 }
773expected-stdout:
774 12
775 19
776 12
777 19
778 19
779---
780name: bksl-nl-3
781description:
Geremy Condra03ebf062011-10-12 18:17:24 -0700782 Check that \newline is collapsed in $(..) and `...` sequences
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700783 (ksh93 fails this)
784stdin:
785 echo $\
786 (echo foobar1)
787 echo $(\
788 echo foobar2)
789 echo $(echo foo\
790 bar3)
791 echo $(echo foobar4\
792 )
793 echo `
794 echo stuff1`
795 echo `echo st\
796 uff2`
797expected-stdout:
798 foobar1
799 foobar2
800 foobar3
801 foobar4
802 stuff1
803 stuff2
804---
805name: bksl-nl-4
806description:
Geremy Condra03ebf062011-10-12 18:17:24 -0700807 Check that \newline is collapsed in $((..)) sequences
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700808 (ksh93 fails this)
809stdin:
810 echo $\
811 ((1+2))
812 echo $(\
813 (1+2+3))
814 echo $((\
815 1+2+3+4))
816 echo $((1+\
817 2+3+4+5))
818 echo $((1+2+3+4+5+6)\
819 )
820expected-stdout:
821 3
822 6
823 10
824 15
825 21
826---
827name: bksl-nl-5
828description:
Geremy Condra03ebf062011-10-12 18:17:24 -0700829 Check that \newline is collapsed in double quoted strings
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700830stdin:
831 echo "\
832 hi"
833 echo "foo\
834 bar"
835 echo "folks\
836 "
837expected-stdout:
838 hi
839 foobar
840 folks
841---
842name: bksl-nl-6
843description:
Geremy Condra03ebf062011-10-12 18:17:24 -0700844 Check that \newline is collapsed in here document delimiters
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700845 (ksh93 fails second part of this)
846stdin:
847 a=12
848 cat << EO\
849 F
850 a=$a
851 foo\
852 bar
853 EOF
854 cat << E_O_F
855 foo
856 E_O_\
857 F
858 echo done
859expected-stdout:
860 a=12
861 foobar
862 foo
863 done
864---
865name: bksl-nl-7
866description:
Geremy Condra03ebf062011-10-12 18:17:24 -0700867 Check that \newline is collapsed in double-quoted here-document
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700868 delimiter.
869stdin:
870 a=12
871 cat << "EO\
872 F"
873 a=$a
874 foo\
875 bar
876 EOF
877 echo done
878expected-stdout:
879 a=$a
880 foo\
881 bar
882 done
883---
884name: bksl-nl-8
885description:
Geremy Condra03ebf062011-10-12 18:17:24 -0700886 Check that \newline is collapsed in various 2+ character tokens
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -0700887 delimiter.
888 (ksh93 fails this)
889stdin:
890 echo hi &\
891 & echo there
892 echo foo |\
893 | echo bar
894 cat <\
895 < EOF
896 stuff
897 EOF
898 cat <\
899 <\
900 - EOF
901 more stuff
902 EOF
903 cat <<\
904 EOF
905 abcdef
906 EOF
907 echo hi >\
908 > /dev/null
909 echo $?
910 i=1
911 case $i in
912 (\
913 x|\
914 1\
915 ) echo hi;\
916 ;
917 (*) echo oops
918 esac
919expected-stdout:
920 hi
921 there
922 foo
923 stuff
924 more stuff
925 abcdef
926 0
927 hi
928---
929name: bksl-nl-9
930description:
931 Check that \ at the end of an alias is collapsed when followed
932 by a newline
933 (don't know what POSIX has to say about this)
934stdin:
935 alias x='echo hi\'
936 x
937 echo there
938expected-stdout:
939 hiecho there
940---
941name: bksl-nl-10
942description:
943 Check that \newline in a keyword is collapsed
944stdin:
945 i\
946 f true; then\
947 echo pass; el\
948 se echo fail; fi
949expected-stdout:
950 pass
951---
952#
953# Places \newline should be collapsed (ksh extensions)
954#
955name: bksl-nl-ksh-1
956description:
957 Check that \newline is collapsed in extended globbing
958 (ksh93 fails this)
959stdin:
960 xxx=foo
961 case $xxx in
962 (f*\
963 (\
964 o\
965 )\
966 ) echo ok ;;
967 *) echo bad
968 esac
969expected-stdout:
970 ok
971---
972name: bksl-nl-ksh-2
973description:
974 Check that \newline is collapsed in ((...)) expressions
975 (ksh93 fails this)
976stdin:
977 i=1
978 (\
979 (\
980 i=i+2\
981 )\
982 )
983 echo $i
984expected-stdout:
985 3
986---
987name: break-1
988description:
989 See if break breaks out of loops
990stdin:
991 for i in a b c; do echo $i; break; echo bad-$i; done
992 echo end-1
993 for i in a b c; do echo $i; break 1; echo bad-$i; done
994 echo end-2
995 for i in a b c; do
996 for j in x y z; do
997 echo $i:$j
998 break
999 echo bad-$i
1000 done
1001 echo end-$i
1002 done
1003 echo end-3
Elliott Hughesa3c3f962017-04-12 16:52:30 -07001004 for i in a b c; do echo $i; eval break; echo bad-$i; done
1005 echo end-4
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001006expected-stdout:
1007 a
1008 end-1
1009 a
1010 end-2
1011 a:x
1012 end-a
1013 b:x
1014 end-b
1015 c:x
1016 end-c
1017 end-3
Elliott Hughesa3c3f962017-04-12 16:52:30 -07001018 a
1019 end-4
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001020---
1021name: break-2
1022description:
1023 See if break breaks out of nested loops
1024stdin:
1025 for i in a b c; do
1026 for j in x y z; do
1027 echo $i:$j
1028 break 2
1029 echo bad-$i
1030 done
1031 echo end-$i
1032 done
1033 echo end
1034expected-stdout:
1035 a:x
1036 end
1037---
1038name: break-3
1039description:
1040 What if break used outside of any loops
1041 (ksh88,ksh93 don't print error messages here)
1042stdin:
1043 break
1044expected-stderr-pattern:
1045 /.*break.*/
1046---
1047name: break-4
1048description:
1049 What if break N used when only N-1 loops
1050 (ksh88,ksh93 don't print error messages here)
1051stdin:
1052 for i in a b c; do echo $i; break 2; echo bad-$i; done
1053 echo end
1054expected-stdout:
1055 a
1056 end
1057expected-stderr-pattern:
1058 /.*break.*/
1059---
1060name: break-5
1061description:
1062 Error if break argument isn't a number
1063stdin:
1064 for i in a b c; do echo $i; break abc; echo more-$i; done
1065 echo end
1066expected-stdout:
1067 a
1068expected-exit: e != 0
1069expected-stderr-pattern:
1070 /.*break.*/
1071---
1072name: continue-1
1073description:
1074 See if continue continues loops
1075stdin:
1076 for i in a b c; do echo $i; continue; echo bad-$i ; done
1077 echo end-1
1078 for i in a b c; do echo $i; continue 1; echo bad-$i; done
1079 echo end-2
1080 for i in a b c; do
1081 for j in x y z; do
1082 echo $i:$j
1083 continue
1084 echo bad-$i-$j
1085 done
1086 echo end-$i
1087 done
1088 echo end-3
Elliott Hughesa3c3f962017-04-12 16:52:30 -07001089 for i in a b c; do echo $i; eval continue; echo bad-$i ; done
1090 echo end-4
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001091expected-stdout:
1092 a
1093 b
1094 c
1095 end-1
1096 a
1097 b
1098 c
1099 end-2
1100 a:x
1101 a:y
1102 a:z
1103 end-a
1104 b:x
1105 b:y
1106 b:z
1107 end-b
1108 c:x
1109 c:y
1110 c:z
1111 end-c
1112 end-3
Elliott Hughesa3c3f962017-04-12 16:52:30 -07001113 a
1114 b
1115 c
1116 end-4
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001117---
1118name: continue-2
1119description:
1120 See if continue breaks out of nested loops
1121stdin:
1122 for i in a b c; do
1123 for j in x y z; do
1124 echo $i:$j
1125 continue 2
1126 echo bad-$i-$j
1127 done
1128 echo end-$i
1129 done
1130 echo end
1131expected-stdout:
1132 a:x
1133 b:x
1134 c:x
1135 end
1136---
1137name: continue-3
1138description:
1139 What if continue used outside of any loops
1140 (ksh88,ksh93 don't print error messages here)
1141stdin:
1142 continue
1143expected-stderr-pattern:
1144 /.*continue.*/
1145---
1146name: continue-4
1147description:
1148 What if continue N used when only N-1 loops
1149 (ksh88,ksh93 don't print error messages here)
1150stdin:
1151 for i in a b c; do echo $i; continue 2; echo bad-$i; done
1152 echo end
1153expected-stdout:
1154 a
1155 b
1156 c
1157 end
1158expected-stderr-pattern:
1159 /.*continue.*/
1160---
1161name: continue-5
1162description:
1163 Error if continue argument isn't a number
1164stdin:
1165 for i in a b c; do echo $i; continue abc; echo more-$i; done
1166 echo end
1167expected-stdout:
1168 a
1169expected-exit: e != 0
1170expected-stderr-pattern:
1171 /.*continue.*/
1172---
1173name: cd-history
1174description:
1175 Test someone's CD history package (uses arrays)
1176stdin:
1177 # go to known place before doing anything
1178 cd /
1179
1180 alias cd=_cd
1181 function _cd
1182 {
1183 typeset -i cdlen i
1184 typeset t
1185
1186 if [ $# -eq 0 ]
1187 then
1188 set -- $HOME
1189 fi
1190
1191 if [ "$CDHISTFILE" -a -r "$CDHISTFILE" ] # if directory history exists
1192 then
1193 typeset CDHIST
1194 i=-1
1195 while read -r t # read directory history file
1196 do
1197 CDHIST[i=i+1]=$t
1198 done <$CDHISTFILE
1199 fi
1200
1201 if [ "${CDHIST[0]}" != "$PWD" -a "$PWD" != "" ]
1202 then
1203 _cdins # insert $PWD into cd history
1204 fi
1205
1206 cdlen=${#CDHIST[*]} # number of elements in history
1207
1208 case "$@" in
1209 -) # cd to new dir
1210 if [ "$OLDPWD" = "" ] && ((cdlen>1))
1211 then
1212 'print' ${CDHIST[1]}
1213 'cd' ${CDHIST[1]}
1214 _pwd
1215 else
1216 'cd' $@
1217 _pwd
1218 fi
1219 ;;
1220 -l) # print directory list
1221 typeset -R3 num
1222 ((i=cdlen))
1223 while (((i=i-1)>=0))
1224 do
1225 num=$i
1226 'print' "$num ${CDHIST[i]}"
1227 done
1228 return
1229 ;;
1230 -[0-9]|-[0-9][0-9]) # cd to dir in list
1231 if (((i=${1#-})<cdlen))
1232 then
1233 'print' ${CDHIST[i]}
1234 'cd' ${CDHIST[i]}
1235 _pwd
1236 else
1237 'cd' $@
1238 _pwd
1239 fi
1240 ;;
1241 -*) # cd to matched dir in list
1242 t=${1#-}
1243 i=1
1244 while ((i<cdlen))
1245 do
1246 case ${CDHIST[i]} in
1247 *$t*)
1248 'print' ${CDHIST[i]}
1249 'cd' ${CDHIST[i]}
1250 _pwd
1251 break
1252 ;;
1253 esac
1254 ((i=i+1))
1255 done
1256 if ((i>=cdlen))
1257 then
1258 'cd' $@
1259 _pwd
1260 fi
1261 ;;
1262 *) # cd to new dir
1263 'cd' $@
1264 _pwd
1265 ;;
1266 esac
1267
1268 _cdins # insert $PWD into cd history
1269
1270 if [ "$CDHISTFILE" ]
1271 then
1272 cdlen=${#CDHIST[*]} # number of elements in history
1273
1274 i=0
1275 while ((i<cdlen))
1276 do
1277 'print' -r ${CDHIST[i]} # update directory history
1278 ((i=i+1))
1279 done >$CDHISTFILE
1280 fi
1281 }
1282
1283 function _cdins # insert $PWD into cd history
1284 { # meant to be called only by _cd
1285 typeset -i i
1286
1287 ((i=0))
1288 while ((i<${#CDHIST[*]})) # see if dir is already in list
1289 do
1290 if [ "${CDHIST[$i]}" = "$PWD" ]
1291 then
1292 break
1293 fi
1294 ((i=i+1))
1295 done
1296
1297 if ((i>22)) # limit max size of list
1298 then
1299 i=22
1300 fi
1301
1302 while (((i=i-1)>=0)) # bump old dirs in list
1303 do
1304 CDHIST[i+1]=${CDHIST[i]}
1305 done
1306
1307 CDHIST[0]=$PWD # insert new directory in list
1308 }
1309
1310
1311 function _pwd
1312 {
1313 if [ -n "$ECD" ]
1314 then
1315 pwd 1>&6
1316 fi
1317 }
1318 # Start of test
1319 cd /tmp
1320 cd /bin
1321 cd /etc
1322 cd -
1323 cd -2
1324 cd -l
1325expected-stdout:
1326 /bin
1327 /tmp
1328 3 /
1329 2 /etc
1330 1 /bin
1331 0 /tmp
1332---
Geremy Condra03ebf062011-10-12 18:17:24 -07001333name: cd-pe
1334description:
1335 Check package for cd -Pe
1336need-pass: no
1337# the mv command fails on Cygwin
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001338# Hurd aborts the testsuite (permission denied)
1339# QNX does not find subdir to cd into
Elliott Hughes96b43632015-07-17 11:39:41 -07001340category: !os:cygwin,!os:gnu,!os:msys,!os:nto,!os:os390,!nosymlink
Geremy Condra03ebf062011-10-12 18:17:24 -07001341file-setup: file 644 "x"
1342 mkdir noread noread/target noread/target/subdir
1343 ln -s noread link
1344 chmod 311 noread
1345 cd -P$1 .
1346 echo 0=$?
1347 bwd=$PWD
1348 cd -P$1 link/target
1349 echo 1=$?,${PWD#$bwd/}
1350 epwd=$($TSHELL -c pwd 2>/dev/null)
1351 # This unexpectedly succeeds on GNU/Linux and MidnightBSD
1352 #echo pwd=$?,$epwd
1353 # expect: pwd=1,
1354 mv ../../noread ../../renamed
1355 cd -P$1 subdir
1356 echo 2=$?,${PWD#$bwd/}
1357 cd $bwd
1358 chmod 755 renamed
1359 rm -rf noread link renamed
1360stdin:
1361 export TSHELL="$__progname"
1362 "$__progname" x
1363 echo "now with -e:"
1364 "$__progname" x e
1365expected-stdout:
1366 0=0
1367 1=0,noread/target
1368 2=0,noread/target/subdir
1369 now with -e:
1370 0=0
1371 1=0,noread/target
1372 2=1,noread/target/subdir
1373---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001374name: env-prompt
1375description:
1376 Check that prompt not printed when processing ENV
1377env-setup: !ENV=./foo!
1378file-setup: file 644 "foo"
1379 XXX=_
1380 PS1=X
1381 false && echo hmmm
Geremy Condra03ebf062011-10-12 18:17:24 -07001382need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001383arguments: !-i!
1384stdin:
1385 echo hi${XXX}there
1386expected-stdout:
1387 hi_there
1388expected-stderr: !
1389 XX
1390---
1391name: expand-ugly
1392description:
1393 Check that weird ${foo+bar} constructs are parsed correctly
1394stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001395 print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
1396 print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "<$x> "; done' >pfs
1397 chmod +x pfn pfs
1398 (echo 1 ${IFS+'}'z}) 2>/dev/null || echo failed in 1
1399 (echo 2 "${IFS+'}'z}") 2>/dev/null || echo failed in 2
1400 (echo 3 "foo ${IFS+'bar} baz") 2>/dev/null || echo failed in 3
1401 (echo -n '4 '; ./pfn "foo ${IFS+"b c"} baz") 2>/dev/null || echo failed in 4
1402 (echo -n '5 '; ./pfn "foo ${IFS+b c} baz") 2>/dev/null || echo failed in 5
1403 (echo 6 ${IFS+"}"z}) 2>/dev/null || echo failed in 6
1404 (echo 7 "${IFS+"}"z}") 2>/dev/null || echo failed in 7
1405 (echo 8 "${IFS+\"}\"z}") 2>/dev/null || echo failed in 8
1406 (echo 9 "${IFS+\"\}\"z}") 2>/dev/null || echo failed in 9
1407 (echo 10 foo ${IFS+'bar} baz'}) 2>/dev/null || echo failed in 10
1408 (echo 11 "$(echo "${IFS+'}'z}")") 2>/dev/null || echo failed in 11
1409 (echo 12 "$(echo ${IFS+'}'z})") 2>/dev/null || echo failed in 12
1410 (echo 13 ${IFS+\}z}) 2>/dev/null || echo failed in 13
1411 (echo 14 "${IFS+\}z}") 2>/dev/null || echo failed in 14
1412 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
1413 l=t; (echo 16 ${IFS+h`echo -n i ${IFS+$l}h`ere}) 2>/dev/null || echo failed in 16
1414 l=t; (echo 17 ${IFS+h$(echo -n i ${IFS+$l}h)ere}) 2>/dev/null || echo failed in 17
1415 l=t; (echo 18 "${IFS+h`echo -n i ${IFS+$l}h`ere}") 2>/dev/null || echo failed in 18
1416 l=t; (echo 19 "${IFS+h$(echo -n i ${IFS+$l}h)ere}") 2>/dev/null || echo failed in 19
1417 l=t; (echo 20 ${IFS+h`echo -n i "${IFS+$l}"h`ere}) 2>/dev/null || echo failed in 20
1418 l=t; (echo 21 ${IFS+h$(echo -n i "${IFS+$l}"h)ere}) 2>/dev/null || echo failed in 21
1419 l=t; (echo 22 "${IFS+h`echo -n i "${IFS+$l}"h`ere}") 2>/dev/null || echo failed in 22
1420 l=t; (echo 23 "${IFS+h$(echo -n i "${IFS+$l}"h)ere}") 2>/dev/null || echo failed in 23
1421 key=value; (echo -n '24 '; ./pfn "${IFS+'$key'}") 2>/dev/null || echo failed in 24
1422 key=value; (echo -n '25 '; ./pfn "${IFS+"'$key'"}") 2>/dev/null || echo failed in 25 # ksh93: “'$key'”
1423 key=value; (echo -n '26 '; ./pfn ${IFS+'$key'}) 2>/dev/null || echo failed in 26
1424 key=value; (echo -n '27 '; ./pfn ${IFS+"'$key'"}) 2>/dev/null || echo failed in 27
1425 (echo -n '28 '; ./pfn "${IFS+"'"x ~ x'}'x"'}"x}" #') 2>/dev/null || echo failed in 28
1426 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
1427 (echo -n '30 '; ./pfs ${IFS+foo 'b\
1428 ar' baz}; echo .) 2>/dev/null || (echo failed in 30; echo failed in 31)
1429 (echo -n '32 '; ./pfs ${IFS+foo "b\
1430 ar" baz}; echo .) 2>/dev/null || echo failed in 32
1431 (echo -n '33 '; ./pfs "${IFS+foo 'b\
1432 ar' baz}"; echo .) 2>/dev/null || echo failed in 33
1433 (echo -n '34 '; ./pfs "${IFS+foo "b\
1434 ar" baz}"; echo .) 2>/dev/null || echo failed in 34
1435 (echo -n '35 '; ./pfs ${v=a\ b} x ${v=c\ d}; echo .) 2>/dev/null || echo failed in 35
1436 (echo -n '36 '; ./pfs "${v=a\ b}" x "${v=c\ d}"; echo .) 2>/dev/null || echo failed in 36
1437 (echo -n '37 '; ./pfs ${v-a\ b} x ${v-c\ d}; echo .) 2>/dev/null || echo failed in 37
1438 (echo 38 ${IFS+x'a'y} / "${IFS+x'a'y}" .) 2>/dev/null || echo failed in 38
1439 foo="x'a'y"; (echo 39 ${foo%*'a'*} / "${foo%*'a'*}" .) 2>/dev/null || echo failed in 39
1440 foo="a b c"; (echo -n '40 '; ./pfs "${foo#a}"; echo .) 2>/dev/null || echo failed in 40
Elliott Hughes77740fc2016-08-12 15:06:53 -07001441 (foo() { return 100; }; foo; echo 41 ${#+${#:+${#?}}\ \}\}\}}) 2>/dev/null || echo failed in 41
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001442expected-stdout:
1443 1 }z
1444 2 ''z}
1445 3 foo 'bar baz
1446 4 foo b c baz
1447 5 foo b c baz
1448 6 }z
1449 7 }z
1450 8 ""z}
1451 9 "}"z
1452 10 foo bar} baz
1453 11 ''z}
1454 12 }z
1455 13 }z
1456 14 }z
1457 15 <foo abx{ {{{}b c d{} bar> <}> <baz> .
1458 16 hi there
1459 17 hi there
1460 18 hi there
1461 19 hi there
1462 20 hi there
1463 21 hi there
1464 22 hi there
1465 23 hi there
1466 24 'value'
1467 25 'value'
1468 26 $key
1469 27 'value'
1470 28 'x ~ x''x}"x}" #
1471 29 <foo> <abx{ {{> <{}b> <c> <d{}> <bar> <}> <baz> .
1472 30 <foo> <b\
1473 ar> <baz> .
1474 32 <foo> <bar> <baz> .
1475 33 <foo 'bar' baz> .
1476 34 <foo bar baz> .
1477 35 <a> <b> <x> <a> <b> .
1478 36 <a\ b> <x> <a\ b> .
1479 37 <a b> <x> <c d> .
1480 38 xay / x'a'y .
1481 39 x' / x' .
1482 40 < b c> .
Elliott Hughes77740fc2016-08-12 15:06:53 -07001483 41 3 }}}
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001484---
1485name: expand-unglob-dblq
1486description:
1487 Check that regular "${foo+bar}" constructs are parsed correctly
1488stdin:
1489 u=x
1490 tl_norm() {
1491 v=$2
1492 test x"$v" = x"-" && unset v
1493 (echo "$1 plus norm foo ${v+'bar'} baz")
1494 (echo "$1 dash norm foo ${v-'bar'} baz")
1495 (echo "$1 eqal norm foo ${v='bar'} baz")
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001496 (echo "$1 qstn norm foo ${v?'bar'} baz") 2>/dev/null || \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001497 echo "$1 qstn norm -> error"
1498 (echo "$1 PLUS norm foo ${v:+'bar'} baz")
1499 (echo "$1 DASH norm foo ${v:-'bar'} baz")
1500 (echo "$1 EQAL norm foo ${v:='bar'} baz")
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001501 (echo "$1 QSTN norm foo ${v:?'bar'} baz") 2>/dev/null || \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001502 echo "$1 QSTN norm -> error"
1503 }
1504 tl_paren() {
1505 v=$2
1506 test x"$v" = x"-" && unset v
1507 (echo "$1 plus parn foo ${v+(bar)} baz")
1508 (echo "$1 dash parn foo ${v-(bar)} baz")
1509 (echo "$1 eqal parn foo ${v=(bar)} baz")
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001510 (echo "$1 qstn parn foo ${v?(bar)} baz") 2>/dev/null || \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001511 echo "$1 qstn parn -> error"
1512 (echo "$1 PLUS parn foo ${v:+(bar)} baz")
1513 (echo "$1 DASH parn foo ${v:-(bar)} baz")
1514 (echo "$1 EQAL parn foo ${v:=(bar)} baz")
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001515 (echo "$1 QSTN parn foo ${v:?(bar)} baz") 2>/dev/null || \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001516 echo "$1 QSTN parn -> error"
1517 }
1518 tl_brace() {
1519 v=$2
1520 test x"$v" = x"-" && unset v
1521 (echo "$1 plus brac foo ${v+a$u{{{\}b} c ${v+d{}} baz")
1522 (echo "$1 dash brac foo ${v-a$u{{{\}b} c ${v-d{}} baz")
1523 (echo "$1 eqal brac foo ${v=a$u{{{\}b} c ${v=d{}} baz")
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001524 (echo "$1 qstn brac foo ${v?a$u{{{\}b} c ${v?d{}} baz") 2>/dev/null || \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001525 echo "$1 qstn brac -> error"
1526 (echo "$1 PLUS brac foo ${v:+a$u{{{\}b} c ${v:+d{}} baz")
1527 (echo "$1 DASH brac foo ${v:-a$u{{{\}b} c ${v:-d{}} baz")
1528 (echo "$1 EQAL brac foo ${v:=a$u{{{\}b} c ${v:=d{}} baz")
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001529 (echo "$1 QSTN brac foo ${v:?a$u{{{\}b} c ${v:?d{}} baz") 2>/dev/null || \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001530 echo "$1 QSTN brac -> error"
1531 }
Elliott Hughes77740fc2016-08-12 15:06:53 -07001532 : '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}'
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001533 tl_norm 1 -
1534 tl_norm 2 ''
1535 tl_norm 3 x
1536 tl_paren 4 -
1537 tl_paren 5 ''
1538 tl_paren 6 x
1539 tl_brace 7 -
1540 tl_brace 8 ''
1541 tl_brace 9 x
1542expected-stdout:
1543 1 plus norm foo baz
1544 1 dash norm foo 'bar' baz
1545 1 eqal norm foo 'bar' baz
1546 1 qstn norm -> error
1547 1 PLUS norm foo baz
1548 1 DASH norm foo 'bar' baz
1549 1 EQAL norm foo 'bar' baz
1550 1 QSTN norm -> error
1551 2 plus norm foo 'bar' baz
1552 2 dash norm foo baz
1553 2 eqal norm foo baz
1554 2 qstn norm foo baz
1555 2 PLUS norm foo baz
1556 2 DASH norm foo 'bar' baz
1557 2 EQAL norm foo 'bar' baz
1558 2 QSTN norm -> error
1559 3 plus norm foo 'bar' baz
1560 3 dash norm foo x baz
1561 3 eqal norm foo x baz
1562 3 qstn norm foo x baz
1563 3 PLUS norm foo 'bar' baz
1564 3 DASH norm foo x baz
1565 3 EQAL norm foo x baz
1566 3 QSTN norm foo x baz
1567 4 plus parn foo baz
1568 4 dash parn foo (bar) baz
1569 4 eqal parn foo (bar) baz
1570 4 qstn parn -> error
1571 4 PLUS parn foo baz
1572 4 DASH parn foo (bar) baz
1573 4 EQAL parn foo (bar) baz
1574 4 QSTN parn -> error
1575 5 plus parn foo (bar) baz
1576 5 dash parn foo baz
1577 5 eqal parn foo baz
1578 5 qstn parn foo baz
1579 5 PLUS parn foo baz
1580 5 DASH parn foo (bar) baz
1581 5 EQAL parn foo (bar) baz
1582 5 QSTN parn -> error
1583 6 plus parn foo (bar) baz
1584 6 dash parn foo x baz
1585 6 eqal parn foo x baz
1586 6 qstn parn foo x baz
1587 6 PLUS parn foo (bar) baz
1588 6 DASH parn foo x baz
1589 6 EQAL parn foo x baz
1590 6 QSTN parn foo x baz
1591 7 plus brac foo c } baz
1592 7 dash brac foo ax{{{}b c d{} baz
1593 7 eqal brac foo ax{{{}b c ax{{{}b} baz
1594 7 qstn brac -> error
1595 7 PLUS brac foo c } baz
1596 7 DASH brac foo ax{{{}b c d{} baz
1597 7 EQAL brac foo ax{{{}b c ax{{{}b} baz
1598 7 QSTN brac -> error
1599 8 plus brac foo ax{{{}b c d{} baz
1600 8 dash brac foo c } baz
1601 8 eqal brac foo c } baz
1602 8 qstn brac foo c } baz
1603 8 PLUS brac foo c } baz
1604 8 DASH brac foo ax{{{}b c d{} baz
1605 8 EQAL brac foo ax{{{}b c ax{{{}b} baz
1606 8 QSTN brac -> error
1607 9 plus brac foo ax{{{}b c d{} baz
1608 9 dash brac foo x c x} baz
1609 9 eqal brac foo x c x} baz
1610 9 qstn brac foo x c x} baz
1611 9 PLUS brac foo ax{{{}b c d{} baz
1612 9 DASH brac foo x c x} baz
1613 9 EQAL brac foo x c x} baz
1614 9 QSTN brac foo x c x} baz
1615---
1616name: expand-unglob-unq
1617description:
1618 Check that regular ${foo+bar} constructs are parsed correctly
1619stdin:
1620 u=x
1621 tl_norm() {
1622 v=$2
1623 test x"$v" = x"-" && unset v
1624 (echo $1 plus norm foo ${v+'bar'} baz)
1625 (echo $1 dash norm foo ${v-'bar'} baz)
1626 (echo $1 eqal norm foo ${v='bar'} baz)
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001627 (echo $1 qstn norm foo ${v?'bar'} baz) 2>/dev/null || \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001628 echo "$1 qstn norm -> error"
1629 (echo $1 PLUS norm foo ${v:+'bar'} baz)
1630 (echo $1 DASH norm foo ${v:-'bar'} baz)
1631 (echo $1 EQAL norm foo ${v:='bar'} baz)
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001632 (echo $1 QSTN norm foo ${v:?'bar'} baz) 2>/dev/null || \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001633 echo "$1 QSTN norm -> error"
1634 }
1635 tl_paren() {
1636 v=$2
1637 test x"$v" = x"-" && unset v
1638 (echo $1 plus parn foo ${v+\(bar')'} baz)
1639 (echo $1 dash parn foo ${v-\(bar')'} baz)
1640 (echo $1 eqal parn foo ${v=\(bar')'} baz)
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001641 (echo $1 qstn parn foo ${v?\(bar')'} baz) 2>/dev/null || \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001642 echo "$1 qstn parn -> error"
1643 (echo $1 PLUS parn foo ${v:+\(bar')'} baz)
1644 (echo $1 DASH parn foo ${v:-\(bar')'} baz)
1645 (echo $1 EQAL parn foo ${v:=\(bar')'} baz)
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001646 (echo $1 QSTN parn foo ${v:?\(bar')'} baz) 2>/dev/null || \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001647 echo "$1 QSTN parn -> error"
1648 }
1649 tl_brace() {
1650 v=$2
1651 test x"$v" = x"-" && unset v
1652 (echo $1 plus brac foo ${v+a$u{{{\}b} c ${v+d{}} baz)
1653 (echo $1 dash brac foo ${v-a$u{{{\}b} c ${v-d{}} baz)
1654 (echo $1 eqal brac foo ${v=a$u{{{\}b} c ${v=d{}} baz)
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001655 (echo $1 qstn brac foo ${v?a$u{{{\}b} c ${v?d{}} baz) 2>/dev/null || \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001656 echo "$1 qstn brac -> error"
1657 (echo $1 PLUS brac foo ${v:+a$u{{{\}b} c ${v:+d{}} baz)
1658 (echo $1 DASH brac foo ${v:-a$u{{{\}b} c ${v:-d{}} baz)
1659 (echo $1 EQAL brac foo ${v:=a$u{{{\}b} c ${v:=d{}} baz)
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001660 (echo $1 QSTN brac foo ${v:?a$u{{{\}b} c ${v:?d{}} baz) 2>/dev/null || \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001661 echo "$1 QSTN brac -> error"
1662 }
Elliott Hughes77740fc2016-08-12 15:06:53 -07001663 : '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}'
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001664 tl_norm 1 -
1665 tl_norm 2 ''
1666 tl_norm 3 x
1667 tl_paren 4 -
1668 tl_paren 5 ''
1669 tl_paren 6 x
1670 tl_brace 7 -
1671 tl_brace 8 ''
1672 tl_brace 9 x
1673expected-stdout:
1674 1 plus norm foo baz
1675 1 dash norm foo bar baz
1676 1 eqal norm foo bar baz
1677 1 qstn norm -> error
1678 1 PLUS norm foo baz
1679 1 DASH norm foo bar baz
1680 1 EQAL norm foo bar baz
1681 1 QSTN norm -> error
1682 2 plus norm foo bar baz
1683 2 dash norm foo baz
1684 2 eqal norm foo baz
1685 2 qstn norm foo baz
1686 2 PLUS norm foo baz
1687 2 DASH norm foo bar baz
1688 2 EQAL norm foo bar baz
1689 2 QSTN norm -> error
1690 3 plus norm foo bar baz
1691 3 dash norm foo x baz
1692 3 eqal norm foo x baz
1693 3 qstn norm foo x baz
1694 3 PLUS norm foo bar baz
1695 3 DASH norm foo x baz
1696 3 EQAL norm foo x baz
1697 3 QSTN norm foo x baz
1698 4 plus parn foo baz
1699 4 dash parn foo (bar) baz
1700 4 eqal parn foo (bar) baz
1701 4 qstn parn -> error
1702 4 PLUS parn foo baz
1703 4 DASH parn foo (bar) baz
1704 4 EQAL parn foo (bar) baz
1705 4 QSTN parn -> error
1706 5 plus parn foo (bar) baz
1707 5 dash parn foo baz
1708 5 eqal parn foo baz
1709 5 qstn parn foo baz
1710 5 PLUS parn foo baz
1711 5 DASH parn foo (bar) baz
1712 5 EQAL parn foo (bar) baz
1713 5 QSTN parn -> error
1714 6 plus parn foo (bar) baz
1715 6 dash parn foo x baz
1716 6 eqal parn foo x baz
1717 6 qstn parn foo x baz
1718 6 PLUS parn foo (bar) baz
1719 6 DASH parn foo x baz
1720 6 EQAL parn foo x baz
1721 6 QSTN parn foo x baz
1722 7 plus brac foo c } baz
1723 7 dash brac foo ax{{{}b c d{} baz
1724 7 eqal brac foo ax{{{}b c ax{{{}b} baz
1725 7 qstn brac -> error
1726 7 PLUS brac foo c } baz
1727 7 DASH brac foo ax{{{}b c d{} baz
1728 7 EQAL brac foo ax{{{}b c ax{{{}b} baz
1729 7 QSTN brac -> error
1730 8 plus brac foo ax{{{}b c d{} baz
1731 8 dash brac foo c } baz
1732 8 eqal brac foo c } baz
1733 8 qstn brac foo c } baz
1734 8 PLUS brac foo c } baz
1735 8 DASH brac foo ax{{{}b c d{} baz
1736 8 EQAL brac foo ax{{{}b c ax{{{}b} baz
1737 8 QSTN brac -> error
1738 9 plus brac foo ax{{{}b c d{} baz
1739 9 dash brac foo x c x} baz
1740 9 eqal brac foo x c x} baz
1741 9 qstn brac foo x c x} baz
1742 9 PLUS brac foo ax{{{}b c d{} baz
1743 9 DASH brac foo x c x} baz
1744 9 EQAL brac foo x c x} baz
1745 9 QSTN brac foo x c x} baz
1746---
Geremy Condra03ebf062011-10-12 18:17:24 -07001747name: expand-threecolons-dblq
1748description:
1749 Check for a particular thing that used to segfault
1750stdin:
1751 TEST=1234
1752 echo "${TEST:1:2:3}"
1753 echo $? but still living
1754expected-stderr-pattern:
1755 /bad substitution/
1756expected-exit: 1
1757---
1758name: expand-threecolons-unq
1759description:
1760 Check for a particular thing that used to not error out
1761stdin:
1762 TEST=1234
1763 echo ${TEST:1:2:3}
1764 echo $? but still living
1765expected-stderr-pattern:
1766 /bad substitution/
1767expected-exit: 1
1768---
1769name: expand-weird-1
1770description:
Elliott Hughes77740fc2016-08-12 15:06:53 -07001771 Check corner cases of trim expansion vs. $# vs. ${#var} vs. ${var?}
Geremy Condra03ebf062011-10-12 18:17:24 -07001772stdin:
1773 set 1 2 3 4 5 6 7 8 9 10 11
1774 echo ${#} # value of $#
1775 echo ${##} # length of $#
1776 echo ${##1} # $# trimmed 1
1777 set 1 2 3 4 5 6 7 8 9 10 11 12
1778 echo ${##1}
Geremy Condra03ebf062011-10-12 18:17:24 -07001779 (exit 0)
1780 echo $? = ${#?} .
1781 (exit 111)
1782 echo $? = ${#?} .
1783expected-stdout:
Elliott Hughes77740fc2016-08-12 15:06:53 -07001784 11
1785 2
1786 1
1787 2
Geremy Condra03ebf062011-10-12 18:17:24 -07001788 0 = 1 .
1789 111 = 3 .
1790---
Elliott Hughes77740fc2016-08-12 15:06:53 -07001791name: expand-weird-2
1792description:
1793 Check more substitution and extension corner cases
1794stdin:
1795 :& set -C; pid=$$; sub=$!; flg=$-; set -- i; exec 3>x.tmp
1796 #echo "D: !=$! #=$# \$=$$ -=$- ?=$?"
1797 echo >&3 3 = s^${!-word} , ${#-word} , p^${$-word} , f^${--word} , ${?-word} .
1798 echo >&3 4 = ${!+word} , ${#+word} , ${$+word} , ${-+word} , ${?+word} .
1799 echo >&3 5 = s^${!=word} , ${#=word} , p^${$=word} , f^${-=word} , ${?=word} .
1800 echo >&3 6 = s^${!?word} , ${#?word} , p^${$?word} , f^${-?word} , ${??word} .
1801 echo >&3 7 = sl^${#!} , ${##} , pl^${#$} , fl^${#-} , ${#?} .
1802 echo >&3 8 = sw^${%!} , ${%#} , pw^${%$} , fw^${%-} , ${%?} .
1803 echo >&3 9 = ${!!} , s^${!#} , ${!$} , s^${!-} , s^${!?} .
1804 echo >&3 10 = s^${!#pattern} , ${##pattern} , p^${$#pattern} , f^${-#pattern} , ${?#pattern} .
1805 echo >&3 11 = s^${!%pattern} , ${#%pattern} , p^${$%pattern} , f^${-%pattern} , ${?%pattern} .
1806 echo >&3 12 = $# : ${##} , ${##1} .
1807 set --
1808 echo >&3 14 = $# : ${##} , ${##1} .
1809 set -- 1 2 3 4 5
1810 echo >&3 16 = $# : ${##} , ${##1} .
1811 set -- 1 2 3 4 5 6 7 8 9 a b c d e
1812 echo >&3 18 = $# : ${##} , ${##1} .
1813 exec 3>&-
1814 <x.tmp sed \
1815 -e "s/ pl^${#pid} / PID /g" -e "s/ sl^${#sub} / SUB /g" -e "s/ fl^${#flg} / FLG /g" \
1816 -e "s/ pw^${%pid} / PID /g" -e "s/ sw^${%sub} / SUB /g" -e "s/ fw^${%flg} / FLG /g" \
1817 -e "s/ p^$pid / PID /g" -e "s/ s^$sub / SUB /g" -e "s/ f^$flg / FLG /g"
1818expected-stdout:
1819 3 = SUB , 1 , PID , FLG , 0 .
1820 4 = word , word , word , word , word .
1821 5 = SUB , 1 , PID , FLG , 0 .
1822 6 = SUB , 1 , PID , FLG , 0 .
1823 7 = SUB , 1 , PID , FLG , 1 .
1824 8 = SUB , 1 , PID , FLG , 1 .
1825 9 = ! , SUB , $ , SUB , SUB .
1826 10 = SUB , 1 , PID , FLG , 0 .
1827 11 = SUB , 1 , PID , FLG , 0 .
1828 12 = 1 : 1 , .
1829 14 = 0 : 1 , 0 .
1830 16 = 5 : 1 , 5 .
1831 18 = 14 : 2 , 4 .
1832---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00001833name: expand-weird-3
1834description:
1835 Check that trimming works with positional parameters (Debian #48453)
1836stdin:
1837 A=9999-02
1838 B=9999
1839 echo 1=${A#$B?}.
1840 set -- $A $B
1841 echo 2=${1#$2?}.
1842expected-stdout:
1843 1=02.
1844 2=02.
1845---
Elliott Hughesfc0307d2016-02-02 15:26:47 -08001846name: expand-weird-4
1847description:
1848 Check that tilde expansion is enabled in ${x#~}
1849 and cases that are modelled after it (${x/~/~})
1850stdin:
1851 HOME=/etc
1852 a="~/x"
1853 echo "<${a#~}> <${a#\~}> <${b:-~}> <${b:-\~}> <${c:=~}><$c> <${a/~}> <${a/x/~}> <${a/x/\~}>"
1854expected-stdout:
1855 <~/x> </x> <~> <\~> <~><~> <~/x> <~//etc> <~/~>
1856---
Elliott Hughes77740fc2016-08-12 15:06:53 -07001857name: expand-bang-1
1858description:
1859 Check corner case of ${!?} with ! being var vs. op
1860stdin:
1861 echo ${!?}
1862expected-exit: 1
1863expected-stderr-pattern: /not set/
1864---
1865name: expand-bang-2
1866description:
1867 Check corner case of ${!var} vs. ${var op} with var=!
1868stdin:
1869 echo 1 $! .
1870 echo 2 ${!#} .
1871 echo 3 ${!#[0-9]} .
1872 echo 4 ${!-foo} .
1873 # get an at least three-digit bg pid
1874 while :; do
1875 :&
1876 x=$!
1877 if [[ $x != +([0-9]) ]]; then
1878 echo >&2 "cannot test, pid '$x' not numeric"
1879 echo >&2 report this with as many details as possible
1880 exit 1
1881 fi
1882 [[ $x = [0-9][0-9][0-9]* ]] && break
1883 done
1884 y=${x#?}
1885 t=$!; [[ $t = $x ]]; echo 5 $? .
1886 t=${!#}; [[ $t = $x ]]; echo 6 $? .
1887 t=${!#[0-9]}; [[ $t = $y ]]; echo 7 $? .
1888 t=${!-foo}; [[ $t = $x ]]; echo 8 $? .
1889 t=${!?bar}; [[ $t = $x ]]; echo 9 $? .
1890expected-stdout:
1891 1 .
1892 2 .
1893 3 .
1894 4 foo .
1895 5 0 .
1896 6 0 .
1897 7 0 .
1898 8 0 .
1899 9 0 .
1900---
Elliott Hughes737fdce2014-08-07 12:59:26 -07001901name: expand-number-1
1902description:
1903 Check that positional arguments do not overflow
1904stdin:
1905 echo "1 ${12345678901234567890} ."
1906expected-stdout:
1907 1 .
1908---
Elliott Hughes77740fc2016-08-12 15:06:53 -07001909name: expand-slashes-1
1910description:
1911 Check that side effects in substring replacement are handled correctly
1912stdin:
1913 foo=n1n1n1n2n3
1914 i=2
1915 n=1
1916 echo 1 ${foo//n$((n++))/[$((++i))]} .
1917 echo 2 $n , $i .
1918expected-stdout:
1919 1 [3][3][3]n2n3 .
1920 2 2 , 3 .
1921---
1922name: expand-slashes-2
1923description:
1924 Check that side effects in substring replacement are handled correctly
1925stdin:
1926 foo=n1n1n1n2n3
1927 i=2
1928 n=1
1929 echo 1 ${foo@/n$((n++))/[$((++i))]} .
1930 echo 2 $n , $i .
1931expected-stdout:
1932 1 [3]n1n1[4][5] .
1933 2 5 , 5 .
1934---
1935name: expand-slashes-3
1936description:
1937 Check that we can access the replaced string
1938stdin:
1939 foo=n1n1n1n2n3
1940 echo 1 ${foo@/n[12]/[$KSH_MATCH]} .
1941expected-stdout:
1942 1 [n1][n1][n1][n2]n3 .
1943---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07001944name: eglob-bad-1
1945description:
1946 Check that globbing isn't done when glob has syntax error
1947file-setup: file 644 "abcx"
1948file-setup: file 644 "abcz"
1949file-setup: file 644 "bbc"
1950stdin:
1951 echo !([*)*
1952 echo +(a|b[)*
1953expected-stdout:
1954 !([*)*
1955 +(a|b[)*
1956---
1957name: eglob-bad-2
1958description:
1959 Check that globbing isn't done when glob has syntax error
1960 (AT&T ksh fails this test)
1961file-setup: file 644 "abcx"
1962file-setup: file 644 "abcz"
1963file-setup: file 644 "bbc"
1964stdin:
1965 echo [a*(]*)z
1966expected-stdout:
1967 [a*(]*)z
1968---
1969name: eglob-infinite-plus
1970description:
1971 Check that shell doesn't go into infinite loop expanding +(...)
1972 expressions.
1973file-setup: file 644 "abc"
1974time-limit: 3
1975stdin:
1976 echo +()c
1977 echo +()x
1978 echo +(*)c
1979 echo +(*)x
1980expected-stdout:
1981 +()c
1982 +()x
1983 abc
1984 +(*)x
1985---
1986name: eglob-subst-1
1987description:
1988 Check that eglobbing isn't done on substitution results
1989file-setup: file 644 "abc"
1990stdin:
1991 x='@(*)'
1992 echo $x
1993expected-stdout:
1994 @(*)
1995---
1996name: eglob-nomatch-1
1997description:
1998 Check that the pattern doesn't match
1999stdin:
2000 echo 1: no-file+(a|b)stuff
2001 echo 2: no-file+(a*(c)|b)stuff
2002 echo 3: no-file+((((c)))|b)stuff
2003expected-stdout:
2004 1: no-file+(a|b)stuff
2005 2: no-file+(a*(c)|b)stuff
2006 3: no-file+((((c)))|b)stuff
2007---
2008name: eglob-match-1
2009description:
2010 Check that the pattern matches correctly
2011file-setup: file 644 "abd"
2012file-setup: file 644 "acd"
2013file-setup: file 644 "abac"
2014stdin:
2015 echo 1: a+(b|c)d
2016 echo 2: a!(@(b|B))d
2017 echo 3: *(a(b|c)) # (...|...) can be used within X(..)
2018 echo 4: a[b*(foo|bar)]d # patterns not special inside [...]
2019expected-stdout:
2020 1: abd acd
2021 2: acd
2022 3: abac
2023 4: abd
2024---
2025name: eglob-case-1
2026description:
2027 Simple negation tests
2028stdin:
2029 case foo in !(foo|bar)) echo yes;; *) echo no;; esac
2030 case bar in !(foo|bar)) echo yes;; *) echo no;; esac
2031expected-stdout:
2032 no
2033 no
2034---
2035name: eglob-case-2
2036description:
2037 Simple kleene tests
2038stdin:
2039 case foo in *(a|b[)) echo yes;; *) echo no;; esac
2040 case foo in *(a|b[)|f*) echo yes;; *) echo no;; esac
2041 case '*(a|b[)' in *(a|b[)) echo yes;; *) echo no;; esac
2042expected-stdout:
2043 no
2044 yes
2045 yes
2046---
2047name: eglob-trim-1
2048description:
2049 Eglobbing in trim expressions...
2050 (AT&T ksh fails this - docs say # matches shortest string, ## matches
2051 longest...)
2052stdin:
2053 x=abcdef
2054 echo 1: ${x#a|abc}
2055 echo 2: ${x##a|abc}
2056 echo 3: ${x%def|f}
2057 echo 4: ${x%%f|def}
2058expected-stdout:
2059 1: bcdef
2060 2: def
2061 3: abcde
2062 4: abc
2063---
2064name: eglob-trim-2
2065description:
2066 Check eglobbing works in trims...
2067stdin:
2068 x=abcdef
2069 echo 1: ${x#*(a|b)cd}
2070 echo 2: "${x#*(a|b)cd}"
2071 echo 3: ${x#"*(a|b)cd"}
2072 echo 4: ${x#a(b|c)}
2073expected-stdout:
2074 1: ef
2075 2: ef
2076 3: abcdef
2077 4: cdef
2078---
Geremy Condra03ebf062011-10-12 18:17:24 -07002079name: eglob-trim-3
2080description:
2081 Check eglobbing works in trims, for Korn Shell
2082 Ensure eglobbing does not work for reduced-feature /bin/sh
2083stdin:
2084 set +o sh
2085 x=foobar
2086 y=foobaz
2087 z=fooba\?
2088 echo "<${x%bar|baz},${y%bar|baz},${z%\?}>"
2089 echo "<${x%ba(r|z)},${y%ba(r|z)}>"
2090 set -o sh
2091 echo "<${x%bar|baz},${y%bar|baz},${z%\?}>"
2092 z='foo(bar'
2093 echo "<${z%(*}>"
2094expected-stdout:
2095 <foo,foo,fooba>
2096 <foo,foo>
2097 <foobar,foobaz,fooba>
2098 <foo>
2099---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002100name: eglob-substrpl-1
2101description:
2102 Check eglobbing works in substs... and they work at all
2103stdin:
2104 [[ -n $BASH_VERSION ]] && shopt -s extglob
2105 x=1222321_ab/cde_b/c_1221
2106 y=xyz
Elliott Hughes77740fc2016-08-12 15:06:53 -07002107 echo 1: ${x/2} . ${x/}
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002108 echo 2: ${x//2}
2109 echo 3: ${x/+(2)}
2110 echo 4: ${x//+(2)}
2111 echo 5: ${x/2/4}
2112 echo 6: ${x//2/4}
2113 echo 7: ${x/+(2)/4}
2114 echo 8: ${x//+(2)/4}
2115 echo 9: ${x/b/c/e/f}
2116 echo 10: ${x/b\/c/e/f}
2117 echo 11: ${x/b\/c/e\/f}
2118 echo 12: ${x/b\/c/e\\/f}
2119 echo 13: ${x/b\\/c/e\\/f}
2120 echo 14: ${x//b/c/e/f}
2121 echo 15: ${x//b\/c/e/f}
2122 echo 16: ${x//b\/c/e\/f}
2123 echo 17: ${x//b\/c/e\\/f}
2124 echo 18: ${x//b\\/c/e\\/f}
2125 echo 19: ${x/b\/*\/c/x}
2126 echo 20: ${x/\//.}
2127 echo 21: ${x//\//.}
2128 echo 22: ${x///.}
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002129 echo 23: ${x/#1/9}
2130 echo 24: ${x//#1/9}
2131 echo 25: ${x/%1/9}
2132 echo 26: ${x//%1/9}
2133 echo 27: ${x//\%1/9}
2134 echo 28: ${x//\\%1/9}
2135 echo 29: ${x//\a/9}
2136 echo 30: ${x//\\a/9}
2137 echo 31: ${x/2/$y}
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002138expected-stdout:
Elliott Hughes77740fc2016-08-12 15:06:53 -07002139 1: 122321_ab/cde_b/c_1221 . 1222321_ab/cde_b/c_1221
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002140 2: 131_ab/cde_b/c_11
2141 3: 1321_ab/cde_b/c_1221
2142 4: 131_ab/cde_b/c_11
2143 5: 1422321_ab/cde_b/c_1221
2144 6: 1444341_ab/cde_b/c_1441
2145 7: 14321_ab/cde_b/c_1221
2146 8: 14341_ab/cde_b/c_141
2147 9: 1222321_ac/e/f/cde_b/c_1221
2148 10: 1222321_ae/fde_b/c_1221
2149 11: 1222321_ae/fde_b/c_1221
2150 12: 1222321_ae\/fde_b/c_1221
2151 13: 1222321_ab/cde_b/c_1221
2152 14: 1222321_ac/e/f/cde_c/e/f/c_1221
2153 15: 1222321_ae/fde_e/f_1221
2154 16: 1222321_ae/fde_e/f_1221
2155 17: 1222321_ae\/fde_e\/f_1221
2156 18: 1222321_ab/cde_b/c_1221
2157 19: 1222321_ax_1221
2158 20: 1222321_ab.cde_b/c_1221
2159 21: 1222321_ab.cde_b.c_1221
2160 22: 1222321_ab/cde_b/c_1221
2161 23: 9222321_ab/cde_b/c_1221
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002162 24: 1222321_ab/cde_b/c_1221
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002163 25: 1222321_ab/cde_b/c_1229
2164 26: 1222321_ab/cde_b/c_1221
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002165 27: 1222321_ab/cde_b/c_1221
2166 28: 1222321_ab/cde_b/c_1221
2167 29: 1222321_9b/cde_b/c_1221
2168 30: 1222321_ab/cde_b/c_1221
2169 31: 1xyz22321_ab/cde_b/c_1221
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002170---
2171name: eglob-substrpl-2
2172description:
2173 Check anchored substring replacement works, corner cases
2174stdin:
2175 foo=123
2176 echo 1: ${foo/#/x}
2177 echo 2: ${foo/%/x}
2178 echo 3: ${foo/#/}
2179 echo 4: ${foo/#}
2180 echo 5: ${foo/%/}
2181 echo 6: ${foo/%}
2182expected-stdout:
2183 1: x123
2184 2: 123x
2185 3: 123
2186 4: 123
2187 5: 123
2188 6: 123
2189---
2190name: eglob-substrpl-3a
2191description:
2192 Check substring replacement works with variables and slashes, too
2193stdin:
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002194 HOME=/etc
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002195 pfx=/home/user
2196 wd=/home/user/tmp
2197 echo "${wd/#$pfx/~}"
2198 echo "${wd/#\$pfx/~}"
2199 echo "${wd/#"$pfx"/~}"
2200 echo "${wd/#'$pfx'/~}"
2201 echo "${wd/#"\$pfx"/~}"
2202 echo "${wd/#'\$pfx'/~}"
2203expected-stdout:
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002204 /etc/tmp
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002205 /home/user/tmp
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002206 /etc/tmp
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002207 /home/user/tmp
2208 /home/user/tmp
2209 /home/user/tmp
2210---
2211name: eglob-substrpl-3b
2212description:
2213 More of this, bash fails it (bash4 passes)
2214stdin:
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002215 HOME=/etc
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002216 pfx=/home/user
2217 wd=/home/user/tmp
2218 echo "${wd/#$(echo /home/user)/~}"
2219 echo "${wd/#"$(echo /home/user)"/~}"
2220 echo "${wd/#'$(echo /home/user)'/~}"
2221expected-stdout:
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002222 /etc/tmp
2223 /etc/tmp
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002224 /home/user/tmp
2225---
2226name: eglob-substrpl-3c
2227description:
2228 Even more weird cases
2229stdin:
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002230 HOME=/etc
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002231 pfx=/home/user
2232 wd='$pfx/tmp'
2233 echo 1: ${wd/#$pfx/~}
2234 echo 2: ${wd/#\$pfx/~}
2235 echo 3: ${wd/#"$pfx"/~}
2236 echo 4: ${wd/#'$pfx'/~}
2237 echo 5: ${wd/#"\$pfx"/~}
2238 echo 6: ${wd/#'\$pfx'/~}
2239 ts='a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)'
2240 tp=a/b
2241 tr=c/d
2242 [[ -n $BASH_VERSION ]] && shopt -s extglob
2243 echo 7: ${ts/a\/b/$tr}
2244 echo 8: ${ts/a\/b/\$tr}
2245 echo 9: ${ts/$tp/$tr}
2246 echo 10: ${ts/\$tp/$tr}
2247 echo 11: ${ts/\\$tp/$tr}
2248 echo 12: ${ts/$tp/c/d}
2249 echo 13: ${ts/$tp/c\/d}
2250 echo 14: ${ts/$tp/c\\/d}
2251 echo 15: ${ts/+(a\/b)/$tr}
2252 echo 16: ${ts/+(a\/b)/\$tr}
2253 echo 17: ${ts/+($tp)/$tr}
2254 echo 18: ${ts/+($tp)/c/d}
2255 echo 19: ${ts/+($tp)/c\/d}
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002256 echo 20: ${ts//a\/b/$tr}
2257 echo 21: ${ts//a\/b/\$tr}
2258 echo 22: ${ts//$tp/$tr}
2259 echo 23: ${ts//$tp/c/d}
2260 echo 24: ${ts//$tp/c\/d}
2261 echo 25: ${ts//+(a\/b)/$tr}
2262 echo 26: ${ts//+(a\/b)/\$tr}
2263 echo 27: ${ts//+($tp)/$tr}
2264 echo 28: ${ts//+($tp)/c/d}
2265 echo 29: ${ts//+($tp)/c\/d}
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002266 tp="+($tp)"
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002267 echo 30: ${ts/$tp/$tr}
2268 echo 31: ${ts//$tp/$tr}
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002269expected-stdout:
2270 1: $pfx/tmp
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002271 2: /etc/tmp
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002272 3: $pfx/tmp
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002273 4: /etc/tmp
2274 5: /etc/tmp
2275 6: $pfx/tmp
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002276 7: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2277 8: $tra/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2278 9: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2279 10: a/ba/bc/d$tp_a/b$tp_*(a/b)_*($tp)
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002280 11: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002281 12: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2282 13: c/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2283 14: c\/da/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2284 15: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2285 16: $tr$tp$tp_a/b$tp_*(a/b)_*($tp)
2286 17: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2287 18: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2288 19: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002289 20: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2290 21: $tr$tr$tp$tp_$tr$tp_*($tr)_*($tp)
2291 22: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2292 23: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2293 24: c/dc/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2294 25: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2295 26: $tr$tp$tp_$tr$tp_*($tr)_*($tp)
2296 27: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2297 28: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2298 29: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
2299 30: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)
2300 31: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp)
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002301# This is what GNU bash does:
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002302# 30: c/d$tp$tp_a/b$tp_*(a/b)_*($tp)
2303# 31: c/d$tp$tp_c/d$tp_*(c/d)_*($tp)
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002304---
2305name: eglob-utf8-1
2306description:
2307 UTF-8 mode differences for eglobbing
2308stdin:
2309 s=blöd
2310 set +U
2311 print 1: ${s%???} .
2312 print 2: ${s/b???d/x} .
2313 set -U
2314 print 3: ${s%???} .
2315 print 4: ${s/b??d/x} .
2316 x=nö
2317 print 5: ${x%?} ${x%%?} .
2318 x=äh
2319 print 6: ${x#?} ${x##?} .
2320 x=‚
2321 print 7: ${x%?} ${x%%?} .
2322 x=mä€
2323 print 8: ${x%?} ${x%%?} .
2324 x=何
2325 print 9: ${x%?} ${x%%?} .
2326expected-stdout:
2327 1: bl .
2328 2: x .
2329 3: b .
2330 4: x .
2331 5: n n .
2332 6: h h .
2333 7:   .
2334 8: mä mä .
2335 9: .
2336---
2337name: glob-bad-1
2338description:
2339 Check that globbing isn't done when glob has syntax error
2340file-setup: dir 755 "[x"
2341file-setup: file 644 "[x/foo"
2342stdin:
2343 echo [*
2344 echo *[x
2345 echo [x/*
2346expected-stdout:
2347 [*
2348 *[x
2349 [x/foo
2350---
2351name: glob-bad-2
2352description:
2353 Check that symbolic links aren't stat()'d
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00002354# breaks on Dell UNIX 4.0 R2.2 (SVR4) where unlink also fails
Elliott Hughes96b43632015-07-17 11:39:41 -07002355# breaks on FreeMiNT (cannot unlink dangling symlinks)
2356# breaks on MSYS, OS/2 (do not support symlinks)
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00002357category: !os:mint,!os:msys,!os:svr4.0,!nosymlink
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002358file-setup: dir 755 "dir"
2359file-setup: symlink 644 "dir/abc"
2360 non-existent-file
2361stdin:
2362 echo d*/*
2363 echo d*/abc
2364expected-stdout:
2365 dir/abc
2366 dir/abc
2367---
2368name: glob-range-1
2369description:
2370 Test range matching
2371file-setup: file 644 ".bc"
2372file-setup: file 644 "abc"
2373file-setup: file 644 "bbc"
2374file-setup: file 644 "cbc"
2375file-setup: file 644 "-bc"
2376stdin:
2377 echo [ab-]*
2378 echo [-ab]*
2379 echo [!-ab]*
2380 echo [!ab]*
2381 echo []ab]*
Elliott Hughes737fdce2014-08-07 12:59:26 -07002382 :>'./!bc'
2383 :>'./^bc'
2384 echo [^ab]*
2385 echo [!ab]*
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002386expected-stdout:
2387 -bc abc bbc
2388 -bc abc bbc
2389 cbc
2390 -bc cbc
2391 abc bbc
Elliott Hughes737fdce2014-08-07 12:59:26 -07002392 ^bc abc bbc
2393 !bc -bc ^bc cbc
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002394---
2395name: glob-range-2
2396description:
2397 Test range matching
2398 (AT&T ksh fails this; POSIX says invalid)
2399file-setup: file 644 "abc"
2400stdin:
2401 echo [a--]*
2402expected-stdout:
2403 [a--]*
2404---
2405name: glob-range-3
2406description:
2407 Check that globbing matches the right things...
2408# breaks on Mac OSX (HFS+ non-standard Unicode canonical decomposition)
Geremy Condra03ebf062011-10-12 18:17:24 -07002409# breaks on Cygwin 1.7 (files are now UTF-16 or something)
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00002410# breaks on QNX 6.4.1 (says RT)
Elliott Hughes96b43632015-07-17 11:39:41 -07002411category: !os:cygwin,!os:darwin,!os:msys,!os:nto,!os:os2
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00002412need-pass: no
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002413file-setup: file 644 "aÂc"
2414stdin:
2415 echo a[Á-Ú]*
2416expected-stdout:
2417 aÂc
2418---
2419name: glob-range-4
2420description:
2421 Results unspecified according to POSIX
2422file-setup: file 644 ".bc"
2423stdin:
2424 echo [a.]*
2425expected-stdout:
2426 [a.]*
2427---
2428name: glob-range-5
2429description:
2430 Results unspecified according to POSIX
2431 (AT&T ksh treats this like [a-cc-e]*)
2432file-setup: file 644 "abc"
2433file-setup: file 644 "bbc"
2434file-setup: file 644 "cbc"
2435file-setup: file 644 "dbc"
2436file-setup: file 644 "ebc"
2437file-setup: file 644 "-bc"
2438stdin:
2439 echo [a-c-e]*
2440expected-stdout:
2441 -bc abc bbc cbc ebc
2442---
Elliott Hughes737fdce2014-08-07 12:59:26 -07002443name: glob-trim-1
2444description:
2445 Check against a regression from fixing IFS-subst-2
2446stdin:
2447 x='#foo'
2448 print -r "before='$x'"
2449 x=${x%%#*}
2450 print -r "after ='$x'"
2451expected-stdout:
2452 before='#foo'
2453 after =''
2454---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002455name: heredoc-1
2456description:
2457 Check ordering/content of redundent here documents.
2458stdin:
2459 cat << EOF1 << EOF2
2460 hi
2461 EOF1
2462 there
2463 EOF2
2464expected-stdout:
2465 there
2466---
2467name: heredoc-2
2468description:
2469 Check quoted here-doc is protected.
2470stdin:
2471 a=foo
2472 cat << 'EOF'
2473 hi\
2474 there$a
2475 stuff
2476 EO\
2477 F
2478 EOF
2479expected-stdout:
2480 hi\
2481 there$a
2482 stuff
2483 EO\
2484 F
2485---
2486name: heredoc-3
2487description:
2488 Check that newline isn't needed after heredoc-delimiter marker.
2489stdin: !
2490 cat << EOF
2491 hi
2492 there
2493 EOF
2494expected-stdout:
2495 hi
2496 there
2497---
Elliott Hughes77740fc2016-08-12 15:06:53 -07002498name: heredoc-4a
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002499description:
2500 Check that an error occurs if the heredoc-delimiter is missing.
2501stdin: !
2502 cat << EOF
2503 hi
2504 there
2505expected-exit: e > 0
2506expected-stderr-pattern: /.*/
2507---
Elliott Hughes77740fc2016-08-12 15:06:53 -07002508name: heredoc-4an
2509description:
2510 Check that an error occurs if the heredoc-delimiter is missing.
2511arguments: !-n!
2512stdin: !
2513 cat << EOF
2514 hi
2515 there
2516expected-exit: e > 0
2517expected-stderr-pattern: /.*/
2518---
2519name: heredoc-4b
2520description:
2521 Check that an error occurs if the heredoc is missing.
2522stdin: !
2523 cat << EOF
2524expected-exit: e > 0
2525expected-stderr-pattern: /.*/
2526---
2527name: heredoc-4bn
2528description:
2529 Check that an error occurs if the heredoc is missing.
2530arguments: !-n!
2531stdin: !
2532 cat << EOF
2533expected-exit: e > 0
2534expected-stderr-pattern: /.*/
2535---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002536name: heredoc-5
2537description:
2538 Check that backslash quotes a $, ` and \ and kills a \newline
2539stdin:
2540 a=BAD
2541 b=ok
2542 cat << EOF
2543 h\${a}i
2544 h\\${b}i
2545 th\`echo not-run\`ere
2546 th\\`echo is-run`ere
2547 fol\\ks
2548 more\\
2549 last \
2550 line
2551 EOF
2552expected-stdout:
2553 h${a}i
2554 h\oki
2555 th`echo not-run`ere
2556 th\is-runere
2557 fol\ks
2558 more\
2559 last line
2560---
2561name: heredoc-6
2562description:
2563 Check that \newline in initial here-delim word doesn't imply
2564 a quoted here-doc.
2565stdin:
2566 a=i
2567 cat << EO\
2568 F
2569 h$a
2570 there
2571 EOF
2572expected-stdout:
2573 hi
2574 there
2575---
2576name: heredoc-7
2577description:
2578 Check that double quoted $ expressions in here delimiters are
2579 not expanded and match the delimiter.
2580 POSIX says only quote removal is applied to the delimiter.
2581stdin:
2582 a=b
2583 cat << "E$a"
2584 hi
2585 h$a
2586 hb
2587 E$a
2588 echo done
2589expected-stdout:
2590 hi
2591 h$a
2592 hb
2593 done
2594---
2595name: heredoc-8
2596description:
2597 Check that double quoted escaped $ expressions in here
2598 delimiters are not expanded and match the delimiter.
2599 POSIX says only quote removal is applied to the delimiter
2600 (\ counts as a quote).
2601stdin:
2602 a=b
2603 cat << "E\$a"
2604 hi
2605 h$a
2606 h\$a
2607 hb
2608 h\b
2609 E$a
2610 echo done
2611expected-stdout:
2612 hi
2613 h$a
2614 h\$a
2615 hb
2616 h\b
2617 done
2618---
2619name: heredoc-9a
2620description:
2621 Check that here strings work.
2622stdin:
2623 bar="bar
2624 baz"
2625 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<foo
2626 "$__progname" -c "tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<foo"
2627 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"$bar"
2628 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<'$bar'
2629 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<\$bar
2630 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<-foo
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00002631 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"$(echo "foo bar")"
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002632 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"A $(echo "foo bar") B"
2633 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<\$b\$b$bar
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002634expected-stdout:
2635 sbb
2636 sbb
2637 one
2638 onm
2639 $one
2640 $one
2641 -sbb
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00002642 sbb one
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002643 A sbb one B
2644 $o$oone
2645 onm
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07002646---
2647name: heredoc-9b
2648description:
2649 Check that a corner case of here strings works like bash
2650stdin:
2651 fnord=42
2652 bar="bar
2653 \$fnord baz"
2654 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<$bar
2655expected-stdout:
2656 one $sabeq onm
2657category: bash
2658---
2659name: heredoc-9c
2660description:
2661 Check that a corner case of here strings works like ksh93, zsh
2662stdin:
2663 fnord=42
2664 bar="bar
2665 \$fnord baz"
2666 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<$bar
2667expected-stdout:
2668 one
2669 $sabeq onm
2670---
2671name: heredoc-9d
2672description:
2673 Check another corner case of here strings
2674stdin:
2675 tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<< bar
2676expected-stdout:
2677 one
2678---
Geremy Condra03ebf062011-10-12 18:17:24 -07002679name: heredoc-9e
2680description:
2681 Check here string related regression with multiple iops
2682stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00002683 echo $(tr r z <<<'bar' 2>/dev/null)
Geremy Condra03ebf062011-10-12 18:17:24 -07002684expected-stdout:
2685 baz
2686---
Elliott Hughes50012062015-03-10 22:22:24 -07002687name: heredoc-9f
2688description:
2689 Check long here strings
2690stdin:
2691 cat <<< "$( : )aa"
2692expected-stdout:
2693 aa
2694---
Geremy Condra03ebf062011-10-12 18:17:24 -07002695name: heredoc-10
2696description:
2697 Check direct here document assignment
2698stdin:
2699 x=u
2700 va=<<EOF
2701 =a $x \x40=
2702 EOF
2703 vb=<<'EOF'
2704 =b $x \x40=
2705 EOF
2706 function foo {
2707 vc=<<-EOF
2708 =c $x \x40=
2709 EOF
2710 }
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00002711 fnd=$(typeset -f foo)
2712 print -r -- "$fnd"
2713 function foo {
2714 echo blub
2715 }
2716 foo
2717 eval "$fnd"
Geremy Condra03ebf062011-10-12 18:17:24 -07002718 foo
2719 # rather nonsensical, but…
2720 vd=<<<"=d $x \x40="
2721 ve=<<<'=e $x \x40='
2722 vf=<<<$'=f $x \x40='
2723 # now check
2724 print -r -- "| va={$va} vb={$vb} vc={$vc} vd={$vd} ve={$ve} vf={$vf} |"
Elliott Hughes50012062015-03-10 22:22:24 -07002725 # check append
2726 v=<<-EOF
2727 vapp1
2728 EOF
2729 v+=<<-EOF
2730 vapp2
2731 EOF
2732 print -r -- "| ${v//$'\n'/^} |"
Geremy Condra03ebf062011-10-12 18:17:24 -07002733expected-stdout:
2734 function foo {
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002735 vc=<<-EOF
Geremy Condra03ebf062011-10-12 18:17:24 -07002736 =c $x \x40=
2737 EOF
2738
2739 }
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00002740 blub
Geremy Condra03ebf062011-10-12 18:17:24 -07002741 | va={=a u \x40=
2742 } vb={=b $x \x40=
2743 } vc={=c u \x40=
2744 } vd={=d u \x40=
2745 } ve={=e $x \x40=
2746 } vf={=f $x @=
2747 } |
Elliott Hughes50012062015-03-10 22:22:24 -07002748 | vapp1^vapp2^ |
Geremy Condra03ebf062011-10-12 18:17:24 -07002749---
2750name: heredoc-11
2751description:
2752 Check here documents with no or empty delimiter
2753stdin:
2754 x=u
2755 va=<<
2756 =a $x \x40=
2757 <<
2758 vb=<<''
2759 =b $x \x40=
2760
2761 function foo {
2762 vc=<<-
2763 =c $x \x40=
2764 <<
2765 vd=<<-''
2766 =d $x \x40=
2767
2768 }
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00002769 fnd=$(typeset -f foo)
2770 print -r -- "$fnd"
2771 function foo {
2772 echo blub
2773 }
2774 foo
2775 eval "$fnd"
Geremy Condra03ebf062011-10-12 18:17:24 -07002776 foo
2777 print -r -- "| va={$va} vb={$vb} vc={$vc} vd={$vd} |"
Elliott Hughes77740fc2016-08-12 15:06:53 -07002778 x=y
2779 foo
2780 typeset -f foo
2781 print -r -- "| vc={$vc} vd={$vd} |"
Elliott Hughes50012062015-03-10 22:22:24 -07002782 # check append
2783 v=<<-
2784 vapp1
2785 <<
2786 v+=<<-''
2787 vapp2
2788
2789 print -r -- "| ${v//$'\n'/^} |"
Geremy Condra03ebf062011-10-12 18:17:24 -07002790expected-stdout:
2791 function foo {
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002792 vc=<<-
Geremy Condra03ebf062011-10-12 18:17:24 -07002793 =c $x \x40=
2794 <<
2795
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002796 vd=<<-""
Geremy Condra03ebf062011-10-12 18:17:24 -07002797 =d $x \x40=
2798
2799
2800 }
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00002801 blub
Geremy Condra03ebf062011-10-12 18:17:24 -07002802 | va={=a u \x40=
2803 } vb={=b $x \x40=
2804 } vc={=c u \x40=
2805 } vd={=d $x \x40=
2806 } |
Elliott Hughes77740fc2016-08-12 15:06:53 -07002807 function foo {
2808 vc=<<-
2809 =c $x \x40=
2810 <<
2811
2812 vd=<<-""
2813 =d $x \x40=
2814
2815
2816 }
2817 | vc={=c y \x40=
2818 } vd={=d $x \x40=
2819 } |
Elliott Hughes50012062015-03-10 22:22:24 -07002820 | vapp1^vapp2^ |
2821---
2822name: heredoc-12
2823description:
2824 Check here documents can use $* and $@; note shells vary:
2825 • pdksh 5.2.14 acts the same
2826 • dash has 1 and 2 the same but 3 lacks the space
2827 • ksh93, bash4 differ in 2 by using space ipv colon
2828stdin:
2829 set -- a b
2830 nl='
2831 '
2832 IFS=" $nl"; n=1
2833 cat <<EOF
2834 $n foo $* foo
2835 $n bar "$*" bar
2836 $n baz $@ baz
2837 $n bla "$@" bla
2838 EOF
2839 IFS=":"; n=2
2840 cat <<EOF
2841 $n foo $* foo
2842 $n bar "$*" bar
2843 $n baz $@ baz
2844 $n bla "$@" bla
2845 EOF
2846 IFS=; n=3
2847 cat <<EOF
2848 $n foo $* foo
2849 $n bar "$*" bar
2850 $n baz $@ baz
2851 $n bla "$@" bla
2852 EOF
2853expected-stdout:
2854 1 foo a b foo
2855 1 bar "a b" bar
2856 1 baz a b baz
2857 1 bla "a b" bla
2858 2 foo a:b foo
2859 2 bar "a:b" bar
2860 2 baz a:b baz
2861 2 bla "a:b" bla
2862 3 foo a b foo
2863 3 bar "a b" bar
2864 3 baz a b baz
2865 3 bla "a b" bla
Geremy Condra03ebf062011-10-12 18:17:24 -07002866---
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002867name: heredoc-14
2868description:
2869 Check that using multiple here documents works
2870stdin:
2871 foo() {
2872 echo "got $(cat) on stdin"
2873 echo "got $(cat <&4) on fd#4"
2874 echo "got $(cat <&5) on fd#5"
2875 }
2876 bar() {
2877 foo 4<<-a <<-b 5<<-c
2878 four
2879 a
2880 zero
2881 b
2882 five
2883 c
2884 }
2885 x=$(typeset -f bar)
2886 eval "$x"
2887 y=$(typeset -f bar)
2888 [[ $x = "$y" ]]; echo $?
2889 typeset -f bar
2890 bar
2891expected-stdout:
2892 0
2893 bar() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -07002894 \foo 4<<-a <<-b 5<<-c
Elliott Hughesfc0307d2016-02-02 15:26:47 -08002895 four
2896 a
2897 zero
2898 b
2899 five
2900 c
2901
2902 }
2903 got zero on stdin
2904 got four on fd#4
2905 got five on fd#5
2906---
Geremy Condra03ebf062011-10-12 18:17:24 -07002907name: heredoc-comsub-1
2908description:
2909 Tests for here documents in COMSUB, taken from Austin ML
2910stdin:
2911 text=$(cat <<EOF
2912 here is the text
2913 EOF)
2914 echo = $text =
2915expected-stdout:
2916 = here is the text =
2917---
2918name: heredoc-comsub-2
2919description:
2920 Tests for here documents in COMSUB, taken from Austin ML
2921stdin:
2922 unbalanced=$(cat <<EOF
2923 this paren ) is a problem
2924 EOF)
2925 echo = $unbalanced =
2926expected-stdout:
2927 = this paren ) is a problem =
2928---
2929name: heredoc-comsub-3
2930description:
2931 Tests for here documents in COMSUB, taken from Austin ML
2932stdin:
2933 balanced=$(cat <<EOF
2934 these parens ( ) are not a problem
2935 EOF)
2936 echo = $balanced =
2937expected-stdout:
2938 = these parens ( ) are not a problem =
2939---
2940name: heredoc-comsub-4
2941description:
2942 Tests for here documents in COMSUB, taken from Austin ML
2943stdin:
2944 balanced=$(cat <<EOF
2945 these parens \( ) are a problem
2946 EOF)
2947 echo = $balanced =
2948expected-stdout:
2949 = these parens \( ) are a problem =
2950---
Elliott Hughes77740fc2016-08-12 15:06:53 -07002951name: heredoc-comsub-5
2952description:
2953 Check heredoc and COMSUB mixture in input
2954stdin:
2955 prefix() { sed -e "s/^/$1:/"; }
2956 XXX() { echo x-en; }
2957 YYY() { echo y-es; }
2958
2959 prefix A <<XXX && echo "$(prefix B <<XXX
2960 echo line 1
2961 XXX
2962 echo line 2)" && prefix C <<YYY
2963 echo line 3
2964 XXX
2965 echo line 4)"
2966 echo line 5
2967 YYY
2968 XXX
2969expected-stdout:
2970 A:echo line 3
2971 B:echo line 1
2972 line 2
2973 C:echo line 4)"
2974 C:echo line 5
2975 x-en
2976---
2977name: heredoc-comsub-6
2978description:
2979 Check here documents and here strings can be used
2980 without a specific command, like $(<…) (extension)
2981stdin:
2982 foo=bar
2983 x=$(<<<EO${foo}F)
2984 echo "3<$x>"
2985 y=$(<<-EOF
2986 hi!
2987
2988 $foo) is not a problem
2989
2990
2991 EOF)
2992 echo "7<$y>"
2993expected-stdout:
2994 3<EObarF>
2995 7<hi!
2996
2997 bar) is not a problem>
2998---
Geremy Condra03ebf062011-10-12 18:17:24 -07002999name: heredoc-subshell-1
3000description:
3001 Tests for here documents in subshells, taken from Austin ML
3002stdin:
3003 (cat <<EOF
3004 some text
3005 EOF)
3006 echo end
3007expected-stdout:
3008 some text
3009 end
3010---
3011name: heredoc-subshell-2
3012description:
3013 Tests for here documents in subshells, taken from Austin ML
3014stdin:
3015 (cat <<EOF
3016 some text
3017 EOF
3018 )
3019 echo end
3020expected-stdout:
3021 some text
3022 end
3023---
3024name: heredoc-subshell-3
3025description:
3026 Tests for here documents in subshells, taken from Austin ML
3027stdin:
3028 (cat <<EOF; )
3029 some text
3030 EOF
3031 echo end
3032expected-stdout:
3033 some text
3034 end
3035---
3036name: heredoc-weird-1
3037description:
3038 Tests for here documents, taken from Austin ML
3039 Documents current state in mksh, *NOT* necessarily correct!
3040stdin:
3041 cat <<END
3042 hello
3043 END\
3044 END
3045 END
3046 echo end
3047expected-stdout:
3048 hello
3049 ENDEND
3050 end
3051---
3052name: heredoc-weird-2
3053description:
3054 Tests for here documents, taken from Austin ML
3055stdin:
3056 cat <<' END '
3057 hello
3058 END
3059 echo end
3060expected-stdout:
3061 hello
3062 end
3063---
3064name: heredoc-weird-4
3065description:
3066 Tests for here documents, taken from Austin ML
3067 Documents current state in mksh, *NOT* necessarily correct!
3068stdin:
3069 cat <<END
3070 hello\
3071 END
3072 END
3073 echo end
3074expected-stdout:
3075 helloEND
3076 end
3077---
3078name: heredoc-weird-5
3079description:
3080 Tests for here documents, taken from Austin ML
3081 Documents current state in mksh, *NOT* necessarily correct!
3082stdin:
3083 cat <<END
3084 hello
3085 \END
3086 END
3087 echo end
3088expected-stdout:
3089 hello
3090 \END
3091 end
3092---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003093name: heredoc-tmpfile-1
3094description:
3095 Check that heredoc temp files aren't removed too soon or too late.
3096 Heredoc in simple command.
3097stdin:
3098 TMPDIR=$PWD
3099 eval '
3100 cat <<- EOF
3101 hi
3102 EOF
3103 for i in a b ; do
3104 cat <<- EOF
3105 more
3106 EOF
3107 done
3108 ' &
3109 sleep 1
3110 echo Left overs: *
3111expected-stdout:
3112 hi
3113 more
3114 more
3115 Left overs: *
3116---
3117name: heredoc-tmpfile-2
3118description:
3119 Check that heredoc temp files aren't removed too soon or too late.
3120 Heredoc in function, multiple calls to function.
3121stdin:
3122 TMPDIR=$PWD
3123 eval '
3124 foo() {
3125 cat <<- EOF
3126 hi
3127 EOF
3128 }
3129 foo
3130 foo
3131 ' &
3132 sleep 1
3133 echo Left overs: *
3134expected-stdout:
3135 hi
3136 hi
3137 Left overs: *
3138---
3139name: heredoc-tmpfile-3
3140description:
3141 Check that heredoc temp files aren't removed too soon or too late.
3142 Heredoc in function in loop, multiple calls to function.
3143stdin:
3144 TMPDIR=$PWD
3145 eval '
3146 foo() {
3147 cat <<- EOF
3148 hi
3149 EOF
3150 }
3151 for i in a b; do
3152 foo
3153 foo() {
3154 cat <<- EOF
3155 folks $i
3156 EOF
3157 }
3158 done
3159 foo
3160 ' &
3161 sleep 1
3162 echo Left overs: *
3163expected-stdout:
3164 hi
3165 folks b
3166 folks b
3167 Left overs: *
3168---
3169name: heredoc-tmpfile-4
3170description:
3171 Check that heredoc temp files aren't removed too soon or too late.
3172 Backgrounded simple command with here doc
3173stdin:
3174 TMPDIR=$PWD
3175 eval '
3176 cat <<- EOF &
3177 hi
3178 EOF
3179 ' &
3180 sleep 1
3181 echo Left overs: *
3182expected-stdout:
3183 hi
3184 Left overs: *
3185---
3186name: heredoc-tmpfile-5
3187description:
3188 Check that heredoc temp files aren't removed too soon or too late.
3189 Backgrounded subshell command with here doc
3190stdin:
3191 TMPDIR=$PWD
3192 eval '
3193 (
3194 sleep 1 # so parent exits
3195 echo A
3196 cat <<- EOF
3197 hi
3198 EOF
3199 echo B
3200 ) &
3201 ' &
3202 sleep 2
3203 echo Left overs: *
3204expected-stdout:
3205 A
3206 hi
3207 B
3208 Left overs: *
3209---
3210name: heredoc-tmpfile-6
3211description:
3212 Check that heredoc temp files aren't removed too soon or too late.
3213 Heredoc in pipeline.
3214stdin:
3215 TMPDIR=$PWD
3216 eval '
3217 cat <<- EOF | sed "s/hi/HI/"
3218 hi
3219 EOF
3220 ' &
3221 sleep 1
3222 echo Left overs: *
3223expected-stdout:
3224 HI
3225 Left overs: *
3226---
3227name: heredoc-tmpfile-7
3228description:
3229 Check that heredoc temp files aren't removed too soon or too late.
3230 Heredoc in backgrounded pipeline.
3231stdin:
3232 TMPDIR=$PWD
3233 eval '
3234 cat <<- EOF | sed 's/hi/HI/' &
3235 hi
3236 EOF
3237 ' &
3238 sleep 1
3239 echo Left overs: *
3240expected-stdout:
3241 HI
3242 Left overs: *
3243---
3244name: heredoc-tmpfile-8
3245description:
3246 Check that heredoc temp files aren't removed too soon or too
3247 late. Heredoc in function, backgrounded call to function.
3248 This check can fail on slow machines (<100 MHz), or Cygwin,
3249 that's normal.
Geremy Condra03ebf062011-10-12 18:17:24 -07003250need-pass: no
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003251stdin:
3252 TMPDIR=$PWD
3253 # Background eval so main shell doesn't do parsing
3254 eval '
3255 foo() {
3256 cat <<- EOF
3257 hi
3258 EOF
3259 }
3260 foo
3261 # sleep so eval can die
3262 (sleep 1; foo) &
3263 (sleep 1; foo) &
3264 foo
3265 ' &
3266 sleep 2
3267 echo Left overs: *
3268expected-stdout:
3269 hi
3270 hi
3271 hi
3272 hi
3273 Left overs: *
3274---
Thorsten Glaser811a5752013-07-25 14:24:45 +00003275name: heredoc-quoting-unsubst
3276description:
3277 Check for correct handling of quoted characters in
3278 here documents without substitution (marker is quoted).
3279stdin:
3280 foo=bar
3281 cat <<-'EOF'
3282 x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
3283 EOF
3284expected-stdout:
3285 x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
3286---
3287name: heredoc-quoting-subst
3288description:
3289 Check for correct handling of quoted characters in
3290 here documents with substitution (marker is not quoted).
3291stdin:
3292 foo=bar
3293 cat <<-EOF
3294 x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x
3295 EOF
3296expected-stdout:
3297 x " \" \ \ $ $ baz `echo baz` bar $foo x
3298---
3299name: single-quotes-in-braces
3300description:
3301 Check that single quotes inside unquoted {} are treated as quotes
3302stdin:
3303 foo=1
3304 echo ${foo:+'blah $foo'}
3305expected-stdout:
3306 blah $foo
3307---
3308name: single-quotes-in-quoted-braces
3309description:
3310 Check that single quotes inside quoted {} are treated as
3311 normal char
3312stdin:
3313 foo=1
3314 echo "${foo:+'blah $foo'}"
3315expected-stdout:
3316 'blah 1'
3317---
3318name: single-quotes-in-braces-nested
3319description:
3320 Check that single quotes inside unquoted {} are treated as quotes,
3321 even if that's inside a double-quoted command expansion
3322stdin:
3323 foo=1
3324 echo "$( echo ${foo:+'blah $foo'})"
3325expected-stdout:
3326 blah $foo
3327---
3328name: single-quotes-in-brace-pattern
3329description:
3330 Check that single quotes inside {} pattern are treated as quotes
3331stdin:
3332 foo=1234
3333 echo ${foo%'2'*} "${foo%'2'*}" ${foo%2'*'} "${foo%2'*'}"
3334expected-stdout:
3335 1 1 1234 1234
3336---
3337name: single-quotes-in-heredoc-braces
3338description:
3339 Check that single quotes inside {} in heredoc are treated
3340 as normal char
3341stdin:
3342 foo=1
3343 cat <<EOM
3344 ${foo:+'blah $foo'}
3345 EOM
3346expected-stdout:
3347 'blah 1'
3348---
3349name: single-quotes-in-nested-braces
3350description:
3351 Check that single quotes inside nested unquoted {} are
3352 treated as quotes
3353stdin:
3354 foo=1
3355 echo ${foo:+${foo:+'blah $foo'}}
3356expected-stdout:
3357 blah $foo
3358---
3359name: single-quotes-in-nested-quoted-braces
3360description:
3361 Check that single quotes inside nested quoted {} are treated
3362 as normal char
3363stdin:
3364 foo=1
3365 echo "${foo:+${foo:+'blah $foo'}}"
3366expected-stdout:
3367 'blah 1'
3368---
3369name: single-quotes-in-nested-braces-nested
3370description:
3371 Check that single quotes inside nested unquoted {} are treated
3372 as quotes, even if that's inside a double-quoted command expansion
3373stdin:
3374 foo=1
3375 echo "$( echo ${foo:+${foo:+'blah $foo'}})"
3376expected-stdout:
3377 blah $foo
3378---
3379name: single-quotes-in-nested-brace-pattern
3380description:
3381 Check that single quotes inside nested {} pattern are treated as quotes
3382stdin:
3383 foo=1234
3384 echo ${foo:+${foo%'2'*}} "${foo:+${foo%'2'*}}" ${foo:+${foo%2'*'}} "${foo:+${foo%2'*'}}"
3385expected-stdout:
3386 1 1 1234 1234
3387---
3388name: single-quotes-in-heredoc-nested-braces
3389description:
3390 Check that single quotes inside nested {} in heredoc are treated
3391 as normal char
3392stdin:
3393 foo=1
3394 cat <<EOM
3395 ${foo:+${foo:+'blah $foo'}}
3396 EOM
3397expected-stdout:
3398 'blah 1'
3399---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003400name: history-basic
3401description:
3402 See if we can test history at all
Geremy Condra03ebf062011-10-12 18:17:24 -07003403need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003404arguments: !-i!
3405env-setup: !ENV=./Env!HISTFILE=hist.file!
3406file-setup: file 644 "Env"
3407 PS1=X
3408stdin:
3409 echo hi
3410 fc -l
3411expected-stdout:
3412 hi
3413 1 echo hi
3414expected-stderr-pattern:
3415 /^X*$/
3416---
3417name: history-dups
3418description:
3419 Verify duplicates and spaces are not entered
Geremy Condra03ebf062011-10-12 18:17:24 -07003420need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003421arguments: !-i!
3422env-setup: !ENV=./Env!HISTFILE=hist.file!
3423file-setup: file 644 "Env"
3424 PS1=X
3425stdin:
3426 echo hi
3427 echo yo
3428 echo hi
3429 fc -l
3430expected-stdout:
3431 hi
3432 yo
3433 hi
3434 1 echo hi
3435expected-stderr-pattern:
3436 /^X*$/
3437---
3438name: history-unlink
3439description:
3440 Check if broken HISTFILEs do not cause trouble
Geremy Condra03ebf062011-10-12 18:17:24 -07003441need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003442arguments: !-i!
3443env-setup: !ENV=./Env!HISTFILE=foo/hist.file!
3444file-setup: file 644 "Env"
3445 PS1=X
3446file-setup: dir 755 "foo"
3447file-setup: file 644 "foo/hist.file"
3448 sometext
3449time-limit: 5
3450perl-setup: chmod(0555, "foo");
3451stdin:
3452 echo hi
3453 fc -l
3454 chmod 0755 foo
3455expected-stdout:
3456 hi
3457 1 echo hi
3458expected-stderr-pattern:
Geremy Condra03ebf062011-10-12 18:17:24 -07003459 /(.*can't unlink HISTFILE.*\n)?X*$/
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003460---
Elliott Hughes77740fc2016-08-12 15:06:53 -07003461name: history-multiline
3462description:
3463 Check correct multiline history, Debian #783978
3464need-ctty: yes
3465arguments: !-i!
3466env-setup: !ENV=./Env!
3467file-setup: file 644 "Env"
3468 PS1=X
3469 PS2=Y
3470stdin:
3471 for i in A B C
3472 do
3473 print $i
3474 print $i
3475 done
3476 fc -l
3477expected-stdout:
3478 A
3479 A
3480 B
3481 B
3482 C
3483 C
3484 1 for i in A B C
3485 do
3486 print $i
3487 print $i
3488 done
3489expected-stderr-pattern:
3490 /^XYYYYXX$/
3491---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003492name: history-e-minus-1
3493description:
3494 Check if more recent command is executed
Geremy Condra03ebf062011-10-12 18:17:24 -07003495need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003496arguments: !-i!
3497env-setup: !ENV=./Env!HISTFILE=hist.file!
3498file-setup: file 644 "Env"
3499 PS1=X
3500stdin:
3501 echo hi
3502 echo there
3503 fc -e -
3504expected-stdout:
3505 hi
3506 there
3507 there
3508expected-stderr-pattern:
3509 /^X*echo there\nX*$/
3510---
3511name: history-e-minus-2
3512description:
3513 Check that repeated command is printed before command
3514 is re-executed.
Geremy Condra03ebf062011-10-12 18:17:24 -07003515need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003516arguments: !-i!
3517env-setup: !ENV=./Env!HISTFILE=hist.file!
3518file-setup: file 644 "Env"
3519 PS1=X
3520stdin:
3521 exec 2>&1
3522 echo hi
3523 echo there
3524 fc -e -
3525expected-stdout-pattern:
3526 /X*hi\nX*there\nX*echo there\nthere\nX*/
3527expected-stderr-pattern:
3528 /^X*$/
3529---
3530name: history-e-minus-3
3531description:
3532 fc -e - fails when there is no history
3533 (ksh93 has a bug that causes this to fail)
3534 (ksh88 loops on this)
Geremy Condra03ebf062011-10-12 18:17:24 -07003535need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003536arguments: !-i!
3537env-setup: !ENV=./Env!HISTFILE=hist.file!
3538file-setup: file 644 "Env"
3539 PS1=X
3540stdin:
3541 fc -e -
3542 echo ok
3543expected-stdout:
3544 ok
3545expected-stderr-pattern:
3546 /^X*.*:.*history.*\nX*$/
3547---
3548name: history-e-minus-4
3549description:
3550 Check if "fc -e -" command output goes to stdout.
Geremy Condra03ebf062011-10-12 18:17:24 -07003551need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003552arguments: !-i!
3553env-setup: !ENV=./Env!HISTFILE=hist.file!
3554file-setup: file 644 "Env"
3555 PS1=X
3556stdin:
3557 echo abc
3558 fc -e - | (read x; echo "A $x")
3559 echo ok
3560expected-stdout:
3561 abc
3562 A abc
3563 ok
3564expected-stderr-pattern:
3565 /^X*echo abc\nX*/
3566---
3567name: history-e-minus-5
3568description:
3569 fc is replaced in history by new command.
Geremy Condra03ebf062011-10-12 18:17:24 -07003570need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003571arguments: !-i!
3572env-setup: !ENV=./Env!HISTFILE=hist.file!
3573file-setup: file 644 "Env"
3574 PS1=X
3575stdin:
3576 echo abc def
3577 echo ghi jkl
3578 :
3579 fc -e - echo
3580 fc -l 2 5
3581expected-stdout:
3582 abc def
3583 ghi jkl
3584 ghi jkl
3585 2 echo ghi jkl
3586 3 :
3587 4 echo ghi jkl
3588 5 fc -l 2 5
3589expected-stderr-pattern:
3590 /^X*echo ghi jkl\nX*$/
3591---
3592name: history-list-1
3593description:
3594 List lists correct range
3595 (ksh88 fails 'cause it lists the fc command)
Geremy Condra03ebf062011-10-12 18:17:24 -07003596need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003597arguments: !-i!
3598env-setup: !ENV=./Env!HISTFILE=hist.file!
3599file-setup: file 644 "Env"
3600 PS1=X
3601stdin:
3602 echo line 1
3603 echo line 2
3604 echo line 3
3605 fc -l -- -2
3606expected-stdout:
3607 line 1
3608 line 2
3609 line 3
3610 2 echo line 2
3611 3 echo line 3
3612expected-stderr-pattern:
3613 /^X*$/
3614---
3615name: history-list-2
3616description:
3617 Lists oldest history if given pre-historic number
3618 (ksh93 has a bug that causes this to fail)
3619 (ksh88 fails 'cause it lists the fc command)
Geremy Condra03ebf062011-10-12 18:17:24 -07003620need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003621arguments: !-i!
3622env-setup: !ENV=./Env!HISTFILE=hist.file!
3623file-setup: file 644 "Env"
3624 PS1=X
3625stdin:
3626 echo line 1
3627 echo line 2
3628 echo line 3
3629 fc -l -- -40
3630expected-stdout:
3631 line 1
3632 line 2
3633 line 3
3634 1 echo line 1
3635 2 echo line 2
3636 3 echo line 3
3637expected-stderr-pattern:
3638 /^X*$/
3639---
3640name: history-list-3
3641description:
3642 Can give number 'options' to fc
Geremy Condra03ebf062011-10-12 18:17:24 -07003643need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003644arguments: !-i!
3645env-setup: !ENV=./Env!HISTFILE=hist.file!
3646file-setup: file 644 "Env"
3647 PS1=X
3648stdin:
3649 echo line 1
3650 echo line 2
3651 echo line 3
3652 echo line 4
3653 fc -l -3 -2
3654expected-stdout:
3655 line 1
3656 line 2
3657 line 3
3658 line 4
3659 2 echo line 2
3660 3 echo line 3
3661expected-stderr-pattern:
3662 /^X*$/
3663---
3664name: history-list-4
3665description:
3666 -1 refers to previous command
Geremy Condra03ebf062011-10-12 18:17:24 -07003667need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003668arguments: !-i!
3669env-setup: !ENV=./Env!HISTFILE=hist.file!
3670file-setup: file 644 "Env"
3671 PS1=X
3672stdin:
3673 echo line 1
3674 echo line 2
3675 echo line 3
3676 echo line 4
3677 fc -l -1 -1
3678expected-stdout:
3679 line 1
3680 line 2
3681 line 3
3682 line 4
3683 4 echo line 4
3684expected-stderr-pattern:
3685 /^X*$/
3686---
3687name: history-list-5
3688description:
3689 List command stays in history
Geremy Condra03ebf062011-10-12 18:17:24 -07003690need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003691arguments: !-i!
3692env-setup: !ENV=./Env!HISTFILE=hist.file!
3693file-setup: file 644 "Env"
3694 PS1=X
3695stdin:
3696 echo line 1
3697 echo line 2
3698 echo line 3
3699 echo line 4
3700 fc -l -1 -1
3701 fc -l -2 -1
3702expected-stdout:
3703 line 1
3704 line 2
3705 line 3
3706 line 4
3707 4 echo line 4
3708 4 echo line 4
3709 5 fc -l -1 -1
3710expected-stderr-pattern:
3711 /^X*$/
3712---
3713name: history-list-6
3714description:
3715 HISTSIZE limits about of history kept.
3716 (ksh88 fails 'cause it lists the fc command)
Geremy Condra03ebf062011-10-12 18:17:24 -07003717need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003718arguments: !-i!
3719env-setup: !ENV=./Env!HISTFILE=hist.file!HISTSIZE=3!
3720file-setup: file 644 "Env"
3721 PS1=X
3722stdin:
3723 echo line 1
3724 echo line 2
3725 echo line 3
3726 echo line 4
3727 echo line 5
3728 fc -l
3729expected-stdout:
3730 line 1
3731 line 2
3732 line 3
3733 line 4
3734 line 5
3735 4 echo line 4
3736 5 echo line 5
3737expected-stderr-pattern:
3738 /^X*$/
3739---
3740name: history-list-7
3741description:
3742 fc allows too old/new errors in range specification
Geremy Condra03ebf062011-10-12 18:17:24 -07003743need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003744arguments: !-i!
3745env-setup: !ENV=./Env!HISTFILE=hist.file!HISTSIZE=3!
3746file-setup: file 644 "Env"
3747 PS1=X
3748stdin:
3749 echo line 1
3750 echo line 2
3751 echo line 3
3752 echo line 4
3753 echo line 5
3754 fc -l 1 30
3755expected-stdout:
3756 line 1
3757 line 2
3758 line 3
3759 line 4
3760 line 5
3761 4 echo line 4
3762 5 echo line 5
3763 6 fc -l 1 30
3764expected-stderr-pattern:
3765 /^X*$/
3766---
3767name: history-list-r-1
3768description:
3769 test -r flag in history
Geremy Condra03ebf062011-10-12 18:17:24 -07003770need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003771arguments: !-i!
3772env-setup: !ENV=./Env!HISTFILE=hist.file!
3773file-setup: file 644 "Env"
3774 PS1=X
3775stdin:
3776 echo line 1
3777 echo line 2
3778 echo line 3
3779 echo line 4
3780 echo line 5
3781 fc -l -r 2 4
3782expected-stdout:
3783 line 1
3784 line 2
3785 line 3
3786 line 4
3787 line 5
3788 4 echo line 4
3789 3 echo line 3
3790 2 echo line 2
3791expected-stderr-pattern:
3792 /^X*$/
3793---
3794name: history-list-r-2
3795description:
3796 If first is newer than last, -r is implied.
Geremy Condra03ebf062011-10-12 18:17:24 -07003797need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003798arguments: !-i!
3799env-setup: !ENV=./Env!HISTFILE=hist.file!
3800file-setup: file 644 "Env"
3801 PS1=X
3802stdin:
3803 echo line 1
3804 echo line 2
3805 echo line 3
3806 echo line 4
3807 echo line 5
3808 fc -l 4 2
3809expected-stdout:
3810 line 1
3811 line 2
3812 line 3
3813 line 4
3814 line 5
3815 4 echo line 4
3816 3 echo line 3
3817 2 echo line 2
3818expected-stderr-pattern:
3819 /^X*$/
3820---
3821name: history-list-r-3
3822description:
3823 If first is newer than last, -r is cancelled.
Geremy Condra03ebf062011-10-12 18:17:24 -07003824need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003825arguments: !-i!
3826env-setup: !ENV=./Env!HISTFILE=hist.file!
3827file-setup: file 644 "Env"
3828 PS1=X
3829stdin:
3830 echo line 1
3831 echo line 2
3832 echo line 3
3833 echo line 4
3834 echo line 5
3835 fc -l -r 4 2
3836expected-stdout:
3837 line 1
3838 line 2
3839 line 3
3840 line 4
3841 line 5
3842 2 echo line 2
3843 3 echo line 3
3844 4 echo line 4
3845expected-stderr-pattern:
3846 /^X*$/
3847---
3848name: history-subst-1
3849description:
3850 Basic substitution
Geremy Condra03ebf062011-10-12 18:17:24 -07003851need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003852arguments: !-i!
3853env-setup: !ENV=./Env!HISTFILE=hist.file!
3854file-setup: file 644 "Env"
3855 PS1=X
3856stdin:
3857 echo abc def
3858 echo ghi jkl
3859 fc -e - abc=AB 'echo a'
3860expected-stdout:
3861 abc def
3862 ghi jkl
3863 AB def
3864expected-stderr-pattern:
3865 /^X*echo AB def\nX*$/
3866---
3867name: history-subst-2
3868description:
3869 Does subst find previous command?
Geremy Condra03ebf062011-10-12 18:17:24 -07003870need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003871arguments: !-i!
3872env-setup: !ENV=./Env!HISTFILE=hist.file!
3873file-setup: file 644 "Env"
3874 PS1=X
3875stdin:
3876 echo abc def
3877 echo ghi jkl
3878 fc -e - jkl=XYZQRT 'echo g'
3879expected-stdout:
3880 abc def
3881 ghi jkl
3882 ghi XYZQRT
3883expected-stderr-pattern:
3884 /^X*echo ghi XYZQRT\nX*$/
3885---
3886name: history-subst-3
3887description:
3888 Does subst find previous command when no arguments given
Geremy Condra03ebf062011-10-12 18:17:24 -07003889need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003890arguments: !-i!
3891env-setup: !ENV=./Env!HISTFILE=hist.file!
3892file-setup: file 644 "Env"
3893 PS1=X
3894stdin:
3895 echo abc def
3896 echo ghi jkl
3897 fc -e - jkl=XYZQRT
3898expected-stdout:
3899 abc def
3900 ghi jkl
3901 ghi XYZQRT
3902expected-stderr-pattern:
3903 /^X*echo ghi XYZQRT\nX*$/
3904---
3905name: history-subst-4
3906description:
3907 Global substitutions work
3908 (ksh88 and ksh93 do not have -g option)
Geremy Condra03ebf062011-10-12 18:17:24 -07003909need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003910arguments: !-i!
3911env-setup: !ENV=./Env!HISTFILE=hist.file!
3912file-setup: file 644 "Env"
3913 PS1=X
3914stdin:
3915 echo abc def asjj sadjhasdjh asdjhasd
3916 fc -e - -g a=FooBAR
3917expected-stdout:
3918 abc def asjj sadjhasdjh asdjhasd
3919 FooBARbc def FooBARsjj sFooBARdjhFooBARsdjh FooBARsdjhFooBARsd
3920expected-stderr-pattern:
3921 /^X*echo FooBARbc def FooBARsjj sFooBARdjhFooBARsdjh FooBARsdjhFooBARsd\nX*$/
3922---
3923name: history-subst-5
3924description:
3925 Make sure searches don't find current (fc) command
3926 (ksh88/ksh93 don't have the ? prefix thing so they fail this test)
Geremy Condra03ebf062011-10-12 18:17:24 -07003927need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003928arguments: !-i!
3929env-setup: !ENV=./Env!HISTFILE=hist.file!
3930file-setup: file 644 "Env"
3931 PS1=X
3932stdin:
3933 echo abc def
3934 echo ghi jkl
3935 fc -e - abc=AB \?abc
3936expected-stdout:
3937 abc def
3938 ghi jkl
3939 AB def
3940expected-stderr-pattern:
3941 /^X*echo AB def\nX*$/
3942---
3943name: history-ed-1-old
3944description:
3945 Basic (ed) editing works (assumes you have generic ed editor
3946 that prints no prompts). This is for oldish ed(1) which write
3947 the character count to stdout.
3948category: stdout-ed
Geremy Condra03ebf062011-10-12 18:17:24 -07003949need-ctty: yes
3950need-pass: no
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003951arguments: !-i!
3952env-setup: !ENV=./Env!HISTFILE=hist.file!
3953file-setup: file 644 "Env"
3954 PS1=X
3955stdin:
3956 echo abc def
3957 fc echo
3958 s/abc/FOOBAR/
3959 w
3960 q
3961expected-stdout:
3962 abc def
3963 13
3964 16
3965 FOOBAR def
3966expected-stderr-pattern:
3967 /^X*echo FOOBAR def\nX*$/
3968---
3969name: history-ed-2-old
3970description:
3971 Correct command is edited when number given
3972category: stdout-ed
Geremy Condra03ebf062011-10-12 18:17:24 -07003973need-ctty: yes
3974need-pass: no
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07003975arguments: !-i!
3976env-setup: !ENV=./Env!HISTFILE=hist.file!
3977file-setup: file 644 "Env"
3978 PS1=X
3979stdin:
3980 echo line 1
3981 echo line 2 is here
3982 echo line 3
3983 echo line 4
3984 fc 2
3985 s/is here/is changed/
3986 w
3987 q
3988expected-stdout:
3989 line 1
3990 line 2 is here
3991 line 3
3992 line 4
3993 20
3994 23
3995 line 2 is changed
3996expected-stderr-pattern:
3997 /^X*echo line 2 is changed\nX*$/
3998---
3999name: history-ed-3-old
4000description:
4001 Newly created multi line commands show up as single command
4002 in history.
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004003 (ksh88 fails 'cause it lists the fc command)
4004category: stdout-ed
Geremy Condra03ebf062011-10-12 18:17:24 -07004005need-ctty: yes
4006need-pass: no
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004007arguments: !-i!
4008env-setup: !ENV=./Env!HISTFILE=hist.file!
4009file-setup: file 644 "Env"
4010 PS1=X
4011stdin:
4012 echo abc def
4013 fc echo
4014 s/abc/FOOBAR/
4015 $a
4016 echo a new line
4017 .
4018 w
4019 q
4020 fc -l
4021expected-stdout:
4022 abc def
4023 13
4024 32
4025 FOOBAR def
4026 a new line
4027 1 echo abc def
4028 2 echo FOOBAR def
Elliott Hughes96b43632015-07-17 11:39:41 -07004029 echo a new line
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004030expected-stderr-pattern:
4031 /^X*echo FOOBAR def\necho a new line\nX*$/
4032---
4033name: history-ed-1
4034description:
4035 Basic (ed) editing works (assumes you have generic ed editor
4036 that prints no prompts). This is for newish ed(1) and stderr.
4037category: !no-stderr-ed
Geremy Condra03ebf062011-10-12 18:17:24 -07004038need-ctty: yes
4039need-pass: no
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004040arguments: !-i!
4041env-setup: !ENV=./Env!HISTFILE=hist.file!
4042file-setup: file 644 "Env"
4043 PS1=X
4044stdin:
4045 echo abc def
4046 fc echo
4047 s/abc/FOOBAR/
4048 w
4049 q
4050expected-stdout:
4051 abc def
4052 FOOBAR def
4053expected-stderr-pattern:
4054 /^X*13\n16\necho FOOBAR def\nX*$/
4055---
4056name: history-ed-2
4057description:
4058 Correct command is edited when number given
4059category: !no-stderr-ed
Geremy Condra03ebf062011-10-12 18:17:24 -07004060need-ctty: yes
4061need-pass: no
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004062arguments: !-i!
4063env-setup: !ENV=./Env!HISTFILE=hist.file!
4064file-setup: file 644 "Env"
4065 PS1=X
4066stdin:
4067 echo line 1
4068 echo line 2 is here
4069 echo line 3
4070 echo line 4
4071 fc 2
4072 s/is here/is changed/
4073 w
4074 q
4075expected-stdout:
4076 line 1
4077 line 2 is here
4078 line 3
4079 line 4
4080 line 2 is changed
4081expected-stderr-pattern:
4082 /^X*20\n23\necho line 2 is changed\nX*$/
4083---
4084name: history-ed-3
4085description:
4086 Newly created multi line commands show up as single command
4087 in history.
4088category: !no-stderr-ed
Geremy Condra03ebf062011-10-12 18:17:24 -07004089need-ctty: yes
4090need-pass: no
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004091arguments: !-i!
4092env-setup: !ENV=./Env!HISTFILE=hist.file!
4093file-setup: file 644 "Env"
4094 PS1=X
4095stdin:
4096 echo abc def
4097 fc echo
4098 s/abc/FOOBAR/
4099 $a
4100 echo a new line
4101 .
4102 w
4103 q
4104 fc -l
4105expected-stdout:
4106 abc def
4107 FOOBAR def
4108 a new line
4109 1 echo abc def
4110 2 echo FOOBAR def
Elliott Hughes96b43632015-07-17 11:39:41 -07004111 echo a new line
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004112expected-stderr-pattern:
4113 /^X*13\n32\necho FOOBAR def\necho a new line\nX*$/
4114---
4115name: IFS-space-1
4116description:
4117 Simple test, default IFS
4118stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004119 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004120 set -- A B C
4121 showargs 1 $*
4122 showargs 2 "$*"
4123 showargs 3 $@
4124 showargs 4 "$@"
4125expected-stdout:
Elliott Hughes50012062015-03-10 22:22:24 -07004126 <1> <A> <B> <C> .
4127 <2> <A B C> .
4128 <3> <A> <B> <C> .
4129 <4> <A> <B> <C> .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004130---
4131name: IFS-colon-1
4132description:
4133 Simple test, IFS=:
4134stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004135 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004136 IFS=:
4137 set -- A B C
4138 showargs 1 $*
4139 showargs 2 "$*"
4140 showargs 3 $@
4141 showargs 4 "$@"
4142expected-stdout:
Elliott Hughes50012062015-03-10 22:22:24 -07004143 <1> <A> <B> <C> .
4144 <2> <A:B:C> .
4145 <3> <A> <B> <C> .
4146 <4> <A> <B> <C> .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004147---
4148name: IFS-null-1
4149description:
4150 Simple test, IFS=""
4151stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004152 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004153 IFS=""
4154 set -- A B C
4155 showargs 1 $*
4156 showargs 2 "$*"
4157 showargs 3 $@
4158 showargs 4 "$@"
4159expected-stdout:
Elliott Hughes50012062015-03-10 22:22:24 -07004160 <1> <A> <B> <C> .
4161 <2> <ABC> .
4162 <3> <A> <B> <C> .
4163 <4> <A> <B> <C> .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004164---
4165name: IFS-space-colon-1
4166description:
4167 Simple test, IFS=<white-space>:
4168stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004169 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004170 IFS="$IFS:"
4171 set --
4172 showargs 1 $*
4173 showargs 2 "$*"
4174 showargs 3 $@
4175 showargs 4 "$@"
4176 showargs 5 : "$@"
4177expected-stdout:
Elliott Hughes50012062015-03-10 22:22:24 -07004178 <1> .
4179 <2> <> .
4180 <3> .
4181 <4> .
4182 <5> <:> .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004183---
4184name: IFS-space-colon-2
4185description:
4186 Simple test, IFS=<white-space>:
4187 AT&T ksh fails this, POSIX says the test is correct.
4188stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004189 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004190 IFS="$IFS:"
4191 set --
4192 showargs :"$@"
4193expected-stdout:
Elliott Hughes50012062015-03-10 22:22:24 -07004194 <:> .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004195---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004196name: IFS-space-colon-4
4197description:
4198 Simple test, IFS=<white-space>:
4199stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004200 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004201 IFS="$IFS:"
4202 set --
4203 showargs "$@$@"
4204expected-stdout:
Elliott Hughes50012062015-03-10 22:22:24 -07004205 .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004206---
4207name: IFS-space-colon-5
4208description:
4209 Simple test, IFS=<white-space>:
4210 Don't know what POSIX thinks of this. AT&T ksh does not do this.
4211stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004212 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004213 IFS="$IFS:"
4214 set --
4215 showargs "${@:-}"
4216expected-stdout:
Elliott Hughes50012062015-03-10 22:22:24 -07004217 <> .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004218---
4219name: IFS-subst-1
4220description:
4221 Simple test, IFS=<white-space>:
4222stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004223 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004224 IFS="$IFS:"
4225 x=":b: :"
4226 echo -n '1:'; for i in $x ; do echo -n " [$i]" ; done ; echo
4227 echo -n '2:'; for i in :b:: ; do echo -n " [$i]" ; done ; echo
4228 showargs 3 $x
4229 showargs 4 :b::
4230 x="a:b:"
4231 echo -n '5:'; for i in $x ; do echo -n " [$i]" ; done ; echo
4232 showargs 6 $x
4233 x="a::c"
4234 echo -n '7:'; for i in $x ; do echo -n " [$i]" ; done ; echo
4235 showargs 8 $x
4236 echo -n '9:'; for i in ${FOO-`echo -n h:i`th:ere} ; do echo -n " [$i]" ; done ; echo
4237 showargs 10 ${FOO-`echo -n h:i`th:ere}
4238 showargs 11 "${FOO-`echo -n h:i`th:ere}"
4239 x=" A : B::D"
4240 echo -n '12:'; for i in $x ; do echo -n " [$i]" ; done ; echo
4241 showargs 13 $x
4242expected-stdout:
4243 1: [] [b] []
4244 2: [:b::]
Elliott Hughes50012062015-03-10 22:22:24 -07004245 <3> <> <b> <> .
4246 <4> <:b::> .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004247 5: [a] [b]
Elliott Hughes50012062015-03-10 22:22:24 -07004248 <6> <a> <b> .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004249 7: [a] [] [c]
Elliott Hughes50012062015-03-10 22:22:24 -07004250 <8> <a> <> <c> .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004251 9: [h] [ith] [ere]
Elliott Hughes50012062015-03-10 22:22:24 -07004252 <10> <h> <ith> <ere> .
4253 <11> <h:ith:ere> .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004254 12: [A] [B] [] [D]
Elliott Hughes50012062015-03-10 22:22:24 -07004255 <13> <A> <B> <> <D> .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004256---
Elliott Hughes737fdce2014-08-07 12:59:26 -07004257name: IFS-subst-2
4258description:
4259 Check leading whitespace after trim does not make a field
4260stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004261 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
Elliott Hughes737fdce2014-08-07 12:59:26 -07004262 x="X 1 2"
4263 showargs 1 shift ${x#X}
4264expected-stdout:
Elliott Hughes50012062015-03-10 22:22:24 -07004265 <1> <shift> <1> <2> .
Elliott Hughes737fdce2014-08-07 12:59:26 -07004266---
Elliott Hughes50012062015-03-10 22:22:24 -07004267name: IFS-subst-3-arr
Elliott Hughes56b517d2014-10-06 11:30:44 -07004268description:
4269 Check leading IFS non-whitespace after trim does make a field
Elliott Hughesf7f79562014-10-07 15:04:14 -07004270 but leading IFS whitespace does not, nor empty replacements
Elliott Hughes56b517d2014-10-06 11:30:44 -07004271stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004272 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
Elliott Hughesf7f79562014-10-07 15:04:14 -07004273 showargs 0 ${-+}
Elliott Hughes56b517d2014-10-06 11:30:44 -07004274 IFS=:
4275 showargs 1 ${-+:foo:bar}
Elliott Hughesf7f79562014-10-07 15:04:14 -07004276 IFS=' '
4277 showargs 2 ${-+ foo bar}
Elliott Hughes56b517d2014-10-06 11:30:44 -07004278expected-stdout:
Elliott Hughes50012062015-03-10 22:22:24 -07004279 <0> .
4280 <1> <> <foo> <bar> .
4281 <2> <foo> <bar> .
4282---
4283name: IFS-subst-3-ass
4284description:
4285 Check non-field semantics
4286stdin:
4287 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4288 showargs 0 x=${-+}
4289 IFS=:
4290 showargs 1 x=${-+:foo:bar}
4291 IFS=' '
4292 showargs 2 x=${-+ foo bar}
4293expected-stdout:
4294 <0> <x=> .
4295 <1> <x=> <foo> <bar> .
4296 <2> <x=> <foo> <bar> .
4297---
4298name: IFS-subst-3-lcl
4299description:
4300 Check non-field semantics, smaller corner case (LP#1381965)
4301stdin:
4302 set -x
4303 local regex=${2:-}
4304 exit 1
4305expected-exit: e != 0
4306expected-stderr-pattern:
4307 /regex=/
Elliott Hughes56b517d2014-10-06 11:30:44 -07004308---
4309name: IFS-subst-4-1
4310description:
4311 reported by mikeserv
4312stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004313 pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
Elliott Hughes56b517d2014-10-06 11:30:44 -07004314 a='space divded argument
4315 here'
4316 IFS=\ ; set -- $a
4317 IFS= ; q="$*" ; nq=$*
Elliott Hughes50012062015-03-10 22:22:24 -07004318 pfn "$*" $* "$q" "$nq"
Elliott Hughes56b517d2014-10-06 11:30:44 -07004319 [ "$q" = "$nq" ] && echo =true || echo =false
4320expected-stdout:
4321 <spacedivdedargument
4322 here>
4323 <space>
4324 <divded>
4325 <argument
4326 here>
4327 <spacedivdedargument
4328 here>
4329 <spacedivdedargument
4330 here>
4331 =true
4332---
4333name: IFS-subst-4-2
4334description:
4335 extended testsuite based on problem by mikeserv
4336stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004337 pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
Elliott Hughes56b517d2014-10-06 11:30:44 -07004338 a='space divded argument
4339 here'
4340 IFS=\ ; set -- $a
4341 IFS= ; q="$@" ; nq=$@
Elliott Hughes50012062015-03-10 22:22:24 -07004342 pfn "$*" $* "$q" "$nq"
Elliott Hughes56b517d2014-10-06 11:30:44 -07004343 [ "$q" = "$nq" ] && echo =true || echo =false
4344expected-stdout:
4345 <spacedivdedargument
4346 here>
4347 <space>
4348 <divded>
4349 <argument
4350 here>
4351 <space divded argument
4352 here>
4353 <space divded argument
4354 here>
4355 =true
4356---
4357name: IFS-subst-4-3
4358description:
4359 extended testsuite based on problem by mikeserv
4360stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004361 pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
Elliott Hughes56b517d2014-10-06 11:30:44 -07004362 a='space divded argument
4363 here'
4364 IFS=\ ; set -- $a; IFS=
4365 qs="$*"
4366 nqs=$*
4367 qk="$@"
4368 nqk=$@
Elliott Hughes50012062015-03-10 22:22:24 -07004369 print -nr -- '= qs '; pfn "$qs"
4370 print -nr -- '=nqs '; pfn "$nqs"
4371 print -nr -- '= qk '; pfn "$qk"
4372 print -nr -- '=nqk '; pfn "$nqk"
4373 print -nr -- '~ qs '; pfn "$*"
4374 print -nr -- '~nqs '; pfn $*
4375 print -nr -- '~ qk '; pfn "$@"
4376 print -nr -- '~nqk '; pfn $@
Elliott Hughes56b517d2014-10-06 11:30:44 -07004377expected-stdout:
4378 = qs <spacedivdedargument
4379 here>
4380 =nqs <spacedivdedargument
4381 here>
4382 = qk <space divded argument
4383 here>
4384 =nqk <space divded argument
4385 here>
4386 ~ qs <spacedivdedargument
4387 here>
4388 ~nqs <space>
4389 <divded>
4390 <argument
4391 here>
4392 ~ qk <space>
4393 <divded>
4394 <argument
4395 here>
4396 ~nqk <space>
4397 <divded>
4398 <argument
4399 here>
4400---
4401name: IFS-subst-4-4
4402description:
4403 extended testsuite based on problem by mikeserv
4404stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004405 pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
Elliott Hughes56b517d2014-10-06 11:30:44 -07004406 a='space divded argument
4407 here'
4408 IFS=\ ; set -- $a; IFS=
4409 qs="$*"
Elliott Hughes50012062015-03-10 22:22:24 -07004410 print -nr -- '= qs '; pfn "$qs"
4411 print -nr -- '~ qs '; pfn "$*"
Elliott Hughes56b517d2014-10-06 11:30:44 -07004412 nqs=$*
Elliott Hughes50012062015-03-10 22:22:24 -07004413 print -nr -- '=nqs '; pfn "$nqs"
4414 print -nr -- '~nqs '; pfn $*
Elliott Hughes56b517d2014-10-06 11:30:44 -07004415 qk="$@"
Elliott Hughes50012062015-03-10 22:22:24 -07004416 print -nr -- '= qk '; pfn "$qk"
4417 print -nr -- '~ qk '; pfn "$@"
Elliott Hughes56b517d2014-10-06 11:30:44 -07004418 nqk=$@
Elliott Hughes50012062015-03-10 22:22:24 -07004419 print -nr -- '=nqk '; pfn "$nqk"
4420 print -nr -- '~nqk '; pfn $@
Elliott Hughes56b517d2014-10-06 11:30:44 -07004421expected-stdout:
4422 = qs <spacedivdedargument
4423 here>
4424 ~ qs <spacedivdedargument
4425 here>
4426 =nqs <spacedivdedargument
4427 here>
4428 ~nqs <space>
4429 <divded>
4430 <argument
4431 here>
4432 = qk <space divded argument
4433 here>
4434 ~ qk <space>
4435 <divded>
4436 <argument
4437 here>
4438 =nqk <space divded argument
4439 here>
4440 ~nqk <space>
4441 <divded>
4442 <argument
4443 here>
4444---
4445name: IFS-subst-4-4p
4446description:
4447 extended testsuite based on problem by mikeserv
4448stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004449 pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
Elliott Hughes56b517d2014-10-06 11:30:44 -07004450 a='space divded argument
4451 here'
4452 IFS=\ ; set -- $a; IFS=
4453 unset v
4454 qs=${v:-"$*"}
Elliott Hughes50012062015-03-10 22:22:24 -07004455 print -nr -- '= qs '; pfn "$qs"
4456 print -nr -- '~ qs '; pfn ${v:-"$*"}
Elliott Hughes56b517d2014-10-06 11:30:44 -07004457 nqs=${v:-$*}
Elliott Hughes50012062015-03-10 22:22:24 -07004458 print -nr -- '=nqs '; pfn "$nqs"
4459 print -nr -- '~nqs '; pfn ${v:-$*}
Elliott Hughes56b517d2014-10-06 11:30:44 -07004460 qk=${v:-"$@"}
Elliott Hughes50012062015-03-10 22:22:24 -07004461 print -nr -- '= qk '; pfn "$qk"
4462 print -nr -- '~ qk '; pfn ${v:-"$@"}
Elliott Hughes56b517d2014-10-06 11:30:44 -07004463 nqk=${v:-$@}
Elliott Hughes50012062015-03-10 22:22:24 -07004464 print -nr -- '=nqk '; pfn "$nqk"
4465 print -nr -- '~nqk '; pfn ${v:-$@}
Elliott Hughes56b517d2014-10-06 11:30:44 -07004466expected-stdout:
4467 = qs <spacedivdedargument
4468 here>
4469 ~ qs <spacedivdedargument
4470 here>
4471 =nqs <spacedivdedargument
4472 here>
4473 ~nqs <space>
4474 <divded>
4475 <argument
4476 here>
4477 = qk <space divded argument
4478 here>
4479 ~ qk <space>
4480 <divded>
4481 <argument
4482 here>
4483 =nqk <space divded argument
4484 here>
4485 ~nqk <space>
4486 <divded>
4487 <argument
4488 here>
4489---
4490name: IFS-subst-4-5
4491description:
4492 extended testsuite based on problem by mikeserv
4493stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004494 pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
Elliott Hughes56b517d2014-10-06 11:30:44 -07004495 a='space divded argument
4496 here'
4497 IFS=\ ; set -- $a; IFS=,
4498 qs="$*"
Elliott Hughes50012062015-03-10 22:22:24 -07004499 print -nr -- '= qs '; pfn "$qs"
4500 print -nr -- '~ qs '; pfn "$*"
Elliott Hughes56b517d2014-10-06 11:30:44 -07004501 nqs=$*
Elliott Hughes50012062015-03-10 22:22:24 -07004502 print -nr -- '=nqs '; pfn "$nqs"
4503 print -nr -- '~nqs '; pfn $*
Elliott Hughes56b517d2014-10-06 11:30:44 -07004504 qk="$@"
Elliott Hughes50012062015-03-10 22:22:24 -07004505 print -nr -- '= qk '; pfn "$qk"
4506 print -nr -- '~ qk '; pfn "$@"
Elliott Hughes56b517d2014-10-06 11:30:44 -07004507 nqk=$@
Elliott Hughes50012062015-03-10 22:22:24 -07004508 print -nr -- '=nqk '; pfn "$nqk"
4509 print -nr -- '~nqk '; pfn $@
Elliott Hughes56b517d2014-10-06 11:30:44 -07004510expected-stdout:
4511 = qs <space,divded,argument
4512 here>
4513 ~ qs <space,divded,argument
4514 here>
4515 =nqs <space,divded,argument
4516 here>
4517 ~nqs <space>
4518 <divded>
4519 <argument
4520 here>
4521 = qk <space divded argument
4522 here>
4523 ~ qk <space>
4524 <divded>
4525 <argument
4526 here>
4527 =nqk <space divded argument
4528 here>
4529 ~nqk <space>
4530 <divded>
4531 <argument
4532 here>
4533---
4534name: IFS-subst-4-5p
4535description:
4536 extended testsuite based on problem by mikeserv
4537stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004538 pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; }
Elliott Hughes56b517d2014-10-06 11:30:44 -07004539 a='space divded argument
4540 here'
4541 IFS=\ ; set -- $a; IFS=,
4542 unset v
4543 qs=${v:-"$*"}
Elliott Hughes50012062015-03-10 22:22:24 -07004544 print -nr -- '= qs '; pfn "$qs"
4545 print -nr -- '~ qs '; pfn ${v:-"$*"}
Elliott Hughes56b517d2014-10-06 11:30:44 -07004546 nqs=${v:-$*}
Elliott Hughes50012062015-03-10 22:22:24 -07004547 print -nr -- '=nqs '; pfn "$nqs"
4548 print -nr -- '~nqs '; pfn ${v:-$*}
Elliott Hughes56b517d2014-10-06 11:30:44 -07004549 qk=${v:-"$@"}
Elliott Hughes50012062015-03-10 22:22:24 -07004550 print -nr -- '= qk '; pfn "$qk"
4551 print -nr -- '~ qk '; pfn ${v:-"$@"}
Elliott Hughes56b517d2014-10-06 11:30:44 -07004552 nqk=${v:-$@}
Elliott Hughes50012062015-03-10 22:22:24 -07004553 print -nr -- '=nqk '; pfn "$nqk"
4554 print -nr -- '~nqk '; pfn ${v:-$@}
Elliott Hughes56b517d2014-10-06 11:30:44 -07004555expected-stdout:
4556 = qs <space,divded,argument
4557 here>
4558 ~ qs <space,divded,argument
4559 here>
4560 =nqs <space,divded,argument
4561 here>
4562 ~nqs <space>
4563 <divded>
4564 <argument
4565 here>
4566 = qk <space divded argument
4567 here>
4568 ~ qk <space>
4569 <divded>
4570 <argument
4571 here>
4572 =nqk <space divded argument
4573 here>
4574 ~nqk <space>
4575 <divded>
4576 <argument
4577 here>
4578---
4579name: IFS-subst-5
4580description:
4581 extended testsuite based on IFS-subst-3
4582 differs slightly from ksh93:
4583 - omit trailing field in a3zna, a7ina (unquoted $@ expansion)
4584 - has extra middle fields in b5ins, b7ina (IFS_NWS unquoted expansion)
4585 differs slightly from bash:
4586 - omit leading field in a5ins, a7ina (IFS_NWS unquoted expansion)
4587 differs slightly from zsh:
4588 - differs in assignment, not expansion; probably zsh bug
4589 - has extra middle fields in b5ins, b7ina (IFS_NWS unquoted expansion)
4590 'emulate sh' zsh has extra fields in
4591 - a5ins (IFS_NWS unquoted $*)
4592 - b5ins, matching mksh’s
Elliott Hughes50012062015-03-10 22:22:24 -07004593 !!WARNING!! more to come: http://austingroupbugs.net/view.php?id=888
Elliott Hughes56b517d2014-10-06 11:30:44 -07004594stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07004595 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4596 IFS=; set -- "" 2 ""; pfb $*; x=$*; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004597 echo '=a1zns'
Elliott Hughes50012062015-03-10 22:22:24 -07004598 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4599 IFS=; set -- "" 2 ""; pfb "$*"; x="$*"; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004600 echo '=a2zqs'
Elliott Hughes50012062015-03-10 22:22:24 -07004601 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4602 IFS=; set -- "" 2 ""; pfb $@; x=$@; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004603 echo '=a3zna'
Elliott Hughes50012062015-03-10 22:22:24 -07004604 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4605 IFS=; set -- "" 2 ""; pfb "$@"; x="$@"; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004606 echo '=a4zqa'
Elliott Hughes50012062015-03-10 22:22:24 -07004607 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4608 IFS=,; set -- "" 2 ""; pfb $*; x=$*; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004609 echo '=a5ins'
Elliott Hughes50012062015-03-10 22:22:24 -07004610 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4611 IFS=,; set -- "" 2 ""; pfb "$*"; x="$*"; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004612 echo '=a6iqs'
Elliott Hughes50012062015-03-10 22:22:24 -07004613 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4614 IFS=,; set -- "" 2 ""; pfb $@; x=$@; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004615 echo '=a7ina'
Elliott Hughes50012062015-03-10 22:22:24 -07004616 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4617 IFS=,; set -- "" 2 ""; pfb "$@"; x="$@"; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004618 echo '=a8iqa'
Elliott Hughes50012062015-03-10 22:22:24 -07004619 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4620 IFS=; set -- A B "" "" C; pfb $*; x=$*; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004621 echo '=b1zns'
Elliott Hughes50012062015-03-10 22:22:24 -07004622 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4623 IFS=; set -- A B "" "" C; pfb "$*"; x="$*"; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004624 echo '=b2zqs'
Elliott Hughes50012062015-03-10 22:22:24 -07004625 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4626 IFS=; set -- A B "" "" C; pfb $@; x=$@; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004627 echo '=b3zna'
Elliott Hughes50012062015-03-10 22:22:24 -07004628 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4629 IFS=; set -- A B "" "" C; pfb "$@"; x="$@"; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004630 echo '=b4zqa'
Elliott Hughes50012062015-03-10 22:22:24 -07004631 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4632 IFS=,; set -- A B "" "" C; pfb $*; x=$*; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004633 echo '=b5ins'
Elliott Hughes50012062015-03-10 22:22:24 -07004634 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4635 IFS=,; set -- A B "" "" C; pfb "$*"; x="$*"; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004636 echo '=b6iqs'
Elliott Hughes50012062015-03-10 22:22:24 -07004637 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4638 IFS=,; set -- A B "" "" C; pfb $@; x=$@; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004639 echo '=b7ina'
Elliott Hughes50012062015-03-10 22:22:24 -07004640 "$__progname" -c 'pfb() { for s_arg in "$@"; do print -r -- "[$s_arg]"; done; }; pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; };
4641 IFS=,; set -- A B "" "" C; pfb "$@"; x="$@"; pfn "$x"'
Elliott Hughes56b517d2014-10-06 11:30:44 -07004642 echo '=b8iqa'
4643expected-stdout:
4644 [2]
4645 <2>
4646 =a1zns
4647 [2]
4648 <2>
4649 =a2zqs
4650 [2]
4651 < 2 >
4652 =a3zna
4653 []
4654 [2]
4655 []
4656 < 2 >
4657 =a4zqa
4658 [2]
4659 <,2,>
4660 =a5ins
4661 [,2,]
4662 <,2,>
4663 =a6iqs
4664 [2]
4665 < 2 >
4666 =a7ina
4667 []
4668 [2]
4669 []
4670 < 2 >
4671 =a8iqa
4672 [A]
4673 [B]
4674 [C]
4675 <ABC>
4676 =b1zns
4677 [ABC]
4678 <ABC>
4679 =b2zqs
4680 [A]
4681 [B]
4682 [C]
4683 <A B C>
4684 =b3zna
4685 [A]
4686 [B]
4687 []
4688 []
4689 [C]
4690 <A B C>
4691 =b4zqa
4692 [A]
4693 [B]
4694 []
4695 []
4696 [C]
4697 <A,B,,,C>
4698 =b5ins
4699 [A,B,,,C]
4700 <A,B,,,C>
4701 =b6iqs
4702 [A]
4703 [B]
4704 []
4705 []
4706 [C]
4707 <A B C>
4708 =b7ina
4709 [A]
4710 [B]
4711 []
4712 []
4713 [C]
4714 <A B C>
4715 =b8iqa
4716---
Elliott Hughes50012062015-03-10 22:22:24 -07004717name: IFS-subst-6
4718description:
4719 Regression wrt. vector expansion in trim
4720stdin:
4721 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4722 IFS=
4723 x=abc
4724 set -- a b
4725 showargs ${x#$*}
4726expected-stdout:
4727 <c> .
4728---
4729name: IFS-subst-7
4730description:
4731 ksh93 bug wrt. vector expansion in trim
4732stdin:
4733 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4734 IFS="*"
4735 a=abcd
4736 set -- '' c
4737 showargs "$*" ${a##"$*"}
4738expected-stdout:
4739 <*c> <abcd> .
4740---
4741name: IFS-subst-8
4742description:
4743 http://austingroupbugs.net/view.php?id=221
4744stdin:
4745 n() { echo "$#"; }; n "${foo-$@}"
4746expected-stdout:
4747 1
4748---
4749name: IFS-subst-9
4750description:
4751 Scalar context for $*/$@ in [[ and case
4752stdin:
4753 "$__progname" -c 'IFS=; set a b; [[ $* = "$1$2" ]]; echo 1 $?' sh a b
4754 "$__progname" -c 'IFS=; [[ $* = ab ]]; echo 2 "$?"' sh a b
4755 "$__progname" -c 'IFS=; [[ "$*" = ab ]]; echo 3 "$?"' sh a b
4756 "$__progname" -c 'IFS=; [[ $* = a ]]; echo 4 "$?"' sh a b
4757 "$__progname" -c 'IFS=; [[ "$*" = a ]]; echo 5 "$?"' sh a b
4758 "$__progname" -c 'IFS=; [[ "$@" = a ]]; echo 6 "$?"' sh a b
4759 "$__progname" -c 'IFS=; case "$@" in a) echo 7 a;; ab) echo 7 b;; a\ b) echo 7 ok;; esac' sh a b
4760 "$__progname" -c 'IFS=; case $* in a) echo 8 a;; ab) echo 8 ok;; esac' sh a b
4761 "$__progname" -c 'pfsp() { for s_arg in "$@"; do print -nr -- "<$s_arg> "; done; print .; }; IFS=; star=$* at="$@"; pfsp 9 "$star" "$at"' sh a b
4762expected-stdout:
4763 1 0
4764 2 0
4765 3 0
4766 4 1
4767 5 1
4768 6 1
4769 7 ok
4770 8 ok
4771 <9> <ab> <a b> .
4772---
Elliott Hughesa3c3f962017-04-12 16:52:30 -07004773name: IFS-subst-10
4774description:
4775 Scalar context in ${var=$subst}
4776stdin:
4777 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
4778 set -- one "two three" four
4779 unset -v var
4780 save_IFS=$IFS
4781 IFS=
4782 set -- ${var=$*}
4783 IFS=$save_IFS
4784 echo "var=$var"
4785 showargs "$@"
4786expected-stdout:
4787 var=onetwo threefour
4788 <onetwo threefour> .
4789---
Elliott Hughes737fdce2014-08-07 12:59:26 -07004790name: IFS-arith-1
4791description:
4792 http://austingroupbugs.net/view.php?id=832
4793stdin:
4794 ${ZSH_VERSION+false} || emulate sh
4795 ${BASH_VERSION+set -o posix}
Elliott Hughes50012062015-03-10 22:22:24 -07004796 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
Elliott Hughes737fdce2014-08-07 12:59:26 -07004797 IFS=0
4798 showargs $((1230456))
4799expected-stdout:
4800 <123> <456> .
4801---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004802name: integer-base-err-1
4803description:
4804 Can't have 0 base (causes shell to exit)
4805expected-exit: e != 0
4806stdin:
4807 typeset -i i
4808 i=3
4809 i=0#4
4810 echo $i
4811expected-stderr-pattern:
4812 /^.*:.*0#4.*\n$/
4813---
4814name: integer-base-err-2
4815description:
4816 Can't have multiple bases in a 'constant' (causes shell to exit)
4817 (ksh88 fails this test)
4818expected-exit: e != 0
4819stdin:
4820 typeset -i i
4821 i=3
4822 i=2#110#11
4823 echo $i
4824expected-stderr-pattern:
4825 /^.*:.*2#110#11.*\n$/
4826---
4827name: integer-base-err-3
4828description:
4829 Syntax errors in expressions and effects on bases
4830 (interactive so errors don't cause exits)
4831 (ksh88 fails this test - shell exits, even with -i)
Geremy Condra03ebf062011-10-12 18:17:24 -07004832need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07004833arguments: !-i!
4834stdin:
4835 PS1= # minimise prompt hassles
4836 typeset -i4 a=10
4837 typeset -i a=2+
4838 echo $a
4839 typeset -i4 a=10
4840 typeset -i2 a=2+
4841 echo $a
4842expected-stderr-pattern:
4843 /^([#\$] )?.*:.*2+.*\n.*:.*2+.*\n$/
4844expected-stdout:
4845 4#22
4846 4#22
4847---
4848name: integer-base-err-4
4849description:
4850 Are invalid digits (according to base) errors?
4851 (ksh93 fails this test)
4852expected-exit: e != 0
4853stdin:
4854 typeset -i i;
4855 i=3#4
4856expected-stderr-pattern:
4857 /^([#\$] )?.*:.*3#4.*\n$/
4858---
4859name: integer-base-1
4860description:
4861 Missing number after base is treated as 0.
4862stdin:
4863 typeset -i i
4864 i=3
4865 i=2#
4866 echo $i
4867expected-stdout:
4868 0
4869---
4870name: integer-base-2
4871description:
4872 Check 'stickyness' of base in various situations
4873stdin:
4874 typeset -i i=8
4875 echo $i
4876 echo ---------- A
4877 typeset -i4 j=8
4878 echo $j
4879 echo ---------- B
4880 typeset -i k=8
4881 typeset -i4 k=8
4882 echo $k
4883 echo ---------- C
4884 typeset -i4 l
4885 l=3#10
4886 echo $l
4887 echo ---------- D
4888 typeset -i m
4889 m=3#10
4890 echo $m
4891 echo ---------- E
4892 n=2#11
4893 typeset -i n
4894 echo $n
4895 n=10
4896 echo $n
4897 echo ---------- F
4898 typeset -i8 o=12
4899 typeset -i4 o
4900 echo $o
4901 echo ---------- G
4902 typeset -i p
4903 let p=8#12
4904 echo $p
4905expected-stdout:
4906 8
4907 ---------- A
4908 4#20
4909 ---------- B
4910 4#20
4911 ---------- C
4912 4#3
4913 ---------- D
4914 3#10
4915 ---------- E
4916 2#11
4917 2#1010
4918 ---------- F
4919 4#30
4920 ---------- G
4921 8#12
4922---
4923name: integer-base-3
4924description:
4925 More base parsing (hmm doesn't test much..)
4926stdin:
4927 typeset -i aa
4928 aa=1+12#10+2
4929 echo $aa
4930 typeset -i bb
4931 bb=1+$aa
4932 echo $bb
4933 typeset -i bb
4934 bb=$aa
4935 echo $bb
4936 typeset -i cc
4937 cc=$aa
4938 echo $cc
4939expected-stdout:
4940 15
4941 16
4942 15
4943 15
4944---
4945name: integer-base-4
4946description:
4947 Check that things not declared as integers are not made integers,
4948 also, check if base is not reset by -i with no arguments.
4949 (ksh93 fails - prints 10#20 - go figure)
4950stdin:
4951 xx=20
4952 let xx=10
4953 typeset -i | grep '^xx='
4954 typeset -i4 a=10
4955 typeset -i a=20
4956 echo $a
4957expected-stdout:
4958 4#110
4959---
4960name: integer-base-5
4961description:
4962 More base stuff
4963stdin:
4964 typeset -i4 a=3#10
4965 echo $a
4966 echo --
4967 typeset -i j=3
4968 j='~3'
4969 echo $j
4970 echo --
4971 typeset -i k=1
4972 x[k=k+1]=3
4973 echo $k
4974 echo --
4975 typeset -i l
4976 for l in 1 2+3 4; do echo $l; done
4977expected-stdout:
4978 4#3
4979 --
4980 -4
4981 --
4982 2
4983 --
4984 1
4985 5
4986 4
4987---
4988name: integer-base-6
4989description:
4990 Even more base stuff
4991 (ksh93 fails this test - prints 0)
4992stdin:
4993 typeset -i7 i
4994 i=
4995 echo $i
4996expected-stdout:
4997 7#0
4998---
4999name: integer-base-7
5000description:
5001 Check that non-integer parameters don't get bases assigned
5002stdin:
5003 echo $(( zz = 8#100 ))
5004 echo $zz
5005expected-stdout:
5006 64
5007 64
5008---
Elliott Hughes96b43632015-07-17 11:39:41 -07005009name: integer-base-8
5010description:
5011 Check that base-36 works (full span)
5012stdin:
5013 echo 1:$((36#109AZ)).
5014 typeset -i36 x=1691675
5015 echo 2:$x.
5016 typeset -Uui36 x
5017 echo 3:$x.
5018expected-stdout:
5019 1:1691675.
5020 2:36#109az.
5021 3:36#109AZ.
5022---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005023name: integer-base-check-flat
5024description:
Thorsten Glaser811a5752013-07-25 14:24:45 +00005025 Check behaviour does not match POSuX (except if set -o posix),
5026 because a not type-safe scripting language has *no* business
Elliott Hughes966dd552016-12-08 15:56:04 -08005027 interpreting the string "010" as octal number eight (dangerous).
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005028stdin:
Thorsten Glaser811a5752013-07-25 14:24:45 +00005029 echo 1 "$("$__progname" -c 'echo :$((10))/$((010)),$((0x10)):')" .
5030 echo 2 "$("$__progname" -o posix -c 'echo :$((10))/$((010)),$((0x10)):')" .
5031 echo 3 "$("$__progname" -o sh -c 'echo :$((10))/$((010)),$((0x10)):')" .
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005032expected-stdout:
Thorsten Glaser811a5752013-07-25 14:24:45 +00005033 1 :10/10,16: .
5034 2 :10/8,16: .
5035 3 :10/10,16: .
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005036---
5037name: integer-base-check-numeric-from
5038description:
Elliott Hughes96b43632015-07-17 11:39:41 -07005039 Check behaviour for base one to 36, and that 37 degrades to 10
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005040stdin:
5041 echo 1:$((1#1))0.
5042 i=1
Elliott Hughes96b43632015-07-17 11:39:41 -07005043 while (( ++i <= 37 )); do
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005044 eval 'echo '$i':$(('$i'#10)).'
5045 done
5046 echo 37:$($__progname -c 'echo $((37#10))').$?:
5047expected-stdout:
5048 1:490.
5049 2:2.
5050 3:3.
5051 4:4.
5052 5:5.
5053 6:6.
5054 7:7.
5055 8:8.
5056 9:9.
5057 10:10.
5058 11:11.
5059 12:12.
5060 13:13.
5061 14:14.
5062 15:15.
5063 16:16.
5064 17:17.
5065 18:18.
5066 19:19.
5067 20:20.
5068 21:21.
5069 22:22.
5070 23:23.
5071 24:24.
5072 25:25.
5073 26:26.
5074 27:27.
5075 28:28.
5076 29:29.
5077 30:30.
5078 31:31.
5079 32:32.
5080 33:33.
5081 34:34.
5082 35:35.
5083 36:36.
Elliott Hughes96b43632015-07-17 11:39:41 -07005084 37:10.
5085 37:10.0:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005086---
5087name: integer-base-check-numeric-to
5088description:
Elliott Hughes96b43632015-07-17 11:39:41 -07005089 Check behaviour for base one to 36, and that 37 degrades to 10
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005090stdin:
5091 i=0
5092 while (( ++i <= 37 )); do
5093 typeset -Uui$i x=0x40
5094 eval "typeset -i10 y=$x"
5095 print $i:$x.$y.
5096 done
5097expected-stdout:
5098 1:1#@.64.
5099 2:2#1000000.64.
5100 3:3#2101.64.
5101 4:4#1000.64.
5102 5:5#224.64.
5103 6:6#144.64.
5104 7:7#121.64.
5105 8:8#100.64.
5106 9:9#71.64.
5107 10:64.64.
5108 11:11#59.64.
5109 12:12#54.64.
5110 13:13#4C.64.
5111 14:14#48.64.
5112 15:15#44.64.
5113 16:16#40.64.
5114 17:17#3D.64.
5115 18:18#3A.64.
5116 19:19#37.64.
5117 20:20#34.64.
5118 21:21#31.64.
5119 22:22#2K.64.
5120 23:23#2I.64.
5121 24:24#2G.64.
5122 25:25#2E.64.
5123 26:26#2C.64.
5124 27:27#2A.64.
5125 28:28#28.64.
5126 29:29#26.64.
5127 30:30#24.64.
5128 31:31#22.64.
5129 32:32#20.64.
5130 33:33#1V.64.
5131 34:34#1U.64.
5132 35:35#1T.64.
5133 36:36#1S.64.
Elliott Hughes96b43632015-07-17 11:39:41 -07005134 37:64.64.
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005135---
5136name: integer-arithmetic-span
5137description:
5138 Check wraparound and size that is defined in mksh
5139category: int:32
5140stdin:
5141 echo s:$((2147483647+1)).$(((2147483647*2)+1)).$(((2147483647*2)+2)).
5142 echo u:$((#2147483647+1)).$((#(2147483647*2)+1)).$((#(2147483647*2)+2)).
5143expected-stdout:
5144 s:-2147483648.-1.0.
5145 u:2147483648.4294967295.0.
5146---
5147name: integer-arithmetic-span-64
5148description:
5149 Check wraparound and size that is defined in mksh
5150category: int:64
5151stdin:
5152 echo s:$((9223372036854775807+1)).$(((9223372036854775807*2)+1)).$(((9223372036854775807*2)+2)).
5153 echo u:$((#9223372036854775807+1)).$((#(9223372036854775807*2)+1)).$((#(9223372036854775807*2)+2)).
5154expected-stdout:
5155 s:-9223372036854775808.-1.0.
5156 u:9223372036854775808.18446744073709551615.0.
5157---
Thorsten Glaser811a5752013-07-25 14:24:45 +00005158name: integer-size-FAIL-to-detect
5159description:
5160 Notify the user that their ints are not 32 or 64 bit
5161category: int:u
5162stdin:
5163 :
5164---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07005165name: lineno-stdin
5166description:
5167 See if $LINENO is updated and can be modified.
5168stdin:
5169 echo A $LINENO
5170 echo B $LINENO
5171 LINENO=20
5172 echo C $LINENO
5173expected-stdout:
5174 A 1
5175 B 2
5176 C 20
5177---
5178name: lineno-inc
5179description:
5180 See if $LINENO is set for .'d files.
5181file-setup: file 644 "dotfile"
5182 echo dot A $LINENO
5183 echo dot B $LINENO
5184 LINENO=20
5185 echo dot C $LINENO
5186stdin:
5187 echo A $LINENO
5188 echo B $LINENO
5189 . ./dotfile
5190expected-stdout:
5191 A 1
5192 B 2
5193 dot A 1
5194 dot B 2
5195 dot C 20
5196---
5197name: lineno-func
5198description:
5199 See if $LINENO is set for commands in a function.
5200stdin:
5201 echo A $LINENO
5202 echo B $LINENO
5203 bar() {
5204 echo func A $LINENO
5205 echo func B $LINENO
5206 }
5207 bar
5208 echo C $LINENO
5209expected-stdout:
5210 A 1
5211 B 2
5212 func A 4
5213 func B 5
5214 C 8
5215---
5216name: lineno-unset
5217description:
5218 See if unsetting LINENO makes it non-magic.
5219file-setup: file 644 "dotfile"
5220 echo dot A $LINENO
5221 echo dot B $LINENO
5222stdin:
5223 unset LINENO
5224 echo A $LINENO
5225 echo B $LINENO
5226 bar() {
5227 echo func A $LINENO
5228 echo func B $LINENO
5229 }
5230 bar
5231 . ./dotfile
5232 echo C $LINENO
5233expected-stdout:
5234 A
5235 B
5236 func A
5237 func B
5238 dot A
5239 dot B
5240 C
5241---
5242name: lineno-unset-use
5243description:
5244 See if unsetting LINENO makes it non-magic even
5245 when it is re-used.
5246file-setup: file 644 "dotfile"
5247 echo dot A $LINENO
5248 echo dot B $LINENO
5249stdin:
5250 unset LINENO
5251 LINENO=3
5252 echo A $LINENO
5253 echo B $LINENO
5254 bar() {
5255 echo func A $LINENO
5256 echo func B $LINENO
5257 }
5258 bar
5259 . ./dotfile
5260 echo C $LINENO
5261expected-stdout:
5262 A 3
5263 B 3
5264 func A 3
5265 func B 3
5266 dot A 3
5267 dot B 3
5268 C 3
5269---
5270name: lineno-trap
5271description:
5272 Check if LINENO is tracked in traps
5273stdin:
5274 fail() {
5275 echo "line <$1>"
5276 exit 1
5277 }
5278 trap 'fail $LINENO' INT ERR
5279 false
5280expected-stdout:
5281 line <6>
5282expected-exit: 1
5283---
Elliott Hughesa3c3f962017-04-12 16:52:30 -07005284name: lineno-eval-alias
5285description:
5286 Check if LINENO is trapped in eval and aliases
5287stdin:
5288 ${ZSH_VERSION+false} || emulate sh; echo $LINENO
5289 echo $LINENO
5290 eval ' echo $LINENO
5291 echo $LINENO
5292 echo $LINENO'
5293 echo $LINENO
5294expected-stdout:
5295 1
5296 2
5297 3
5298 3
5299 3
5300 6
5301---
Geremy Condra03ebf062011-10-12 18:17:24 -07005302name: unknown-trap
5303description:
5304 Ensure unknown traps are not a syntax error
5305stdin:
5306 (
5307 trap "echo trap 1 executed" UNKNOWNSIGNAL || echo "foo"
5308 echo =1
5309 trap "echo trap 2 executed" UNKNOWNSIGNAL EXIT 999999 FNORD
5310 echo = $?
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005311 ) 2>&1 | sed "s^${__progname%.exe}\.*e*x*e*: <stdin>\[[0-9]*]PROG"
Geremy Condra03ebf062011-10-12 18:17:24 -07005312expected-stdout:
5313 PROG: trap: bad signal 'UNKNOWNSIGNAL'
5314 foo
5315 =1
5316 PROG: trap: bad signal 'UNKNOWNSIGNAL'
5317 PROG: trap: bad signal '999999'
5318 PROG: trap: bad signal 'FNORD'
Elliott Hughes96b43632015-07-17 11:39:41 -07005319 = 1
Geremy Condra03ebf062011-10-12 18:17:24 -07005320 trap 2 executed
5321---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07005322name: read-IFS-1
5323description:
5324 Simple test, default IFS
5325stdin:
5326 echo "A B " > IN
5327 unset x y z
5328 read x y z < IN
5329 echo 1: "x[$x] y[$y] z[$z]"
5330 echo 1a: ${z-z not set}
5331 read x < IN
5332 echo 2: "x[$x]"
5333expected-stdout:
5334 1: x[A] y[B] z[]
5335 1a:
5336 2: x[A B]
5337---
Elliott Hughesb27ce952015-04-21 13:39:18 -07005338name: read-IFS-2
5339description:
5340 Complex tests, IFS either colon (IFS-NWS) or backslash (tricky)
5341stdin:
5342 n=0
5343 showargs() { print -nr "$1"; shift; for s_arg in "$@"; do print -nr -- " [$s_arg]"; done; print; }
5344 (IFS=\\ a=\<\\\>; showargs 3 $a)
5345 (IFS=: b=\<:\>; showargs 4 $b)
5346 print -r '<\>' | (IFS=\\ read f g; showargs 5 "$f" "$g")
5347 print -r '<\\>' | (IFS=\\ read f g; showargs 6 "$f" "$g")
5348 print '<\\\n>' | (IFS=\\ read f g; showargs 7 "$f" "$g")
5349 print -r '<\>' | (IFS=\\ read f; showargs 8 "$f")
5350 print -r '<\\>' | (IFS=\\ read f; showargs 9 "$f")
5351 print '<\\\n>' | (IFS=\\ read f; showargs 10 "$f")
5352 print -r '<\>' | (IFS=\\ read -r f g; showargs 11 "$f" "$g")
5353 print -r '<\\>' | (IFS=\\ read -r f g; showargs 12 "$f" "$g")
5354 print '<\\\n>' | (IFS=\\ read -r f g; showargs 13 "$f" "$g")
5355 print -r '<\>' | (IFS=\\ read -r f; showargs 14 "$f")
5356 print -r '<\\>' | (IFS=\\ read -r f; showargs 15 "$f")
5357 print '<\\\n>' | (IFS=\\ read -r f; showargs 16 "$f")
5358 print -r '<:>' | (IFS=: read f g; showargs 17 "$f" "$g")
5359 print -r '<::>' | (IFS=: read f g; showargs 18 "$f" "$g")
5360 print '<:\n>' | (IFS=: read f g; showargs 19 "$f" "$g")
5361 print -r '<:>' | (IFS=: read f; showargs 20 "$f")
5362 print -r '<::>' | (IFS=: read f; showargs 21 "$f")
5363 print '<:\n>' | (IFS=: read f; showargs 22 "$f")
5364 print -r '<:>' | (IFS=: read -r f g; showargs 23 "$f" "$g")
5365 print -r '<::>' | (IFS=: read -r f g; showargs 24 "$f" "$g")
5366 print '<:\n>' | (IFS=: read -r f g; showargs 25 "$f" "$g")
5367 print -r '<:>' | (IFS=: read -r f; showargs 26 "$f")
5368 print -r '<::>' | (IFS=: read -r f; showargs 27 "$f")
5369 print '<:\n>' | (IFS=: read -r f; showargs 28 "$f")
5370expected-stdout:
5371 3 [<] [>]
5372 4 [<] [>]
5373 5 [<] [>]
5374 6 [<] [>]
5375 7 [<>] []
5376 8 [<>]
5377 9 [<\>]
5378 10 [<>]
5379 11 [<] [>]
5380 12 [<] [\>]
5381 13 [<] []
5382 14 [<\>]
5383 15 [<\\>]
5384 16 [<]
5385 17 [<] [>]
5386 18 [<] [:>]
5387 19 [<] []
5388 20 [<:>]
5389 21 [<::>]
5390 22 [<]
5391 23 [<] [>]
5392 24 [<] [:>]
5393 25 [<] []
5394 26 [<:>]
5395 27 [<::>]
5396 28 [<]
5397---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07005398name: read-ksh-1
5399description:
5400 If no var specified, REPLY is used
5401stdin:
5402 echo "abc" > IN
5403 read < IN
5404 echo "[$REPLY]";
5405expected-stdout:
5406 [abc]
5407---
Geremy Condra03ebf062011-10-12 18:17:24 -07005408name: read-regress-1
5409description:
5410 Check a regression of read
5411file-setup: file 644 "foo"
5412 foo bar
5413 baz
5414 blah
5415stdin:
5416 while read a b c; do
5417 read d
5418 break
5419 done <foo
5420 echo "<$a|$b|$c><$d>"
5421expected-stdout:
5422 <foo|bar|><baz>
5423---
5424name: read-delim-1
5425description:
5426 Check read with delimiters
5427stdin:
5428 emit() {
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005429 print -n 'foo bar\tbaz\nblah \0blub\tblech\nmyok meck \0'
Geremy Condra03ebf062011-10-12 18:17:24 -07005430 }
5431 emit | while IFS= read -d "" foo; do print -r -- "<$foo>"; done
5432 emit | while read -d "" foo; do print -r -- "<$foo>"; done
5433 emit | while read -d "eh?" foo; do print -r -- "<$foo>"; done
5434expected-stdout:
5435 <foo bar baz
5436 blah >
5437 <blub blech
5438 myok meck >
5439 <foo bar baz
5440 blah>
5441 <blub blech
5442 myok meck>
5443 <foo bar baz
5444 blah blub bl>
5445 <ch
5446 myok m>
5447---
5448name: read-ext-1
5449description:
5450 Check read with number of bytes specified, and -A
5451stdin:
5452 print 'foo\nbar' >x1
5453 print -n x >x2
5454 print 'foo\\ bar baz' >x3
5455 x1a=u; read x1a <x1
5456 x1b=u; read -N-1 x1b <x1
5457 x2a=u; read x2a <x2; r2a=$?
5458 x2b=u; read -N2 x2c <x2; r2b=$?
5459 x2c=u; read -n2 x2c <x2; r2c=$?
5460 x3a=u; read -A x3a <x3
5461 print -r "x1a=<$x1a>"
5462 print -r "x1b=<$x1b>"
5463 print -r "x2a=$r2a<$x2a>"
5464 print -r "x2b=$r2b<$x2b>"
5465 print -r "x2c=$r2c<$x2c>"
5466 print -r "x3a=<${x3a[0]}|${x3a[1]}|${x3a[2]}>"
5467expected-stdout:
5468 x1a=<foo>
5469 x1b=<foo
5470 bar>
5471 x2a=1<x>
5472 x2b=1<u>
5473 x2c=0<x>
5474 x3a=<foo bar|baz|>
5475---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07005476name: regression-1
5477description:
5478 Lex array code had problems with this.
5479stdin:
5480 echo foo[
5481 n=bar
5482 echo "hi[ $n ]=1"
5483expected-stdout:
5484 foo[
5485 hi[ bar ]=1
5486---
5487name: regression-2
5488description:
5489 When PATH is set before running a command, the new path is
5490 not used in doing the path search
5491 $ echo echo hi > /tmp/q ; chmod a+rx /tmp/q
5492 $ PATH=/tmp q
5493 q: not found
5494 $
5495 in comexec() the two lines
5496 while (*vp != NULL)
5497 (void) typeset(*vp++, xxx, 0);
5498 need to be moved out of the switch to before findcom() is
5499 called - I don't know what this will break.
5500stdin:
Elliott Hughes96b43632015-07-17 11:39:41 -07005501 : "${PWD:-`pwd 2> /dev/null`}"
Elliott Hughesfc0307d2016-02-02 15:26:47 -08005502 : "${PWD:?"PWD not set - cannot do test"}"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07005503 mkdir Y
5504 cat > Y/xxxscript << EOF
5505 #!/bin/sh
5506 # Need to restore path so echo can be found (some shells don't have
5507 # it as a built-in)
5508 PATH=\$OLDPATH
5509 echo hi
5510 exit 0
5511 EOF
5512 chmod a+rx Y/xxxscript
5513 export OLDPATH="$PATH"
5514 PATH=$PWD/Y xxxscript
5515 exit $?
5516expected-stdout:
5517 hi
5518---
5519name: regression-6
5520description:
5521 Parsing of $(..) expressions is non-optimal. It is
5522 impossible to have any parentheses inside the expression.
5523 I.e.,
5524 $ ksh -c 'echo $(echo \( )'
5525 no closing quote
5526 $ ksh -c 'echo $(echo "(" )'
5527 no closing quote
5528 $
5529 The solution is to hack the parsing clode in lex.c, the
5530 question is how to hack it: should any parentheses be
5531 escaped by a backslash, or should recursive parsing be done
5532 (so quotes could also be used to hide hem). The former is
5533 easier, the later better...
5534stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005535 echo $(echo \( )
5536 echo $(echo "(" )
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07005537expected-stdout:
5538 (
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005539 (
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07005540---
5541name: regression-9
5542description:
5543 Continue in a for loop does not work right:
5544 for i in a b c ; do
5545 if [ $i = b ] ; then
5546 continue
5547 fi
5548 echo $i
5549 done
5550 Prints a forever...
5551stdin:
5552 first=yes
5553 for i in a b c ; do
5554 if [ $i = b ] ; then
5555 if [ $first = no ] ; then
5556 echo 'continue in for loop broken'
5557 break # hope break isn't broken too :-)
5558 fi
5559 first=no
5560 continue
5561 fi
5562 done
5563 echo bye
5564expected-stdout:
5565 bye
5566---
5567name: regression-10
5568description:
5569 The following:
5570 set -- `false`
5571 echo $?
5572 should print 0 according to POSIX (dash, bash, ksh93, posh)
5573 but not 0 according to the getopt(1) manual page, ksh88, and
5574 Bourne sh (such as /bin/sh on Solaris).
Thorsten Glaser811a5752013-07-25 14:24:45 +00005575 We honour POSIX except when -o sh is set.
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005576category: shell:legacy-no
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07005577stdin:
5578 showf() {
5579 [[ -o posix ]]; FPOSIX=$((1-$?))
5580 [[ -o sh ]]; FSH=$((1-$?))
5581 echo -n "FPOSIX=$FPOSIX FSH=$FSH "
5582 }
5583 set +o posix +o sh
5584 showf
5585 set -- `false`
5586 echo rv=$?
5587 set -o sh
5588 showf
5589 set -- `false`
5590 echo rv=$?
5591 set -o posix
5592 showf
5593 set -- `false`
5594 echo rv=$?
Thorsten Glaser811a5752013-07-25 14:24:45 +00005595 set -o posix -o sh
5596 showf
5597 set -- `false`
5598 echo rv=$?
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07005599expected-stdout:
5600 FPOSIX=0 FSH=0 rv=0
5601 FPOSIX=0 FSH=1 rv=1
5602 FPOSIX=1 FSH=0 rv=0
Thorsten Glaser811a5752013-07-25 14:24:45 +00005603 FPOSIX=1 FSH=1 rv=0
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07005604---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005605name: regression-10-legacy
5606description:
5607 The following:
5608 set -- `false`
5609 echo $?
5610 should print 0 according to POSIX (dash, bash, ksh93, posh)
5611 but not 0 according to the getopt(1) manual page, ksh88, and
5612 Bourne sh (such as /bin/sh on Solaris).
5613category: shell:legacy-yes
5614stdin:
5615 showf() {
5616 [[ -o posix ]]; FPOSIX=$((1-$?))
5617 [[ -o sh ]]; FSH=$((1-$?))
5618 echo -n "FPOSIX=$FPOSIX FSH=$FSH "
5619 }
5620 set +o posix +o sh
5621 showf
5622 set -- `false`
5623 echo rv=$?
5624 set -o sh
5625 showf
5626 set -- `false`
5627 echo rv=$?
5628 set -o posix
5629 showf
5630 set -- `false`
5631 echo rv=$?
Thorsten Glaser811a5752013-07-25 14:24:45 +00005632 set -o posix -o sh
5633 showf
5634 set -- `false`
5635 echo rv=$?
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005636expected-stdout:
5637 FPOSIX=0 FSH=0 rv=1
5638 FPOSIX=0 FSH=1 rv=1
Thorsten Glaser811a5752013-07-25 14:24:45 +00005639 FPOSIX=1 FSH=0 rv=0
5640 FPOSIX=1 FSH=1 rv=0
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005641---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07005642name: regression-11
5643description:
5644 The following:
5645 x=/foo/bar/blah
5646 echo ${x##*/}
5647 should echo blah but on some machines echos /foo/bar/blah.
5648stdin:
5649 x=/foo/bar/blah
5650 echo ${x##*/}
5651expected-stdout:
5652 blah
5653---
5654name: regression-12
5655description:
5656 Both of the following echos produce the same output under sh/ksh.att:
5657 #!/bin/sh
5658 x="foo bar"
5659 echo "`echo \"$x\"`"
5660 echo "`echo "$x"`"
5661 pdksh produces different output for the former (foo instead of foo\tbar)
5662stdin:
5663 x="foo bar"
5664 echo "`echo \"$x\"`"
5665 echo "`echo "$x"`"
5666expected-stdout:
5667 foo bar
5668 foo bar
5669---
5670name: regression-13
5671description:
5672 The following command hangs forever:
5673 $ (: ; cat /etc/termcap) | sleep 2
5674 This is because the shell forks a shell to run the (..) command
5675 and this shell has the pipe open. When the sleep dies, the cat
5676 doesn't get a SIGPIPE 'cause a process (ie, the second shell)
5677 still has the pipe open.
5678
5679 NOTE: this test provokes a bizarre bug in ksh93 (shell starts reading
5680 commands from /etc/termcap..)
5681time-limit: 10
5682stdin:
5683 echo A line of text that will be duplicated quite a number of times.> t1
5684 cat t1 t1 t1 t1 t1 t1 t1 t1 t1 t1 t1 t1 t1 t1 t1 t1 > t2
5685 cat t2 t2 t2 t2 t2 t2 t2 t2 t2 t2 t2 t2 t2 t2 t2 t2 > t1
5686 cat t1 t1 t1 t1 > t2
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00005687 (: ; cat t2 2>/dev/null) | sleep 1
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07005688---
5689name: regression-14
5690description:
5691 The command
5692 $ (foobar) 2> /dev/null
5693 generates no output under /bin/sh, but pdksh produces the error
5694 foobar: not found
5695 Also, the command
5696 $ foobar 2> /dev/null
5697 generates an error under /bin/sh and pdksh, but AT&T ksh88 produces
5698 no error (redirected to /dev/null).
5699stdin:
5700 (you/should/not/see/this/error/1) 2> /dev/null
5701 you/should/not/see/this/error/2 2> /dev/null
5702 true
5703---
5704name: regression-15
5705description:
5706 The command
5707 $ whence foobar
5708 generates a blank line under pdksh and sets the exit status to 0.
5709 AT&T ksh88 generates no output and sets the exit status to 1. Also,
5710 the command
5711 $ whence foobar cat
5712 generates no output under AT&T ksh88 (pdksh generates a blank line
5713 and /bin/cat).
5714stdin:
5715 whence does/not/exist > /dev/null
5716 echo 1: $?
5717 echo 2: $(whence does/not/exist | wc -l)
5718 echo 3: $(whence does/not/exist cat | wc -l)
5719expected-stdout:
5720 1: 1
5721 2: 0
5722 3: 0
5723---
5724name: regression-16
5725description:
5726 ${var%%expr} seems to be broken in many places. On the mips
5727 the commands
5728 $ read line < /etc/passwd
5729 $ echo $line
5730 root:0:1:...
5731 $ echo ${line%%:*}
5732 root
5733 $ echo $line
5734 root
5735 $
5736 change the value of line. On sun4s & pas, the echo ${line%%:*} doesn't
5737 work. Haven't checked elsewhere...
5738script:
5739 read x
5740 y=$x
5741 echo ${x%%:*}
5742 echo $x
5743stdin:
5744 root:asdjhasdasjhs:0:1:Root:/:/bin/sh
5745expected-stdout:
5746 root
5747 root:asdjhasdasjhs:0:1:Root:/:/bin/sh
5748---
5749name: regression-17
5750description:
5751 The command
5752 . /foo/bar
5753 should set the exit status to non-zero (sh and AT&T ksh88 do).
5754 XXX doting a non existent file is a fatal error for a script
5755stdin:
5756 . does/not/exist
5757expected-exit: e != 0
5758expected-stderr-pattern: /.?/
5759---
5760name: regression-19
5761description:
5762 Both of the following echos should produce the same thing, but don't:
5763 $ x=foo/bar
5764 $ echo ${x%/*}
5765 foo
5766 $ echo "${x%/*}"
5767 foo/bar
5768stdin:
5769 x=foo/bar
5770 echo "${x%/*}"
5771expected-stdout:
5772 foo
5773---
5774name: regression-21
5775description:
5776 backslash does not work as expected in case labels:
5777 $ x='-x'
5778 $ case $x in
5779 -\?) echo hi
5780 esac
5781 hi
5782 $ x='-?'
5783 $ case $x in
5784 -\\?) echo hi
5785 esac
5786 hi
5787 $
5788stdin:
5789 case -x in
5790 -\?) echo fail
5791 esac
5792---
5793name: regression-22
5794description:
5795 Quoting backquotes inside backquotes doesn't work:
5796 $ echo `echo hi \`echo there\` folks`
5797 asks for more info. sh and AT&T ksh88 both echo
5798 hi there folks
5799stdin:
5800 echo `echo hi \`echo there\` folks`
5801expected-stdout:
5802 hi there folks
5803---
5804name: regression-23
5805description:
5806 )) is not treated `correctly':
5807 $ (echo hi ; (echo there ; echo folks))
5808 missing ((
5809 $
5810 instead of (as sh and ksh.att)
5811 $ (echo hi ; (echo there ; echo folks))
5812 hi
5813 there
5814 folks
5815 $
5816stdin:
5817 ( : ; ( : ; echo hi))
5818expected-stdout:
5819 hi
5820---
5821name: regression-25
5822description:
5823 Check reading stdin in a while loop. The read should only read
5824 a single line, not a whole stdio buffer; the cat should get
5825 the rest.
5826stdin:
5827 (echo a; echo b) | while read x ; do
5828 echo $x
5829 cat > /dev/null
5830 done
5831expected-stdout:
5832 a
5833---
5834name: regression-26
5835description:
5836 Check reading stdin in a while loop. The read should read both
5837 lines, not just the first.
5838script:
5839 a=
5840 while [ "$a" != xxx ] ; do
5841 last=$x
5842 read x
5843 cat /dev/null | sed 's/x/y/'
5844 a=x$a
5845 done
5846 echo $last
5847stdin:
5848 a
5849 b
5850expected-stdout:
5851 b
5852---
5853name: regression-27
5854description:
5855 The command
5856 . /does/not/exist
5857 should cause a script to exit.
5858stdin:
5859 . does/not/exist
5860 echo hi
5861expected-exit: e != 0
5862expected-stderr-pattern: /does\/not\/exist/
5863---
5864name: regression-28
5865description:
5866 variable assignements not detected well
5867stdin:
5868 a.x=1 echo hi
5869expected-exit: e != 0
5870expected-stderr-pattern: /a\.x=1/
5871---
5872name: regression-29
5873description:
5874 alias expansion different from AT&T ksh88
5875stdin:
5876 alias a='for ' b='i in'
5877 a b hi ; do echo $i ; done
5878expected-stdout:
5879 hi
5880---
5881name: regression-30
5882description:
5883 strange characters allowed inside ${...}
5884stdin:
5885 echo ${a{b}}
5886expected-exit: e != 0
5887expected-stderr-pattern: /.?/
5888---
5889name: regression-31
5890description:
5891 Does read handle partial lines correctly
5892script:
5893 a= ret=
5894 while [ "$a" != xxx ] ; do
5895 read x y z
5896 ret=$?
5897 a=x$a
5898 done
5899 echo "[$x]"
5900 echo $ret
5901stdin: !
5902 a A aA
5903 b B Bb
5904 c
5905expected-stdout:
5906 [c]
5907 1
5908---
5909name: regression-32
5910description:
5911 Does read set variables to null at eof?
5912script:
5913 a=
5914 while [ "$a" != xxx ] ; do
5915 read x y z
5916 a=x$a
5917 done
5918 echo 1: ${x-x not set} ${y-y not set} ${z-z not set}
5919 echo 2: ${x:+x not null} ${y:+y not null} ${z:+z not null}
5920stdin:
5921 a A Aa
5922 b B Bb
5923expected-stdout:
5924 1:
5925 2:
5926---
5927name: regression-33
5928description:
5929 Does umask print a leading 0 when umask is 3 digits?
5930stdin:
Geremy Condra03ebf062011-10-12 18:17:24 -07005931 # on MiNT, the first umask call seems to fail
5932 umask 022
5933 # now, the test proper
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07005934 umask 222
5935 umask
5936expected-stdout:
5937 0222
5938---
5939name: regression-35
5940description:
5941 Tempory files used for here-docs in functions get trashed after
5942 the function is parsed (before it is executed)
5943stdin:
5944 f1() {
5945 cat <<- EOF
5946 F1
5947 EOF
5948 f2() {
5949 cat <<- EOF
5950 F2
5951 EOF
5952 }
5953 }
5954 f1
5955 f2
5956 unset -f f1
5957 f2
5958expected-stdout:
5959 F1
5960 F2
5961 F2
5962---
5963name: regression-36
5964description:
5965 Command substitution breaks reading in while loop
5966 (test from <sjg@void.zen.oz.au>)
5967stdin:
5968 (echo abcdef; echo; echo 123) |
5969 while read line
5970 do
5971 # the following line breaks it
5972 c=`echo $line | wc -c`
5973 echo $c
5974 done
5975expected-stdout:
5976 7
5977 1
5978 4
5979---
5980name: regression-37
5981description:
5982 Machines with broken times() (reported by <sjg@void.zen.oz.au>)
5983 time does not report correct real time
5984stdin:
5985 time sleep 1
5986expected-stderr-pattern: !/^\s*0\.0[\s\d]+real|^\s*real[\s]+0+\.0/
5987---
5988name: regression-38
5989description:
5990 set -e doesn't ignore exit codes for if/while/until/&&/||/!.
5991arguments: !-e!
5992stdin:
5993 if false; then echo hi ; fi
5994 false || true
5995 false && true
5996 while false; do echo hi; done
5997 echo ok
5998expected-stdout:
5999 ok
6000---
6001name: regression-39
6002description:
Thorsten Glaser811a5752013-07-25 14:24:45 +00006003 Only posh and oksh(2013-07) say “hi” below; FreeBSD sh,
6004 GNU bash in POSIX mode, dash, ksh93, mksh don’t. All of
6005 them exit 0. The POSIX behaviour is needed by BSD make.
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006006stdin:
Thorsten Glaser811a5752013-07-25 14:24:45 +00006007 set -e
Elliott Hughes737fdce2014-08-07 12:59:26 -07006008 echo `false; echo hi` $(<this-file-does-not-exist)
Thorsten Glaser811a5752013-07-25 14:24:45 +00006009 echo $?
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006010expected-stdout:
6011
Thorsten Glaser811a5752013-07-25 14:24:45 +00006012 0
Elliott Hughes737fdce2014-08-07 12:59:26 -07006013expected-stderr-pattern: /this-file-does-not-exist/
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006014---
6015name: regression-40
6016description:
6017 This used to cause a core dump
6018env-setup: !RANDOM=12!
6019stdin:
6020 echo hi
6021expected-stdout:
6022 hi
6023---
6024name: regression-41
6025description:
6026 foo should be set to bar (should not be empty)
6027stdin:
6028 foo=`
6029 echo bar`
6030 echo "($foo)"
6031expected-stdout:
6032 (bar)
6033---
6034name: regression-42
6035description:
6036 Can't use command line assignments to assign readonly parameters.
6037stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006038 print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
6039 'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
Elliott Hughes96b43632015-07-17 11:39:41 -07006040 done >env; chmod +x env; PATH=.$PATHSEP$PATH
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006041 foo=bar
6042 readonly foo
6043 foo=stuff env | grep '^foo'
6044expected-exit: e != 0
6045expected-stderr-pattern:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006046 /read-only/
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006047---
6048name: regression-43
6049description:
6050 Can subshells be prefixed by redirections (historical shells allow
6051 this)
6052stdin:
6053 < /dev/null (sed 's/^/X/')
6054---
6055name: regression-45
6056description:
6057 Parameter assignments with [] recognised correctly
6058stdin:
6059 FOO=*[12]
6060 BAR=abc[
6061 MORE=[abc]
6062 JUNK=a[bc
6063 echo "<$FOO>"
6064 echo "<$BAR>"
6065 echo "<$MORE>"
6066 echo "<$JUNK>"
6067expected-stdout:
6068 <*[12]>
6069 <abc[>
6070 <[abc]>
6071 <a[bc>
6072---
6073name: regression-46
6074description:
6075 Check that alias expansion works in command substitutions and
6076 at the end of file.
6077stdin:
6078 alias x='echo hi'
6079 FOO="`x` "
6080 echo "[$FOO]"
6081 x
6082expected-stdout:
6083 [hi ]
6084 hi
6085---
6086name: regression-47
6087description:
6088 Check that aliases are fully read.
6089stdin:
6090 alias x='echo hi;
6091 echo there'
6092 x
6093 echo done
6094expected-stdout:
6095 hi
6096 there
6097 done
6098---
6099name: regression-48
6100description:
6101 Check that (here doc) temp files are not left behind after an exec.
6102stdin:
6103 mkdir foo || exit 1
6104 TMPDIR=$PWD/foo "$__progname" <<- 'EOF'
6105 x() {
6106 sed 's/^/X /' << E_O_F
6107 hi
6108 there
6109 folks
6110 E_O_F
6111 echo "done ($?)"
6112 }
6113 echo=echo; [ -x /bin/echo ] && echo=/bin/echo
6114 exec $echo subtest-1 hi
6115 EOF
6116 echo subtest-1 foo/*
6117 TMPDIR=$PWD/foo "$__progname" <<- 'EOF'
6118 echo=echo; [ -x /bin/echo ] && echo=/bin/echo
6119 sed 's/^/X /' << E_O_F; exec $echo subtest-2 hi
6120 a
6121 few
6122 lines
6123 E_O_F
6124 EOF
6125 echo subtest-2 foo/*
6126expected-stdout:
6127 subtest-1 hi
6128 subtest-1 foo/*
6129 X a
6130 X few
6131 X lines
6132 subtest-2 hi
6133 subtest-2 foo/*
6134---
6135name: regression-49
6136description:
6137 Check that unset params with attributes are reported by set, those
6138 sans attributes are not.
6139stdin:
6140 unset FOO BAR
6141 echo X$FOO
6142 export BAR
6143 typeset -i BLAH
6144 set | grep FOO
6145 set | grep BAR
6146 set | grep BLAH
6147expected-stdout:
6148 X
6149 BAR
6150 BLAH
6151---
6152name: regression-50
6153description:
6154 Check that aliases do not use continuation prompt after trailing
6155 semi-colon.
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006156file-setup: file 644 "envf"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006157 PS1=Y
6158 PS2=X
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006159env-setup: !ENV=./envf!
Geremy Condra03ebf062011-10-12 18:17:24 -07006160need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006161arguments: !-i!
6162stdin:
6163 alias foo='echo hi ; '
6164 foo
6165 foo echo there
6166expected-stdout:
6167 hi
6168 hi
6169 there
6170expected-stderr: !
6171 YYYY
6172---
6173name: regression-51
6174description:
6175 Check that set allows both +o and -o options on same command line.
6176stdin:
6177 set a b c
6178 set -o noglob +o allexport
6179 echo A: $*, *
6180expected-stdout:
6181 A: a b c, *
6182---
6183name: regression-52
6184description:
6185 Check that globbing works in pipelined commands
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006186file-setup: file 644 "envf"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006187 PS1=P
6188file-setup: file 644 "abc"
6189 stuff
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006190env-setup: !ENV=./envf!
Geremy Condra03ebf062011-10-12 18:17:24 -07006191need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006192arguments: !-i!
6193stdin:
6194 sed 's/^/X /' < ab*
6195 echo mark 1
6196 sed 's/^/X /' < ab* | sed 's/^/Y /'
6197 echo mark 2
6198expected-stdout:
6199 X stuff
6200 mark 1
6201 Y X stuff
6202 mark 2
6203expected-stderr: !
6204 PPPPP
6205---
6206name: regression-53
6207description:
6208 Check that getopts works in functions
6209stdin:
6210 bfunc() {
6211 echo bfunc: enter "(args: $*; OPTIND=$OPTIND)"
6212 while getopts B oc; do
6213 case $oc in
6214 (B)
6215 echo bfunc: B option
6216 ;;
6217 (*)
6218 echo bfunc: odd option "($oc)"
6219 ;;
6220 esac
6221 done
6222 echo bfunc: leave
6223 }
6224
6225 function kfunc {
6226 echo kfunc: enter "(args: $*; OPTIND=$OPTIND)"
6227 while getopts K oc; do
6228 case $oc in
6229 (K)
6230 echo kfunc: K option
6231 ;;
6232 (*)
6233 echo bfunc: odd option "($oc)"
6234 ;;
6235 esac
6236 done
6237 echo kfunc: leave
6238 }
6239
6240 set -- -f -b -k -l
6241 echo "line 1: OPTIND=$OPTIND"
6242 getopts kbfl optc
6243 echo "line 2: ret=$?, optc=$optc, OPTIND=$OPTIND"
6244 bfunc -BBB blah
6245 echo "line 3: OPTIND=$OPTIND"
6246 getopts kbfl optc
6247 echo "line 4: ret=$?, optc=$optc, OPTIND=$OPTIND"
6248 kfunc -KKK blah
6249 echo "line 5: OPTIND=$OPTIND"
6250 getopts kbfl optc
6251 echo "line 6: ret=$?, optc=$optc, OPTIND=$OPTIND"
6252 echo
6253
6254 OPTIND=1
6255 set -- -fbkl
6256 echo "line 10: OPTIND=$OPTIND"
6257 getopts kbfl optc
6258 echo "line 20: ret=$?, optc=$optc, OPTIND=$OPTIND"
6259 bfunc -BBB blah
6260 echo "line 30: OPTIND=$OPTIND"
6261 getopts kbfl optc
6262 echo "line 40: ret=$?, optc=$optc, OPTIND=$OPTIND"
6263 kfunc -KKK blah
6264 echo "line 50: OPTIND=$OPTIND"
6265 getopts kbfl optc
6266 echo "line 60: ret=$?, optc=$optc, OPTIND=$OPTIND"
6267expected-stdout:
6268 line 1: OPTIND=1
6269 line 2: ret=0, optc=f, OPTIND=2
6270 bfunc: enter (args: -BBB blah; OPTIND=2)
6271 bfunc: B option
6272 bfunc: B option
6273 bfunc: leave
6274 line 3: OPTIND=2
6275 line 4: ret=0, optc=b, OPTIND=3
6276 kfunc: enter (args: -KKK blah; OPTIND=1)
6277 kfunc: K option
6278 kfunc: K option
6279 kfunc: K option
6280 kfunc: leave
6281 line 5: OPTIND=3
6282 line 6: ret=0, optc=k, OPTIND=4
6283
6284 line 10: OPTIND=1
6285 line 20: ret=0, optc=f, OPTIND=2
6286 bfunc: enter (args: -BBB blah; OPTIND=2)
6287 bfunc: B option
6288 bfunc: B option
6289 bfunc: leave
6290 line 30: OPTIND=2
6291 line 40: ret=1, optc=?, OPTIND=2
6292 kfunc: enter (args: -KKK blah; OPTIND=1)
6293 kfunc: K option
6294 kfunc: K option
6295 kfunc: K option
6296 kfunc: leave
6297 line 50: OPTIND=2
6298 line 60: ret=1, optc=?, OPTIND=2
6299---
6300name: regression-54
6301description:
6302 Check that ; is not required before the then in if (( ... )) then ...
6303stdin:
6304 if (( 1 )) then
6305 echo ok dparen
6306 fi
6307 if [[ -n 1 ]] then
6308 echo ok dbrackets
6309 fi
6310expected-stdout:
6311 ok dparen
6312 ok dbrackets
6313---
6314name: regression-55
6315description:
6316 Check ${foo:%bar} is allowed (ksh88 allows it...)
6317stdin:
6318 x=fooXbarXblah
6319 echo 1 ${x%X*}
6320 echo 2 ${x:%X*}
6321 echo 3 ${x%%X*}
6322 echo 4 ${x:%%X*}
6323 echo 5 ${x#*X}
6324 echo 6 ${x:#*X}
6325 echo 7 ${x##*X}
6326 echo 8 ${x:##*X}
6327expected-stdout:
6328 1 fooXbar
6329 2 fooXbar
6330 3 foo
6331 4 foo
6332 5 barXblah
6333 6 barXblah
6334 7 blah
6335 8 blah
6336---
6337name: regression-57
6338description:
6339 Check if typeset output is correct for
6340 uninitialised array elements.
6341stdin:
6342 typeset -i xxx[4]
6343 echo A
6344 typeset -i | grep xxx | sed 's/^/ /'
6345 echo B
6346 typeset | grep xxx | sed 's/^/ /'
6347
6348 xxx[1]=2+5
6349 echo M
6350 typeset -i | grep xxx | sed 's/^/ /'
6351 echo N
6352 typeset | grep xxx | sed 's/^/ /'
6353expected-stdout:
6354 A
6355 xxx
6356 B
6357 typeset -i xxx
6358 M
6359 xxx[1]=7
6360 N
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006361 set -A xxx
6362 typeset -i xxx[1]
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006363---
6364name: regression-58
6365description:
6366 Check if trap exit is ok (exit not mistaken for signal name)
6367stdin:
6368 trap 'echo hi' exit
6369 trap exit 1
6370expected-stdout:
6371 hi
6372---
6373name: regression-59
6374description:
6375 Check if ${#array[*]} is calculated correctly.
6376stdin:
6377 a[12]=hi
6378 a[8]=there
6379 echo ${#a[*]}
6380expected-stdout:
6381 2
6382---
6383name: regression-60
6384description:
6385 Check if default exit status is previous command
6386stdin:
6387 (true; exit)
6388 echo A $?
6389 (false; exit)
6390 echo B $?
6391 ( (exit 103) ; exit)
6392 echo C $?
6393expected-stdout:
6394 A 0
6395 B 1
6396 C 103
6397---
6398name: regression-61
6399description:
6400 Check if EXIT trap is executed for sub shells.
6401stdin:
6402 trap 'echo parent exit' EXIT
6403 echo start
6404 (echo A; echo A last)
6405 echo B
6406 (echo C; trap 'echo sub exit' EXIT; echo C last)
6407 echo parent last
6408expected-stdout:
6409 start
6410 A
6411 A last
6412 B
6413 C
6414 C last
6415 sub exit
6416 parent last
6417 parent exit
6418---
6419name: regression-62
6420description:
6421 Check if test -nt/-ot succeeds if second(first) file is missing.
6422stdin:
Elliott Hughesa3c3f962017-04-12 16:52:30 -07006423 :>a
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006424 test a -nt b && echo nt OK || echo nt BAD
6425 test b -ot a && echo ot OK || echo ot BAD
6426expected-stdout:
6427 nt OK
6428 ot OK
6429---
6430name: regression-63
6431description:
6432 Check if typeset, export, and readonly work
6433stdin:
6434 {
6435 echo FNORD-0
6436 FNORD_A=1
6437 FNORD_B=2
6438 FNORD_C=3
6439 FNORD_D=4
6440 FNORD_E=5
6441 FNORD_F=6
6442 FNORD_G=7
6443 FNORD_H=8
6444 integer FNORD_E FNORD_F FNORD_G FNORD_H
6445 export FNORD_C FNORD_D FNORD_G FNORD_H
6446 readonly FNORD_B FNORD_D FNORD_F FNORD_H
6447 echo FNORD-1
6448 export
6449 echo FNORD-2
6450 export -p
6451 echo FNORD-3
6452 readonly
6453 echo FNORD-4
6454 readonly -p
6455 echo FNORD-5
6456 typeset
6457 echo FNORD-6
6458 typeset -p
6459 echo FNORD-7
6460 typeset -
6461 echo FNORD-8
6462 } | fgrep FNORD
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006463 fnord=(42 23)
6464 typeset -p fnord
6465 echo FNORD-9
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006466expected-stdout:
6467 FNORD-0
6468 FNORD-1
6469 FNORD_C
6470 FNORD_D
6471 FNORD_G
6472 FNORD_H
6473 FNORD-2
6474 export FNORD_C=3
6475 export FNORD_D=4
6476 export FNORD_G=7
6477 export FNORD_H=8
6478 FNORD-3
6479 FNORD_B
6480 FNORD_D
6481 FNORD_F
6482 FNORD_H
6483 FNORD-4
6484 readonly FNORD_B=2
6485 readonly FNORD_D=4
6486 readonly FNORD_F=6
6487 readonly FNORD_H=8
6488 FNORD-5
6489 typeset FNORD_A
6490 typeset -r FNORD_B
6491 typeset -x FNORD_C
6492 typeset -x -r FNORD_D
6493 typeset -i FNORD_E
6494 typeset -i -r FNORD_F
6495 typeset -i -x FNORD_G
6496 typeset -i -x -r FNORD_H
6497 FNORD-6
6498 typeset FNORD_A=1
6499 typeset -r FNORD_B=2
6500 typeset -x FNORD_C=3
6501 typeset -x -r FNORD_D=4
6502 typeset -i FNORD_E=5
6503 typeset -i -r FNORD_F=6
6504 typeset -i -x FNORD_G=7
6505 typeset -i -x -r FNORD_H=8
6506 FNORD-7
6507 FNORD_A=1
6508 FNORD_B=2
6509 FNORD_C=3
6510 FNORD_D=4
6511 FNORD_E=5
6512 FNORD_F=6
6513 FNORD_G=7
6514 FNORD_H=8
6515 FNORD-8
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006516 set -A fnord
6517 typeset fnord[0]=42
6518 typeset fnord[1]=23
6519 FNORD-9
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006520---
6521name: regression-64
6522description:
6523 Check that we can redefine functions calling time builtin
6524stdin:
6525 t() {
6526 time >/dev/null
6527 }
6528 t 2>/dev/null
6529 t() {
6530 time
6531 }
6532---
Geremy Condra03ebf062011-10-12 18:17:24 -07006533name: regression-65
6534description:
6535 check for a regression with sleep builtin and signal mask
6536category: !nojsig
6537time-limit: 3
6538stdin:
6539 sleep 1
6540 echo blub |&
6541 while read -p line; do :; done
6542 echo ok
6543expected-stdout:
6544 ok
6545---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006546name: regression-66
6547description:
6548 Check that quoting is sane
6549category: !nojsig
6550stdin:
6551 ac_space=' '
6552 ac_newline='
6553 '
6554 set | grep ^ac_ |&
6555 set -A lines
6556 while IFS= read -pr line; do
6557 if [[ $line = *space* ]]; then
6558 lines[0]=$line
6559 else
6560 lines[1]=$line
6561 fi
6562 done
6563 for line in "${lines[@]}"; do
6564 print -r -- "$line"
6565 done
6566expected-stdout:
6567 ac_space=' '
6568 ac_newline=$'\n'
6569---
Elliott Hughes77740fc2016-08-12 15:06:53 -07006570name: regression-67
6571description:
6572 Check that we can both break and use source on the same line
6573stdin:
6574 for s in s; do break; done; print -s s
6575---
6576name: regression-68
6577description:
6578 Check that all common arithmetic operators work as expected
6579stdin:
6580 echo 1 $(( a = 5 )) .
6581 echo 2 $(( ++a )) , $(( a++ )) , $(( a )) .
6582 echo 3 $(( --a )) , $(( a-- )) , $(( a )) .
6583 echo 4 $(( a == 5 )) , $(( a == 6 )) .
6584 echo 5 $(( a != 5 )) , $(( a != 6 )) .
6585 echo 6 $(( a *= 3 )) .
6586 echo 7 $(( a /= 5 )) .
6587 echo 8 $(( a %= 2 )) .
6588 echo 9 $(( a += 9 )) .
6589 echo 10 $(( a -= 4 )) .
6590 echo 11 $(( a <<= 1 )) .
6591 echo 12 $(( a >>= 1 )) .
6592 echo 13 $(( a &= 4 )) .
6593 echo 14 $(( a ^= a )) .
6594 echo 15 $(( a |= 5 )) .
6595 echo 16 $(( 5 << 1 )) .
6596 echo 17 $(( 5 >> 1 )) .
6597 echo 18 $(( 5 <= 6 )) , $(( 5 <= 5 )) , $(( 5 <= 4 )) .
6598 echo 19 $(( 5 >= 6 )) , $(( 5 >= 5 )) , $(( 5 >= 4 )) .
6599 echo 20 $(( 5 < 6 )) , $(( 5 < 5 )) , $(( 5 < 4 )) .
6600 echo 21 $(( 5 > 6 )) , $(( 5 > 5 )) , $(( 5 > 4 )) .
6601 echo 22 $(( 0 && 0 )) , $(( 0 && 1 )) , $(( 1 && 0 )) , $(( 1 && 1 )) .
6602 echo 23 $(( 0 || 0 )) , $(( 0 || 1 )) , $(( 1 || 0 )) , $(( 1 || 1 )) .
6603 echo 24 $(( 5 * 3 )) .
6604 echo 25 $(( 7 / 2 )) .
6605 echo 26 $(( 5 % 5 )) , $(( 5 % 4 )) , $(( 5 % 1 )) , $(( 5 % -1 )) , $(( 5 % -2 )) .
6606 echo 27 $(( 5 + 2 )) , $(( 5 + 0 )) , $(( 5 + -2 )) .
6607 echo 28 $(( 5 - 2 )) , $(( 5 - 0 )) , $(( 5 - -2 )) .
6608 echo 29 $(( 6 & 4 )) , $(( 6 & 8 )) .
6609 echo 30 $(( 4 ^ 2 )) , $(( 4 ^ 4 )) .
6610 echo 31 $(( 4 | 2 )) , $(( 4 | 4 )) , $(( 4 | 0 )) .
6611 echo 32 $(( 0 ? 1 : 2 )) , $(( 3 ? 4 : 5 )) .
6612 echo 33 $(( 5 , 2 , 3 )) .
6613 echo 34 $(( ~0 )) , $(( ~1 )) , $(( ~~1 )) , $(( ~~2 )) .
6614 echo 35 $(( !0 )) , $(( !1 )) , $(( !!1 )) , $(( !!2 )) .
6615 echo 36 $(( (5) )) .
6616expected-stdout:
6617 1 5 .
6618 2 6 , 6 , 7 .
6619 3 6 , 6 , 5 .
6620 4 1 , 0 .
6621 5 0 , 1 .
6622 6 15 .
6623 7 3 .
6624 8 1 .
6625 9 10 .
6626 10 6 .
6627 11 12 .
6628 12 6 .
6629 13 4 .
6630 14 0 .
6631 15 5 .
6632 16 10 .
6633 17 2 .
6634 18 1 , 1 , 0 .
6635 19 0 , 1 , 1 .
6636 20 1 , 0 , 0 .
6637 21 0 , 0 , 1 .
6638 22 0 , 0 , 0 , 1 .
6639 23 0 , 1 , 1 , 1 .
6640 24 15 .
6641 25 3 .
6642 26 0 , 1 , 0 , 0 , 1 .
6643 27 7 , 5 , 3 .
6644 28 3 , 5 , 7 .
6645 29 4 , 0 .
6646 30 6 , 0 .
6647 31 6 , 4 , 4 .
6648 32 2 , 4 .
6649 33 3 .
6650 34 -1 , -2 , 1 , 2 .
6651 35 1 , 0 , 1 , 1 .
6652 36 5 .
6653---
6654name: regression-69
6655description:
6656 Check that all non-lksh arithmetic operators work as expected
6657category: shell:legacy-no
6658stdin:
6659 a=5 b=0x80000005
6660 echo 1 $(( a ^<= 1 )) , $(( b ^<= 1 )) .
6661 echo 2 $(( a ^>= 2 )) , $(( b ^>= 2 )) .
6662 echo 3 $(( 5 ^< 1 )) .
6663 echo 4 $(( 5 ^> 1 )) .
6664expected-stdout:
6665 1 10 , 11 .
6666 2 -2147483646 , -1073741822 .
6667 3 10 .
6668 4 -2147483646 .
6669---
Geremy Condra03ebf062011-10-12 18:17:24 -07006670name: readonly-0
6671description:
6672 Ensure readonly is honoured for assignments and unset
6673stdin:
6674 "$__progname" -c 'u=x; echo $? $u .' || echo aborted, $?
6675 echo =
6676 "$__progname" -c 'readonly u; u=x; echo $? $u .' || echo aborted, $?
6677 echo =
6678 "$__progname" -c 'u=x; readonly u; unset u; echo $? $u .' || echo aborted, $?
6679expected-stdout:
6680 0 x .
6681 =
6682 aborted, 2
6683 =
6684 1 x .
6685expected-stderr-pattern:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006686 /read-only/
Geremy Condra03ebf062011-10-12 18:17:24 -07006687---
6688name: readonly-1
6689description:
6690 http://austingroupbugs.net/view.php?id=367 for export
6691stdin:
6692 "$__progname" -c 'readonly foo; export foo=a; echo $?' || echo aborted, $?
6693expected-stdout:
6694 aborted, 2
6695expected-stderr-pattern:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006696 /read-only/
Geremy Condra03ebf062011-10-12 18:17:24 -07006697---
6698name: readonly-2a
6699description:
6700 Check that getopts works as intended, for readonly-2b to be valid
6701stdin:
6702 "$__progname" -c 'set -- -a b; getopts a c; echo $? $c .; getopts a c; echo $? $c .' || echo aborted, $?
6703expected-stdout:
6704 0 a .
6705 1 ? .
6706---
6707name: readonly-2b
6708description:
6709 http://austingroupbugs.net/view.php?id=367 for getopts
6710stdin:
6711 "$__progname" -c 'readonly c; set -- -a b; getopts a c; echo $? $c .' || echo aborted, $?
6712expected-stdout:
6713 2 .
6714expected-stderr-pattern:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006715 /read-only/
Geremy Condra03ebf062011-10-12 18:17:24 -07006716---
6717name: readonly-3
6718description:
6719 http://austingroupbugs.net/view.php?id=367 for read
6720stdin:
6721 echo x | "$__progname" -c 'read s; echo $? $s .' || echo aborted, $?
6722 echo y | "$__progname" -c 'readonly s; read s; echo $? $s .' || echo aborted, $?
6723expected-stdout:
6724 0 x .
6725 2 .
6726expected-stderr-pattern:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006727 /read-only/
Geremy Condra03ebf062011-10-12 18:17:24 -07006728---
Elliott Hughes737fdce2014-08-07 12:59:26 -07006729name: readonly-4
6730description:
6731 Do not permit bypassing readonly for first array item
6732stdin:
6733 set -A arr -- foo bar
6734 readonly arr
6735 arr=baz
6736 print -r -- "${arr[@]}"
6737expected-exit: e != 0
6738expected-stderr-pattern:
6739 /read[ -]?only/
6740---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006741name: syntax-1
6742description:
6743 Check that lone ampersand is a syntax error
6744stdin:
6745 &
6746expected-exit: e != 0
6747expected-stderr-pattern:
6748 /syntax error/
6749---
6750name: xxx-quoted-newline-1
6751description:
6752 Check that \<newline> works inside of ${}
6753stdin:
6754 abc=2
6755 echo ${ab\
6756 c}
6757expected-stdout:
6758 2
6759---
6760name: xxx-quoted-newline-2
6761description:
6762 Check that \<newline> works at the start of a here document
6763stdin:
6764 cat << EO\
6765 F
6766 hi
6767 EOF
6768expected-stdout:
6769 hi
6770---
6771name: xxx-quoted-newline-3
6772description:
6773 Check that \<newline> works at the end of a here document
6774stdin:
6775 cat << EOF
6776 hi
6777 EO\
6778 F
6779expected-stdout:
6780 hi
6781---
6782name: xxx-multi-assignment-cmd
6783description:
6784 Check that assignments in a command affect subsequent assignments
6785 in the same command
6786stdin:
6787 FOO=abc
6788 FOO=123 BAR=$FOO
6789 echo $BAR
6790expected-stdout:
6791 123
6792---
6793name: xxx-multi-assignment-posix-cmd
6794description:
6795 Check that the behaviour for multiple assignments with a
6796 command name matches POSIX. See:
6797 http://thread.gmane.org/gmane.comp.standards.posix.austin.general/1925
6798stdin:
6799 X=a Y=b; X=$Y Y=$X "$__progname" -c 'echo 1 $X $Y .'; echo 2 $X $Y .
6800 unset X Y Z
6801 X=a Y=${X=b} Z=$X "$__progname" -c 'echo 3 $Z .'
6802 unset X Y Z
6803 X=a Y=${X=b} Z=$X; echo 4 $Z .
6804expected-stdout:
6805 1 b a .
6806 2 a b .
6807 3 b .
6808 4 a .
6809---
6810name: xxx-multi-assignment-posix-nocmd
6811description:
6812 Check that the behaviour for multiple assignments with no
6813 command name matches POSIX (Debian #334182). See:
6814 http://thread.gmane.org/gmane.comp.standards.posix.austin.general/1925
6815stdin:
6816 X=a Y=b; X=$Y Y=$X; echo 1 $X $Y .
6817expected-stdout:
6818 1 b b .
6819---
6820name: xxx-multi-assignment-posix-subassign
6821description:
6822 Check that the behaviour for multiple assignments matches POSIX:
6823 - The assignment words shall be expanded in the current execution
6824 environment.
6825 - The assignments happen in the temporary execution environment.
6826stdin:
6827 unset X Y Z
6828 Z=a Y=${X:=b} sh -c 'echo +$X+ +$Y+ +$Z+'
6829 echo /$X/
6830 # Now for the special case:
6831 unset X Y Z
6832 X= Y=${X:=b} sh -c 'echo +$X+ +$Y+'
6833 echo /$X/
6834expected-stdout:
6835 ++ +b+ +a+
6836 /b/
6837 ++ +b+
6838 /b/
6839---
6840name: xxx-exec-environment-1
6841description:
6842 Check to see if exec sets it's environment correctly
6843stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006844 print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
6845 'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
Elliott Hughes96b43632015-07-17 11:39:41 -07006846 done >env; chmod +x env; PATH=.$PATHSEP$PATH
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006847 FOO=bar exec env
6848expected-stdout-pattern:
6849 /(^|.*\n)FOO=bar\n/
6850---
6851name: xxx-exec-environment-2
6852description:
6853 Check to make sure exec doesn't change environment if a program
6854 isn't exec-ed
6855stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006856 print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
6857 'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
Elliott Hughes96b43632015-07-17 11:39:41 -07006858 done >env; chmod +x env; PATH=.$PATHSEP$PATH
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00006859 env >bar1
6860 FOO=bar exec; env >bar2
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006861 cmp -s bar1 bar2
6862---
6863name: exec-function-environment-1
6864description:
6865 Check assignments in function calls and whether they affect
6866 the current execution environment (ksh93, SUSv4)
6867stdin:
6868 f() { a=2; }; g() { b=3; echo y$c-; }; a=1 f; b=2; c=1 g
6869 echo x$a-$b- z$c-
6870expected-stdout:
6871 y1-
6872 x2-3- z1-
6873---
6874name: xxx-what-do-you-call-this-1
6875stdin:
6876 echo "${foo:-"a"}*"
6877expected-stdout:
6878 a*
6879---
6880name: xxx-prefix-strip-1
6881stdin:
6882 foo='a cdef'
6883 echo ${foo#a c}
6884expected-stdout:
6885 def
6886---
6887name: xxx-prefix-strip-2
6888stdin:
6889 set a c
6890 x='a cdef'
6891 echo ${x#$*}
6892expected-stdout:
6893 def
6894---
6895name: xxx-variable-syntax-1
6896stdin:
6897 echo ${:}
6898expected-stderr-pattern:
6899 /bad substitution/
6900expected-exit: 1
6901---
6902name: xxx-variable-syntax-2
6903stdin:
6904 set 0
6905 echo ${*:0}
6906expected-stderr-pattern:
6907 /bad substitution/
6908expected-exit: 1
6909---
6910name: xxx-variable-syntax-3
6911stdin:
6912 set -A foo 0
6913 echo ${foo[*]:0}
6914expected-stderr-pattern:
6915 /bad substitution/
6916expected-exit: 1
6917---
Elliott Hughesfc0307d2016-02-02 15:26:47 -08006918name: xxx-variable-syntax-4
6919description:
6920 Not all kinds of trims are currently impossible, check those who do
6921stdin:
6922 foo() {
6923 echo "<$*> X${*:+ }X"
6924 }
6925 foo a b
6926 foo "" c
6927 foo ""
6928 foo "" ""
6929 IFS=:
6930 foo a b
6931 foo "" c
6932 foo ""
6933 foo "" ""
6934 IFS=
6935 foo a b
6936 foo "" c
6937 foo ""
6938 foo "" ""
6939expected-stdout:
6940 <a b> X X
6941 < c> X X
6942 <> XX
6943 < > X X
6944 <a:b> X X
6945 <:c> X X
6946 <> XX
6947 <:> X X
6948 <ab> X X
6949 <c> X X
6950 <> XX
6951 <> XX
6952---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006953name: xxx-substitution-eval-order
6954description:
6955 Check order of evaluation of expressions
6956stdin:
6957 i=1 x= y=
6958 set -A A abc def GHI j G k
6959 echo ${A[x=(i+=1)]#${A[y=(i+=2)]}}
6960 echo $x $y
6961expected-stdout:
6962 HI
6963 2 4
6964---
6965name: xxx-set-option-1
6966description:
6967 Check option parsing in set
6968stdin:
6969 set -vsA foo -- A 1 3 2
6970 echo ${foo[*]}
6971expected-stderr:
6972 echo ${foo[*]}
6973expected-stdout:
6974 1 2 3 A
6975---
6976name: xxx-exec-1
6977description:
6978 Check that exec exits for built-ins
Geremy Condra03ebf062011-10-12 18:17:24 -07006979need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07006980arguments: !-i!
6981stdin:
6982 exec echo hi
6983 echo still herre
6984expected-stdout:
6985 hi
6986expected-stderr-pattern: /.*/
6987---
6988name: xxx-while-1
6989description:
6990 Check the return value of while loops
6991 XXX need to do same for for/select/until loops
6992stdin:
6993 i=x
6994 while [ $i != xxx ] ; do
6995 i=x$i
6996 if [ $i = xxx ] ; then
6997 false
6998 continue
6999 fi
7000 done
7001 echo loop1=$?
7002
7003 i=x
7004 while [ $i != xxx ] ; do
7005 i=x$i
7006 if [ $i = xxx ] ; then
7007 false
7008 break
7009 fi
7010 done
7011 echo loop2=$?
7012
7013 i=x
7014 while [ $i != xxx ] ; do
7015 i=x$i
7016 false
7017 done
7018 echo loop3=$?
7019expected-stdout:
7020 loop1=0
7021 loop2=0
7022 loop3=1
7023---
7024name: xxx-status-1
7025description:
7026 Check that blank lines don't clear $?
Geremy Condra03ebf062011-10-12 18:17:24 -07007027need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007028arguments: !-i!
7029stdin:
7030 (exit 1)
7031 echo $?
7032 (exit 1)
7033
7034 echo $?
7035 true
7036expected-stdout:
7037 1
7038 1
7039expected-stderr-pattern: /.*/
7040---
7041name: xxx-status-2
7042description:
7043 Check that $? is preserved in subshells, includes, traps.
7044stdin:
7045 (exit 1)
7046
7047 echo blank: $?
7048
7049 (exit 2)
7050 (echo subshell: $?)
7051
7052 echo 'echo include: $?' > foo
7053 (exit 3)
7054 . ./foo
7055
7056 trap 'echo trap: $?' ERR
7057 (exit 4)
7058 echo exit: $?
7059expected-stdout:
7060 blank: 1
7061 subshell: 2
7062 include: 3
7063 trap: 4
7064 exit: 4
7065---
7066name: xxx-clean-chars-1
7067description:
7068 Check MAGIC character is stuffed correctly
7069stdin:
7070 echo `echo [£`
7071expected-stdout:
7072
7073---
7074name: xxx-param-subst-qmark-1
7075description:
7076 Check suppresion of error message with null string. According to
7077 POSIX, it shouldn't print the error as 'word' isn't ommitted.
Elliott Hughesfc0307d2016-02-02 15:26:47 -08007078 ksh88/93, Solaris /bin/sh and /usr/xpg4/bin/sh all print the error.
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007079stdin:
7080 unset foo
7081 x=
7082 echo x${foo?$x}
7083expected-exit: 1
Elliott Hughesfc0307d2016-02-02 15:26:47 -08007084expected-stderr-pattern: !/not set/
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007085---
Elliott Hughes77740fc2016-08-12 15:06:53 -07007086name: xxx-param-subst-qmark-namespec
7087description:
7088 Check special names are output correctly
7089stdin:
7090 doit() {
7091 "$__progname" -c "$@" >o1 2>o2
7092 rv=$?
7093 echo RETVAL: $rv
7094 sed -e "s^${__progname%.exe}\.*e*x*e*: PROG: " -e 's/^/STDOUT: /g' <o1
7095 sed -e "s^${__progname%.exe}\.*e*x*e*: PROG: " -e 's/^/STDERR: /g' <o2
7096 }
7097 doit 'echo ${1x}'
7098 doit 'echo "${1x}"'
7099 doit 'echo ${1?}'
7100 doit 'echo ${19?}'
7101 doit 'echo ${!:?}'
7102 doit -u 'echo ${*:?}' foo ""
7103expected-stdout:
7104 RETVAL: 1
7105 STDERR: PROG: ${1x}: bad substitution
7106 RETVAL: 1
7107 STDERR: PROG: ${1x}: bad substitution
7108 RETVAL: 1
7109 STDERR: PROG: 1: parameter null or not set
7110 RETVAL: 1
7111 STDERR: PROG: 19: parameter null or not set
7112 RETVAL: 1
7113 STDERR: PROG: !: parameter null or not set
7114 RETVAL: 1
7115 STDERR: foo: ${*:?}: bad substitution
7116---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007117name: xxx-param-_-1
7118# fails due to weirdness of execv stuff
7119category: !os:uwin-nt
7120description:
7121 Check c flag is set.
7122arguments: !-c!echo "[$-]"!
7123expected-stdout-pattern: /^\[.*c.*\]$/
7124---
7125name: tilde-expand-1
7126description:
7127 Check tilde expansion after equal signs
7128env-setup: !HOME=/sweet!
7129stdin:
7130 echo ${A=a=}~ b=~ c=d~ ~
Elliott Hughesfc0307d2016-02-02 15:26:47 -08007131 export e=~ f=d~
7132 command command export g=~ h=d~
7133 echo ". $e . $f ."
7134 echo ". $g . $h ."
7135 set -o posix
7136 unset A e f g h
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007137 echo ${A=a=}~ b=~ c=d~ ~
Elliott Hughesfc0307d2016-02-02 15:26:47 -08007138 export e=~ f=d~
7139 command command export g=~ h=d~
7140 echo ". $e . $f ."
7141 echo ". $g . $h ."
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007142expected-stdout:
7143 a=/sweet b=/sweet c=d~ /sweet
Elliott Hughesfc0307d2016-02-02 15:26:47 -08007144 . /sweet . d~ .
7145 . /sweet . d~ .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007146 a=~ b=~ c=d~ /sweet
Elliott Hughesfc0307d2016-02-02 15:26:47 -08007147 . /sweet . d~ .
7148 . /sweet . d~ .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007149---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007150name: tilde-expand-2
7151description:
7152 Check tilde expansion works
7153env-setup: !HOME=/sweet!
7154stdin:
Elliott Hughesa3c3f962017-04-12 16:52:30 -07007155 :>'c=a'
7156 typeset c=[ab]
7157 :>'d=a'
7158 x=typeset; $x d=[ab]
7159 echo "<$c>" "<$d>"
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007160 wd=$PWD
7161 cd /
7162 plus=$(print -r -- ~+)
7163 minus=$(print -r -- ~-)
7164 nix=$(print -r -- ~)
7165 [[ $plus = / ]]; echo one $? .
7166 [[ $minus = "$wd" ]]; echo two $? .
7167 [[ $nix = /sweet ]]; echo nix $? .
7168expected-stdout:
Elliott Hughesa3c3f962017-04-12 16:52:30 -07007169 <[ab]> <a>
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007170 one 0 .
7171 two 0 .
7172 nix 0 .
7173---
Elliott Hughesa3c3f962017-04-12 16:52:30 -07007174name: tilde-expand-3
7175description:
7176 Check mostly Austin 351 stuff
7177stdin:
7178 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
7179 set "1 b=2" "3 d=4"
7180 export a=$1 \c=$2
7181 showargs 1 "$a" "$b" "$c" "$d"
7182 unset a b c d
7183 HOME=/tmp
7184 export \a=~ b=~
7185 command export c=~
7186 builtin export d=~
7187 \\builtin export e=~
7188 showargs 2 "$a" "$b" "$c" "$d" "$e" ksh
7189 unset a b c d e
7190 set -o posix
7191 export \a=~ b=~
7192 command export c=~
7193 builtin export d=~
7194 \\builtin export e=~
7195 showargs 3 "$a" "$b" "$c" "$d" "$e" posix
7196 unset a b c d e
7197 set +o posix
7198 export a=$1
7199 showargs 4 "$a" "$b" ksh
7200 unset a b
7201 showargs 5 a=$1 ksh
7202 export \a=$1
7203 showargs 6 "$a" "$b" ksh
7204 unset a b
7205 set -o posix
7206 export a=$1
7207 showargs 7 "$a" "$b" posix
7208 unset a b
7209 showargs 8 a=$1 posix
7210 export \a=$1
7211 showargs 9 "$a" "$b" posix
7212 unset a b
7213 set +o posix
7214 command echo 10 ksh a=~
7215 command command export a=~
7216 showargs 11 "$a"
7217 unset a
7218 set -o posix
7219 command echo 12 posix a=~
7220 command command export a=~
7221 showargs 13 "$a"
7222 unset a
7223 # unspecified whether /tmp or ~
7224 var=export; command $var a=~
7225 showargs 14 "$a"
7226 echo 'echo "<$foo>"' >bar
7227 "$__progname" bar
7228 var=foo
7229 export $var=1
7230 "$__progname" bar
7231 export $var=~
7232 "$__progname" bar
7233 # unspecified
7234 command -- export a=~
7235 showargs 18 "$a"
7236 set -A bla
7237 typeset bla[1]=~:~
7238 global gbl=~ g2=$1
7239 local lcl=~ l2=$1
7240 readonly ro=~ r2=$1
7241 showargs 19 "${bla[1]}" a=~ "$gbl" "$lcl" "$ro" "$g2" "$l2" "$r2"
7242 set +o posix
7243 echo "20 some arbitrary stuff "=~
7244 set -o posix
7245 echo "21 some arbitrary stuff "=~
7246expected-stdout:
7247 <1> <1 b=2> <> <3> <4> .
7248 <2> </tmp> </tmp> </tmp> </tmp> </tmp> <ksh> .
7249 <3> <~> </tmp> </tmp> <~> </tmp> <posix> .
7250 <4> <1 b=2> <> <ksh> .
7251 <5> <a=1> <b=2> <ksh> .
7252 <6> <1> <2> <ksh> .
7253 <7> <1 b=2> <> <posix> .
7254 <8> <a=1> <b=2> <posix> .
7255 <9> <1> <2> <posix> .
7256 10 ksh a=/tmp
7257 <11> </tmp> .
7258 12 posix a=~
7259 <13> </tmp> .
7260 <14> <~> .
7261 <>
7262 <1>
7263 <~>
7264 <18> <~> .
7265 <19> </tmp:/tmp> <a=~> </tmp> </tmp> </tmp> <1 b=2> <1 b=2> <1 b=2> .
7266 20 some arbitrary stuff =/tmp
7267 21 some arbitrary stuff =~
7268---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007269name: exit-err-1
7270description:
7271 Check some "exit on error" conditions
7272stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007273 print '#!'"$__progname"'\nexec "$1"' >env
7274 print '#!'"$__progname"'\nexit 1' >false
7275 chmod +x env false
Elliott Hughes96b43632015-07-17 11:39:41 -07007276 PATH=.$PATHSEP$PATH
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007277 set -ex
Geremy Condra03ebf062011-10-12 18:17:24 -07007278 env false && echo something
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007279 echo END
7280expected-stdout:
7281 END
7282expected-stderr:
Geremy Condra03ebf062011-10-12 18:17:24 -07007283 + env false
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007284 + echo END
7285---
7286name: exit-err-2
7287description:
7288 Check some "exit on error" edge conditions (POSIXly)
7289stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007290 print '#!'"$__progname"'\nexec "$1"' >env
7291 print '#!'"$__progname"'\nexit 1' >false
7292 print '#!'"$__progname"'\nexit 0' >true
7293 chmod +x env false
Elliott Hughes96b43632015-07-17 11:39:41 -07007294 PATH=.$PATHSEP$PATH
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007295 set -ex
Geremy Condra03ebf062011-10-12 18:17:24 -07007296 if env true; then
7297 env false && echo something
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007298 fi
7299 echo END
7300expected-stdout:
7301 END
7302expected-stderr:
Geremy Condra03ebf062011-10-12 18:17:24 -07007303 + env true
7304 + env false
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007305 + echo END
7306---
7307name: exit-err-3
7308description:
7309 pdksh regression which AT&T ksh does right
7310 TFM says: [set] -e | errexit
7311 Exit (after executing the ERR trap) ...
7312stdin:
7313 trap 'echo EXIT' EXIT
7314 trap 'echo ERR' ERR
7315 set -e
7316 cd /XXXXX 2>/dev/null
7317 echo DONE
7318 exit 0
7319expected-stdout:
7320 ERR
7321 EXIT
7322expected-exit: e != 0
7323---
7324name: exit-err-4
7325description:
7326 "set -e" test suite (POSIX)
7327stdin:
7328 set -e
7329 echo pre
7330 if true ; then
7331 false && echo foo
7332 fi
7333 echo bar
7334expected-stdout:
7335 pre
7336 bar
7337---
7338name: exit-err-5
7339description:
7340 "set -e" test suite (POSIX)
7341stdin:
7342 set -e
7343 foo() {
7344 while [ "$1" ]; do
7345 for E in $x; do
7346 [ "$1" = "$E" ] && { shift ; continue 2 ; }
7347 done
7348 x="$x $1"
7349 shift
7350 done
7351 echo $x
7352 }
7353 echo pre
7354 foo a b b c
7355 echo post
7356expected-stdout:
7357 pre
7358 a b c
7359 post
7360---
7361name: exit-err-6
7362description:
7363 "set -e" test suite (BSD make)
7364category: os:mirbsd
7365stdin:
7366 mkdir zd zd/a zd/b
7367 print 'all:\n\t@echo eins\n\t@exit 42\n' >zd/a/Makefile
7368 print 'all:\n\t@echo zwei\n' >zd/b/Makefile
7369 wd=$(pwd)
7370 set -e
7371 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"
7372expected-stdout:
7373 ===> a
7374 eins
7375 *** Error code 42
7376
7377 Stop in WD/zd/a (line 2 of Makefile).
7378---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007379name: exit-err-7
7380description:
7381 "set -e" regression (LP#1104543)
7382stdin:
7383 set -e
7384 bla() {
7385 [ -x $PWD/nonexistant ] && $PWD/nonexistant
7386 }
7387 echo x
7388 bla
7389 echo y$?
7390expected-stdout:
7391 x
7392expected-exit: 1
7393---
7394name: exit-err-8
7395description:
7396 "set -e" regression (Debian #700526)
7397stdin:
7398 set -e
7399 _db_cmd() { return $1; }
7400 db_input() { _db_cmd 30; }
7401 db_go() { _db_cmd 0; }
7402 db_input || :
7403 db_go
7404 exit 0
7405---
Elliott Hughes966dd552016-12-08 15:56:04 -08007406name: exit-err-9
7407description:
7408 "set -e" versus bang pipelines
7409stdin:
7410 set -e
7411 ! false | false
7412 echo 1 ok
7413 ! false && false
7414 echo 2 wrong
7415expected-stdout:
7416 1 ok
7417expected-exit: 1
7418---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007419name: exit-enoent-1
7420description:
7421 SUSv4 says that the shell should exit with 126/127 in some situations
7422stdin:
7423 i=0
7424 (echo; echo :) >x
7425 "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7426 "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7427 echo exit 42 >x
7428 "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7429 "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7430 rm -f x
7431 "$__progname" ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7432 "$__progname" -c ./x >/dev/null 2>&1; r=$?; echo $((i++)) $r .
7433expected-stdout:
7434 0 0 .
7435 1 126 .
7436 2 42 .
7437 3 126 .
7438 4 127 .
7439 5 127 .
7440---
7441name: exit-eval-1
7442description:
7443 Check eval vs substitution exit codes (ksh93 alike)
7444stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007445 (exit 12)
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007446 eval $(false)
7447 echo A $?
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007448 (exit 12)
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007449 eval ' $(false)'
7450 echo B $?
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007451 (exit 12)
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007452 eval " $(false)"
7453 echo C $?
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007454 (exit 12)
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007455 eval "eval $(false)"
7456 echo D $?
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007457 (exit 12)
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007458 eval 'eval '"$(false)"
7459 echo E $?
7460 IFS="$IFS:"
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007461 (exit 12)
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007462 eval $(echo :; false)
7463 echo F $?
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007464 echo -n "G "
7465 (exit 12)
7466 eval 'echo $?'
7467 echo H $?
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007468expected-stdout:
7469 A 0
7470 B 1
7471 C 0
7472 D 0
7473 E 0
7474 F 0
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007475 G 12
7476 H 0
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007477---
Geremy Condra03ebf062011-10-12 18:17:24 -07007478name: exit-trap-1
7479description:
7480 Check that "exit" with no arguments behaves SUSv4 conformant.
7481stdin:
7482 trap 'echo hi; exit' EXIT
7483 exit 9
7484expected-stdout:
7485 hi
7486expected-exit: 9
7487---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007488name: exit-trap-2
7489description:
7490 Check that ERR and EXIT traps are run just like ksh93 does.
7491 GNU bash does not run ERtrap in ±e eval-undef but runs it
7492 twice (bug?) in +e eval-false, so does ksh93 (bug?), which
7493 also has a bug to continue execution (echoing "and out" and
7494 returning 0) in +e eval-undef.
7495file-setup: file 644 "x"
7496 v=; unset v
7497 trap 'echo EXtrap' EXIT
7498 trap 'echo ERtrap' ERR
7499 set $1
7500 echo "and run $2"
7501 eval $2
7502 echo and out
7503file-setup: file 644 "xt"
7504 v=; unset v
7505 trap 'echo EXtrap' EXIT
7506 trap 'echo ERtrap' ERR
7507 set $1
7508 echo 'and run true'
7509 true
7510 echo and out
7511file-setup: file 644 "xf"
7512 v=; unset v
7513 trap 'echo EXtrap' EXIT
7514 trap 'echo ERtrap' ERR
7515 set $1
7516 echo 'and run false'
7517 false
7518 echo and out
7519file-setup: file 644 "xu"
7520 v=; unset v
7521 trap 'echo EXtrap' EXIT
7522 trap 'echo ERtrap' ERR
7523 set $1
7524 echo 'and run ${v?}'
7525 ${v?}
7526 echo and out
7527stdin:
7528 runtest() {
7529 rm -f rc
7530 (
7531 "$__progname" "$@"
7532 echo $? >rc
7533 ) 2>&1 | sed \
7534 -e 's/parameter not set/parameter null or not set/' \
7535 -e 's/[[]6]//' -e 's/: eval: line 1//' -e 's/: line 6//' \
7536 -e "s^${__progname%.exe}\.*e*x*e*: <stdin>\[[0-9]*]PROG"
7537 }
7538 xe=-e
7539 echo : $xe
7540 runtest x $xe true
7541 echo = eval-true $(<rc) .
7542 runtest x $xe false
7543 echo = eval-false $(<rc) .
7544 runtest x $xe '${v?}'
7545 echo = eval-undef $(<rc) .
7546 runtest xt $xe
7547 echo = noeval-true $(<rc) .
7548 runtest xf $xe
7549 echo = noeval-false $(<rc) .
7550 runtest xu $xe
7551 echo = noeval-undef $(<rc) .
7552 xe=+e
7553 echo : $xe
7554 runtest x $xe true
7555 echo = eval-true $(<rc) .
7556 runtest x $xe false
7557 echo = eval-false $(<rc) .
7558 runtest x $xe '${v?}'
7559 echo = eval-undef $(<rc) .
7560 runtest xt $xe
7561 echo = noeval-true $(<rc) .
7562 runtest xf $xe
7563 echo = noeval-false $(<rc) .
7564 runtest xu $xe
7565 echo = noeval-undef $(<rc) .
7566expected-stdout:
7567 : -e
7568 and run true
7569 and out
7570 EXtrap
7571 = eval-true 0 .
7572 and run false
7573 ERtrap
7574 EXtrap
7575 = eval-false 1 .
7576 and run ${v?}
7577 x: v: parameter null or not set
7578 ERtrap
7579 EXtrap
7580 = eval-undef 1 .
7581 and run true
7582 and out
7583 EXtrap
7584 = noeval-true 0 .
7585 and run false
7586 ERtrap
7587 EXtrap
7588 = noeval-false 1 .
7589 and run ${v?}
7590 xu: v: parameter null or not set
7591 EXtrap
7592 = noeval-undef 1 .
7593 : +e
7594 and run true
7595 and out
7596 EXtrap
7597 = eval-true 0 .
7598 and run false
7599 ERtrap
7600 and out
7601 EXtrap
7602 = eval-false 0 .
7603 and run ${v?}
7604 x: v: parameter null or not set
7605 ERtrap
7606 EXtrap
7607 = eval-undef 1 .
7608 and run true
7609 and out
7610 EXtrap
7611 = noeval-true 0 .
7612 and run false
7613 ERtrap
7614 and out
7615 EXtrap
7616 = noeval-false 0 .
7617 and run ${v?}
7618 xu: v: parameter null or not set
7619 EXtrap
7620 = noeval-undef 1 .
7621---
Thorsten Glaser811a5752013-07-25 14:24:45 +00007622name: exit-trap-interactive
7623description:
7624 Check that interactive shell doesn't exit via EXIT trap on syntax error
7625arguments: !-i!
7626stdin:
7627 trap -- EXIT
7628 echo Syntax error <
7629 echo 'After error 1'
7630 trap 'echo Exit trap' EXIT
7631 echo Syntax error <
7632 echo 'After error 2'
7633 trap 'echo Exit trap' EXIT
7634 exit
7635 echo 'After exit'
7636expected-stdout:
7637 After error 1
7638 After error 2
7639 Exit trap
7640expected-stderr-pattern:
Elliott Hughesa3c3f962017-04-12 16:52:30 -07007641 /syntax error: unexpected 'newline'/
Thorsten Glaser811a5752013-07-25 14:24:45 +00007642---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007643name: test-stlt-1
7644description:
7645 Check that test also can handle string1 < string2 etc.
7646stdin:
7647 test 2005/10/08 '<' 2005/08/21 && echo ja || echo nein
7648 test 2005/08/21 \< 2005/10/08 && echo ja || echo nein
7649 test 2005/10/08 '>' 2005/08/21 && echo ja || echo nein
7650 test 2005/08/21 \> 2005/10/08 && echo ja || echo nein
7651expected-stdout:
7652 nein
7653 ja
7654 ja
7655 nein
7656expected-stderr-pattern: !/unexpected op/
7657---
7658name: test-precedence-1
7659description:
7660 Check a weird precedence case (and POSIX echo)
7661stdin:
7662 test \( -f = -f \)
7663 rv=$?
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007664 echo $rv
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007665expected-stdout:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00007666 0
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007667---
7668name: test-option-1
7669description:
7670 Test the test -o operator
7671stdin:
7672 runtest() {
7673 test -o $1; echo $?
7674 [ -o $1 ]; echo $?
7675 [[ -o $1 ]]; echo $?
7676 }
7677 if_test() {
7678 test -o $1 -o -o !$1; echo $?
7679 [ -o $1 -o -o !$1 ]; echo $?
7680 [[ -o $1 || -o !$1 ]]; echo $?
7681 test -o ?$1; echo $?
7682 }
7683 echo 0y $(if_test utf8-mode) =
7684 echo 0n $(if_test utf8-hack) =
7685 echo 1= $(runtest utf8-hack) =
7686 echo 2= $(runtest !utf8-hack) =
7687 echo 3= $(runtest ?utf8-hack) =
7688 set +U
7689 echo 1+ $(runtest utf8-mode) =
7690 echo 2+ $(runtest !utf8-mode) =
7691 echo 3+ $(runtest ?utf8-mode) =
7692 set -U
7693 echo 1- $(runtest utf8-mode) =
7694 echo 2- $(runtest !utf8-mode) =
7695 echo 3- $(runtest ?utf8-mode) =
7696 echo = short flags =
7697 echo 0y $(if_test -U) =
7698 echo 0y $(if_test +U) =
7699 echo 0n $(if_test -_) =
7700 echo 0n $(if_test -U-) =
7701 echo 1= $(runtest -_) =
7702 echo 2= $(runtest !-_) =
7703 echo 3= $(runtest ?-_) =
7704 set +U
7705 echo 1+ $(runtest -U) =
7706 echo 2+ $(runtest !-U) =
7707 echo 3+ $(runtest ?-U) =
7708 echo 1+ $(runtest +U) =
7709 echo 2+ $(runtest !+U) =
7710 echo 3+ $(runtest ?+U) =
7711 set -U
7712 echo 1- $(runtest -U) =
7713 echo 2- $(runtest !-U) =
7714 echo 3- $(runtest ?-U) =
7715 echo 1- $(runtest +U) =
7716 echo 2- $(runtest !+U) =
7717 echo 3- $(runtest ?+U) =
7718expected-stdout:
7719 0y 0 0 0 0 =
7720 0n 1 1 1 1 =
7721 1= 1 1 1 =
7722 2= 1 1 1 =
7723 3= 1 1 1 =
7724 1+ 1 1 1 =
7725 2+ 0 0 0 =
7726 3+ 0 0 0 =
7727 1- 0 0 0 =
7728 2- 1 1 1 =
7729 3- 0 0 0 =
7730 = short flags =
7731 0y 0 0 0 0 =
7732 0y 0 0 0 0 =
7733 0n 1 1 1 1 =
7734 0n 1 1 1 1 =
7735 1= 1 1 1 =
7736 2= 1 1 1 =
7737 3= 1 1 1 =
7738 1+ 1 1 1 =
7739 2+ 0 0 0 =
7740 3+ 0 0 0 =
7741 1+ 1 1 1 =
7742 2+ 0 0 0 =
7743 3+ 0 0 0 =
7744 1- 0 0 0 =
7745 2- 1 1 1 =
7746 3- 0 0 0 =
7747 1- 0 0 0 =
7748 2- 1 1 1 =
7749 3- 0 0 0 =
7750---
Elliott Hughesa3c3f962017-04-12 16:52:30 -07007751name: test-varset-1
7752description:
7753 Test the test -v operator
7754stdin:
7755 [[ -v a ]]
7756 rv=$?; echo $((++i)) $rv
7757 a=
7758 [[ -v a ]]
7759 rv=$?; echo $((++i)) $rv
7760 unset a
7761 [[ -v a ]]
7762 rv=$?; echo $((++i)) $rv
7763 a=x
7764 [[ -v a ]]
7765 rv=$?; echo $((++i)) $rv
7766 nameref b=a
7767 [[ -v b ]]
7768 rv=$?; echo $((++i)) $rv
7769 unset a
7770 [[ -v b ]]
7771 rv=$?; echo $((++i)) $rv
7772 x[1]=y
7773 [[ -v x ]]
7774 rv=$?; echo $((++i)) $rv
7775 [[ -v x[0] ]]
7776 rv=$?; echo $((++i)) $rv
7777 [[ -v x[1] ]]
7778 rv=$?; echo $((++i)) $rv
7779 [[ -v x[2] ]]
7780 rv=$?; echo $((++i)) $rv
7781expected-stdout:
7782 1 1
7783 2 0
7784 3 1
7785 4 0
7786 5 0
7787 6 1
7788 7 1
7789 8 1
7790 9 0
7791 10 1
7792---
7793name: test-varset-2
7794description:
7795 test -v works only on scalars
7796stdin:
7797 [[ -v x[*] ]]
7798 echo ok
7799expected-exit: e != 0
7800expected-stderr-pattern:
7801 /unexpected '\*'/
7802---
Elliott Hughesfc0307d2016-02-02 15:26:47 -08007803name: test-stnze-1
7804description:
7805 Check that the short form [ $x ] works
7806stdin:
7807 i=0
7808 [ -n $x ]
7809 rv=$?; echo $((++i)) $rv
7810 [ $x ]
7811 rv=$?; echo $((++i)) $rv
7812 [ -n "$x" ]
7813 rv=$?; echo $((++i)) $rv
7814 [ "$x" ]
7815 rv=$?; echo $((++i)) $rv
7816 x=0
7817 [ -n $x ]
7818 rv=$?; echo $((++i)) $rv
7819 [ $x ]
7820 rv=$?; echo $((++i)) $rv
7821 [ -n "$x" ]
7822 rv=$?; echo $((++i)) $rv
7823 [ "$x" ]
7824 rv=$?; echo $((++i)) $rv
7825 x='1 -a 1 = 2'
7826 [ -n $x ]
7827 rv=$?; echo $((++i)) $rv
7828 [ $x ]
7829 rv=$?; echo $((++i)) $rv
7830 [ -n "$x" ]
7831 rv=$?; echo $((++i)) $rv
7832 [ "$x" ]
7833 rv=$?; echo $((++i)) $rv
7834expected-stdout:
7835 1 0
7836 2 1
7837 3 1
7838 4 1
7839 5 0
7840 6 0
7841 7 0
7842 8 0
7843 9 1
7844 10 1
7845 11 0
7846 12 0
7847---
7848name: test-stnze-2
7849description:
7850 Check that the short form [[ $x ]] works (ksh93 extension)
7851stdin:
7852 i=0
7853 [[ -n $x ]]
7854 rv=$?; echo $((++i)) $rv
7855 [[ $x ]]
7856 rv=$?; echo $((++i)) $rv
7857 [[ -n "$x" ]]
7858 rv=$?; echo $((++i)) $rv
7859 [[ "$x" ]]
7860 rv=$?; echo $((++i)) $rv
7861 x=0
7862 [[ -n $x ]]
7863 rv=$?; echo $((++i)) $rv
7864 [[ $x ]]
7865 rv=$?; echo $((++i)) $rv
7866 [[ -n "$x" ]]
7867 rv=$?; echo $((++i)) $rv
7868 [[ "$x" ]]
7869 rv=$?; echo $((++i)) $rv
7870 x='1 -a 1 = 2'
7871 [[ -n $x ]]
7872 rv=$?; echo $((++i)) $rv
7873 [[ $x ]]
7874 rv=$?; echo $((++i)) $rv
7875 [[ -n "$x" ]]
7876 rv=$?; echo $((++i)) $rv
7877 [[ "$x" ]]
7878 rv=$?; echo $((++i)) $rv
7879expected-stdout:
7880 1 1
7881 2 1
7882 3 1
7883 4 1
7884 5 0
7885 6 0
7886 7 0
7887 8 0
7888 9 0
7889 10 0
7890 11 0
7891 12 0
7892---
7893name: test-numeq
7894description:
7895 Check numeric -eq works (R40d regression); spotted by Martijn Dekker
7896stdin:
7897 tst() {
7898 eval "$2"
7899 case $? in
7900 (0) echo yepp 0 \#"$*" ;;
7901 (1) echo nope 1 \#"$*" ;;
7902 (2) echo terr 2 \#"$*" ;;
7903 (*) echo wtf\? $? \#"$*" ;;
7904 esac
7905 }
7906 tst 1 'test 2 -eq 2'
7907 tst 2 'test 2 -eq 2a'
7908 tst 3 'test 2 -eq 3'
7909 tst 4 'test 2 -ne 2'
7910 tst 5 'test 2 -ne 2a'
7911 tst 6 'test 2 -ne 3'
7912 tst 7 'test \! 2 -eq 2'
7913 tst 8 'test \! 2 -eq 2a'
7914 tst 9 'test \! 2 -eq 3'
7915expected-stdout:
7916 yepp 0 #1 test 2 -eq 2
7917 terr 2 #2 test 2 -eq 2a
7918 nope 1 #3 test 2 -eq 3
7919 nope 1 #4 test 2 -ne 2
7920 terr 2 #5 test 2 -ne 2a
7921 yepp 0 #6 test 2 -ne 3
7922 nope 1 #7 test \! 2 -eq 2
7923 terr 2 #8 test \! 2 -eq 2a
7924 yepp 0 #9 test \! 2 -eq 3
7925expected-stderr-pattern:
7926 /bad number/
7927---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007928name: mkshrc-1
7929description:
7930 Check that ~/.mkshrc works correctly.
7931 Part 1: verify user environment is not read (internal)
7932stdin:
7933 echo x $FNORD
7934expected-stdout:
7935 x
7936---
7937name: mkshrc-2a
7938description:
7939 Check that ~/.mkshrc works correctly.
7940 Part 2: verify mkshrc is not read (non-interactive shells)
7941file-setup: file 644 ".mkshrc"
7942 FNORD=42
7943env-setup: !HOME=.!ENV=!
7944stdin:
7945 echo x $FNORD
7946expected-stdout:
7947 x
7948---
7949name: mkshrc-2b
7950description:
7951 Check that ~/.mkshrc works correctly.
7952 Part 2: verify mkshrc can be read (interactive shells)
7953file-setup: file 644 ".mkshrc"
7954 FNORD=42
Geremy Condra03ebf062011-10-12 18:17:24 -07007955need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07007956arguments: !-i!
7957env-setup: !HOME=.!ENV=!PS1=!
7958stdin:
7959 echo x $FNORD
7960expected-stdout:
7961 x 42
7962expected-stderr-pattern:
7963 /(# )*/
7964---
7965name: mkshrc-3
7966description:
7967 Check that ~/.mkshrc works correctly.
7968 Part 3: verify mkshrc can be turned off
7969file-setup: file 644 ".mkshrc"
7970 FNORD=42
7971env-setup: !HOME=.!ENV=nonexistant!
7972stdin:
7973 echo x $FNORD
7974expected-stdout:
7975 x
7976---
7977name: sh-mode-1
7978description:
7979 Check that sh mode turns braceexpand off
7980 and that that works correctly
7981stdin:
7982 set -o braceexpand
7983 set +o sh
7984 [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
7985 [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
7986 echo {a,b,c}
7987 set +o braceexpand
7988 echo {a,b,c}
7989 set -o braceexpand
7990 echo {a,b,c}
7991 set -o sh
7992 echo {a,b,c}
7993 [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
7994 [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
7995 set -o braceexpand
7996 echo {a,b,c}
7997 [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
7998 [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
7999expected-stdout:
8000 nosh
8001 brex
8002 a b c
8003 {a,b,c}
8004 a b c
8005 {a,b,c}
8006 sh
8007 nobrex
8008 a b c
8009 sh
8010 brex
8011---
8012name: sh-mode-2a
8013description:
Thorsten Glaser811a5752013-07-25 14:24:45 +00008014 Check that posix or sh mode is *not* automatically turned on
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008015category: !binsh
8016stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00008017 ln -s "$__progname" ksh || cp "$__progname" ksh
8018 ln -s "$__progname" sh || cp "$__progname" sh
8019 ln -s "$__progname" ./-ksh || cp "$__progname" ./-ksh
8020 ln -s "$__progname" ./-sh || cp "$__progname" ./-sh
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008021 for shell in {,-}{,k}sh; do
8022 print -- $shell $(./$shell +l -c \
Thorsten Glaser811a5752013-07-25 14:24:45 +00008023 '[[ $(set +o) == *"-o "@(sh|posix)@(| *) ]] && echo sh || echo nosh')
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008024 done
8025expected-stdout:
8026 sh nosh
8027 ksh nosh
8028 -sh nosh
8029 -ksh nosh
8030---
8031name: sh-mode-2b
8032description:
Thorsten Glaser811a5752013-07-25 14:24:45 +00008033 Check that posix or sh mode *is* automatically turned on
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008034category: binsh
8035stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00008036 ln -s "$__progname" ksh || cp "$__progname" ksh
8037 ln -s "$__progname" sh || cp "$__progname" sh
8038 ln -s "$__progname" ./-ksh || cp "$__progname" ./-ksh
8039 ln -s "$__progname" ./-sh || cp "$__progname" ./-sh
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008040 for shell in {,-}{,k}sh; do
8041 print -- $shell $(./$shell +l -c \
Thorsten Glaser811a5752013-07-25 14:24:45 +00008042 '[[ $(set +o) == *"-o "@(sh|posix)@(| *) ]] && echo sh || echo nosh')
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008043 done
8044expected-stdout:
8045 sh sh
8046 ksh nosh
8047 -sh sh
8048 -ksh nosh
8049---
8050name: pipeline-1
8051description:
8052 pdksh bug: last command of a pipeline is executed in a
8053 subshell - make sure it still is, scripts depend on it
8054file-setup: file 644 "abcx"
8055file-setup: file 644 "abcy"
8056stdin:
8057 echo *
8058 echo a | while read d; do
8059 echo $d
8060 echo $d*
8061 echo *
8062 set -o noglob
8063 echo $d*
8064 echo *
8065 done
8066 echo *
8067expected-stdout:
8068 abcx abcy
8069 a
8070 abcx abcy
8071 abcx abcy
8072 a*
8073 *
8074 abcx abcy
8075---
8076name: pipeline-2
8077description:
8078 check that co-processes work with TCOMs, TPIPEs and TPARENs
Geremy Condra03ebf062011-10-12 18:17:24 -07008079category: !nojsig
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008080stdin:
8081 "$__progname" -c 'i=100; echo hi |& while read -p line; do echo "$((i++)) $line"; done'
8082 "$__progname" -c 'i=200; echo hi | cat |& while read -p line; do echo "$((i++)) $line"; done'
8083 "$__progname" -c 'i=300; (echo hi | cat) |& while read -p line; do echo "$((i++)) $line"; done'
8084expected-stdout:
8085 100 hi
8086 200 hi
8087 300 hi
8088---
Geremy Condra03ebf062011-10-12 18:17:24 -07008089name: pipeline-3
8090description:
8091 Check that PIPESTATUS does what it's supposed to
8092stdin:
8093 echo 1 $PIPESTATUS .
8094 echo 2 ${PIPESTATUS[0]} .
8095 echo 3 ${PIPESTATUS[1]} .
8096 (echo x; exit 12) | (cat; exit 23) | (cat; exit 42)
8097 echo 5 $? , $PIPESTATUS , ${PIPESTATUS[0]} , ${PIPESTATUS[1]} , ${PIPESTATUS[2]} , ${PIPESTATUS[3]} .
8098 echo 6 ${PIPESTATUS[0]} .
8099 set | fgrep PIPESTATUS
8100 echo 8 $(set | fgrep PIPESTATUS) .
8101expected-stdout:
8102 1 0 .
8103 2 0 .
8104 3 .
8105 x
8106 5 42 , 12 , 12 , 23 , 42 , .
8107 6 0 .
8108 PIPESTATUS[0]=0
8109 8 PIPESTATUS[0]=0 PIPESTATUS[1]=0 .
8110---
Thorsten Glaser811a5752013-07-25 14:24:45 +00008111name: pipeline-4
8112description:
8113 Check that "set -o pipefail" does what it's supposed to
8114stdin:
8115 echo 1 "$("$__progname" -c '(exit 12) | (exit 23) | (exit 42); echo $?')" .
8116 echo 2 "$("$__progname" -c '! (exit 12) | (exit 23) | (exit 42); echo $?')" .
8117 echo 3 "$("$__progname" -o pipefail -c '(exit 12) | (exit 23) | (exit 42); echo $?')" .
8118 echo 4 "$("$__progname" -o pipefail -c '! (exit 12) | (exit 23) | (exit 42); echo $?')" .
8119 echo 5 "$("$__progname" -c '(exit 23) | (exit 42) | :; echo $?')" .
8120 echo 6 "$("$__progname" -c '! (exit 23) | (exit 42) | :; echo $?')" .
8121 echo 7 "$("$__progname" -o pipefail -c '(exit 23) | (exit 42) | :; echo $?')" .
8122 echo 8 "$("$__progname" -o pipefail -c '! (exit 23) | (exit 42) | :; echo $?')" .
Elliott Hughes737fdce2014-08-07 12:59:26 -07008123 echo 9 "$("$__progname" -o pipefail -c 'x=$( (exit 23) | (exit 42) | :); echo $?')" .
Thorsten Glaser811a5752013-07-25 14:24:45 +00008124expected-stdout:
8125 1 42 .
8126 2 0 .
8127 3 42 .
8128 4 0 .
8129 5 0 .
8130 6 1 .
8131 7 42 .
8132 8 0 .
Elliott Hughes737fdce2014-08-07 12:59:26 -07008133 9 42 .
Thorsten Glaser811a5752013-07-25 14:24:45 +00008134---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008135name: persist-history-1
8136description:
8137 Check if persistent history saving works
8138category: !no-histfile
Geremy Condra03ebf062011-10-12 18:17:24 -07008139need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008140arguments: !-i!
8141env-setup: !ENV=./Env!HISTFILE=hist.file!
8142file-setup: file 644 "Env"
8143 PS1=X
8144stdin:
8145 cat hist.file
8146expected-stdout-pattern:
8147 /cat hist.file/
8148expected-stderr-pattern:
8149 /^X*$/
8150---
Geremy Condra03ebf062011-10-12 18:17:24 -07008151name: typeset-1
8152description:
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008153 Check that typeset -g works correctly
Geremy Condra03ebf062011-10-12 18:17:24 -07008154stdin:
8155 set -A arrfoo 65
8156 foo() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008157 typeset -g -Uui16 arrfoo[*]
Geremy Condra03ebf062011-10-12 18:17:24 -07008158 }
8159 echo before ${arrfoo[0]} .
8160 foo
8161 echo after ${arrfoo[0]} .
8162 set -A arrbar 65
8163 bar() {
8164 echo inside before ${arrbar[0]} .
8165 arrbar[0]=97
8166 echo inside changed ${arrbar[0]} .
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008167 typeset -g -Uui16 arrbar[*]
Geremy Condra03ebf062011-10-12 18:17:24 -07008168 echo inside typeset ${arrbar[0]} .
8169 arrbar[0]=48
8170 echo inside changed ${arrbar[0]} .
8171 }
8172 echo before ${arrbar[0]} .
8173 bar
8174 echo after ${arrbar[0]} .
8175expected-stdout:
8176 before 65 .
8177 after 16#41 .
8178 before 65 .
8179 inside before 65 .
8180 inside changed 97 .
8181 inside typeset 16#61 .
8182 inside changed 16#30 .
8183 after 16#30 .
8184---
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008185name: typeset-2
8186description:
8187 Check that typeset -p on arrays works correctly
8188stdin:
8189 set -A x -- a b c
8190 echo =
8191 typeset -p x
8192 echo =
8193 typeset -p x[1]
8194expected-stdout:
8195 =
8196 set -A x
8197 typeset x[0]=a
8198 typeset x[1]=b
8199 typeset x[2]=c
8200 =
8201 typeset x[1]=b
8202---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008203name: typeset-padding-1
8204description:
8205 Check if left/right justification works as per TFM
8206stdin:
8207 typeset -L10 ln=0hall0
8208 typeset -R10 rn=0hall0
8209 typeset -ZL10 lz=0hall0
8210 typeset -ZR10 rz=0hall0
8211 typeset -Z10 rx=" hallo "
8212 echo "<$ln> <$rn> <$lz> <$rz> <$rx>"
8213expected-stdout:
8214 <0hall0 > < 0hall0> <hall0 > <00000hall0> <0000 hallo>
8215---
8216name: typeset-padding-2
8217description:
8218 Check if base-!10 integers are padded right
8219stdin:
8220 typeset -Uui16 -L9 ln=16#1
8221 typeset -Uui16 -R9 rn=16#1
8222 typeset -Uui16 -Z9 zn=16#1
8223 typeset -L9 ls=16#1
8224 typeset -R9 rs=16#1
8225 typeset -Z9 zs=16#1
8226 echo "<$ln> <$rn> <$zn> <$ls> <$rs> <$zs>"
8227expected-stdout:
8228 <16#1 > < 16#1> <16#000001> <16#1 > < 16#1> <0000016#1>
8229---
8230name: utf8bom-1
8231description:
8232 Check that the UTF-8 Byte Order Mark is ignored as the first
8233 multibyte character of the shell input (with -c, from standard
8234 input, as file, or as eval argument), but nowhere else
8235# breaks on Mac OSX (HFS+ non-standard Unicode canonical decomposition)
8236category: !os:darwin
8237stdin:
8238 mkdir foo
8239 print '#!/bin/sh\necho ohne' >foo/fnord
8240 print '#!/bin/sh\necho mit' >foo/fnord
8241 print 'fnord\nfnord\nfnord\nfnord' >foo/bar
8242 print eval \''fnord\nfnord\nfnord\nfnord'\' >foo/zoo
8243 set -A anzahl -- foo/*
8244 echo got ${#anzahl[*]} files
8245 chmod +x foo/*
Elliott Hughes96b43632015-07-17 11:39:41 -07008246 export PATH=$(pwd)/foo$PATHSEP$PATH
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008247 "$__progname" -c 'fnord'
8248 echo =
8249 "$__progname" -c 'fnord; fnord; fnord; fnord'
8250 echo =
8251 "$__progname" foo/bar
8252 echo =
8253 "$__progname" <foo/bar
8254 echo =
8255 "$__progname" foo/zoo
8256 echo =
8257 "$__progname" -c 'echo : $(fnord)'
8258 rm -rf foo
8259expected-stdout:
8260 got 4 files
8261 ohne
8262 =
8263 ohne
8264 ohne
8265 mit
8266 ohne
8267 =
8268 ohne
8269 ohne
8270 mit
8271 ohne
8272 =
8273 ohne
8274 ohne
8275 mit
8276 ohne
8277 =
8278 ohne
8279 ohne
8280 mit
8281 ohne
8282 =
Geremy Condra03ebf062011-10-12 18:17:24 -07008283 : ohne
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008284---
8285name: utf8bom-2
8286description:
8287 Check that we can execute BOM-shebangs (failures not fatal)
8288 XXX if the OS can already execute them, we lose
8289 note: cygwin execve(2) doesn't return to us with ENOEXEC, we lose
8290 note: Ultrix perl5 t4 returns 65280 (exit-code 255) and no text
Elliott Hughes50012062015-03-10 22:22:24 -07008291 XXX fails when LD_PRELOAD is set with -e and Perl chokes it (ASan)
Geremy Condra03ebf062011-10-12 18:17:24 -07008292need-pass: no
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00008293category: !os:cygwin,!os:msys,!os:ultrix,!os:uwin-nt,!smksh
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008294env-setup: !FOO=BAR!
8295stdin:
8296 print '#!'"$__progname"'\nprint "1 a=$ENV{FOO}";' >t1
8297 print '#!'"$__progname"'\nprint "2 a=$ENV{FOO}";' >t2
8298 print '#!'"$__perlname"'\nprint "3 a=$ENV{FOO}\n";' >t3
8299 print '#!'"$__perlname"'\nprint "4 a=$ENV{FOO}\n";' >t4
8300 chmod +x t?
8301 ./t1
8302 ./t2
8303 ./t3
8304 ./t4
8305expected-stdout:
8306 1 a=/nonexistant{FOO}
8307 2 a=/nonexistant{FOO}
8308 3 a=BAR
8309 4 a=BAR
8310expected-stderr-pattern:
8311 /(Unrecognized character .... ignored at \..t4 line 1)*/
8312---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008313name: utf8opt-1a
8314description:
8315 Check that the utf8-mode flag is not set at non-interactive startup
8316category: !os:hpux
8317env-setup: !PS1=!PS2=!LC_CTYPE=en_US.UTF-8!
8318stdin:
8319 if [[ $- = *U* ]]; then
8320 echo is set
8321 else
8322 echo is not set
8323 fi
8324expected-stdout:
8325 is not set
8326---
8327name: utf8opt-1b
8328description:
8329 Check that the utf8-mode flag is not set at non-interactive startup
8330category: os:hpux
8331env-setup: !PS1=!PS2=!LC_CTYPE=en_US.utf8!
8332stdin:
8333 if [[ $- = *U* ]]; then
8334 echo is set
8335 else
8336 echo is not set
8337 fi
8338expected-stdout:
8339 is not set
8340---
8341name: utf8opt-2a
8342description:
8343 Check that the utf8-mode flag is set at interactive startup.
8344 -DMKSH_ASSUME_UTF8=0 => expected failure, please ignore
8345 -DMKSH_ASSUME_UTF8=1 => not expected, please investigate
8346 -UMKSH_ASSUME_UTF8 => not expected, but if your OS is old,
8347 try passing HAVE_SETLOCALE_CTYPE=0 to Build.sh
Geremy Condra03ebf062011-10-12 18:17:24 -07008348need-pass: no
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008349category: !os:hpux,!os:msys,!os:os2
Geremy Condra03ebf062011-10-12 18:17:24 -07008350need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008351arguments: !-i!
8352env-setup: !PS1=!PS2=!LC_CTYPE=en_US.UTF-8!
8353stdin:
8354 if [[ $- = *U* ]]; then
8355 echo is set
8356 else
8357 echo is not set
8358 fi
8359expected-stdout:
8360 is set
8361expected-stderr-pattern:
8362 /(# )*/
8363---
8364name: utf8opt-2b
8365description:
8366 Check that the utf8-mode flag is set at interactive startup
8367 Expected failure if -DMKSH_ASSUME_UTF8=0
8368category: os:hpux
Geremy Condra03ebf062011-10-12 18:17:24 -07008369need-ctty: yes
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008370arguments: !-i!
8371env-setup: !PS1=!PS2=!LC_CTYPE=en_US.utf8!
8372stdin:
8373 if [[ $- = *U* ]]; then
8374 echo is set
8375 else
8376 echo is not set
8377 fi
8378expected-stdout:
8379 is set
8380expected-stderr-pattern:
8381 /(# )*/
8382---
Geremy Condra03ebf062011-10-12 18:17:24 -07008383name: utf8opt-3a
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008384description:
8385 Ensure ±U on the command line is honoured
Geremy Condra03ebf062011-10-12 18:17:24 -07008386 (these two tests may pass falsely depending on CPPFLAGS)
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008387stdin:
8388 export i=0
8389 code='if [[ $- = *U* ]]; then echo $i on; else echo $i off; fi'
8390 let i++; "$__progname" -U -c "$code"
8391 let i++; "$__progname" +U -c "$code"
Geremy Condra03ebf062011-10-12 18:17:24 -07008392 echo $((++i)) done
8393expected-stdout:
8394 1 on
8395 2 off
8396 3 done
8397---
8398name: utf8opt-3b
8399description:
8400 Ensure ±U on the command line is honoured, interactive shells
8401need-ctty: yes
8402stdin:
8403 export i=0
8404 code='if [[ $- = *U* ]]; then echo $i on; else echo $i off; fi'
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008405 let i++; "$__progname" -U -ic "$code"
8406 let i++; "$__progname" +U -ic "$code"
8407 echo $((++i)) done
8408expected-stdout:
8409 1 on
8410 2 off
Geremy Condra03ebf062011-10-12 18:17:24 -07008411 3 done
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008412---
Elliott Hughes77740fc2016-08-12 15:06:53 -07008413name: utf8bug-1
8414description:
8415 Ensure trailing combining characters are not lost
8416stdin:
8417 set -U
8418 a=a
8419 b=$'\u0301'
8420 x=$a$b
8421 print -r -- "<e$x>"
8422 x=$a
8423 x+=$b
8424 print -r -- "<e$x>"
8425 b=$'\u0301'b
8426 x=$a
8427 x+=$b
8428 print -r -- "<e$x>"
8429expected-stdout:
8430 <eá>
8431 <eá>
8432 <eáb>
8433---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008434name: aliases-1
8435description:
8436 Check if built-in shell aliases are okay
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008437stdin:
8438 alias
8439 typeset -f
8440expected-stdout:
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008441 autoload='\\builtin typeset -fu'
8442 functions='\\builtin typeset -f'
8443 hash='\\builtin alias -t'
8444 history='\\builtin fc -l'
8445 integer='\\builtin typeset -i'
8446 local='\\builtin typeset'
8447 login='\\builtin exec login'
8448 nameref='\\builtin typeset -n'
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008449 nohup='nohup '
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008450 r='\\builtin fc -e -'
8451 type='\\builtin whence -v'
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008452---
8453name: aliases-2b
8454description:
8455 Check if “set -o sh” does not influence built-in aliases
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008456arguments: !-o!sh!
8457stdin:
8458 alias
8459 typeset -f
8460expected-stdout:
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008461 autoload='\\builtin typeset -fu'
8462 functions='\\builtin typeset -f'
8463 hash='\\builtin alias -t'
8464 history='\\builtin fc -l'
8465 integer='\\builtin typeset -i'
8466 local='\\builtin typeset'
8467 login='\\builtin exec login'
8468 nameref='\\builtin typeset -n'
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008469 nohup='nohup '
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008470 r='\\builtin fc -e -'
8471 type='\\builtin whence -v'
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008472---
8473name: aliases-3b
8474description:
8475 Check if running as sh does not influence built-in aliases
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008476stdin:
8477 cp "$__progname" sh
8478 ./sh -c 'alias; typeset -f'
8479 rm -f sh
8480expected-stdout:
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008481 autoload='\\builtin typeset -fu'
8482 functions='\\builtin typeset -f'
8483 hash='\\builtin alias -t'
8484 history='\\builtin fc -l'
8485 integer='\\builtin typeset -i'
8486 local='\\builtin typeset'
8487 login='\\builtin exec login'
8488 nameref='\\builtin typeset -n'
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008489 nohup='nohup '
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008490 r='\\builtin fc -e -'
8491 type='\\builtin whence -v'
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008492---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00008493name: aliases-cmdline
8494description:
8495 Check that aliases work from the command line (Debian #517009)
8496 Note that due to the nature of the lexing process, defining
8497 aliases in COMSUBs then immediately using them, and things
8498 like 'alias foo=bar && foo', still fail.
8499stdin:
8500 "$__progname" -c $'alias a="echo OK"\na'
8501expected-stdout:
8502 OK
8503---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008504name: aliases-funcdef-1
8505description:
8506 Check if POSIX functions take precedences over aliases
Elliott Hughes96b43632015-07-17 11:39:41 -07008507stdin:
8508 alias foo='echo makro'
8509 foo() {
8510 echo funktion
8511 }
8512 foo
8513expected-stdout:
8514 makro
8515---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008516name: aliases-funcdef-2
8517description:
8518 Check if POSIX functions take precedences over aliases
Elliott Hughes96b43632015-07-17 11:39:41 -07008519stdin:
8520 alias foo='echo makro'
8521 foo () {
8522 echo funktion
8523 }
8524 foo
8525expected-stdout:
8526 makro
8527---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008528name: aliases-funcdef-3
8529description:
8530 Check if aliases take precedences over Korn functions
8531stdin:
8532 alias foo='echo makro'
8533 function foo {
8534 echo funktion
8535 }
8536 foo
8537expected-stdout:
8538 makro
8539---
Geremy Condra03ebf062011-10-12 18:17:24 -07008540name: aliases-funcdef-4
8541description:
8542 Functions should only take over if actually being defined
8543stdin:
8544 alias local
8545 :|| local() { :; }
8546 alias local
8547expected-stdout:
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008548 local='\\builtin typeset'
8549 local='\\builtin typeset'
Geremy Condra03ebf062011-10-12 18:17:24 -07008550---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008551name: arrays-1
8552description:
8553 Check if Korn Shell arrays work as expected
8554stdin:
8555 v="c d"
8556 set -A foo -- a \$v "$v" '$v' b
8557 echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|"
8558expected-stdout:
8559 5|a|$v|c d|$v|b|
8560---
Geremy Condra03ebf062011-10-12 18:17:24 -07008561name: arrays-2a
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008562description:
8563 Check if bash-style arrays work as expected
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008564stdin:
8565 v="c d"
8566 foo=(a \$v "$v" '$v' b)
8567 echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|"
8568expected-stdout:
8569 5|a|$v|c d|$v|b|
8570---
Geremy Condra03ebf062011-10-12 18:17:24 -07008571name: arrays-2b
8572description:
8573 Check if bash-style arrays work as expected, with newlines
Geremy Condra03ebf062011-10-12 18:17:24 -07008574stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00008575 print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "$x|"; done' >pfp
8576 chmod +x pfp
Geremy Condra03ebf062011-10-12 18:17:24 -07008577 test -n "$ZSH_VERSION" && setopt KSH_ARRAYS
8578 v="e f"
8579 foo=(a
8580 bc
8581 d \$v "$v" '$v' g
8582 )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00008583 ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
Geremy Condra03ebf062011-10-12 18:17:24 -07008584 foo=(a\
8585 bc
8586 d \$v "$v" '$v' g
8587 )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00008588 ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
Geremy Condra03ebf062011-10-12 18:17:24 -07008589 foo=(a\
8590 bc\\
8591 d \$v "$v" '$v'
8592 g)
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00008593 ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo
Geremy Condra03ebf062011-10-12 18:17:24 -07008594expected-stdout:
8595 7|a|bc|d|$v|e f|$v|g|
8596 7|a|bc|d|$v|e f|$v|g|
8597 6|abc\|d|$v|e f|$v|g||
8598---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008599name: arrays-3
8600description:
8601 Check if array bounds are uint32_t
8602stdin:
8603 set -A foo a b c
8604 foo[4097]=d
8605 foo[2147483637]=e
8606 echo ${foo[*]}
8607 foo[-1]=f
8608 echo ${foo[4294967295]} g ${foo[*]}
8609expected-stdout:
8610 a b c d e
8611 f g a b c d e f
8612---
8613name: arrays-4
8614description:
8615 Check if Korn Shell arrays with specified indices work as expected
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008616stdin:
8617 v="c d"
8618 set -A foo -- [1]=\$v [2]="$v" [4]='$v' [0]=a [5]=b
8619 echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|${foo[5]}|"
Elliott Hughes737fdce2014-08-07 12:59:26 -07008620 # we don't want this at all:
8621 # 5|a|$v|c d||$v|b|
8622 set -A arr "[5]=meh"
8623 echo "<${arr[0]}><${arr[5]}>"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008624expected-stdout:
Elliott Hughes737fdce2014-08-07 12:59:26 -07008625 5|[1]=$v|[2]=c d|[4]=$v|[0]=a|[5]=b||
8626 <[5]=meh><>
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008627---
8628name: arrays-5
8629description:
8630 Check if bash-style arrays with specified indices work as expected
Elliott Hughes737fdce2014-08-07 12:59:26 -07008631 (taken out temporarily to fix arrays-4; see also arrays-9a comment)
8632category: disabled
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008633stdin:
8634 v="c d"
8635 foo=([1]=\$v [2]="$v" [4]='$v' [0]=a [5]=b)
8636 echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|${foo[5]}|"
8637 x=([128]=foo bar baz)
8638 echo k= ${!x[*]} .
8639 echo v= ${x[*]} .
Elliott Hughes737fdce2014-08-07 12:59:26 -07008640 # Check that we do not break this by globbing
8641 :>b=blah
8642 bleh=5
8643 typeset -a arr
8644 arr+=([bleh]=blah)
8645 echo "<${arr[0]}><${arr[5]}>"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008646expected-stdout:
8647 5|a|$v|c d||$v|b|
8648 k= 128 129 130 .
8649 v= foo bar baz .
Elliott Hughes737fdce2014-08-07 12:59:26 -07008650 <><blah>
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008651---
8652name: arrays-6
8653description:
8654 Check if we can get the array keys (indices) for indexed arrays,
8655 Korn shell style
8656stdin:
8657 of() {
8658 i=0
8659 for x in "$@"; do
8660 echo -n "$((i++))<$x>"
8661 done
8662 echo
8663 }
8664 foo[1]=eins
8665 set | grep '^foo'
8666 echo =
8667 foo[0]=zwei
8668 foo[4]=drei
8669 set | grep '^foo'
8670 echo =
8671 echo a $(of ${foo[*]}) = $(of ${bar[*]}) a
8672 echo b $(of "${foo[*]}") = $(of "${bar[*]}") b
8673 echo c $(of ${foo[@]}) = $(of ${bar[@]}) c
8674 echo d $(of "${foo[@]}") = $(of "${bar[@]}") d
8675 echo e $(of ${!foo[*]}) = $(of ${!bar[*]}) e
8676 echo f $(of "${!foo[*]}") = $(of "${!bar[*]}") f
8677 echo g $(of ${!foo[@]}) = $(of ${!bar[@]}) g
8678 echo h $(of "${!foo[@]}") = $(of "${!bar[@]}") h
8679expected-stdout:
8680 foo[1]=eins
8681 =
8682 foo[0]=zwei
8683 foo[1]=eins
8684 foo[4]=drei
8685 =
8686 a 0<zwei>1<eins>2<drei> = a
8687 b 0<zwei eins drei> = 0<> b
8688 c 0<zwei>1<eins>2<drei> = c
8689 d 0<zwei>1<eins>2<drei> = d
8690 e 0<0>1<1>2<4> = e
8691 f 0<0 1 4> = 0<> f
8692 g 0<0>1<1>2<4> = g
8693 h 0<0>1<1>2<4> = h
8694---
8695name: arrays-7
8696description:
8697 Check if we can get the array keys (indices) for indexed arrays,
8698 Korn shell style, in some corner cases
8699stdin:
8700 echo !arz: ${!arz}
8701 echo !arz[0]: ${!arz[0]}
8702 echo !arz[1]: ${!arz[1]}
8703 arz=foo
8704 echo !arz: ${!arz}
8705 echo !arz[0]: ${!arz[0]}
8706 echo !arz[1]: ${!arz[1]}
8707 unset arz
8708 echo !arz: ${!arz}
8709 echo !arz[0]: ${!arz[0]}
8710 echo !arz[1]: ${!arz[1]}
8711expected-stdout:
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008712 !arz: arz
Elliott Hughes737fdce2014-08-07 12:59:26 -07008713 !arz[0]: arz[0]
8714 !arz[1]: arz[1]
8715 !arz: arz
8716 !arz[0]: arz[0]
8717 !arz[1]: arz[1]
8718 !arz: arz
8719 !arz[0]: arz[0]
8720 !arz[1]: arz[1]
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07008721---
8722name: arrays-8
8723description:
8724 Check some behavioural rules for arrays.
8725stdin:
8726 fna() {
8727 set -A aa 9
8728 }
8729 fnb() {
8730 typeset ab
8731 set -A ab 9
8732 }
8733 fnc() {
8734 typeset ac
8735 set -A ac 91
8736 unset ac
8737 set -A ac 92
8738 }
8739 fnd() {
8740 set +A ad 9
8741 }
8742 fne() {
8743 unset ae
8744 set +A ae 9
8745 }
8746 fnf() {
8747 unset af[0]
8748 set +A af 9
8749 }
8750 fng() {
8751 unset ag[*]
8752 set +A ag 9
8753 }
8754 set -A aa 1 2
8755 set -A ab 1 2
8756 set -A ac 1 2
8757 set -A ad 1 2
8758 set -A ae 1 2
8759 set -A af 1 2
8760 set -A ag 1 2
8761 set -A ah 1 2
8762 typeset -Z3 aa ab ac ad ae af ag
8763 print 1a ${aa[*]} .
8764 print 1b ${ab[*]} .
8765 print 1c ${ac[*]} .
8766 print 1d ${ad[*]} .
8767 print 1e ${ae[*]} .
8768 print 1f ${af[*]} .
8769 print 1g ${ag[*]} .
8770 print 1h ${ah[*]} .
8771 fna
8772 fnb
8773 fnc
8774 fnd
8775 fne
8776 fnf
8777 fng
8778 typeset -Z5 ah[*]
8779 print 2a ${aa[*]} .
8780 print 2b ${ab[*]} .
8781 print 2c ${ac[*]} .
8782 print 2d ${ad[*]} .
8783 print 2e ${ae[*]} .
8784 print 2f ${af[*]} .
8785 print 2g ${ag[*]} .
8786 print 2h ${ah[*]} .
8787expected-stdout:
8788 1a 001 002 .
8789 1b 001 002 .
8790 1c 001 002 .
8791 1d 001 002 .
8792 1e 001 002 .
8793 1f 001 002 .
8794 1g 001 002 .
8795 1h 1 2 .
8796 2a 9 .
8797 2b 001 002 .
8798 2c 92 .
8799 2d 009 002 .
8800 2e 9 .
8801 2f 9 002 .
8802 2g 009 .
8803 2h 00001 00002 .
8804---
Geremy Condra03ebf062011-10-12 18:17:24 -07008805name: arrays-9a
8806description:
8807 Check that we can concatenate arrays
Geremy Condra03ebf062011-10-12 18:17:24 -07008808stdin:
8809 unset foo; foo=(bar); foo+=(baz); echo 1 ${!foo[*]} : ${foo[*]} .
8810 unset foo; foo=(foo bar); foo+=(baz); echo 2 ${!foo[*]} : ${foo[*]} .
Elliott Hughes737fdce2014-08-07 12:59:26 -07008811# unset foo; foo=([2]=foo [0]=bar); foo+=(baz [5]=quux); echo 3 ${!foo[*]} : ${foo[*]} .
Geremy Condra03ebf062011-10-12 18:17:24 -07008812expected-stdout:
8813 1 0 1 : bar baz .
8814 2 0 1 2 : foo bar baz .
Elliott Hughes737fdce2014-08-07 12:59:26 -07008815# 3 0 2 3 5 : bar foo baz quux .
Geremy Condra03ebf062011-10-12 18:17:24 -07008816---
8817name: arrays-9b
8818description:
8819 Check that we can concatenate parameters too
8820stdin:
8821 unset foo; foo=bar; foo+=baz; echo 1 $foo .
8822 unset foo; typeset -i16 foo=10; foo+=20; echo 2 $foo .
8823expected-stdout:
8824 1 barbaz .
8825 2 16#a20 .
8826---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00008827name: arrassign-basic
8828description:
8829 Check basic whitespace conserving properties of wdarrassign
8830stdin:
8831 a=($(echo a b))
8832 b=($(echo "a b"))
8833 c=("$(echo "a b")")
8834 d=("$(echo a b)")
8835 a+=($(echo c d))
8836 b+=($(echo "c d"))
8837 c+=("$(echo "c d")")
8838 d+=("$(echo c d)")
8839 echo ".a:${a[0]}.${a[1]}.${a[2]}.${a[3]}:"
8840 echo ".b:${b[0]}.${b[1]}.${b[2]}.${b[3]}:"
8841 echo ".c:${c[0]}.${c[1]}.${c[2]}.${c[3]}:"
8842 echo ".d:${d[0]}.${d[1]}.${d[2]}.${d[3]}:"
8843expected-stdout:
8844 .a:a.b.c.d:
8845 .b:a.b.c.d:
8846 .c:a b.c d..:
8847 .d:a b.c d..:
8848---
8849name: arrassign-fnc-none
8850description:
8851 Check locality of array access inside a function
8852stdin:
8853 function fn {
8854 x+=(f)
8855 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8856 }
8857 function rfn {
8858 if [[ -n $BASH_VERSION ]]; then
8859 y=()
8860 else
8861 set -A y
8862 fi
8863 y+=(f)
8864 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8865 }
8866 x=(m m)
8867 y=(m m)
8868 echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8869 fn
8870 echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8871 fn
8872 echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8873 echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8874 rfn
8875 echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8876 rfn
8877 echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8878expected-stdout:
8879 .f0:m.m..:
8880 .fn:m.m.f.:
8881 .f1:m.m.f.:
8882 .fn:m.m.f.f:
8883 .f2:m.m.f.f:
8884 .rf0:m.m..:
8885 .rfn:f...:
8886 .rf1:f...:
8887 .rfn:f...:
8888 .rf2:f...:
8889---
8890name: arrassign-fnc-local
8891description:
8892 Check locality of array access inside a function
8893 with the bash/mksh/ksh93 local/typeset keyword
8894 (note: ksh93 has no local; typeset works only in FKSH)
8895stdin:
8896 function fn {
8897 typeset x
8898 x+=(f)
8899 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8900 }
8901 function rfn {
8902 if [[ -n $BASH_VERSION ]]; then
8903 y=()
8904 else
8905 set -A y
8906 fi
8907 typeset y
8908 y+=(f)
8909 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8910 }
8911 function fnr {
8912 typeset z
8913 if [[ -n $BASH_VERSION ]]; then
8914 z=()
8915 else
8916 set -A z
8917 fi
8918 z+=(f)
8919 echo ".fnr:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8920 }
8921 x=(m m)
8922 y=(m m)
8923 z=(m m)
8924 echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8925 fn
8926 echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8927 fn
8928 echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8929 echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8930 rfn
8931 echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8932 rfn
8933 echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8934 echo ".f0r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8935 fnr
8936 echo ".f1r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8937 fnr
8938 echo ".f2r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8939expected-stdout:
8940 .f0:m.m..:
8941 .fn:f...:
8942 .f1:m.m..:
8943 .fn:f...:
8944 .f2:m.m..:
8945 .rf0:m.m..:
8946 .rfn:f...:
8947 .rf1:...:
8948 .rfn:f...:
8949 .rf2:...:
8950 .f0r:m.m..:
8951 .fnr:f...:
8952 .f1r:m.m..:
8953 .fnr:f...:
8954 .f2r:m.m..:
8955---
8956name: arrassign-fnc-global
8957description:
8958 Check locality of array access inside a function
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008959 with the bash4/mksh/yash/zsh typeset -g keyword
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00008960stdin:
8961 function fn {
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008962 typeset -g x
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00008963 x+=(f)
8964 echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8965 }
8966 function rfn {
8967 set -A y
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008968 typeset -g y
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00008969 y+=(f)
8970 echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8971 }
8972 function fnr {
Elliott Hughesa3c3f962017-04-12 16:52:30 -07008973 typeset -g z
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00008974 set -A z
8975 z+=(f)
8976 echo ".fnr:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8977 }
8978 x=(m m)
8979 y=(m m)
8980 z=(m m)
8981 echo ".f0:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8982 fn
8983 echo ".f1:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8984 fn
8985 echo ".f2:${x[0]}.${x[1]}.${x[2]}.${x[3]}:"
8986 echo ".rf0:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8987 rfn
8988 echo ".rf1:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8989 rfn
8990 echo ".rf2:${y[0]}.${y[1]}.${y[2]}.${y[3]}:"
8991 echo ".f0r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8992 fnr
8993 echo ".f1r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8994 fnr
8995 echo ".f2r:${z[0]}.${z[1]}.${z[2]}.${z[3]}:"
8996expected-stdout:
8997 .f0:m.m..:
8998 .fn:m.m.f.:
8999 .f1:m.m.f.:
9000 .fn:m.m.f.f:
9001 .f2:m.m.f.f:
9002 .rf0:m.m..:
9003 .rfn:f...:
9004 .rf1:f...:
9005 .rfn:f...:
9006 .rf2:f...:
9007 .f0r:m.m..:
9008 .fnr:f...:
9009 .f1r:f...:
9010 .fnr:f...:
9011 .f2r:f...:
9012---
9013name: strassign-fnc-none
9014description:
9015 Check locality of string access inside a function
9016stdin:
9017 function fn {
9018 x+=f
9019 echo ".fn:$x:"
9020 }
9021 function rfn {
9022 y=
9023 y+=f
9024 echo ".rfn:$y:"
9025 }
9026 x=m
9027 y=m
9028 echo ".f0:$x:"
9029 fn
9030 echo ".f1:$x:"
9031 fn
9032 echo ".f2:$x:"
9033 echo ".rf0:$y:"
9034 rfn
9035 echo ".rf1:$y:"
9036 rfn
9037 echo ".rf2:$y:"
9038expected-stdout:
9039 .f0:m:
9040 .fn:mf:
9041 .f1:mf:
9042 .fn:mff:
9043 .f2:mff:
9044 .rf0:m:
9045 .rfn:f:
9046 .rf1:f:
9047 .rfn:f:
9048 .rf2:f:
9049---
9050name: strassign-fnc-local
9051description:
9052 Check locality of string access inside a function
9053 with the bash/mksh/ksh93 local/typeset keyword
9054 (note: ksh93 has no local; typeset works only in FKSH)
9055stdin:
9056 function fn {
9057 typeset x
9058 x+=f
9059 echo ".fn:$x:"
9060 }
9061 function rfn {
9062 y=
9063 typeset y
9064 y+=f
9065 echo ".rfn:$y:"
9066 }
9067 function fnr {
9068 typeset z
9069 z=
9070 z+=f
9071 echo ".fnr:$z:"
9072 }
9073 x=m
9074 y=m
9075 z=m
9076 echo ".f0:$x:"
9077 fn
9078 echo ".f1:$x:"
9079 fn
9080 echo ".f2:$x:"
9081 echo ".rf0:$y:"
9082 rfn
9083 echo ".rf1:$y:"
9084 rfn
9085 echo ".rf2:$y:"
9086 echo ".f0r:$z:"
9087 fnr
9088 echo ".f1r:$z:"
9089 fnr
9090 echo ".f2r:$z:"
9091expected-stdout:
9092 .f0:m:
9093 .fn:f:
9094 .f1:m:
9095 .fn:f:
9096 .f2:m:
9097 .rf0:m:
9098 .rfn:f:
9099 .rf1::
9100 .rfn:f:
9101 .rf2::
9102 .f0r:m:
9103 .fnr:f:
9104 .f1r:m:
9105 .fnr:f:
9106 .f2r:m:
9107---
9108name: strassign-fnc-global
9109description:
9110 Check locality of string access inside a function
Elliott Hughesa3c3f962017-04-12 16:52:30 -07009111 with the bash4/mksh/yash/zsh typeset -g keyword
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009112stdin:
9113 function fn {
Elliott Hughesa3c3f962017-04-12 16:52:30 -07009114 typeset -g x
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009115 x+=f
9116 echo ".fn:$x:"
9117 }
9118 function rfn {
9119 y=
Elliott Hughesa3c3f962017-04-12 16:52:30 -07009120 typeset -g y
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009121 y+=f
9122 echo ".rfn:$y:"
9123 }
9124 function fnr {
Elliott Hughesa3c3f962017-04-12 16:52:30 -07009125 typeset -g z
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009126 z=
9127 z+=f
9128 echo ".fnr:$z:"
9129 }
9130 x=m
9131 y=m
9132 z=m
9133 echo ".f0:$x:"
9134 fn
9135 echo ".f1:$x:"
9136 fn
9137 echo ".f2:$x:"
9138 echo ".rf0:$y:"
9139 rfn
9140 echo ".rf1:$y:"
9141 rfn
9142 echo ".rf2:$y:"
9143 echo ".f0r:$z:"
9144 fnr
9145 echo ".f1r:$z:"
9146 fnr
9147 echo ".f2r:$z:"
9148expected-stdout:
9149 .f0:m:
9150 .fn:mf:
9151 .f1:mf:
9152 .fn:mff:
9153 .f2:mff:
9154 .rf0:m:
9155 .rfn:f:
9156 .rf1:f:
9157 .rfn:f:
9158 .rf2:f:
9159 .f0r:m:
9160 .fnr:f:
9161 .f1r:f:
9162 .fnr:f:
9163 .f2r:f:
9164---
Elliott Hughes50012062015-03-10 22:22:24 -07009165name: unset-fnc-local-ksh
9166description:
9167 Check that “unset” removes a previous “local”
9168 (ksh93 syntax compatible version); apparently,
9169 there are shells which fail this?
9170stdin:
9171 function f {
9172 echo f0: $x
9173 typeset x
9174 echo f1: $x
9175 x=fa
9176 echo f2: $x
9177 unset x
9178 echo f3: $x
9179 x=fb
9180 echo f4: $x
9181 }
9182 x=o
9183 echo before: $x
9184 f
9185 echo after: $x
9186expected-stdout:
9187 before: o
9188 f0: o
9189 f1:
9190 f2: fa
9191 f3: o
9192 f4: fb
9193 after: fb
9194---
9195name: unset-fnc-local-sh
9196description:
9197 Check that “unset” removes a previous “local”
9198 (Debian Policy §10.4 sh version); apparently,
9199 there are shells which fail this?
9200stdin:
9201 f() {
9202 echo f0: $x
9203 local x
9204 echo f1: $x
9205 x=fa
9206 echo f2: $x
9207 unset x
9208 echo f3: $x
9209 x=fb
9210 echo f4: $x
9211 }
9212 x=o
9213 echo before: $x
9214 f
9215 echo after: $x
9216expected-stdout:
9217 before: o
9218 f0: o
9219 f1:
9220 f2: fa
9221 f3: o
9222 f4: fb
9223 after: fb
9224---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009225name: varexpand-substr-1
9226description:
9227 Check if bash-style substring expansion works
9228 when using positive numerics
9229stdin:
9230 x=abcdefghi
9231 typeset -i y=123456789
9232 typeset -i 16 z=123456789 # 16#75bcd15
9233 echo a t${x:2:2} ${y:2:3} ${z:2:3} a
9234 echo b ${x::3} ${y::3} ${z::3} b
9235 echo c ${x:2:} ${y:2:} ${z:2:} c
9236 echo d ${x:2} ${y:2} ${z:2} d
9237 echo e ${x:2:6} ${y:2:6} ${z:2:7} e
9238 echo f ${x:2:7} ${y:2:7} ${z:2:8} f
9239 echo g ${x:2:8} ${y:2:8} ${z:2:9} g
9240expected-stdout:
9241 a tcd 345 #75 a
9242 b abc 123 16# b
9243 c c
9244 d cdefghi 3456789 #75bcd15 d
9245 e cdefgh 345678 #75bcd1 e
9246 f cdefghi 3456789 #75bcd15 f
9247 g cdefghi 3456789 #75bcd15 g
9248---
9249name: varexpand-substr-2
9250description:
9251 Check if bash-style substring expansion works
9252 when using negative numerics or expressions
9253stdin:
9254 x=abcdefghi
9255 typeset -i y=123456789
9256 typeset -i 16 z=123456789 # 16#75bcd15
9257 n=2
9258 echo a ${x:$n:3} ${y:$n:3} ${z:$n:3} a
9259 echo b ${x:(n):3} ${y:(n):3} ${z:(n):3} b
9260 echo c ${x:(-2):1} ${y:(-2):1} ${z:(-2):1} c
9261 echo d t${x: n:2} ${y: n:3} ${z: n:3} d
9262expected-stdout:
9263 a cde 345 #75 a
9264 b cde 345 #75 b
9265 c h 8 1 c
9266 d tcd 345 #75 d
9267---
9268name: varexpand-substr-3
9269description:
9270 Check that some things that work in bash fail.
Elliott Hughesfc0307d2016-02-02 15:26:47 -08009271 This is by design. Oh and vice versa, nowadays.
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009272stdin:
9273 export x=abcdefghi n=2
9274 "$__progname" -c 'echo v${x:(n)}x'
9275 "$__progname" -c 'echo w${x: n}x'
9276 "$__progname" -c 'echo x${x:n}x'
9277 "$__progname" -c 'echo y${x:}x'
9278 "$__progname" -c 'echo z${x}x'
Elliott Hughesfc0307d2016-02-02 15:26:47 -08009279 # next fails only in bash
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009280 "$__progname" -c 'x=abcdef;y=123;echo ${x:${y:2:1}:2}' >/dev/null 2>&1; echo $?
9281expected-stdout:
9282 vcdefghix
9283 wcdefghix
9284 zabcdefghix
Elliott Hughesfc0307d2016-02-02 15:26:47 -08009285 0
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009286expected-stderr-pattern:
9287 /x:n.*bad substitution.*\n.*bad substitution/
9288---
9289name: varexpand-substr-4
9290description:
9291 Check corner cases for substring expansion
9292stdin:
9293 x=abcdefghi
9294 integer y=2
9295 echo a ${x:(y == 1 ? 2 : 3):4} a
9296expected-stdout:
9297 a defg a
9298---
9299name: varexpand-substr-5A
9300description:
9301 Check that substring expansions work on characters
9302stdin:
9303 set +U
9304 x=mäh
9305 echo a ${x::1} ${x: -1} a
9306 echo b ${x::3} ${x: -3} b
9307 echo c ${x:1:2} ${x: -3:2} c
9308 echo d ${#x} d
9309expected-stdout:
9310 a m h a
9311 b mä äh b
9312 c ä ä c
9313 d 4 d
9314---
9315name: varexpand-substr-5W
9316description:
9317 Check that substring expansions work on characters
9318stdin:
9319 set -U
9320 x=mäh
9321 echo a ${x::1} ${x: -1} a
9322 echo b ${x::2} ${x: -2} b
9323 echo c ${x:1:1} ${x: -2:1} c
9324 echo d ${#x} d
9325expected-stdout:
9326 a m h a
9327 b mä äh b
9328 c ä ä c
9329 d 3 d
9330---
9331name: varexpand-substr-6
9332description:
9333 Check that string substitution works correctly
9334stdin:
9335 foo=1
9336 bar=2
9337 baz=qwertyuiop
9338 echo a ${baz: foo: bar}
9339 echo b ${baz: foo: $bar}
9340 echo c ${baz: $foo: bar}
9341 echo d ${baz: $foo: $bar}
9342expected-stdout:
9343 a we
9344 b we
9345 c we
9346 d we
9347---
Geremy Condra03ebf062011-10-12 18:17:24 -07009348name: varexpand-special-hash
9349description:
9350 Check special ${var@x} expansion for x=hash
9351stdin:
9352 typeset -i8 foo=10
9353 bar=baz
9354 unset baz
9355 print ${foo@#} ${bar@#} ${baz@#} .
9356expected-stdout:
Elliott Hughes737fdce2014-08-07 12:59:26 -07009357 9B15FBFB CFBDD32B 00000000 .
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009358---
9359name: varexpand-special-quote
9360description:
9361 Check special ${var@Q} expansion for quoted strings
9362stdin:
9363 set +U
9364 i=x
9365 j=a\ b
9366 k=$'c
9367 d\xA0''e€f'
9368 print -r -- "<i=$i j=$j k=$k>"
9369 s="u=${i@Q} v=${j@Q} w=${k@Q}"
9370 print -r -- "s=\"$s\""
9371 eval "$s"
9372 typeset -p u v w
9373expected-stdout:
9374 <i=x j=a b k=c
9375 d e€f>
9376 s="u=x v='a b' w=$'c\nd\240e\u20ACf'"
9377 typeset u=x
9378 typeset v='a b'
9379 typeset w=$'c\nd\240e\u20ACf'
Geremy Condra03ebf062011-10-12 18:17:24 -07009380---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009381name: varexpand-null-1
9382description:
9383 Ensure empty strings expand emptily
9384stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07009385 print s ${a} . ${b} S
9386 print t ${a#?} . ${b%?} T
9387 print r ${a=} . ${b/c/d} R
9388 print q
9389 print s "${a}" . "${b}" S
9390 print t "${a#?}" . "${b%?}" T
9391 print r "${a=}" . "${b/c/d}" R
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009392expected-stdout:
Elliott Hughes50012062015-03-10 22:22:24 -07009393 s . S
9394 t . T
9395 r . R
9396 q
9397 s . S
9398 t . T
9399 r . R
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009400---
9401name: varexpand-null-2
9402description:
9403 Ensure empty strings, when quoted, are expanded as empty strings
9404stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009405 print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "<$x> "; done' >pfs
9406 chmod +x pfs
9407 ./pfs 1 "${a}" 2 "${a#?}" + "${b%?}" 3 "${a=}" + "${b/c/d}"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009408 echo .
9409expected-stdout:
9410 <1> <> <2> <> <+> <> <3> <> <+> <> .
9411---
Elliott Hughes56b517d2014-10-06 11:30:44 -07009412name: varexpand-null-3
9413description:
9414 Ensure concatenating behaviour matches other shells
Elliott Hughes56b517d2014-10-06 11:30:44 -07009415stdin:
Elliott Hughes50012062015-03-10 22:22:24 -07009416 showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; }
Elliott Hughes96b43632015-07-17 11:39:41 -07009417 showargs 0 ""$@
Elliott Hughes50012062015-03-10 22:22:24 -07009418 x=; showargs 1 "$x"$@
9419 set A; showargs 2 "${@:+}"
9420 n() { echo "$#"; }
9421 unset e
9422 set -- a b
9423 n """$@"
9424 n "$@"
9425 n "$@"""
9426 n "$e""$@"
9427 n "$@"
9428 n "$@""$e"
9429 set --
9430 n """$@"
9431 n "$@"
9432 n "$@"""
9433 n "$e""$@"
9434 n "$@"
9435 n "$@""$e"
Elliott Hughes56b517d2014-10-06 11:30:44 -07009436expected-stdout:
Elliott Hughes96b43632015-07-17 11:39:41 -07009437 <0> <> .
Elliott Hughes50012062015-03-10 22:22:24 -07009438 <1> <> .
9439 <2> <> .
9440 2
9441 2
9442 2
9443 2
9444 2
9445 2
9446 1
9447 0
9448 1
9449 1
9450 0
9451 1
Elliott Hughes56b517d2014-10-06 11:30:44 -07009452---
Elliott Hughesfc0307d2016-02-02 15:26:47 -08009453name: varexpand-funny-chars
9454description:
9455 Check some characters
9456 XXX \uEF80 is asymmetric, possibly buggy so we don’t check this
9457stdin:
9458 x=$'<\x00>'; typeset -p x
9459 x=$'<\x01>'; typeset -p x
9460 x=$'<\u0000>'; typeset -p x
9461 x=$'<\u0001>'; typeset -p x
9462expected-stdout:
9463 typeset x='<'
9464 typeset x=$'<\001>'
9465 typeset x='<'
9466 typeset x=$'<\001>'
9467---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009468name: print-funny-chars
9469description:
9470 Check print builtin's capability to output designated characters
9471stdin:
Elliott Hughes77740fc2016-08-12 15:06:53 -07009472 {
9473 print '<\0144\0344\xDB\u00DB\u20AC\uDB\x40>'
9474 print '<\x00>'
9475 print '<\x01>'
9476 print '<\u0000>'
9477 print '<\u0001>'
9478 } | {
9479 # integer-base-one-3Ar
9480 typeset -Uui16 -Z11 pos=0
9481 typeset -Uui16 -Z5 hv=2147483647
9482 dasc=
9483 if read -arN -1 line; then
9484 typeset -i1 line
9485 i=0
9486 while (( i < ${#line[*]} )); do
9487 hv=${line[i++]}
9488 if (( (pos & 15) == 0 )); then
Elliott Hughesa3c3f962017-04-12 16:52:30 -07009489 (( pos )) && print -r -- "$dasc|"
Elliott Hughes77740fc2016-08-12 15:06:53 -07009490 print -n "${pos#16#} "
9491 dasc=' |'
9492 fi
9493 print -n "${hv#16#} "
9494 if (( (hv < 32) || (hv > 126) )); then
9495 dasc=$dasc.
9496 else
9497 dasc=$dasc${line[i-1]#1#}
9498 fi
9499 (( (pos++ & 15) == 7 )) && print -n -- '- '
9500 done
9501 fi
9502 while (( pos & 15 )); do
9503 print -n ' '
9504 (( (pos++ & 15) == 7 )) && print -n -- '- '
9505 done
Elliott Hughesa3c3f962017-04-12 16:52:30 -07009506 (( hv == 2147483647 )) || print -r -- "$dasc|"
Elliott Hughes77740fc2016-08-12 15:06:53 -07009507 }
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009508expected-stdout:
Elliott Hughes77740fc2016-08-12 15:06:53 -07009509 00000000 3C 64 E4 DB C3 9B E2 82 - AC C3 9B 40 3E 0A 3C 00 |<d.........@>.<.|
9510 00000010 3E 0A 3C 01 3E 0A 3C 00 - 3E 0A 3C 01 3E 0A |>.<.>.<.>.<.>.|
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009511---
9512name: print-bksl-c
9513description:
9514 Check print builtin's \c escape
9515stdin:
9516 print '\ca'; print b
9517expected-stdout:
9518 ab
9519---
Thorsten Glaser811a5752013-07-25 14:24:45 +00009520name: print-cr
9521description:
9522 Check that CR+LF is not collapsed into LF as some MSYS shells wrongly do
9523stdin:
9524 echo '#!'"$__progname" >foo
9525 cat >>foo <<-'EOF'
9526 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'
9527 print \?
9528 EOF
9529 chmod +x foo
9530 echo "[$(./foo)]"
9531 ./foo | while IFS= read -r line; do
9532 print -r -- "{$line}"
9533 done
9534expected-stdout:
9535 [220-blau.mirbsd.org ESMTP ready at Thu, 25 Jul 2013 15:57:57 GMT
9536 220->> Bitte keine Werbung einwerfen! <<
9537 220 Who do you wanna pretend to be today? ]
9538 {220-blau.mirbsd.org ESMTP ready at Thu, 25 Jul 2013 15:57:57 GMT }
9539 {220->> Bitte keine Werbung einwerfen! << }
9540 {220 Who do you wanna pretend to be today? }
9541---
Elliott Hughesb27ce952015-04-21 13:39:18 -07009542name: print-crlf
9543description:
9544 Check that CR+LF is shown and read as-is
Elliott Hughesa3c3f962017-04-12 16:52:30 -07009545category: shell:textmode-no
Elliott Hughesb27ce952015-04-21 13:39:18 -07009546stdin:
9547 cat >foo <<-'EOF'
9548 x='bar
9549 ' #
Elliott Hughes96b43632015-07-17 11:39:41 -07009550 echo .${#x} #
Elliott Hughesb27ce952015-04-21 13:39:18 -07009551 if test x"$KSH_VERSION" = x""; then #
9552 printf '<%s>' "$x" #
9553 else #
9554 print -nr -- "<$x>" #
9555 fi #
9556 EOF
9557 echo "[$("$__progname" foo)]"
9558 "$__progname" foo | while IFS= read -r line; do
9559 print -r -- "{$line}"
9560 done
9561expected-stdout:
Elliott Hughes96b43632015-07-17 11:39:41 -07009562 [.5
9563 <bar
Elliott Hughesb27ce952015-04-21 13:39:18 -07009564 >]
Elliott Hughes96b43632015-07-17 11:39:41 -07009565 {.5}
Elliott Hughesb27ce952015-04-21 13:39:18 -07009566 {<bar }
9567---
Elliott Hughesa3c3f962017-04-12 16:52:30 -07009568name: print-crlf-textmode
9569description:
9570 Check that CR+LF is treated as newline
9571category: shell:textmode-yes
9572stdin:
9573 cat >foo <<-'EOF'
9574 x='bar
9575 ' #
9576 echo .${#x} #
9577 if test x"$KSH_VERSION" = x""; then #
9578 printf '<%s>' "$x" #
9579 else #
9580 print -nr -- "<$x>" #
9581 fi #
9582 EOF
9583 echo "[$("$__progname" foo)]"
9584 "$__progname" foo | while IFS= read -r line; do
9585 print -r -- "{$line}"
9586 done
9587expected-stdout:
9588 [.4
9589 <bar
9590 >]
9591 {.4}
9592 {<bar}
9593---
Elliott Hughesb27ce952015-04-21 13:39:18 -07009594name: print-lf
9595description:
9596 Check that LF-only is shown and read as-is
9597stdin:
9598 cat >foo <<-'EOF'
9599 x='bar
9600 ' #
Elliott Hughes96b43632015-07-17 11:39:41 -07009601 echo .${#x} #
Elliott Hughesb27ce952015-04-21 13:39:18 -07009602 if test x"$KSH_VERSION" = x""; then #
9603 printf '<%s>' "$x" #
9604 else #
9605 print -nr -- "<$x>" #
9606 fi #
9607 EOF
9608 echo "[$("$__progname" foo)]"
9609 "$__progname" foo | while IFS= read -r line; do
9610 print -r -- "{$line}"
9611 done
9612expected-stdout:
Elliott Hughes96b43632015-07-17 11:39:41 -07009613 [.4
9614 <bar
Elliott Hughesb27ce952015-04-21 13:39:18 -07009615 >]
Elliott Hughes96b43632015-07-17 11:39:41 -07009616 {.4}
Elliott Hughesb27ce952015-04-21 13:39:18 -07009617 {<bar}
9618---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009619name: print-nul-chars
9620description:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009621 Check handling of NUL characters for print and COMSUB
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009622stdin:
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009623 x=$(print '<\0>')
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009624 print $(($(print '<\0>' | wc -c))) $(($(print "$x" | wc -c))) \
9625 ${#x} "$x" '<\0>'
9626expected-stdout-pattern:
9627 /^4 3 2 <> <\0>$/
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009628---
Elliott Hughes77740fc2016-08-12 15:06:53 -07009629name: print-array
9630description:
9631 Check that print -A works as expected
9632stdin:
9633 print -An 0x20AC 0xC3 0xBC 8#101
9634 set -U
9635 print -A 0x20AC 0xC3 0xBC 8#102
9636expected-stdout:
9637 ¬Ã¼A€Ã¼B
9638---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009639name: print-escapes
9640description:
9641 Check backslash expansion by the print builtin
9642stdin:
9643 print '\ \!\"\#\$\%\&'\\\''\(\)\*\+\,\-\.\/\0\1\2\3\4\5\6\7\8' \
9644 '\9\:\;\<\=\>\?\@\A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T' \
9645 '\U\V\W\X\Y\Z\[\\\]\^\_\`\a\b \d\e\f\g\h\i\j\k\l\m\n\o\p' \
9646 '\q\r\s\t\u\v\w\x\y\z\{\|\}\~' '\u20acd' '\U20acd' '\x123' \
9647 '\0x' '\0123' '\01234' | {
Geremy Condra03ebf062011-10-12 18:17:24 -07009648 # integer-base-one-3As
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009649 typeset -Uui16 -Z11 pos=0
Geremy Condra03ebf062011-10-12 18:17:24 -07009650 typeset -Uui16 -Z5 hv=2147483647
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009651 typeset -i1 wc=0x0A
9652 dasc=
9653 nl=${wc#1#}
9654 while IFS= read -r line; do
9655 line=$line$nl
9656 while [[ -n $line ]]; do
9657 hv=1#${line::1}
9658 if (( (pos & 15) == 0 )); then
Elliott Hughesa3c3f962017-04-12 16:52:30 -07009659 (( pos )) && print -r -- "$dasc|"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009660 print -n "${pos#16#} "
9661 dasc=' |'
9662 fi
9663 print -n "${hv#16#} "
9664 if (( (hv < 32) || (hv > 126) )); then
9665 dasc=$dasc.
9666 else
9667 dasc=$dasc${line::1}
9668 fi
9669 (( (pos++ & 15) == 7 )) && print -n -- '- '
9670 line=${line:1}
9671 done
9672 done
Geremy Condra03ebf062011-10-12 18:17:24 -07009673 while (( pos & 15 )); do
9674 print -n ' '
9675 (( (pos++ & 15) == 7 )) && print -n -- '- '
9676 done
Elliott Hughesa3c3f962017-04-12 16:52:30 -07009677 (( hv == 2147483647 )) || print -r -- "$dasc|"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009678 }
9679expected-stdout:
9680 00000000 5C 20 5C 21 5C 22 5C 23 - 5C 24 5C 25 5C 26 5C 27 |\ \!\"\#\$\%\&\'|
9681 00000010 5C 28 5C 29 5C 2A 5C 2B - 5C 2C 5C 2D 5C 2E 5C 2F |\(\)\*\+\,\-\.\/|
9682 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|
9683 00000030 20 5C 39 5C 3A 5C 3B 5C - 3C 5C 3D 5C 3E 5C 3F 5C | \9\:\;\<\=\>\?\|
9684 00000040 40 5C 41 5C 42 5C 43 5C - 44 1B 5C 46 5C 47 5C 48 |@\A\B\C\D.\F\G\H|
9685 00000050 5C 49 5C 4A 5C 4B 5C 4C - 5C 4D 5C 4E 5C 4F 5C 50 |\I\J\K\L\M\N\O\P|
Elliott Hughesa3c3f962017-04-12 16:52:30 -07009686 00000060 5C 51 5C 52 5C 53 5C 54 - 20 5C 55 5C 56 5C 57 5C |\Q\R\S\T \U\V\W\|
9687 00000070 58 5C 59 5C 5A 5C 5B 5C - 5C 5D 5C 5E 5C 5F 5C 60 |X\Y\Z\[\\]\^\_\`|
9688 00000080 07 08 20 20 5C 64 1B 0C - 5C 67 5C 68 5C 69 5C 6A |.. \d..\g\h\i\j|
9689 00000090 5C 6B 5C 6C 5C 6D 0A 5C - 6F 5C 70 20 5C 71 0D 5C |\k\l\m.\o\p \q.\|
9690 000000A0 73 09 5C 75 0B 5C 77 5C - 78 5C 79 5C 7A 5C 7B 5C |s.\u.\w\x\y\z\{\|
9691 000000B0 7C 5C 7D 5C 7E 20 E2 82 - AC 64 20 EF BF BD 20 12 ||\}\~ ...d ... .|
9692 000000C0 33 20 78 20 53 20 53 34 - 0A |3 x S S4.|
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009693---
Geremy Condra03ebf062011-10-12 18:17:24 -07009694name: dollar-doublequoted-strings
9695description:
9696 Check that a $ preceding "…" is ignored
9697stdin:
9698 echo $"Localise me!"
9699 cat <<<$"Me too!"
9700 V=X
9701 aol=aol
9702 cat <<-$"aol"
9703 I do not take a $V for a V!
9704 aol
9705expected-stdout:
9706 Localise me!
9707 Me too!
9708 I do not take a $V for a V!
9709---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009710name: dollar-quoted-strings
9711description:
9712 Check backslash expansion by $'…' strings
9713stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009714 print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
9715 chmod +x pfn
9716 ./pfn $'\ \!\"\#\$\%\&\'\(\)\*\+\,\-\.\/ \1\2\3\4\5\6' \
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009717 $'a\0b' $'a\01b' $'\7\8\9\:\;\<\=\>\?\@\A\B\C\D\E\F\G\H\I' \
9718 $'\J\K\L\M\N\O\P\Q\R\S\T\U1\V\W\X\Y\Z\[\\\]\^\_\`\a\b\d\e' \
9719 $'\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u1\v\w\x1\y\z\{\|\}\~ $x' \
9720 $'\u20acd' $'\U20acd' $'\x123' $'fn\x0rd' $'\0234' $'\234' \
9721 $'\2345' $'\ca' $'\c!' $'\c?' $'\c€' $'a\
9722 b' | {
Geremy Condra03ebf062011-10-12 18:17:24 -07009723 # integer-base-one-3As
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009724 typeset -Uui16 -Z11 pos=0
Geremy Condra03ebf062011-10-12 18:17:24 -07009725 typeset -Uui16 -Z5 hv=2147483647
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009726 typeset -i1 wc=0x0A
9727 dasc=
9728 nl=${wc#1#}
9729 while IFS= read -r line; do
9730 line=$line$nl
9731 while [[ -n $line ]]; do
9732 hv=1#${line::1}
9733 if (( (pos & 15) == 0 )); then
Elliott Hughesa3c3f962017-04-12 16:52:30 -07009734 (( pos )) && print -r -- "$dasc|"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009735 print -n "${pos#16#} "
9736 dasc=' |'
9737 fi
9738 print -n "${hv#16#} "
9739 if (( (hv < 32) || (hv > 126) )); then
9740 dasc=$dasc.
9741 else
9742 dasc=$dasc${line::1}
9743 fi
9744 (( (pos++ & 15) == 7 )) && print -n -- '- '
9745 line=${line:1}
9746 done
9747 done
Geremy Condra03ebf062011-10-12 18:17:24 -07009748 while (( pos & 15 )); do
9749 print -n ' '
9750 (( (pos++ & 15) == 7 )) && print -n -- '- '
9751 done
Elliott Hughesa3c3f962017-04-12 16:52:30 -07009752 (( hv == 2147483647 )) || print -r -- "$dasc|"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009753 }
9754expected-stdout:
9755 00000000 20 21 22 23 24 25 26 27 - 28 29 2A 2B 2C 2D 2E 2F | !"#$%&'()*+,-./|
9756 00000010 20 01 02 03 04 05 06 0A - 61 0A 61 01 62 0A 07 38 | .......a.a.b..8|
9757 00000020 39 3A 3B 3C 3D 3E 3F 40 - 41 42 43 44 1B 46 47 48 |9:;<=>?@ABCD.FGH|
9758 00000030 49 0A 4A 4B 4C 4D 4E 4F - 50 51 52 53 54 01 56 57 |I.JKLMNOPQRST.VW|
9759 00000040 58 59 5A 5B 5C 5D 5E 5F - 60 07 08 64 1B 0A 0C 67 |XYZ[\]^_`..d...g|
9760 00000050 68 69 6A 6B 6C 6D 0A 6F - 70 71 0D 73 09 01 0B 77 |hijklm.opq.s...w|
9761 00000060 01 79 7A 7B 7C 7D 7E 20 - 24 78 0A E2 82 AC 64 0A |.yz{|}~ $x....d.|
9762 00000070 EF BF BD 0A C4 A3 0A 66 - 6E 0A 13 34 0A 9C 0A 9C |.......fn..4....|
9763 00000080 35 0A 01 0A 01 0A 7F 0A - 02 82 AC 0A 61 0A 62 0A |5...........a.b.|
9764---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009765name: dollar-quotes-in-heredocs-strings
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009766description:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009767 They are, however, not parsed in here documents, here strings
9768 (outside of string delimiters) or regular strings, but in
9769 parameter substitutions.
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009770stdin:
9771 cat <<EOF
9772 dollar = strchr(s, '$'); /* ' */
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009773 foo " bar \" baz
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009774 EOF
9775 cat <<$'a\tb'
9776 a\tb
9777 a b
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009778 cat <<<"dollar = strchr(s, '$'); /* ' */"
9779 cat <<<'dollar = strchr(s, '\''$'\''); /* '\'' */'
9780 x="dollar = strchr(s, '$'); /* ' */"
9781 cat <<<"$x"
9782 cat <<<$'a\E[0m\tb'
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009783 unset nl; print -r -- "x${nl:=$'\n'}y"
9784 echo "1 foo\"bar"
9785 # cf & HEREDOC
9786 cat <<EOF
9787 2 foo\"bar
9788 EOF
9789 # probably never reached for here strings?
9790 cat <<<"3 foo\"bar"
9791 cat <<<"4 foo\\\"bar"
9792 cat <<<'5 foo\"bar'
9793 # old scripts use this (e.g. ncurses)
9794 echo "^$"
9795 # make sure this works, outside of quotes
9796 cat <<<'7'$'\t''.'
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009797expected-stdout:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009798 dollar = strchr(s, '$'); /* ' */
9799 foo " bar \" baz
9800 a\tb
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009801 dollar = strchr(s, '$'); /* ' */
9802 dollar = strchr(s, '$'); /* ' */
9803 dollar = strchr(s, '$'); /* ' */
9804 a b
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009805 x
9806 y
9807 1 foo"bar
9808 2 foo\"bar
9809 3 foo"bar
9810 4 foo\"bar
9811 5 foo\"bar
9812 ^$
9813 7 .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009814---
9815name: dot-needs-argument
9816description:
9817 check Debian #415167 solution: '.' without arguments should fail
9818stdin:
9819 "$__progname" -c .
9820 "$__progname" -c source
9821expected-exit: e != 0
9822expected-stderr-pattern:
Elliott Hughesfc0307d2016-02-02 15:26:47 -08009823 /\.: missing argument.*\n.*source: missing argument/
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009824---
Elliott Hughes77740fc2016-08-12 15:06:53 -07009825name: dot-errorlevel
9826description:
9827 Ensure dot resets $?
9828stdin:
9829 :>dotfile
9830 (exit 42)
9831 . ./dotfile
9832 echo 1 $? .
9833expected-stdout:
9834 1 0 .
9835---
Elliott Hughes96b43632015-07-17 11:39:41 -07009836name: alias-function-no-conflict
9837description:
9838 make aliases not conflict with function definitions
Elliott Hughes96b43632015-07-17 11:39:41 -07009839stdin:
9840 # POSIX function can be defined, but alias overrides it
9841 alias foo='echo bar'
9842 foo
9843 foo() {
9844 echo baz
9845 }
9846 foo
9847 unset -f foo
9848 foo 2>/dev/null || echo rab
9849 # alias overrides ksh function
9850 alias korn='echo bar'
9851 korn
9852 function korn {
9853 echo baz
9854 }
9855 korn
9856 # alias temporarily overrides POSIX function
9857 bla() {
9858 echo bfn
9859 }
9860 bla
9861 alias bla='echo bal'
9862 bla
9863 unalias bla
9864 bla
9865expected-stdout:
9866 bar
9867 bar
9868 bar
9869 bar
9870 bar
9871 bfn
9872 bal
9873 bfn
9874---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009875name: bash-function-parens
9876description:
9877 ensure the keyword function is ignored when preceding
9878 POSIX style function declarations (bashism)
9879stdin:
9880 mk() {
9881 echo '#!'"$__progname"
9882 echo "$1 {"
9883 echo ' echo "bar='\''$0'\'\"
9884 echo '}'
Elliott Hughesb27ce952015-04-21 13:39:18 -07009885 print -r -- "${2:-foo}"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009886 }
9887 mk 'function foo' >f-korn
9888 mk 'foo ()' >f-dash
9889 mk 'function foo ()' >f-bash
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009890 print '#!'"$__progname"'\nprint -r -- "${0%/f-argh}"' >f-argh
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009891 chmod +x f-*
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +00009892 u=$(./f-argh)
9893 x="korn: $(./f-korn)"; echo "${x/@("$u")/.}"
9894 x="dash: $(./f-dash)"; echo "${x/@("$u")/.}"
9895 x="bash: $(./f-bash)"; echo "${x/@("$u")/.}"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009896expected-stdout:
9897 korn: bar='foo'
9898 dash: bar='./f-dash'
9899 bash: bar='./f-bash'
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -07009900---
9901name: integer-base-one-1
9902description:
9903 check if the use of fake integer base 1 works
9904stdin:
9905 set -U
9906 typeset -Uui16 i0=1#ï i1=1#€
9907 typeset -i1 o0a=64
9908 typeset -i1 o1a=0x263A
9909 typeset -Uui1 o0b=0x7E
9910 typeset -Uui1 o1b=0xFDD0
9911 integer px=0xCAFE 'p0=1# ' p1=1#… pl=1#f
9912 echo "in <$i0> <$i1>"
9913 echo "out <${o0a#1#}|${o0b#1#}> <${o1a#1#}|${o1b#1#}>"
9914 typeset -Uui1 i0 i1
9915 echo "pass <$px> <$p0> <$p1> <$pl> <${i0#1#}|${i1#1#}>"
9916 typeset -Uui16 tv1=1#~ tv2=1# tv3=1#€ tv4=1# tv5=1#À tv6=1#Á tv7=1#  tv8=1#€
9917 echo "specX <${tv1#16#}> <${tv2#16#}> <${tv3#16#}> <${tv4#16#}> <${tv5#16#}> <${tv6#16#}> <${tv7#16#}> <${tv8#16#}>"
9918 typeset -i1 tv1 tv2 tv3 tv4 tv5 tv6 tv7 tv8
9919 echo "specW <${tv1#1#}> <${tv2#1#}> <${tv3#1#}> <${tv4#1#}> <${tv5#1#}> <${tv6#1#}> <${tv7#1#}> <${tv8#1#}>"
9920 typeset -i1 xs1=0xEF7F xs2=0xEF80 xs3=0xFDD0
9921 echo "specU <${xs1#1#}> <${xs2#1#}> <${xs3#1#}>"
9922expected-stdout:
9923 in <16#EFEF> <16#20AC>
9924 out <@|~> <☺|﷐>
9925 pass <16#cafe> <1# > <1#…> <1#f> <ï|€>
9926 specX <7E> <7F> <EF80> <EF81> <EFC0> <EFC1> <A0> <80>
9927 specW <~> <> <€> <> <À> <Á> < > <€>
9928 specU <> <€> <﷐>
9929---
9930name: integer-base-one-2a
9931description:
9932 check if the use of fake integer base 1 stops at correct characters
9933stdin:
9934 set -U
9935 integer x=1#foo
9936 echo /$x/
9937expected-stderr-pattern:
9938 /1#foo: unexpected 'oo'/
9939expected-exit: e != 0
9940---
9941name: integer-base-one-2b
9942description:
9943 check if the use of fake integer base 1 stops at correct characters
9944stdin:
9945 set -U
9946 integer x=1#
9947 echo /$x/
9948expected-stderr-pattern:
9949 /1#À€: unexpected '€'/
9950expected-exit: e != 0
9951---
9952name: integer-base-one-2c1
9953description:
9954 check if the use of fake integer base 1 stops at correct characters
9955stdin:
9956 set -U
9957 integer x=1#…
9958 echo /$x/
9959expected-stdout:
9960 /1#…/
9961---
9962name: integer-base-one-2c2
9963description:
9964 check if the use of fake integer base 1 stops at correct characters
9965stdin:
9966 set +U
9967 integer x=1#…
9968 echo /$x/
9969expected-stderr-pattern:
9970 /1#…: unexpected '€'/
9971expected-exit: e != 0
9972---
9973name: integer-base-one-2d1
9974description:
9975 check if the use of fake integer base 1 handles octets okay
9976stdin:
9977 set -U
9978 typeset -i16 x=1#ÿ
9979 echo /$x/ # invalid utf-8
9980expected-stdout:
9981 /16#efff/
9982---
9983name: integer-base-one-2d2
9984description:
9985 check if the use of fake integer base 1 handles octets
9986stdin:
9987 set -U
9988 typeset -i16 x=1#Â
9989 echo /$x/ # invalid 2-byte
9990expected-stdout:
9991 /16#efc2/
9992---
9993name: integer-base-one-2d3
9994description:
9995 check if the use of fake integer base 1 handles octets
9996stdin:
9997 set -U
9998 typeset -i16 x=1#ï
9999 echo /$x/ # invalid 2-byte
10000expected-stdout:
10001 /16#efef/
10002---
10003name: integer-base-one-2d4
10004description:
10005 check if the use of fake integer base 1 stops at invalid input
10006stdin:
10007 set -U
10008 typeset -i16 x=1#ï¿À
10009 echo /$x/ # invalid 3-byte
10010expected-stderr-pattern:
10011 /1#ï¿À: unexpected '¿'/
10012expected-exit: e != 0
10013---
10014name: integer-base-one-2d5
10015description:
10016 check if the use of fake integer base 1 stops at invalid input
10017stdin:
10018 set -U
10019 typeset -i16 x=1#
10020 echo /$x/ # non-minimalistic
10021expected-stderr-pattern:
10022 /1#À€: unexpected '€'/
10023expected-exit: e != 0
10024---
10025name: integer-base-one-2d6
10026description:
10027 check if the use of fake integer base 1 stops at invalid input
10028stdin:
10029 set -U
10030 typeset -i16 x=1#à€€
10031 echo /$x/ # non-minimalistic
10032expected-stderr-pattern:
10033 /1#à€€: unexpected '€'/
10034expected-exit: e != 0
10035---
Geremy Condra03ebf062011-10-12 18:17:24 -070010036name: integer-base-one-3As
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010037description:
10038 some sample code for hexdumping
Geremy Condra03ebf062011-10-12 18:17:24 -070010039 not NUL safe; input lines must be NL terminated
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010040stdin:
10041 {
10042 print 'Hello, World!\\\nこんにちは!'
10043 typeset -Uui16 i=0x100
10044 # change that to 0xFF once we can handle embedded
10045 # NUL characters in strings / here documents
10046 while (( i++ < 0x1FF )); do
10047 print -n "\x${i#16#1}"
10048 done
Geremy Condra03ebf062011-10-12 18:17:24 -070010049 print '\0z'
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010050 } | {
Geremy Condra03ebf062011-10-12 18:17:24 -070010051 # integer-base-one-3As
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010052 typeset -Uui16 -Z11 pos=0
Geremy Condra03ebf062011-10-12 18:17:24 -070010053 typeset -Uui16 -Z5 hv=2147483647
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010054 typeset -i1 wc=0x0A
10055 dasc=
10056 nl=${wc#1#}
10057 while IFS= read -r line; do
10058 line=$line$nl
10059 while [[ -n $line ]]; do
10060 hv=1#${line::1}
10061 if (( (pos & 15) == 0 )); then
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010062 (( pos )) && print -r -- "$dasc|"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010063 print -n "${pos#16#} "
10064 dasc=' |'
10065 fi
10066 print -n "${hv#16#} "
10067 if (( (hv < 32) || (hv > 126) )); then
10068 dasc=$dasc.
10069 else
10070 dasc=$dasc${line::1}
10071 fi
10072 (( (pos++ & 15) == 7 )) && print -n -- '- '
10073 line=${line:1}
10074 done
10075 done
Geremy Condra03ebf062011-10-12 18:17:24 -070010076 while (( pos & 15 )); do
10077 print -n ' '
10078 (( (pos++ & 15) == 7 )) && print -n -- '- '
10079 done
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010080 (( hv == 2147483647 )) || print -r -- "$dasc|"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010081 }
10082expected-stdout:
10083 00000000 48 65 6C 6C 6F 2C 20 57 - 6F 72 6C 64 21 5C 0A E3 |Hello, World!\..|
10084 00000010 81 93 E3 82 93 E3 81 AB - E3 81 A1 E3 81 AF EF BC |................|
10085 00000020 81 0A 01 02 03 04 05 06 - 07 08 09 0A 0B 0C 0D 0E |................|
10086 00000030 0F 10 11 12 13 14 15 16 - 17 18 19 1A 1B 1C 1D 1E |................|
10087 00000040 1F 20 21 22 23 24 25 26 - 27 28 29 2A 2B 2C 2D 2E |. !"#$%&'()*+,-.|
10088 00000050 2F 30 31 32 33 34 35 36 - 37 38 39 3A 3B 3C 3D 3E |/0123456789:;<=>|
10089 00000060 3F 40 41 42 43 44 45 46 - 47 48 49 4A 4B 4C 4D 4E |?@ABCDEFGHIJKLMN|
10090 00000070 4F 50 51 52 53 54 55 56 - 57 58 59 5A 5B 5C 5D 5E |OPQRSTUVWXYZ[\]^|
10091 00000080 5F 60 61 62 63 64 65 66 - 67 68 69 6A 6B 6C 6D 6E |_`abcdefghijklmn|
10092 00000090 6F 70 71 72 73 74 75 76 - 77 78 79 7A 7B 7C 7D 7E |opqrstuvwxyz{|}~|
10093 000000A0 7F 80 81 82 83 84 85 86 - 87 88 89 8A 8B 8C 8D 8E |................|
10094 000000B0 8F 90 91 92 93 94 95 96 - 97 98 99 9A 9B 9C 9D 9E |................|
10095 000000C0 9F A0 A1 A2 A3 A4 A5 A6 - A7 A8 A9 AA AB AC AD AE |................|
10096 000000D0 AF B0 B1 B2 B3 B4 B5 B6 - B7 B8 B9 BA BB BC BD BE |................|
10097 000000E0 BF C0 C1 C2 C3 C4 C5 C6 - C7 C8 C9 CA CB CC CD CE |................|
10098 000000F0 CF D0 D1 D2 D3 D4 D5 D6 - D7 D8 D9 DA DB DC DD DE |................|
10099 00000100 DF E0 E1 E2 E3 E4 E5 E6 - E7 E8 E9 EA EB EC ED EE |................|
10100 00000110 EF F0 F1 F2 F3 F4 F5 F6 - F7 F8 F9 FA FB FC FD FE |................|
Geremy Condra03ebf062011-10-12 18:17:24 -070010101 00000120 FF 7A 0A - |.z.|
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010102---
Geremy Condra03ebf062011-10-12 18:17:24 -070010103name: integer-base-one-3Ws
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010104description:
10105 some sample code for hexdumping Unicode
Geremy Condra03ebf062011-10-12 18:17:24 -070010106 not NUL safe; input lines must be NL terminated
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010107stdin:
10108 set -U
10109 {
10110 print 'Hello, World!\\\nこんにちは!'
10111 typeset -Uui16 i=0x100
10112 # change that to 0xFF once we can handle embedded
10113 # NUL characters in strings / here documents
10114 while (( i++ < 0x1FF )); do
10115 print -n "\u${i#16#1}"
10116 done
10117 print
10118 print \\xff # invalid utf-8
10119 print \\xc2 # invalid 2-byte
10120 print \\xef\\xbf\\xc0 # invalid 3-byte
10121 print \\xc0\\x80 # non-minimalistic
10122 print \\xe0\\x80\\x80 # non-minimalistic
10123 print '�￾￿' # end of range
Geremy Condra03ebf062011-10-12 18:17:24 -070010124 print '\0z' # embedded NUL
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010125 } | {
Geremy Condra03ebf062011-10-12 18:17:24 -070010126 # integer-base-one-3Ws
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010127 typeset -Uui16 -Z11 pos=0
10128 typeset -Uui16 -Z7 hv
10129 typeset -i1 wc=0x0A
10130 typeset -i lpos
10131 dasc=
10132 nl=${wc#1#}
10133 while IFS= read -r line; do
10134 line=$line$nl
10135 lpos=0
10136 while (( lpos < ${#line} )); do
10137 wc=1#${line:(lpos++):1}
10138 if (( (wc < 32) || \
10139 ((wc > 126) && (wc < 160)) )); then
10140 dch=.
10141 elif (( (wc & 0xFF80) == 0xEF80 )); then
10142 dch=�
10143 else
10144 dch=${wc#1#}
10145 fi
10146 if (( (pos & 7) == 7 )); then
10147 dasc=$dasc$dch
10148 dch=
10149 elif (( (pos & 7) == 0 )); then
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010150 (( pos )) && print -r -- "$dasc|"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010151 print -n "${pos#16#} "
10152 dasc=' |'
10153 fi
10154 let hv=wc
10155 print -n "${hv#16#} "
10156 (( (pos++ & 7) == 3 )) && \
10157 print -n -- '- '
10158 dasc=$dasc$dch
10159 done
10160 done
Geremy Condra03ebf062011-10-12 18:17:24 -070010161 while (( pos & 7 )); do
10162 print -n ' '
10163 (( (pos++ & 7) == 3 )) && print -n -- '- '
10164 done
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010165 (( hv == 2147483647 )) || print -r -- "$dasc|"
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010166 }
10167expected-stdout:
10168 00000000 0048 0065 006C 006C - 006F 002C 0020 0057 |Hello, W|
10169 00000008 006F 0072 006C 0064 - 0021 005C 000A 3053 |orld!\.こ|
10170 00000010 3093 306B 3061 306F - FF01 000A 0001 0002 |んにちは!...|
10171 00000018 0003 0004 0005 0006 - 0007 0008 0009 000A |........|
10172 00000020 000B 000C 000D 000E - 000F 0010 0011 0012 |........|
10173 00000028 0013 0014 0015 0016 - 0017 0018 0019 001A |........|
10174 00000030 001B 001C 001D 001E - 001F 0020 0021 0022 |..... !"|
10175 00000038 0023 0024 0025 0026 - 0027 0028 0029 002A |#$%&'()*|
10176 00000040 002B 002C 002D 002E - 002F 0030 0031 0032 |+,-./012|
10177 00000048 0033 0034 0035 0036 - 0037 0038 0039 003A |3456789:|
10178 00000050 003B 003C 003D 003E - 003F 0040 0041 0042 |;<=>?@AB|
10179 00000058 0043 0044 0045 0046 - 0047 0048 0049 004A |CDEFGHIJ|
10180 00000060 004B 004C 004D 004E - 004F 0050 0051 0052 |KLMNOPQR|
10181 00000068 0053 0054 0055 0056 - 0057 0058 0059 005A |STUVWXYZ|
10182 00000070 005B 005C 005D 005E - 005F 0060 0061 0062 |[\]^_`ab|
10183 00000078 0063 0064 0065 0066 - 0067 0068 0069 006A |cdefghij|
10184 00000080 006B 006C 006D 006E - 006F 0070 0071 0072 |klmnopqr|
10185 00000088 0073 0074 0075 0076 - 0077 0078 0079 007A |stuvwxyz|
10186 00000090 007B 007C 007D 007E - 007F 0080 0081 0082 |{|}~....|
10187 00000098 0083 0084 0085 0086 - 0087 0088 0089 008A |........|
10188 000000A0 008B 008C 008D 008E - 008F 0090 0091 0092 |........|
10189 000000A8 0093 0094 0095 0096 - 0097 0098 0099 009A |........|
10190 000000B0 009B 009C 009D 009E - 009F 00A0 00A1 00A2 |..... ¡¢|
10191 000000B8 00A3 00A4 00A5 00A6 - 00A7 00A8 00A9 00AA |£¤¥¦§¨©ª|
10192 000000C0 00AB 00AC 00AD 00AE - 00AF 00B0 00B1 00B2 |«¬­®¯°±²|
10193 000000C8 00B3 00B4 00B5 00B6 - 00B7 00B8 00B9 00BA |³´µ¶·¸¹º|
10194 000000D0 00BB 00BC 00BD 00BE - 00BF 00C0 00C1 00C2 |»¼½¾¿ÀÁÂ|
10195 000000D8 00C3 00C4 00C5 00C6 - 00C7 00C8 00C9 00CA |ÃÄÅÆÇÈÉÊ|
10196 000000E0 00CB 00CC 00CD 00CE - 00CF 00D0 00D1 00D2 |ËÌÍÎÏÐÑÒ|
10197 000000E8 00D3 00D4 00D5 00D6 - 00D7 00D8 00D9 00DA |ÓÔÕÖרÙÚ|
10198 000000F0 00DB 00DC 00DD 00DE - 00DF 00E0 00E1 00E2 |ÛÜÝÞßàáâ|
10199 000000F8 00E3 00E4 00E5 00E6 - 00E7 00E8 00E9 00EA |ãäåæçèéê|
10200 00000100 00EB 00EC 00ED 00EE - 00EF 00F0 00F1 00F2 |ëìíîïðñò|
10201 00000108 00F3 00F4 00F5 00F6 - 00F7 00F8 00F9 00FA |óôõö÷øùú|
10202 00000110 00FB 00FC 00FD 00FE - 00FF 000A EFFF 000A |ûüýþÿ.�.|
10203 00000118 EFC2 000A EFEF EFBF - EFC0 000A EFC0 EF80 |�.���.��|
10204 00000120 000A EFE0 EF80 EF80 - 000A FFFD EFEF EFBF |.���.���|
Geremy Condra03ebf062011-10-12 18:17:24 -070010205 00000128 EFBE EFEF EFBF EFBF - 000A 007A 000A |����.z.|
10206---
10207name: integer-base-one-3Ar
10208description:
10209 some sample code for hexdumping; NUL and binary safe
10210stdin:
10211 {
10212 print 'Hello, World!\\\nこんにちは!'
10213 typeset -Uui16 i=0x100
10214 # change that to 0xFF once we can handle embedded
10215 # NUL characters in strings / here documents
10216 while (( i++ < 0x1FF )); do
10217 print -n "\x${i#16#1}"
10218 done
10219 print '\0z'
10220 } | {
10221 # integer-base-one-3Ar
10222 typeset -Uui16 -Z11 pos=0
10223 typeset -Uui16 -Z5 hv=2147483647
10224 dasc=
10225 if read -arN -1 line; then
10226 typeset -i1 line
10227 i=0
10228 while (( i < ${#line[*]} )); do
10229 hv=${line[i++]}
10230 if (( (pos & 15) == 0 )); then
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010231 (( pos )) && print -r -- "$dasc|"
Geremy Condra03ebf062011-10-12 18:17:24 -070010232 print -n "${pos#16#} "
10233 dasc=' |'
10234 fi
10235 print -n "${hv#16#} "
10236 if (( (hv < 32) || (hv > 126) )); then
10237 dasc=$dasc.
10238 else
10239 dasc=$dasc${line[i-1]#1#}
10240 fi
10241 (( (pos++ & 15) == 7 )) && print -n -- '- '
10242 done
10243 fi
10244 while (( pos & 15 )); do
10245 print -n ' '
10246 (( (pos++ & 15) == 7 )) && print -n -- '- '
10247 done
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010248 (( hv == 2147483647 )) || print -r -- "$dasc|"
Geremy Condra03ebf062011-10-12 18:17:24 -070010249 }
10250expected-stdout:
10251 00000000 48 65 6C 6C 6F 2C 20 57 - 6F 72 6C 64 21 5C 0A E3 |Hello, World!\..|
10252 00000010 81 93 E3 82 93 E3 81 AB - E3 81 A1 E3 81 AF EF BC |................|
10253 00000020 81 0A 01 02 03 04 05 06 - 07 08 09 0A 0B 0C 0D 0E |................|
10254 00000030 0F 10 11 12 13 14 15 16 - 17 18 19 1A 1B 1C 1D 1E |................|
10255 00000040 1F 20 21 22 23 24 25 26 - 27 28 29 2A 2B 2C 2D 2E |. !"#$%&'()*+,-.|
10256 00000050 2F 30 31 32 33 34 35 36 - 37 38 39 3A 3B 3C 3D 3E |/0123456789:;<=>|
10257 00000060 3F 40 41 42 43 44 45 46 - 47 48 49 4A 4B 4C 4D 4E |?@ABCDEFGHIJKLMN|
10258 00000070 4F 50 51 52 53 54 55 56 - 57 58 59 5A 5B 5C 5D 5E |OPQRSTUVWXYZ[\]^|
10259 00000080 5F 60 61 62 63 64 65 66 - 67 68 69 6A 6B 6C 6D 6E |_`abcdefghijklmn|
10260 00000090 6F 70 71 72 73 74 75 76 - 77 78 79 7A 7B 7C 7D 7E |opqrstuvwxyz{|}~|
10261 000000A0 7F 80 81 82 83 84 85 86 - 87 88 89 8A 8B 8C 8D 8E |................|
10262 000000B0 8F 90 91 92 93 94 95 96 - 97 98 99 9A 9B 9C 9D 9E |................|
10263 000000C0 9F A0 A1 A2 A3 A4 A5 A6 - A7 A8 A9 AA AB AC AD AE |................|
10264 000000D0 AF B0 B1 B2 B3 B4 B5 B6 - B7 B8 B9 BA BB BC BD BE |................|
10265 000000E0 BF C0 C1 C2 C3 C4 C5 C6 - C7 C8 C9 CA CB CC CD CE |................|
10266 000000F0 CF D0 D1 D2 D3 D4 D5 D6 - D7 D8 D9 DA DB DC DD DE |................|
10267 00000100 DF E0 E1 E2 E3 E4 E5 E6 - E7 E8 E9 EA EB EC ED EE |................|
10268 00000110 EF F0 F1 F2 F3 F4 F5 F6 - F7 F8 F9 FA FB FC FD FE |................|
10269 00000120 FF 00 7A 0A - |..z.|
10270---
10271name: integer-base-one-3Wr
10272description:
10273 some sample code for hexdumping Unicode; NUL and binary safe
10274stdin:
10275 set -U
10276 {
10277 print 'Hello, World!\\\nこんにちは!'
10278 typeset -Uui16 i=0x100
10279 # change that to 0xFF once we can handle embedded
10280 # NUL characters in strings / here documents
10281 while (( i++ < 0x1FF )); do
10282 print -n "\u${i#16#1}"
10283 done
10284 print
10285 print \\xff # invalid utf-8
10286 print \\xc2 # invalid 2-byte
10287 print \\xef\\xbf\\xc0 # invalid 3-byte
10288 print \\xc0\\x80 # non-minimalistic
10289 print \\xe0\\x80\\x80 # non-minimalistic
10290 print '�￾￿' # end of range
10291 print '\0z' # embedded NUL
10292 } | {
10293 # integer-base-one-3Wr
10294 typeset -Uui16 -Z11 pos=0
10295 typeset -Uui16 -Z7 hv=2147483647
10296 dasc=
10297 if read -arN -1 line; then
10298 typeset -i1 line
10299 i=0
10300 while (( i < ${#line[*]} )); do
10301 hv=${line[i++]}
10302 if (( (hv < 32) || \
10303 ((hv > 126) && (hv < 160)) )); then
10304 dch=.
10305 elif (( (hv & 0xFF80) == 0xEF80 )); then
10306 dch=�
10307 else
10308 dch=${line[i-1]#1#}
10309 fi
10310 if (( (pos & 7) == 7 )); then
10311 dasc=$dasc$dch
10312 dch=
10313 elif (( (pos & 7) == 0 )); then
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010314 (( pos )) && print -r -- "$dasc|"
Geremy Condra03ebf062011-10-12 18:17:24 -070010315 print -n "${pos#16#} "
10316 dasc=' |'
10317 fi
10318 print -n "${hv#16#} "
10319 (( (pos++ & 7) == 3 )) && \
10320 print -n -- '- '
10321 dasc=$dasc$dch
10322 done
10323 fi
10324 while (( pos & 7 )); do
10325 print -n ' '
10326 (( (pos++ & 7) == 3 )) && print -n -- '- '
10327 done
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010328 (( hv == 2147483647 )) || print -r -- "$dasc|"
Geremy Condra03ebf062011-10-12 18:17:24 -070010329 }
10330expected-stdout:
10331 00000000 0048 0065 006C 006C - 006F 002C 0020 0057 |Hello, W|
10332 00000008 006F 0072 006C 0064 - 0021 005C 000A 3053 |orld!\.こ|
10333 00000010 3093 306B 3061 306F - FF01 000A 0001 0002 |んにちは!...|
10334 00000018 0003 0004 0005 0006 - 0007 0008 0009 000A |........|
10335 00000020 000B 000C 000D 000E - 000F 0010 0011 0012 |........|
10336 00000028 0013 0014 0015 0016 - 0017 0018 0019 001A |........|
10337 00000030 001B 001C 001D 001E - 001F 0020 0021 0022 |..... !"|
10338 00000038 0023 0024 0025 0026 - 0027 0028 0029 002A |#$%&'()*|
10339 00000040 002B 002C 002D 002E - 002F 0030 0031 0032 |+,-./012|
10340 00000048 0033 0034 0035 0036 - 0037 0038 0039 003A |3456789:|
10341 00000050 003B 003C 003D 003E - 003F 0040 0041 0042 |;<=>?@AB|
10342 00000058 0043 0044 0045 0046 - 0047 0048 0049 004A |CDEFGHIJ|
10343 00000060 004B 004C 004D 004E - 004F 0050 0051 0052 |KLMNOPQR|
10344 00000068 0053 0054 0055 0056 - 0057 0058 0059 005A |STUVWXYZ|
10345 00000070 005B 005C 005D 005E - 005F 0060 0061 0062 |[\]^_`ab|
10346 00000078 0063 0064 0065 0066 - 0067 0068 0069 006A |cdefghij|
10347 00000080 006B 006C 006D 006E - 006F 0070 0071 0072 |klmnopqr|
10348 00000088 0073 0074 0075 0076 - 0077 0078 0079 007A |stuvwxyz|
10349 00000090 007B 007C 007D 007E - 007F 0080 0081 0082 |{|}~....|
10350 00000098 0083 0084 0085 0086 - 0087 0088 0089 008A |........|
10351 000000A0 008B 008C 008D 008E - 008F 0090 0091 0092 |........|
10352 000000A8 0093 0094 0095 0096 - 0097 0098 0099 009A |........|
10353 000000B0 009B 009C 009D 009E - 009F 00A0 00A1 00A2 |..... ¡¢|
10354 000000B8 00A3 00A4 00A5 00A6 - 00A7 00A8 00A9 00AA |£¤¥¦§¨©ª|
10355 000000C0 00AB 00AC 00AD 00AE - 00AF 00B0 00B1 00B2 |«¬­®¯°±²|
10356 000000C8 00B3 00B4 00B5 00B6 - 00B7 00B8 00B9 00BA |³´µ¶·¸¹º|
10357 000000D0 00BB 00BC 00BD 00BE - 00BF 00C0 00C1 00C2 |»¼½¾¿ÀÁÂ|
10358 000000D8 00C3 00C4 00C5 00C6 - 00C7 00C8 00C9 00CA |ÃÄÅÆÇÈÉÊ|
10359 000000E0 00CB 00CC 00CD 00CE - 00CF 00D0 00D1 00D2 |ËÌÍÎÏÐÑÒ|
10360 000000E8 00D3 00D4 00D5 00D6 - 00D7 00D8 00D9 00DA |ÓÔÕÖרÙÚ|
10361 000000F0 00DB 00DC 00DD 00DE - 00DF 00E0 00E1 00E2 |ÛÜÝÞßàáâ|
10362 000000F8 00E3 00E4 00E5 00E6 - 00E7 00E8 00E9 00EA |ãäåæçèéê|
10363 00000100 00EB 00EC 00ED 00EE - 00EF 00F0 00F1 00F2 |ëìíîïðñò|
10364 00000108 00F3 00F4 00F5 00F6 - 00F7 00F8 00F9 00FA |óôõö÷øùú|
10365 00000110 00FB 00FC 00FD 00FE - 00FF 000A EFFF 000A |ûüýþÿ.�.|
10366 00000118 EFC2 000A EFEF EFBF - EFC0 000A EFC0 EF80 |�.���.��|
10367 00000120 000A EFE0 EF80 EF80 - 000A FFFD EFEF EFBF |.���.���|
10368 00000128 EFBE EFEF EFBF EFBF - 000A 0000 007A 000A |����..z.|
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010369---
10370name: integer-base-one-4
10371description:
10372 Check if ksh93-style base-one integers work
10373category: !smksh
10374stdin:
10375 set -U
10376 echo 1 $(('a'))
10377 (echo 2f $(('aa'))) 2>&1 | sed "s/^[^']*'/2p '/"
10378 echo 3 $(('…'))
10379 x="'a'"
10380 echo "4 <$x>"
10381 echo 5 $(($x))
10382 echo 6 $((x))
10383expected-stdout:
10384 1 97
10385 2p 'aa': multi-character character constant
10386 3 8230
10387 4 <'a'>
10388 5 97
10389 6 97
10390---
Geremy Condra03ebf062011-10-12 18:17:24 -070010391name: integer-base-one-5A
10392description:
10393 Check to see that we’re NUL and Unicode safe
10394stdin:
10395 set +U
10396 print 'a\0b\xfdz' >x
10397 read -a y <x
10398 set -U
10399 typeset -Uui16 y
10400 print ${y[*]} .
10401expected-stdout:
10402 16#61 16#0 16#62 16#FD 16#7A .
10403---
10404name: integer-base-one-5W
10405description:
10406 Check to see that we’re NUL and Unicode safe
10407stdin:
10408 set -U
10409 print 'a\0b€c' >x
10410 read -a y <x
10411 set +U
10412 typeset -Uui16 y
10413 print ${y[*]} .
10414expected-stdout:
10415 16#61 16#0 16#62 16#20AC 16#63 .
10416---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010417name: ulimit-1
10418description:
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010419 Check that ulimit as used in dot.mksh works or is stubbed
10420stdin:
10421 ulimit -c 0
10422---
10423name: ulimit-2
10424description:
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010425 Check if we can use a specific syntax idiom for ulimit
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010426 XXX Haiku works, but only for -n and -V
10427category: !os:haiku,!os:syllable
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010428stdin:
10429 if ! x=$(ulimit -d) || [[ $x = unknown ]]; then
10430 #echo expected to fail on this OS
10431 echo okay
10432 else
10433 ulimit -dS $x && echo okay
10434 fi
10435expected-stdout:
10436 okay
10437---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000010438name: redir-1
10439description:
10440 Check some of the most basic invariants of I/O redirection
10441stdin:
10442 i=0
10443 function d {
10444 print o$i.
10445 print -u2 e$((i++)).
10446 }
10447 d >a 2>b
10448 echo =1=
10449 cat a
10450 echo =2=
10451 cat b
10452 echo =3=
10453 d 2>&1 >c
10454 echo =4=
10455 cat c
10456 echo =5=
10457expected-stdout:
10458 =1=
10459 o0.
10460 =2=
10461 e0.
10462 =3=
10463 e1.
10464 =4=
10465 o1.
10466 =5=
10467---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010468name: bashiop-1
10469description:
10470 Check if GNU bash-like I/O redirection works
10471 Part 1: this is also supported by GNU bash
10472stdin:
10473 exec 3>&1
10474 function threeout {
10475 echo ras
10476 echo dwa >&2
10477 echo tri >&3
10478 }
10479 threeout &>foo
10480 echo ===
10481 cat foo
10482expected-stdout:
10483 tri
10484 ===
10485 ras
10486 dwa
10487---
10488name: bashiop-2a
10489description:
10490 Check if GNU bash-like I/O redirection works
10491 Part 2: this is *not* supported by GNU bash
10492stdin:
10493 exec 3>&1
10494 function threeout {
10495 echo ras
10496 echo dwa >&2
10497 echo tri >&3
10498 }
10499 threeout 3&>foo
10500 echo ===
10501 cat foo
10502expected-stdout:
10503 ras
10504 ===
10505 dwa
10506 tri
10507---
10508name: bashiop-2b
10509description:
10510 Check if GNU bash-like I/O redirection works
10511 Part 2: this is *not* supported by GNU bash
10512stdin:
10513 exec 3>&1
10514 function threeout {
10515 echo ras
10516 echo dwa >&2
10517 echo tri >&3
10518 }
10519 threeout 3>foo &>&3
10520 echo ===
10521 cat foo
10522expected-stdout:
10523 ===
10524 ras
10525 dwa
10526 tri
10527---
10528name: bashiop-2c
10529description:
10530 Check if GNU bash-like I/O redirection works
10531 Part 2: this is supported by GNU bash 4 only
10532stdin:
10533 echo mir >foo
10534 set -o noclobber
10535 exec 3>&1
10536 function threeout {
10537 echo ras
10538 echo dwa >&2
10539 echo tri >&3
10540 }
10541 threeout &>>foo
10542 echo ===
10543 cat foo
10544expected-stdout:
10545 tri
10546 ===
10547 mir
10548 ras
10549 dwa
10550---
10551name: bashiop-3a
10552description:
10553 Check if GNU bash-like I/O redirection fails correctly
10554 Part 1: this is also supported by GNU bash
10555stdin:
10556 echo mir >foo
10557 set -o noclobber
10558 exec 3>&1
10559 function threeout {
10560 echo ras
10561 echo dwa >&2
10562 echo tri >&3
10563 }
10564 threeout &>foo
10565 echo ===
10566 cat foo
10567expected-stdout:
10568 ===
10569 mir
Geremy Condra03ebf062011-10-12 18:17:24 -070010570expected-stderr-pattern: /.*: can't (create|overwrite) .*/
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010571---
10572name: bashiop-3b
10573description:
10574 Check if GNU bash-like I/O redirection fails correctly
10575 Part 2: this is *not* supported by GNU bash
10576stdin:
10577 echo mir >foo
10578 set -o noclobber
10579 exec 3>&1
10580 function threeout {
10581 echo ras
10582 echo dwa >&2
10583 echo tri >&3
10584 }
10585 threeout &>|foo
10586 echo ===
10587 cat foo
10588expected-stdout:
10589 tri
10590 ===
10591 ras
10592 dwa
10593---
10594name: bashiop-4
10595description:
10596 Check if GNU bash-like I/O redirection works
10597 Part 4: this is also supported by GNU bash,
10598 but failed in some mksh versions
10599stdin:
10600 exec 3>&1
10601 function threeout {
10602 echo ras
10603 echo dwa >&2
10604 echo tri >&3
10605 }
10606 function blubb {
10607 [[ -e bar ]] && threeout "$bf" &>foo
10608 }
10609 blubb
10610 echo -n >bar
10611 blubb
10612 echo ===
10613 cat foo
10614expected-stdout:
10615 tri
10616 ===
10617 ras
10618 dwa
10619---
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010620name: bashiop-5
Thorsten Glaser811a5752013-07-25 14:24:45 +000010621description:
10622 Check if GNU bash-like I/O redirection is only supported
10623 in !POSIX !sh mode as it breaks existing scripts' syntax
Thorsten Glaser811a5752013-07-25 14:24:45 +000010624stdin:
10625 :>x; echo 1 "$("$__progname" -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
10626 :>x; echo 2 "$("$__progname" -o posix -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
10627 :>x; echo 3 "$("$__progname" -o sh -c 'echo foo>/dev/null&>x echo bar')" = "$(<x)" .
10628expected-stdout:
10629 1 = foo echo bar .
10630 2 = bar .
10631 3 = bar .
10632---
Thorsten Glaser811a5752013-07-25 14:24:45 +000010633name: oksh-eval
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010634description:
Elliott Hughes737fdce2014-08-07 12:59:26 -070010635 Check expansions.
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010636stdin:
Thorsten Glaser811a5752013-07-25 14:24:45 +000010637 a=
10638 for n in ${a#*=}; do echo 1hu ${n} .; done
10639 for n in "${a#*=}"; do echo 1hq ${n} .; done
10640 for n in ${a##*=}; do echo 2hu ${n} .; done
10641 for n in "${a##*=}"; do echo 2hq ${n} .; done
10642 for n in ${a%=*}; do echo 1pu ${n} .; done
10643 for n in "${a%=*}"; do echo 1pq ${n} .; done
10644 for n in ${a%%=*}; do echo 2pu ${n} .; done
10645 for n in "${a%%=*}"; do echo 2pq ${n} .; done
10646expected-stdout:
10647 1hq .
10648 2hq .
10649 1pq .
10650 2pq .
10651---
10652name: oksh-and-list-error-1
10653description:
10654 Test exit status of rightmost element in 2 element && list in -e mode
10655stdin:
10656 true && false
10657 echo "should not print"
10658arguments: !-e!
10659expected-exit: e != 0
10660---
10661name: oksh-and-list-error-2
10662description:
10663 Test exit status of rightmost element in 3 element && list in -e mode
10664stdin:
10665 true && true && false
10666 echo "should not print"
10667arguments: !-e!
10668expected-exit: e != 0
10669---
10670name: oksh-or-list-error-1
10671description:
10672 Test exit status of || list in -e mode
10673stdin:
10674 false || false
10675 echo "should not print"
10676arguments: !-e!
10677expected-exit: e != 0
10678---
10679name: oksh-longline-crash
10680description:
10681 This used to cause a core dump
10682stdin:
10683 ulimit -c 0
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010684 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"
10685 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"
10686 for deplib in $deplibs; do
10687 case $deplib in
10688 -L*)
10689 new_libs="$deplib $new_libs"
10690 ;;
10691 *)
10692 case " $specialdeplibs " in
10693 *" $deplib "*)
10694 new_libs="$deplib $new_libs";;
10695 esac
10696 ;;
10697 esac
10698 done
10699---
Thorsten Glaser811a5752013-07-25 14:24:45 +000010700name: oksh-seterror-1
10701description:
10702 The -e flag should be ignored when executing a compound list
10703 followed by an if statement.
10704stdin:
10705 if true; then false && false; fi
10706 true
10707arguments: !-e!
10708expected-exit: e == 0
10709---
10710name: oksh-seterror-2
10711description:
10712 The -e flag should be ignored when executing a compound list
10713 followed by an if statement.
10714stdin:
10715 if true; then if true; then false && false; fi; fi
10716 true
10717arguments: !-e!
10718expected-exit: e == 0
10719---
10720name: oksh-seterror-3
10721description:
10722 The -e flag should be ignored when executing a compound list
10723 followed by an elif statement.
10724stdin:
10725 if true; then :; elif true; then false && false; fi
10726arguments: !-e!
10727expected-exit: e == 0
10728---
10729name: oksh-seterror-4
10730description:
10731 The -e flag should be ignored when executing a pipeline
10732 beginning with '!'
10733stdin:
10734 for i in 1 2 3
10735 do
10736 false && false
10737 true || false
10738 done
10739arguments: !-e!
10740expected-exit: e == 0
10741---
10742name: oksh-seterror-5
10743description:
10744 The -e flag should be ignored when executing a pipeline
10745 beginning with '!'
10746stdin:
10747 ! true | false
10748 true
10749arguments: !-e!
10750expected-exit: e == 0
10751---
10752name: oksh-seterror-6
10753description:
10754 When trapping ERR and EXIT, both traps should run in -e mode
10755 when an error occurs.
10756stdin:
10757 trap 'echo EXIT' EXIT
10758 trap 'echo ERR' ERR
10759 set -e
10760 false
10761 echo DONE
10762 exit 0
10763arguments: !-e!
10764expected-exit: e != 0
10765expected-stdout:
10766 ERR
10767 EXIT
10768---
10769name: oksh-seterror-7
10770description:
10771 The -e flag within a command substitution should be honored
10772stdin:
10773 echo $( set -e; false; echo foo )
10774arguments: !-e!
10775expected-stdout:
10776
10777---
10778name: oksh-input-comsub
10779description:
10780 A command substitution using input redirection should exit with
10781 failure if the input file does not exist.
10782stdin:
10783 var=$(< non-existent)
10784expected-exit: e != 0
10785expected-stderr-pattern: /non-existent/
10786---
10787name: oksh-empty-for-list
10788description:
10789 A for list which expands to zero items should not execute the body.
10790stdin:
10791 set foo bar baz ; for out in ; do echo $out ; done
10792---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010793name: oksh-varfunction-mod1
10794description:
Elliott Hughes737fdce2014-08-07 12:59:26 -070010795 (Inspired by PR 2450 on OpenBSD.) Calling
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010796 FOO=bar f
10797 where f is a ksh style function, should not set FOO in the current
10798 env. If f is a Bourne style function, FOO should be set. Furthermore,
10799 the function should receive a correct value of FOO. However, differing
10800 from oksh, setting FOO in the function itself must change the value in
10801 setting FOO in the function itself should not change the value in
10802 global environment.
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010803stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000010804 print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \
10805 'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \
Elliott Hughes96b43632015-07-17 11:39:41 -070010806 done >env; chmod +x env; PATH=.$PATHSEP$PATH
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010807 function k {
10808 if [ x$FOO != xbar ]; then
10809 echo 1
10810 return 1
10811 fi
10812 x=$(env | grep FOO)
10813 if [ "x$x" != "xFOO=bar" ]; then
10814 echo 2
10815 return 1;
10816 fi
10817 FOO=foo
10818 return 0
10819 }
10820 b () {
10821 if [ x$FOO != xbar ]; then
10822 echo 3
10823 return 1
10824 fi
10825 x=$(env | grep FOO)
10826 if [ "x$x" != "xFOO=bar" ]; then
10827 echo 4
10828 return 1;
10829 fi
10830 FOO=foo
10831 return 0
10832 }
10833 FOO=bar k
10834 if [ $? != 0 ]; then
10835 exit 1
10836 fi
10837 if [ x$FOO != x ]; then
10838 exit 1
10839 fi
10840 FOO=bar b
10841 if [ $? != 0 ]; then
10842 exit 1
10843 fi
10844 if [ x$FOO != xfoo ]; then
10845 exit 1
10846 fi
10847 FOO=barbar
10848 FOO=bar k
10849 if [ $? != 0 ]; then
10850 exit 1
10851 fi
10852 if [ x$FOO != xbarbar ]; then
10853 exit 1
10854 fi
10855 FOO=bar b
10856 if [ $? != 0 ]; then
10857 exit 1
10858 fi
10859 if [ x$FOO != xfoo ]; then
10860 exit 1
10861 fi
10862---
10863name: fd-cloexec-1
10864description:
10865 Verify that file descriptors > 2 are private for Korn shells
Geremy Condra03ebf062011-10-12 18:17:24 -070010866 AT&T ksh93 does this still, which means we must keep it as well
Elliott Hughes77740fc2016-08-12 15:06:53 -070010867 XXX fails on some old Perl installations
10868need-pass: no
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010869stdin:
Elliott Hughesb27ce952015-04-21 13:39:18 -070010870 cat >cld <<-EOF
10871 #!$__perlname
10872 open(my \$fh, ">&", 9) or die "E: open \$!";
10873 syswrite(\$fh, "Fowl\\n", 5) or die "E: write \$!";
10874 EOF
10875 chmod +x cld
10876 exec 9>&1
10877 ./cld
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010878expected-exit: e != 0
Geremy Condra03ebf062011-10-12 18:17:24 -070010879expected-stderr-pattern:
Elliott Hughesb27ce952015-04-21 13:39:18 -070010880 /E: open /
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010881---
10882name: fd-cloexec-2
10883description:
10884 Verify that file descriptors > 2 are not private for POSIX shells
10885 See Debian Bug #154540, Closes: #499139
Elliott Hughes77740fc2016-08-12 15:06:53 -070010886 XXX fails on some old Perl installations
10887need-pass: no
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010888stdin:
Elliott Hughesb27ce952015-04-21 13:39:18 -070010889 cat >cld <<-EOF
10890 #!$__perlname
10891 open(my \$fh, ">&", 9) or die "E: open \$!";
10892 syswrite(\$fh, "Fowl\\n", 5) or die "E: write \$!";
10893 EOF
10894 chmod +x cld
10895 test -n "$POSH_VERSION" || set -o posix
10896 exec 9>&1
10897 ./cld
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010898expected-stdout:
10899 Fowl
10900---
Geremy Condra03ebf062011-10-12 18:17:24 -070010901name: comsub-1a
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010902description:
Geremy Condra03ebf062011-10-12 18:17:24 -070010903 COMSUB are now parsed recursively, so this works
10904 see also regression-6: matching parenthesēs bug
10905 Fails on: pdksh bash2 bash3 zsh
10906 Passes on: bash4 ksh93 mksh(20110313+)
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010907stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000010908 echo 1 $(case 1 in (1) echo yes;; (2) echo no;; esac) .
10909 echo 2 $(case 1 in 1) echo yes;; 2) echo no;; esac) .
10910 TEST=1234; echo 3 ${TEST: $(case 1 in (1) echo 1;; (*) echo 2;; esac)} .
10911 TEST=5678; echo 4 ${TEST: $(case 1 in 1) echo 1;; *) echo 2;; esac)} .
10912 a=($(case 1 in (1) echo 1;; (*) echo 2;; esac)); echo 5 ${a[0]} .
10913 a=($(case 1 in 1) echo 1;; *) echo 2;; esac)); echo 6 ${a[0]} .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010914expected-stdout:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000010915 1 yes .
10916 2 yes .
10917 3 234 .
10918 4 678 .
10919 5 1 .
10920 6 1 .
Geremy Condra03ebf062011-10-12 18:17:24 -070010921---
10922name: comsub-1b
10923description:
10924 COMSUB are now parsed recursively, so this works
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000010925 Fails on: pdksh bash2 bash3 bash4 zsh
10926 Passes on: ksh93 mksh(20110313+)
Geremy Condra03ebf062011-10-12 18:17:24 -070010927stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000010928 echo 1 $(($(case 1 in (1) echo 1;; (*) echo 2;; esac)+10)) .
10929 echo 2 $(($(case 1 in 1) echo 1;; *) echo 2;; esac)+20)) .
10930 (( a = $(case 1 in (1) echo 1;; (*) echo 2;; esac) )); echo 3 $a .
10931 (( a = $(case 1 in 1) echo 1;; *) echo 2;; esac) )); echo 4 $a .
10932 a=($(($(case 1 in (1) echo 1;; (*) echo 2;; esac)+10))); echo 5 ${a[0]} .
10933 a=($(($(case 1 in 1) echo 1;; *) echo 2;; esac)+20))); echo 6 ${a[0]} .
Geremy Condra03ebf062011-10-12 18:17:24 -070010934expected-stdout:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000010935 1 11 .
10936 2 21 .
10937 3 1 .
10938 4 1 .
10939 5 11 .
10940 6 21 .
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010941---
10942name: comsub-2
10943description:
10944 RedHat BZ#496791 – another case of missing recursion
10945 in parsing COMSUB expressions
Geremy Condra03ebf062011-10-12 18:17:24 -070010946 Fails on: pdksh bash2 bash3¹ bash4¹ zsh
10947 Passes on: ksh93 mksh(20110305+)
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010948 ① bash[34] seem to choke on comment ending with backslash-newline
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070010949stdin:
10950 # a comment with " ' \
10951 x=$(
10952 echo yes
10953 # a comment with " ' \
10954 )
10955 echo $x
10956expected-stdout:
10957 yes
10958---
Geremy Condra03ebf062011-10-12 18:17:24 -070010959name: comsub-3
10960description:
10961 Extended test for COMSUB explaining why a recursive parser
10962 is a must (a non-recursive parser cannot pass all three of
10963 these test cases, especially the ‘#’ is difficult)
10964stdin:
Elliott Hughes96b43632015-07-17 11:39:41 -070010965 print '#!'"$__progname"'\necho 1234' >id; chmod +x id; PATH=.$PATHSEP$PATH
Geremy Condra03ebf062011-10-12 18:17:24 -070010966 echo $(typeset -i10 x=16#20; echo $x)
10967 echo $(typeset -Uui16 x=16#$(id -u)
10968 ) .
10969 echo $(c=1; d=1
10970 typeset -Uui16 a=36#foo; c=2
10971 typeset -Uui16 b=36 #foo; d=2
10972 echo $a $b $c $d)
10973expected-stdout:
10974 32
10975 .
10976 16#4F68 16#24 2 1
10977---
10978name: comsub-4
10979description:
10980 Check the tree dump functions for !MKSH_SMALL functionality
10981category: !smksh
10982stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000010983 x() { case $1 in u) echo x ;;& *) echo $1 ;; esac; }
Geremy Condra03ebf062011-10-12 18:17:24 -070010984 typeset -f x
10985expected-stdout:
10986 x() {
10987 case $1 in
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000010988 (u)
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010989 \echo x
Geremy Condra03ebf062011-10-12 18:17:24 -070010990 ;|
10991 (*)
Elliott Hughesa3c3f962017-04-12 16:52:30 -070010992 \echo $1
Geremy Condra03ebf062011-10-12 18:17:24 -070010993 ;;
10994 esac
10995 }
10996---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000010997name: comsub-5
10998description:
10999 Check COMSUB works with aliases (does not expand them twice)
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011000 and reentrancy safety
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011001stdin:
11002 print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn
11003 chmod +x pfn
11004 alias echo='echo a'
11005 foo() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011006 echo moo
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011007 ./pfn "$(echo foo)"
11008 }
11009 ./pfn "$(echo b)"
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011010 typeset -f foo >x
11011 cat x
11012 foo
11013 . ./x
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011014 typeset -f foo
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011015 foo
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011016expected-stdout:
11017 a b
11018 foo() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011019 \echo a moo
11020 ./pfn "$(\echo a foo )"
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011021 }
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011022 a moo
11023 a foo
11024 foo() {
11025 \echo a moo
11026 ./pfn "$(\echo a foo )"
11027 }
11028 a moo
11029 a foo
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011030---
Geremy Condra03ebf062011-10-12 18:17:24 -070011031name: comsub-torture
11032description:
11033 Check the tree dump functions work correctly
11034stdin:
11035 if [[ -z $__progname ]]; then echo >&2 call me with __progname; exit 1; fi
11036 while IFS= read -r line; do
11037 if [[ $line = '#1' ]]; then
11038 lastf=0
11039 continue
11040 elif [[ $line = EOFN* ]]; then
11041 fbody=$fbody$'\n'$line
11042 continue
11043 elif [[ $line != '#'* ]]; then
11044 fbody=$fbody$'\n\t'$line
11045 continue
11046 fi
11047 if (( lastf )); then
11048 x="inline_${nextf}() {"$fbody$'\n}\n'
11049 print -nr -- "$x"
11050 print -r -- "${x}typeset -f inline_$nextf" | "$__progname"
11051 x="function comsub_$nextf { x=\$("$fbody$'\n); }\n'
11052 print -nr -- "$x"
11053 print -r -- "${x}typeset -f comsub_$nextf" | "$__progname"
11054 x="function reread_$nextf { x=\$(("$fbody$'\n)|tr u x); }\n'
11055 print -nr -- "$x"
11056 print -r -- "${x}typeset -f reread_$nextf" | "$__progname"
11057 fi
11058 lastf=1
11059 fbody=
11060 nextf=${line#?}
11061 done <<'EOD'
11062 #1
11063 #TCOM
11064 vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4"
11065 #TPAREN_TPIPE_TLIST
11066 (echo $foo | tr -dc 0-9; echo)
11067 #TAND_TOR
11068 cmd && echo ja || echo nein
11069 #TSELECT
11070 select file in *; do echo "<$file>" ; break ; done
11071 #TFOR_TTIME
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011072 time for i in {1,2,3} ; do echo $i ; done
Geremy Condra03ebf062011-10-12 18:17:24 -070011073 #TCASE
11074 case $foo in 1) echo eins;& 2) echo zwei ;| *) echo kann net bis drei zählen;; esac
11075 #TIF_TBANG_TDBRACKET_TELIF
11076 if ! [[ 1 = 1 ]] ; then echo eins; elif [[ 1 = 2 ]]; then echo zwei ;else echo drei; fi
11077 #TWHILE
11078 i=1; while (( i < 10 )); do echo $i; let ++i; done
11079 #TUNTIL
11080 i=10; until (( !--i )) ; do echo $i; done
11081 #TCOPROC
11082 cat * |& ls
11083 #TFUNCT_TBRACE_TASYNC
11084 function korn { echo eins; echo zwei ; }
11085 bourne () { logger * & }
11086 #IOREAD_IOCAT
11087 tr x u 0<foo >>bar
11088 #IOWRITE_IOCLOB_IOHERE_noIOSKIP
11089 cat >|bar <<'EOFN'
11090 foo
11091 EOFN
11092 #IOWRITE_noIOCLOB_IOHERE_IOSKIP
11093 cat 1>bar <<-EOFI
11094 foo
11095 EOFI
11096 #IORDWR_IODUP
11097 sh 1<>/dev/console 0<&1 2>&1
Thorsten Glaser811a5752013-07-25 14:24:45 +000011098 #COMSUB_EXPRSUB_FUNSUB_VALSUB
11099 echo $(true) $((1+ 2)) ${ :;} ${| REPLY=x;}
Geremy Condra03ebf062011-10-12 18:17:24 -070011100 #QCHAR_OQUOTE_CQUOTE
11101 echo fo\ob\"a\`r\'b\$az
11102 echo "fo\ob\"a\`r\'b\$az"
11103 echo 'fo\ob\"a\`r'\''b\$az'
11104 #OSUBST_CSUBST_OPAT_SPAT_CPAT
11105 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
11106 #heredoc_closed
11107 x=$(cat <<EOFN
11108 note there must be no space between EOFN and )
11109 EOFN); echo $x
11110 #heredoc_space
11111 x=$(cat <<EOFN\
11112 note the space between EOFN and ) is actually part of the here document marker
11113 EOFN ); echo $x
11114 #patch_motd
11115 x=$(sysctl -n kern.version | sed 1q)
11116 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
11117 ed -s /etc/motd 2>&1 <<-EOF
11118 1,/^\$/d
11119 0a
11120 $x
11121
11122 .
11123 wq
11124 EOF)" = @(?) ]] && rm -f /etc/motd
11125 if [[ ! -s /etc/motd ]]; then
11126 install -c -o root -g wheel -m 664 /dev/null /etc/motd
11127 print -- "$x\n" >/etc/motd
11128 fi
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011129 #wdarrassign
11130 case x in
11131 x) a+=b; c+=(d e)
11132 esac
Geremy Condra03ebf062011-10-12 18:17:24 -070011133 #0
11134 EOD
11135expected-stdout:
11136 inline_TCOM() {
11137 vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4"
11138 }
11139 inline_TCOM() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011140 vara=1 varb="2 3" \cmd arg1 $arg2 "$arg3 4"
Geremy Condra03ebf062011-10-12 18:17:24 -070011141 }
11142 function comsub_TCOM { x=$(
11143 vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4"
11144 ); }
11145 function comsub_TCOM {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011146 x=$(vara=1 varb="2 3" \cmd arg1 $arg2 "$arg3 4" )
Geremy Condra03ebf062011-10-12 18:17:24 -070011147 }
11148 function reread_TCOM { x=$((
11149 vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4"
11150 )|tr u x); }
11151 function reread_TCOM {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011152 x=$( ( vara=1 varb="2 3" \cmd arg1 $arg2 "$arg3 4" ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011153 }
11154 inline_TPAREN_TPIPE_TLIST() {
11155 (echo $foo | tr -dc 0-9; echo)
11156 }
11157 inline_TPAREN_TPIPE_TLIST() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011158 ( \echo $foo | \tr -dc 0-9
11159 \echo )
Geremy Condra03ebf062011-10-12 18:17:24 -070011160 }
11161 function comsub_TPAREN_TPIPE_TLIST { x=$(
11162 (echo $foo | tr -dc 0-9; echo)
11163 ); }
11164 function comsub_TPAREN_TPIPE_TLIST {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011165 x=$( ( \echo $foo | \tr -dc 0-9 ; \echo ) )
Geremy Condra03ebf062011-10-12 18:17:24 -070011166 }
11167 function reread_TPAREN_TPIPE_TLIST { x=$((
11168 (echo $foo | tr -dc 0-9; echo)
11169 )|tr u x); }
11170 function reread_TPAREN_TPIPE_TLIST {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011171 x=$( ( ( \echo $foo | \tr -dc 0-9 ; \echo ) ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011172 }
11173 inline_TAND_TOR() {
11174 cmd && echo ja || echo nein
11175 }
11176 inline_TAND_TOR() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011177 \cmd && \echo ja || \echo nein
Geremy Condra03ebf062011-10-12 18:17:24 -070011178 }
11179 function comsub_TAND_TOR { x=$(
11180 cmd && echo ja || echo nein
11181 ); }
11182 function comsub_TAND_TOR {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011183 x=$(\cmd && \echo ja || \echo nein )
Geremy Condra03ebf062011-10-12 18:17:24 -070011184 }
11185 function reread_TAND_TOR { x=$((
11186 cmd && echo ja || echo nein
11187 )|tr u x); }
11188 function reread_TAND_TOR {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011189 x=$( ( \cmd && \echo ja || \echo nein ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011190 }
11191 inline_TSELECT() {
11192 select file in *; do echo "<$file>" ; break ; done
11193 }
11194 inline_TSELECT() {
11195 select file in *
11196 do
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011197 \echo "<$file>"
11198 \break
Geremy Condra03ebf062011-10-12 18:17:24 -070011199 done
11200 }
11201 function comsub_TSELECT { x=$(
11202 select file in *; do echo "<$file>" ; break ; done
11203 ); }
11204 function comsub_TSELECT {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011205 x=$(select file in * ; do \echo "<$file>" ; \break ; done )
Geremy Condra03ebf062011-10-12 18:17:24 -070011206 }
11207 function reread_TSELECT { x=$((
11208 select file in *; do echo "<$file>" ; break ; done
11209 )|tr u x); }
11210 function reread_TSELECT {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011211 x=$( ( select file in * ; do \echo "<$file>" ; \break ; done ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011212 }
11213 inline_TFOR_TTIME() {
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011214 time for i in {1,2,3} ; do echo $i ; done
Geremy Condra03ebf062011-10-12 18:17:24 -070011215 }
11216 inline_TFOR_TTIME() {
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011217 time for i in {1,2,3}
Geremy Condra03ebf062011-10-12 18:17:24 -070011218 do
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011219 \echo $i
Geremy Condra03ebf062011-10-12 18:17:24 -070011220 done
11221 }
11222 function comsub_TFOR_TTIME { x=$(
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011223 time for i in {1,2,3} ; do echo $i ; done
Geremy Condra03ebf062011-10-12 18:17:24 -070011224 ); }
11225 function comsub_TFOR_TTIME {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011226 x=$(time for i in {1,2,3} ; do \echo $i ; done )
Geremy Condra03ebf062011-10-12 18:17:24 -070011227 }
11228 function reread_TFOR_TTIME { x=$((
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011229 time for i in {1,2,3} ; do echo $i ; done
Geremy Condra03ebf062011-10-12 18:17:24 -070011230 )|tr u x); }
11231 function reread_TFOR_TTIME {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011232 x=$( ( time for i in {1,2,3} ; do \echo $i ; done ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011233 }
11234 inline_TCASE() {
11235 case $foo in 1) echo eins;& 2) echo zwei ;| *) echo kann net bis drei zählen;; esac
11236 }
11237 inline_TCASE() {
11238 case $foo in
11239 (1)
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011240 \echo eins
Geremy Condra03ebf062011-10-12 18:17:24 -070011241 ;&
11242 (2)
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011243 \echo zwei
Geremy Condra03ebf062011-10-12 18:17:24 -070011244 ;|
11245 (*)
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011246 \echo kann net bis drei zählen
Geremy Condra03ebf062011-10-12 18:17:24 -070011247 ;;
11248 esac
11249 }
11250 function comsub_TCASE { x=$(
11251 case $foo in 1) echo eins;& 2) echo zwei ;| *) echo kann net bis drei zählen;; esac
11252 ); }
11253 function comsub_TCASE {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011254 x=$(case $foo in (1) \echo eins ;& (2) \echo zwei ;| (*) \echo kann net bis drei zählen ;; esac )
Geremy Condra03ebf062011-10-12 18:17:24 -070011255 }
11256 function reread_TCASE { x=$((
11257 case $foo in 1) echo eins;& 2) echo zwei ;| *) echo kann net bis drei zählen;; esac
11258 )|tr u x); }
11259 function reread_TCASE {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011260 x=$( ( case $foo in (1) \echo eins ;& (2) \echo zwei ;| (*) \echo kann net bis drei zählen ;; esac ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011261 }
11262 inline_TIF_TBANG_TDBRACKET_TELIF() {
11263 if ! [[ 1 = 1 ]] ; then echo eins; elif [[ 1 = 2 ]]; then echo zwei ;else echo drei; fi
11264 }
11265 inline_TIF_TBANG_TDBRACKET_TELIF() {
11266 if ! [[ 1 = 1 ]]
11267 then
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011268 \echo eins
Geremy Condra03ebf062011-10-12 18:17:24 -070011269 elif [[ 1 = 2 ]]
11270 then
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011271 \echo zwei
Geremy Condra03ebf062011-10-12 18:17:24 -070011272 else
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011273 \echo drei
Geremy Condra03ebf062011-10-12 18:17:24 -070011274 fi
11275 }
11276 function comsub_TIF_TBANG_TDBRACKET_TELIF { x=$(
11277 if ! [[ 1 = 1 ]] ; then echo eins; elif [[ 1 = 2 ]]; then echo zwei ;else echo drei; fi
11278 ); }
11279 function comsub_TIF_TBANG_TDBRACKET_TELIF {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011280 x=$(if ! [[ 1 = 1 ]] ; then \echo eins ; elif [[ 1 = 2 ]] ; then \echo zwei ; else \echo drei ; fi )
Geremy Condra03ebf062011-10-12 18:17:24 -070011281 }
11282 function reread_TIF_TBANG_TDBRACKET_TELIF { x=$((
11283 if ! [[ 1 = 1 ]] ; then echo eins; elif [[ 1 = 2 ]]; then echo zwei ;else echo drei; fi
11284 )|tr u x); }
11285 function reread_TIF_TBANG_TDBRACKET_TELIF {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011286 x=$( ( if ! [[ 1 = 1 ]] ; then \echo eins ; elif [[ 1 = 2 ]] ; then \echo zwei ; else \echo drei ; fi ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011287 }
11288 inline_TWHILE() {
11289 i=1; while (( i < 10 )); do echo $i; let ++i; done
11290 }
11291 inline_TWHILE() {
11292 i=1
Elliott Hughesfc0307d2016-02-02 15:26:47 -080011293 while {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011294 \\builtin let " i < 10 "
Elliott Hughesfc0307d2016-02-02 15:26:47 -080011295 }
Geremy Condra03ebf062011-10-12 18:17:24 -070011296 do
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011297 \echo $i
11298 \let ++i
Geremy Condra03ebf062011-10-12 18:17:24 -070011299 done
11300 }
11301 function comsub_TWHILE { x=$(
11302 i=1; while (( i < 10 )); do echo $i; let ++i; done
11303 ); }
11304 function comsub_TWHILE {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011305 x=$(i=1 ; while { \\builtin let " i < 10 " ; } ; do \echo $i ; \let ++i ; done )
Geremy Condra03ebf062011-10-12 18:17:24 -070011306 }
11307 function reread_TWHILE { x=$((
11308 i=1; while (( i < 10 )); do echo $i; let ++i; done
11309 )|tr u x); }
11310 function reread_TWHILE {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011311 x=$( ( i=1 ; while { \\builtin let " i < 10 " ; } ; do \echo $i ; \let ++i ; done ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011312 }
11313 inline_TUNTIL() {
11314 i=10; until (( !--i )) ; do echo $i; done
11315 }
11316 inline_TUNTIL() {
11317 i=10
Elliott Hughesfc0307d2016-02-02 15:26:47 -080011318 until {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011319 \\builtin let " !--i "
Elliott Hughesfc0307d2016-02-02 15:26:47 -080011320 }
Geremy Condra03ebf062011-10-12 18:17:24 -070011321 do
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011322 \echo $i
Geremy Condra03ebf062011-10-12 18:17:24 -070011323 done
11324 }
11325 function comsub_TUNTIL { x=$(
11326 i=10; until (( !--i )) ; do echo $i; done
11327 ); }
11328 function comsub_TUNTIL {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011329 x=$(i=10 ; until { \\builtin let " !--i " ; } ; do \echo $i ; done )
Geremy Condra03ebf062011-10-12 18:17:24 -070011330 }
11331 function reread_TUNTIL { x=$((
11332 i=10; until (( !--i )) ; do echo $i; done
11333 )|tr u x); }
11334 function reread_TUNTIL {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011335 x=$( ( i=10 ; until { \\builtin let " !--i " ; } ; do \echo $i ; done ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011336 }
11337 inline_TCOPROC() {
11338 cat * |& ls
11339 }
11340 inline_TCOPROC() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011341 \cat * |&
11342 \ls
Geremy Condra03ebf062011-10-12 18:17:24 -070011343 }
11344 function comsub_TCOPROC { x=$(
11345 cat * |& ls
11346 ); }
11347 function comsub_TCOPROC {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011348 x=$(\cat * |& \ls )
Geremy Condra03ebf062011-10-12 18:17:24 -070011349 }
11350 function reread_TCOPROC { x=$((
11351 cat * |& ls
11352 )|tr u x); }
11353 function reread_TCOPROC {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011354 x=$( ( \cat * |& \ls ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011355 }
11356 inline_TFUNCT_TBRACE_TASYNC() {
11357 function korn { echo eins; echo zwei ; }
11358 bourne () { logger * & }
11359 }
11360 inline_TFUNCT_TBRACE_TASYNC() {
11361 function korn {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011362 \echo eins
11363 \echo zwei
Geremy Condra03ebf062011-10-12 18:17:24 -070011364 }
11365 bourne() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011366 \logger * &
Geremy Condra03ebf062011-10-12 18:17:24 -070011367 }
11368 }
11369 function comsub_TFUNCT_TBRACE_TASYNC { x=$(
11370 function korn { echo eins; echo zwei ; }
11371 bourne () { logger * & }
11372 ); }
11373 function comsub_TFUNCT_TBRACE_TASYNC {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011374 x=$(function korn { \echo eins ; \echo zwei ; } ; bourne() { \logger * & } )
Geremy Condra03ebf062011-10-12 18:17:24 -070011375 }
11376 function reread_TFUNCT_TBRACE_TASYNC { x=$((
11377 function korn { echo eins; echo zwei ; }
11378 bourne () { logger * & }
11379 )|tr u x); }
11380 function reread_TFUNCT_TBRACE_TASYNC {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011381 x=$( ( function korn { \echo eins ; \echo zwei ; } ; bourne() { \logger * & } ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011382 }
11383 inline_IOREAD_IOCAT() {
11384 tr x u 0<foo >>bar
11385 }
11386 inline_IOREAD_IOCAT() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011387 \tr x u <foo >>bar
Geremy Condra03ebf062011-10-12 18:17:24 -070011388 }
11389 function comsub_IOREAD_IOCAT { x=$(
11390 tr x u 0<foo >>bar
11391 ); }
11392 function comsub_IOREAD_IOCAT {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011393 x=$(\tr x u <foo >>bar )
Geremy Condra03ebf062011-10-12 18:17:24 -070011394 }
11395 function reread_IOREAD_IOCAT { x=$((
11396 tr x u 0<foo >>bar
11397 )|tr u x); }
11398 function reread_IOREAD_IOCAT {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011399 x=$( ( \tr x u <foo >>bar ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011400 }
11401 inline_IOWRITE_IOCLOB_IOHERE_noIOSKIP() {
11402 cat >|bar <<'EOFN'
11403 foo
11404 EOFN
11405 }
11406 inline_IOWRITE_IOCLOB_IOHERE_noIOSKIP() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011407 \cat >|bar <<"EOFN"
Geremy Condra03ebf062011-10-12 18:17:24 -070011408 foo
11409 EOFN
11410
11411 }
11412 function comsub_IOWRITE_IOCLOB_IOHERE_noIOSKIP { x=$(
11413 cat >|bar <<'EOFN'
11414 foo
11415 EOFN
11416 ); }
11417 function comsub_IOWRITE_IOCLOB_IOHERE_noIOSKIP {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011418 x=$(\cat >|bar <<"EOFN"
Geremy Condra03ebf062011-10-12 18:17:24 -070011419 foo
11420 EOFN
11421 )
11422 }
11423 function reread_IOWRITE_IOCLOB_IOHERE_noIOSKIP { x=$((
11424 cat >|bar <<'EOFN'
11425 foo
11426 EOFN
11427 )|tr u x); }
11428 function reread_IOWRITE_IOCLOB_IOHERE_noIOSKIP {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011429 x=$( ( \cat >|bar <<"EOFN"
Geremy Condra03ebf062011-10-12 18:17:24 -070011430 foo
11431 EOFN
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011432 ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011433 }
11434 inline_IOWRITE_noIOCLOB_IOHERE_IOSKIP() {
11435 cat 1>bar <<-EOFI
11436 foo
11437 EOFI
11438 }
11439 inline_IOWRITE_noIOCLOB_IOHERE_IOSKIP() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011440 \cat >bar <<-EOFI
Geremy Condra03ebf062011-10-12 18:17:24 -070011441 foo
11442 EOFI
11443
11444 }
11445 function comsub_IOWRITE_noIOCLOB_IOHERE_IOSKIP { x=$(
11446 cat 1>bar <<-EOFI
11447 foo
11448 EOFI
11449 ); }
11450 function comsub_IOWRITE_noIOCLOB_IOHERE_IOSKIP {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011451 x=$(\cat >bar <<-EOFI
Geremy Condra03ebf062011-10-12 18:17:24 -070011452 foo
11453 EOFI
11454 )
11455 }
11456 function reread_IOWRITE_noIOCLOB_IOHERE_IOSKIP { x=$((
11457 cat 1>bar <<-EOFI
11458 foo
11459 EOFI
11460 )|tr u x); }
11461 function reread_IOWRITE_noIOCLOB_IOHERE_IOSKIP {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011462 x=$( ( \cat >bar <<-EOFI
Geremy Condra03ebf062011-10-12 18:17:24 -070011463 foo
11464 EOFI
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011465 ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011466 }
11467 inline_IORDWR_IODUP() {
11468 sh 1<>/dev/console 0<&1 2>&1
11469 }
11470 inline_IORDWR_IODUP() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011471 \sh 1<>/dev/console <&1 2>&1
Geremy Condra03ebf062011-10-12 18:17:24 -070011472 }
11473 function comsub_IORDWR_IODUP { x=$(
11474 sh 1<>/dev/console 0<&1 2>&1
11475 ); }
11476 function comsub_IORDWR_IODUP {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011477 x=$(\sh 1<>/dev/console <&1 2>&1 )
Geremy Condra03ebf062011-10-12 18:17:24 -070011478 }
11479 function reread_IORDWR_IODUP { x=$((
11480 sh 1<>/dev/console 0<&1 2>&1
11481 )|tr u x); }
11482 function reread_IORDWR_IODUP {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011483 x=$( ( \sh 1<>/dev/console <&1 2>&1 ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011484 }
Thorsten Glaser811a5752013-07-25 14:24:45 +000011485 inline_COMSUB_EXPRSUB_FUNSUB_VALSUB() {
11486 echo $(true) $((1+ 2)) ${ :;} ${| REPLY=x;}
Geremy Condra03ebf062011-10-12 18:17:24 -070011487 }
Thorsten Glaser811a5752013-07-25 14:24:45 +000011488 inline_COMSUB_EXPRSUB_FUNSUB_VALSUB() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011489 \echo $(\true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;}
Geremy Condra03ebf062011-10-12 18:17:24 -070011490 }
Thorsten Glaser811a5752013-07-25 14:24:45 +000011491 function comsub_COMSUB_EXPRSUB_FUNSUB_VALSUB { x=$(
11492 echo $(true) $((1+ 2)) ${ :;} ${| REPLY=x;}
Geremy Condra03ebf062011-10-12 18:17:24 -070011493 ); }
Thorsten Glaser811a5752013-07-25 14:24:45 +000011494 function comsub_COMSUB_EXPRSUB_FUNSUB_VALSUB {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011495 x=$(\echo $(\true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} )
Geremy Condra03ebf062011-10-12 18:17:24 -070011496 }
Thorsten Glaser811a5752013-07-25 14:24:45 +000011497 function reread_COMSUB_EXPRSUB_FUNSUB_VALSUB { x=$((
11498 echo $(true) $((1+ 2)) ${ :;} ${| REPLY=x;}
Geremy Condra03ebf062011-10-12 18:17:24 -070011499 )|tr u x); }
Thorsten Glaser811a5752013-07-25 14:24:45 +000011500 function reread_COMSUB_EXPRSUB_FUNSUB_VALSUB {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011501 x=$( ( \echo $(\true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011502 }
11503 inline_QCHAR_OQUOTE_CQUOTE() {
11504 echo fo\ob\"a\`r\'b\$az
11505 echo "fo\ob\"a\`r\'b\$az"
11506 echo 'fo\ob\"a\`r'\''b\$az'
11507 }
11508 inline_QCHAR_OQUOTE_CQUOTE() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011509 \echo fo\ob\"a\`r\'b\$az
11510 \echo "fo\ob\"a\`r\'b\$az"
11511 \echo "fo\\ob\\\"a\\\`r"\'"b\\\$az"
Geremy Condra03ebf062011-10-12 18:17:24 -070011512 }
11513 function comsub_QCHAR_OQUOTE_CQUOTE { x=$(
11514 echo fo\ob\"a\`r\'b\$az
11515 echo "fo\ob\"a\`r\'b\$az"
11516 echo 'fo\ob\"a\`r'\''b\$az'
11517 ); }
11518 function comsub_QCHAR_OQUOTE_CQUOTE {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011519 x=$(\echo fo\ob\"a\`r\'b\$az ; \echo "fo\ob\"a\`r\'b\$az" ; \echo "fo\\ob\\\"a\\\`r"\'"b\\\$az" )
Geremy Condra03ebf062011-10-12 18:17:24 -070011520 }
11521 function reread_QCHAR_OQUOTE_CQUOTE { x=$((
11522 echo fo\ob\"a\`r\'b\$az
11523 echo "fo\ob\"a\`r\'b\$az"
11524 echo 'fo\ob\"a\`r'\''b\$az'
11525 )|tr u x); }
11526 function reread_QCHAR_OQUOTE_CQUOTE {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011527 x=$( ( \echo fo\ob\"a\`r\'b\$az ; \echo "fo\ob\"a\`r\'b\$az" ; \echo "fo\\ob\\\"a\\\`r"\'"b\\\$az" ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011528 }
11529 inline_OSUBST_CSUBST_OPAT_SPAT_CPAT() {
11530 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
11531 }
11532 inline_OSUBST_CSUBST_OPAT_SPAT_CPAT() {
11533 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
11534 }
11535 function comsub_OSUBST_CSUBST_OPAT_SPAT_CPAT { x=$(
11536 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
11537 ); }
11538 function comsub_OSUBST_CSUBST_OPAT_SPAT_CPAT {
11539 x=$([[ ${foo#bl\(u\)b} = @(bar|baz) ]] )
11540 }
11541 function reread_OSUBST_CSUBST_OPAT_SPAT_CPAT { x=$((
11542 [[ ${foo#bl\(u\)b} = @(bar|baz) ]]
11543 )|tr u x); }
11544 function reread_OSUBST_CSUBST_OPAT_SPAT_CPAT {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011545 x=$( ( [[ ${foo#bl\(u\)b} = @(bar|baz) ]] ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011546 }
11547 inline_heredoc_closed() {
11548 x=$(cat <<EOFN
11549 note there must be no space between EOFN and )
11550 EOFN); echo $x
11551 }
11552 inline_heredoc_closed() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011553 x=$(\cat <<EOFN
Geremy Condra03ebf062011-10-12 18:17:24 -070011554 note there must be no space between EOFN and )
11555 EOFN
11556 )
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011557 \echo $x
Geremy Condra03ebf062011-10-12 18:17:24 -070011558 }
11559 function comsub_heredoc_closed { x=$(
11560 x=$(cat <<EOFN
11561 note there must be no space between EOFN and )
11562 EOFN); echo $x
11563 ); }
11564 function comsub_heredoc_closed {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011565 x=$(x=$(\cat <<EOFN
Geremy Condra03ebf062011-10-12 18:17:24 -070011566 note there must be no space between EOFN and )
11567 EOFN
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011568 ) ; \echo $x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011569 }
11570 function reread_heredoc_closed { x=$((
11571 x=$(cat <<EOFN
11572 note there must be no space between EOFN and )
11573 EOFN); echo $x
11574 )|tr u x); }
11575 function reread_heredoc_closed {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011576 x=$( ( x=$(\cat <<EOFN
Geremy Condra03ebf062011-10-12 18:17:24 -070011577 note there must be no space between EOFN and )
11578 EOFN
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011579 ) ; \echo $x ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011580 }
11581 inline_heredoc_space() {
11582 x=$(cat <<EOFN\
11583 note the space between EOFN and ) is actually part of the here document marker
11584 EOFN ); echo $x
11585 }
11586 inline_heredoc_space() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011587 x=$(\cat <<EOFN\
Geremy Condra03ebf062011-10-12 18:17:24 -070011588 note the space between EOFN and ) is actually part of the here document marker
11589 EOFN
11590 )
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011591 \echo $x
Geremy Condra03ebf062011-10-12 18:17:24 -070011592 }
11593 function comsub_heredoc_space { x=$(
11594 x=$(cat <<EOFN\
11595 note the space between EOFN and ) is actually part of the here document marker
11596 EOFN ); echo $x
11597 ); }
11598 function comsub_heredoc_space {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011599 x=$(x=$(\cat <<EOFN\
Geremy Condra03ebf062011-10-12 18:17:24 -070011600 note the space between EOFN and ) is actually part of the here document marker
11601 EOFN
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011602 ) ; \echo $x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011603 }
11604 function reread_heredoc_space { x=$((
11605 x=$(cat <<EOFN\
11606 note the space between EOFN and ) is actually part of the here document marker
11607 EOFN ); echo $x
11608 )|tr u x); }
11609 function reread_heredoc_space {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011610 x=$( ( x=$(\cat <<EOFN\
Geremy Condra03ebf062011-10-12 18:17:24 -070011611 note the space between EOFN and ) is actually part of the here document marker
11612 EOFN
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011613 ) ; \echo $x ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011614 }
11615 inline_patch_motd() {
11616 x=$(sysctl -n kern.version | sed 1q)
11617 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
11618 ed -s /etc/motd 2>&1 <<-EOF
11619 1,/^\$/d
11620 0a
11621 $x
11622
11623 .
11624 wq
11625 EOF)" = @(?) ]] && rm -f /etc/motd
11626 if [[ ! -s /etc/motd ]]; then
11627 install -c -o root -g wheel -m 664 /dev/null /etc/motd
11628 print -- "$x\n" >/etc/motd
11629 fi
11630 }
11631 inline_patch_motd() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011632 x=$(\sysctl -n kern.version | \sed 1q )
11633 [[ -s /etc/motd && "$([[ "$(\head -1 /etc/motd )" != $x ]] && \ed -s /etc/motd 2>&1 <<-EOF
Geremy Condra03ebf062011-10-12 18:17:24 -070011634 1,/^\$/d
11635 0a
11636 $x
11637
11638 .
11639 wq
11640 EOF
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011641 )" = @(?) ]] && \rm -f /etc/motd
Geremy Condra03ebf062011-10-12 18:17:24 -070011642 if [[ ! -s /etc/motd ]]
11643 then
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011644 \install -c -o root -g wheel -m 664 /dev/null /etc/motd
11645 \print -- "$x\n" >/etc/motd
Geremy Condra03ebf062011-10-12 18:17:24 -070011646 fi
11647 }
11648 function comsub_patch_motd { x=$(
11649 x=$(sysctl -n kern.version | sed 1q)
11650 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
11651 ed -s /etc/motd 2>&1 <<-EOF
11652 1,/^\$/d
11653 0a
11654 $x
11655
11656 .
11657 wq
11658 EOF)" = @(?) ]] && rm -f /etc/motd
11659 if [[ ! -s /etc/motd ]]; then
11660 install -c -o root -g wheel -m 664 /dev/null /etc/motd
11661 print -- "$x\n" >/etc/motd
11662 fi
11663 ); }
11664 function comsub_patch_motd {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011665 x=$(x=$(\sysctl -n kern.version | \sed 1q ) ; [[ -s /etc/motd && "$([[ "$(\head -1 /etc/motd )" != $x ]] && \ed -s /etc/motd 2>&1 <<-EOF
Geremy Condra03ebf062011-10-12 18:17:24 -070011666 1,/^\$/d
11667 0a
11668 $x
11669
11670 .
11671 wq
11672 EOF
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011673 )" = @(?) ]] && \rm -f /etc/motd ; if [[ ! -s /etc/motd ]] ; then \install -c -o root -g wheel -m 664 /dev/null /etc/motd ; \print -- "$x\n" >/etc/motd ; fi )
Geremy Condra03ebf062011-10-12 18:17:24 -070011674 }
11675 function reread_patch_motd { x=$((
11676 x=$(sysctl -n kern.version | sed 1q)
11677 [[ -s /etc/motd && "$([[ "$(head -1 /etc/motd)" != $x ]] && \
11678 ed -s /etc/motd 2>&1 <<-EOF
11679 1,/^\$/d
11680 0a
11681 $x
11682
11683 .
11684 wq
11685 EOF)" = @(?) ]] && rm -f /etc/motd
11686 if [[ ! -s /etc/motd ]]; then
11687 install -c -o root -g wheel -m 664 /dev/null /etc/motd
11688 print -- "$x\n" >/etc/motd
11689 fi
11690 )|tr u x); }
11691 function reread_patch_motd {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011692 x=$( ( x=$(\sysctl -n kern.version | \sed 1q ) ; [[ -s /etc/motd && "$([[ "$(\head -1 /etc/motd )" != $x ]] && \ed -s /etc/motd 2>&1 <<-EOF
Geremy Condra03ebf062011-10-12 18:17:24 -070011693 1,/^\$/d
11694 0a
11695 $x
11696
11697 .
11698 wq
11699 EOF
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011700 )" = @(?) ]] && \rm -f /etc/motd ; if [[ ! -s /etc/motd ]] ; then \install -c -o root -g wheel -m 664 /dev/null /etc/motd ; \print -- "$x\n" >/etc/motd ; fi ) | \tr u x )
Geremy Condra03ebf062011-10-12 18:17:24 -070011701 }
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011702 inline_wdarrassign() {
11703 case x in
11704 x) a+=b; c+=(d e)
11705 esac
11706 }
11707 inline_wdarrassign() {
11708 case x in
11709 (x)
11710 a+=b
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011711 \\builtin set -A c+ -- d e
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011712 ;;
11713 esac
11714 }
11715 function comsub_wdarrassign { x=$(
11716 case x in
11717 x) a+=b; c+=(d e)
11718 esac
11719 ); }
11720 function comsub_wdarrassign {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011721 x=$(case x in (x) a+=b ; \\builtin set -A c+ -- d e ;; esac )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011722 }
11723 function reread_wdarrassign { x=$((
11724 case x in
11725 x) a+=b; c+=(d e)
11726 esac
11727 )|tr u x); }
11728 function reread_wdarrassign {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011729 x=$( ( case x in (x) a+=b ; \\builtin set -A c+ -- d e ;; esac ) | \tr u x )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011730 }
11731---
11732name: comsub-torture-io
11733description:
11734 Check the tree dump functions work correctly with I/O redirection
11735stdin:
11736 if [[ -z $__progname ]]; then echo >&2 call me with __progname; exit 1; fi
11737 while IFS= read -r line; do
11738 if [[ $line = '#1' ]]; then
11739 lastf=0
11740 continue
11741 elif [[ $line = EOFN* ]]; then
11742 fbody=$fbody$'\n'$line
11743 continue
11744 elif [[ $line != '#'* ]]; then
11745 fbody=$fbody$'\n\t'$line
11746 continue
11747 fi
11748 if (( lastf )); then
11749 x="inline_${nextf}() {"$fbody$'\n}\n'
11750 print -nr -- "$x"
11751 print -r -- "${x}typeset -f inline_$nextf" | "$__progname"
11752 x="function comsub_$nextf { x=\$("$fbody$'\n); }\n'
11753 print -nr -- "$x"
11754 print -r -- "${x}typeset -f comsub_$nextf" | "$__progname"
11755 x="function reread_$nextf { x=\$(("$fbody$'\n)|tr u x); }\n'
11756 print -nr -- "$x"
11757 print -r -- "${x}typeset -f reread_$nextf" | "$__progname"
11758 fi
11759 lastf=1
11760 fbody=
11761 nextf=${line#?}
11762 done <<'EOD'
11763 #1
11764 #TCOM
11765 vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4" >&3
11766 #TPAREN_TPIPE_TLIST
11767 (echo $foo | tr -dc 0-9 >&3; echo >&3) >&3
11768 #TAND_TOR
11769 cmd >&3 && >&3 echo ja || echo >&3 nein
11770 #TSELECT
11771 select file in *; do echo "<$file>" ; break >&3 ; done >&3
11772 #TFOR_TTIME
11773 for i in {1,2,3} ; do time >&3 echo $i ; done >&3
11774 #TCASE
11775 case $foo in 1) echo eins >&3;& 2) echo zwei >&3 ;| *) echo kann net bis drei zählen >&3;; esac >&3
11776 #TIF_TBANG_TDBRACKET_TELIF
11777 if ! [[ 1 = 1 ]] >&3 ; then echo eins; elif [[ 1 = 2 ]] >&3; then echo zwei ;else echo drei; fi >&3
11778 #TWHILE
11779 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
11780 #TUNTIL
11781 i=10; until (( !--i )) >&3 ; do echo $i; done >&3
11782 #TCOPROC
11783 cat * >&3 |& >&3 ls
11784 #TFUNCT_TBRACE_TASYNC
11785 function korn { echo eins; echo >&3 zwei ; }
11786 bourne () { logger * >&3 & }
11787 #COMSUB_EXPRSUB
11788 echo $(true >&3) $((1+ 2))
11789 #0
11790 EOD
11791expected-stdout:
11792 inline_TCOM() {
11793 vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4" >&3
11794 }
11795 inline_TCOM() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011796 vara=1 varb="2 3" \cmd arg1 $arg2 "$arg3 4" >&3
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011797 }
11798 function comsub_TCOM { x=$(
11799 vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4" >&3
11800 ); }
11801 function comsub_TCOM {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011802 x=$(vara=1 varb="2 3" \cmd arg1 $arg2 "$arg3 4" >&3 )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011803 }
11804 function reread_TCOM { x=$((
11805 vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4" >&3
11806 )|tr u x); }
11807 function reread_TCOM {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011808 x=$( ( vara=1 varb="2 3" \cmd arg1 $arg2 "$arg3 4" >&3 ) | \tr u x )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011809 }
11810 inline_TPAREN_TPIPE_TLIST() {
11811 (echo $foo | tr -dc 0-9 >&3; echo >&3) >&3
11812 }
11813 inline_TPAREN_TPIPE_TLIST() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011814 ( \echo $foo | \tr -dc 0-9 >&3
11815 \echo >&3 ) >&3
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011816 }
11817 function comsub_TPAREN_TPIPE_TLIST { x=$(
11818 (echo $foo | tr -dc 0-9 >&3; echo >&3) >&3
11819 ); }
11820 function comsub_TPAREN_TPIPE_TLIST {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011821 x=$( ( \echo $foo | \tr -dc 0-9 >&3 ; \echo >&3 ) >&3 )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011822 }
11823 function reread_TPAREN_TPIPE_TLIST { x=$((
11824 (echo $foo | tr -dc 0-9 >&3; echo >&3) >&3
11825 )|tr u x); }
11826 function reread_TPAREN_TPIPE_TLIST {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011827 x=$( ( ( \echo $foo | \tr -dc 0-9 >&3 ; \echo >&3 ) >&3 ) | \tr u x )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011828 }
11829 inline_TAND_TOR() {
11830 cmd >&3 && >&3 echo ja || echo >&3 nein
11831 }
11832 inline_TAND_TOR() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011833 \cmd >&3 && \echo ja >&3 || \echo nein >&3
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011834 }
11835 function comsub_TAND_TOR { x=$(
11836 cmd >&3 && >&3 echo ja || echo >&3 nein
11837 ); }
11838 function comsub_TAND_TOR {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011839 x=$(\cmd >&3 && \echo ja >&3 || \echo nein >&3 )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011840 }
11841 function reread_TAND_TOR { x=$((
11842 cmd >&3 && >&3 echo ja || echo >&3 nein
11843 )|tr u x); }
11844 function reread_TAND_TOR {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011845 x=$( ( \cmd >&3 && \echo ja >&3 || \echo nein >&3 ) | \tr u x )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011846 }
11847 inline_TSELECT() {
11848 select file in *; do echo "<$file>" ; break >&3 ; done >&3
11849 }
11850 inline_TSELECT() {
11851 select file in *
11852 do
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011853 \echo "<$file>"
11854 \break >&3
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011855 done >&3
11856 }
11857 function comsub_TSELECT { x=$(
11858 select file in *; do echo "<$file>" ; break >&3 ; done >&3
11859 ); }
11860 function comsub_TSELECT {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011861 x=$(select file in * ; do \echo "<$file>" ; \break >&3 ; done >&3 )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011862 }
11863 function reread_TSELECT { x=$((
11864 select file in *; do echo "<$file>" ; break >&3 ; done >&3
11865 )|tr u x); }
11866 function reread_TSELECT {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011867 x=$( ( select file in * ; do \echo "<$file>" ; \break >&3 ; done >&3 ) | \tr u x )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011868 }
11869 inline_TFOR_TTIME() {
11870 for i in {1,2,3} ; do time >&3 echo $i ; done >&3
11871 }
11872 inline_TFOR_TTIME() {
11873 for i in {1,2,3}
11874 do
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011875 time \echo $i >&3
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011876 done >&3
11877 }
11878 function comsub_TFOR_TTIME { x=$(
11879 for i in {1,2,3} ; do time >&3 echo $i ; done >&3
11880 ); }
11881 function comsub_TFOR_TTIME {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011882 x=$(for i in {1,2,3} ; do time \echo $i >&3 ; done >&3 )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011883 }
11884 function reread_TFOR_TTIME { x=$((
11885 for i in {1,2,3} ; do time >&3 echo $i ; done >&3
11886 )|tr u x); }
11887 function reread_TFOR_TTIME {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011888 x=$( ( for i in {1,2,3} ; do time \echo $i >&3 ; done >&3 ) | \tr u x )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011889 }
11890 inline_TCASE() {
11891 case $foo in 1) echo eins >&3;& 2) echo zwei >&3 ;| *) echo kann net bis drei zählen >&3;; esac >&3
11892 }
11893 inline_TCASE() {
11894 case $foo in
11895 (1)
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011896 \echo eins >&3
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011897 ;&
11898 (2)
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011899 \echo zwei >&3
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011900 ;|
11901 (*)
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011902 \echo kann net bis drei zählen >&3
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011903 ;;
11904 esac >&3
11905 }
11906 function comsub_TCASE { x=$(
11907 case $foo in 1) echo eins >&3;& 2) echo zwei >&3 ;| *) echo kann net bis drei zählen >&3;; esac >&3
11908 ); }
11909 function comsub_TCASE {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011910 x=$(case $foo in (1) \echo eins >&3 ;& (2) \echo zwei >&3 ;| (*) \echo kann net bis drei zählen >&3 ;; esac >&3 )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011911 }
11912 function reread_TCASE { x=$((
11913 case $foo in 1) echo eins >&3;& 2) echo zwei >&3 ;| *) echo kann net bis drei zählen >&3;; esac >&3
11914 )|tr u x); }
11915 function reread_TCASE {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011916 x=$( ( case $foo in (1) \echo eins >&3 ;& (2) \echo zwei >&3 ;| (*) \echo kann net bis drei zählen >&3 ;; esac >&3 ) | \tr u x )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011917 }
11918 inline_TIF_TBANG_TDBRACKET_TELIF() {
11919 if ! [[ 1 = 1 ]] >&3 ; then echo eins; elif [[ 1 = 2 ]] >&3; then echo zwei ;else echo drei; fi >&3
11920 }
11921 inline_TIF_TBANG_TDBRACKET_TELIF() {
11922 if ! [[ 1 = 1 ]] >&3
11923 then
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011924 \echo eins
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011925 elif [[ 1 = 2 ]] >&3
11926 then
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011927 \echo zwei
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011928 else
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011929 \echo drei
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011930 fi >&3
11931 }
11932 function comsub_TIF_TBANG_TDBRACKET_TELIF { x=$(
11933 if ! [[ 1 = 1 ]] >&3 ; then echo eins; elif [[ 1 = 2 ]] >&3; then echo zwei ;else echo drei; fi >&3
11934 ); }
11935 function comsub_TIF_TBANG_TDBRACKET_TELIF {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011936 x=$(if ! [[ 1 = 1 ]] >&3 ; then \echo eins ; elif [[ 1 = 2 ]] >&3 ; then \echo zwei ; else \echo drei ; fi >&3 )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011937 }
11938 function reread_TIF_TBANG_TDBRACKET_TELIF { x=$((
11939 if ! [[ 1 = 1 ]] >&3 ; then echo eins; elif [[ 1 = 2 ]] >&3; then echo zwei ;else echo drei; fi >&3
11940 )|tr u x); }
11941 function reread_TIF_TBANG_TDBRACKET_TELIF {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011942 x=$( ( if ! [[ 1 = 1 ]] >&3 ; then \echo eins ; elif [[ 1 = 2 ]] >&3 ; then \echo zwei ; else \echo drei ; fi >&3 ) | \tr u x )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011943 }
11944 inline_TWHILE() {
11945 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
11946 }
11947 inline_TWHILE() {
11948 i=1
Elliott Hughesfc0307d2016-02-02 15:26:47 -080011949 while {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011950 \\builtin let " i < 10 "
Elliott Hughesfc0307d2016-02-02 15:26:47 -080011951 } >&3
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011952 do
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011953 \echo $i
11954 \let ++i
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011955 done >&3
11956 }
11957 function comsub_TWHILE { x=$(
11958 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
11959 ); }
11960 function comsub_TWHILE {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011961 x=$(i=1 ; while { \\builtin let " i < 10 " ; } >&3 ; do \echo $i ; \let ++i ; done >&3 )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011962 }
11963 function reread_TWHILE { x=$((
11964 i=1; while (( i < 10 )) >&3; do echo $i; let ++i; done >&3
11965 )|tr u x); }
11966 function reread_TWHILE {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011967 x=$( ( i=1 ; while { \\builtin let " i < 10 " ; } >&3 ; do \echo $i ; \let ++i ; done >&3 ) | \tr u x )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011968 }
11969 inline_TUNTIL() {
11970 i=10; until (( !--i )) >&3 ; do echo $i; done >&3
11971 }
11972 inline_TUNTIL() {
11973 i=10
Elliott Hughesfc0307d2016-02-02 15:26:47 -080011974 until {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011975 \\builtin let " !--i "
Elliott Hughesfc0307d2016-02-02 15:26:47 -080011976 } >&3
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011977 do
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011978 \echo $i
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011979 done >&3
11980 }
11981 function comsub_TUNTIL { x=$(
11982 i=10; until (( !--i )) >&3 ; do echo $i; done >&3
11983 ); }
11984 function comsub_TUNTIL {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011985 x=$(i=10 ; until { \\builtin let " !--i " ; } >&3 ; do \echo $i ; done >&3 )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011986 }
11987 function reread_TUNTIL { x=$((
11988 i=10; until (( !--i )) >&3 ; do echo $i; done >&3
11989 )|tr u x); }
11990 function reread_TUNTIL {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011991 x=$( ( i=10 ; until { \\builtin let " !--i " ; } >&3 ; do \echo $i ; done >&3 ) | \tr u x )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011992 }
11993 inline_TCOPROC() {
11994 cat * >&3 |& >&3 ls
11995 }
11996 inline_TCOPROC() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070011997 \cat * >&3 |&
11998 \ls >&3
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000011999 }
12000 function comsub_TCOPROC { x=$(
12001 cat * >&3 |& >&3 ls
12002 ); }
12003 function comsub_TCOPROC {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012004 x=$(\cat * >&3 |& \ls >&3 )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012005 }
12006 function reread_TCOPROC { x=$((
12007 cat * >&3 |& >&3 ls
12008 )|tr u x); }
12009 function reread_TCOPROC {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012010 x=$( ( \cat * >&3 |& \ls >&3 ) | \tr u x )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012011 }
12012 inline_TFUNCT_TBRACE_TASYNC() {
12013 function korn { echo eins; echo >&3 zwei ; }
12014 bourne () { logger * >&3 & }
12015 }
12016 inline_TFUNCT_TBRACE_TASYNC() {
12017 function korn {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012018 \echo eins
12019 \echo zwei >&3
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012020 }
12021 bourne() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012022 \logger * >&3 &
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012023 }
12024 }
12025 function comsub_TFUNCT_TBRACE_TASYNC { x=$(
12026 function korn { echo eins; echo >&3 zwei ; }
12027 bourne () { logger * >&3 & }
12028 ); }
12029 function comsub_TFUNCT_TBRACE_TASYNC {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012030 x=$(function korn { \echo eins ; \echo zwei >&3 ; } ; bourne() { \logger * >&3 & } )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012031 }
12032 function reread_TFUNCT_TBRACE_TASYNC { x=$((
12033 function korn { echo eins; echo >&3 zwei ; }
12034 bourne () { logger * >&3 & }
12035 )|tr u x); }
12036 function reread_TFUNCT_TBRACE_TASYNC {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012037 x=$( ( function korn { \echo eins ; \echo zwei >&3 ; } ; bourne() { \logger * >&3 & } ) | \tr u x )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012038 }
12039 inline_COMSUB_EXPRSUB() {
12040 echo $(true >&3) $((1+ 2))
12041 }
12042 inline_COMSUB_EXPRSUB() {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012043 \echo $(\true >&3 ) $((1+ 2))
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012044 }
12045 function comsub_COMSUB_EXPRSUB { x=$(
12046 echo $(true >&3) $((1+ 2))
12047 ); }
12048 function comsub_COMSUB_EXPRSUB {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012049 x=$(\echo $(\true >&3 ) $((1+ 2)) )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012050 }
12051 function reread_COMSUB_EXPRSUB { x=$((
12052 echo $(true >&3) $((1+ 2))
12053 )|tr u x); }
12054 function reread_COMSUB_EXPRSUB {
Elliott Hughesa3c3f962017-04-12 16:52:30 -070012055 x=$( ( \echo $(\true >&3 ) $((1+ 2)) ) | \tr u x )
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012056 }
12057---
12058name: funsub-1
12059description:
12060 Check that non-subenvironment command substitution works
12061stdin:
12062 set -e
12063 foo=bar
12064 echo "ob $foo ."
12065 echo "${
12066 echo "ib $foo :"
12067 foo=baz
12068 echo "ia $foo :"
12069 false
12070 }" .
12071 echo "oa $foo ."
12072expected-stdout:
12073 ob bar .
12074 ib bar :
12075 ia baz : .
12076 oa baz .
12077---
12078name: funsub-2
12079description:
12080 You can now reliably use local and return in funsubs
12081 (not exit though)
12082stdin:
12083 x=q; e=1; x=${ echo a; e=2; echo x$e;}; echo 1:y$x,$e,$?.
12084 x=q; e=1; x=${ echo a; typeset e=2; echo x$e;}; echo 2:y$x,$e,$?.
12085 x=q; e=1; x=${ echo a; typeset e=2; return 3; echo x$e;}; echo 3:y$x,$e,$?.
12086expected-stdout:
12087 1:ya x2,2,0.
12088 2:ya x2,1,0.
12089 3:ya,1,3.
Geremy Condra03ebf062011-10-12 18:17:24 -070012090---
Thorsten Glaser811a5752013-07-25 14:24:45 +000012091name: valsub-1
12092description:
12093 Check that "value substitutions" work as advertised
12094stdin:
12095 x=1
12096 y=2
12097 z=3
12098 REPLY=4
12099 echo "before: x<$x> y<$y> z<$z> R<$REPLY>"
12100 x=${|
12101 local y
Elliott Hughes966dd552016-12-08 15:56:04 -080012102 echo "start: x<$x> y<$y> z<$z> R<$REPLY>"
Thorsten Glaser811a5752013-07-25 14:24:45 +000012103 x=5
12104 y=6
12105 z=7
12106 REPLY=8
12107 echo "end: x<$x> y<$y> z<$z> R<$REPLY>"
12108 }
12109 echo "after: x<$x> y<$y> z<$z> R<$REPLY>"
12110 # ensure trailing newlines are kept
12111 t=${|REPLY=$'foo\n\n';}
12112 typeset -p t
12113 echo -n this used to segfault
12114 echo ${|true;}$(true).
12115expected-stdout:
12116 before: x<1> y<2> z<3> R<4>
Elliott Hughes966dd552016-12-08 15:56:04 -080012117 start: x<1> y<> z<3> R<>
Thorsten Glaser811a5752013-07-25 14:24:45 +000012118 end: x<5> y<6> z<7> R<8>
12119 after: x<8> y<2> z<7> R<4>
12120 typeset t=$'foo\n\n'
12121 this used to segfault.
12122---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012123name: event-subst-3
12124description:
12125 Check that '!' substitution in noninteractive mode is ignored
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012126file-setup: file 755 "falsetto"
12127 #! /bin/sh
12128 echo molto bene
12129 exit 42
12130file-setup: file 755 "!false"
12131 #! /bin/sh
12132 echo si
12133stdin:
Elliott Hughes96b43632015-07-17 11:39:41 -070012134 export PATH=.$PATHSEP$PATH
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012135 falsetto
12136 echo yeap
12137 !false
12138 echo meow
12139 ! false
12140 echo = $?
12141 if
12142 ! false; then echo foo; else echo bar; fi
12143expected-stdout:
12144 molto bene
12145 yeap
12146 si
12147 meow
12148 = 0
12149 foo
12150---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012151name: event-subst-0
12152description:
12153 Check that '!' substitution in interactive mode is ignored
12154need-ctty: yes
12155arguments: !-i!
12156file-setup: file 755 "falsetto"
12157 #! /bin/sh
12158 echo molto bene
12159 exit 42
12160file-setup: file 755 "!false"
12161 #! /bin/sh
12162 echo si
12163stdin:
Elliott Hughes96b43632015-07-17 11:39:41 -070012164 export PATH=.$PATHSEP$PATH
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012165 falsetto
12166 echo yeap
12167 !false
12168 echo meow
12169 ! false
12170 echo = $?
12171 if
12172 ! false; then echo foo; else echo bar; fi
12173expected-stdout:
12174 molto bene
12175 yeap
12176 si
12177 meow
12178 = 0
12179 foo
12180expected-stderr-pattern:
12181 /.*/
12182---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012183name: nounset-1
12184description:
12185 Check that "set -u" matches (future) SUSv4 requirement
12186stdin:
12187 (set -u
12188 try() {
12189 local v
12190 eval v=\$$1
12191 if [[ -n $v ]]; then
12192 echo $1=nz
12193 else
12194 echo $1=zf
12195 fi
12196 }
12197 x=y
12198 (echo $x)
12199 echo =1
12200 (echo $y)
12201 echo =2
12202 (try x)
12203 echo =3
12204 (try y)
12205 echo =4
12206 (try 0)
12207 echo =5
12208 (try 2)
12209 echo =6
12210 (try)
12211 echo =7
12212 (echo at=$@)
12213 echo =8
12214 (echo asterisk=$*)
12215 echo =9
12216 (echo $?)
12217 echo =10
12218 (echo $!)
12219 echo =11
12220 (echo $-)
12221 echo =12
12222 #(echo $_)
12223 #echo =13
12224 (echo $#)
12225 echo =14
12226 (mypid=$$; try mypid)
12227 echo =15
12228 ) 2>&1 | sed -e 's/^[^]]*]//' -e 's/^[^:]*: *//'
Elliott Hughes50012062015-03-10 22:22:24 -070012229 exit ${PIPESTATUS[0]}
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012230expected-stdout:
12231 y
12232 =1
12233 y: parameter not set
12234 =2
12235 x=nz
12236 =3
12237 y: parameter not set
12238 =4
12239 0=nz
12240 =5
12241 2: parameter not set
12242 =6
12243 1: parameter not set
12244 =7
12245 at=
12246 =8
12247 asterisk=
12248 =9
12249 0
12250 =10
12251 !: parameter not set
12252 =11
12253 ush
12254 =12
12255 0
12256 =14
12257 mypid=nz
12258 =15
12259---
12260name: nameref-1
12261description:
12262 Testsuite for nameref (bound variables)
12263stdin:
12264 bar=global
12265 typeset -n ir2=bar
12266 typeset -n ind=ir2
12267 echo !ind: ${!ind}
12268 echo ind: $ind
12269 echo !ir2: ${!ir2}
12270 echo ir2: $ir2
12271 typeset +n ind
12272 echo !ind: ${!ind}
12273 echo ind: $ind
12274 typeset -n ir2=ind
12275 echo !ir2: ${!ir2}
12276 echo ir2: $ir2
12277 set|grep ^ir2|sed 's/^/s1: /'
12278 typeset|grep ' ir2'|sed -e 's/^/s2: /' -e 's/nameref/typeset -n/'
12279 set -A blub -- e1 e2 e3
12280 typeset -n ind=blub
12281 typeset -n ir2=blub[2]
12282 echo !ind[1]: ${!ind[1]}
12283 echo !ir2: $!ir2
12284 echo ind[1]: ${ind[1]}
12285 echo ir2: $ir2
12286expected-stdout:
12287 !ind: bar
12288 ind: global
12289 !ir2: bar
12290 ir2: global
12291 !ind: ind
12292 ind: ir2
12293 !ir2: ind
12294 ir2: ir2
12295 s1: ir2=ind
12296 s2: typeset -n ir2
Elliott Hughes737fdce2014-08-07 12:59:26 -070012297 !ind[1]: blub[1]
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012298 !ir2: ir2
12299 ind[1]: e2
12300 ir2: e3
12301---
12302name: nameref-2da
12303description:
12304 Testsuite for nameref (bound variables)
12305 Functions, argument given directly, after local
12306stdin:
12307 function foo {
12308 typeset bar=lokal baz=auch
12309 typeset -n v=bar
12310 echo entering
12311 echo !v: ${!v}
12312 echo !bar: ${!bar}
12313 echo !baz: ${!baz}
12314 echo bar: $bar
12315 echo v: $v
12316 v=123
12317 echo bar: $bar
12318 echo v: $v
12319 echo exiting
12320 }
12321 bar=global
12322 echo bar: $bar
12323 foo bar
12324 echo bar: $bar
12325expected-stdout:
12326 bar: global
12327 entering
12328 !v: bar
12329 !bar: bar
12330 !baz: baz
12331 bar: lokal
12332 v: lokal
12333 bar: 123
12334 v: 123
12335 exiting
12336 bar: global
12337---
12338name: nameref-3
12339description:
12340 Advanced testsuite for bound variables (ksh93 fails this)
12341stdin:
12342 typeset -n foo=bar[i]
12343 set -A bar -- b c a
12344 for i in 0 1 2 3; do
12345 print $i $foo .
12346 done
12347expected-stdout:
12348 0 b .
12349 1 c .
12350 2 a .
12351 3 .
12352---
Geremy Condra03ebf062011-10-12 18:17:24 -070012353name: nameref-4
12354description:
12355 Ensure we don't run in an infinite loop
12356time-limit: 3
12357stdin:
12358 baz() {
Thorsten Glaser811a5752013-07-25 14:24:45 +000012359 typeset -n foo=fnord fnord=foo
Geremy Condra03ebf062011-10-12 18:17:24 -070012360 foo[0]=bar
12361 }
12362 set -A foo bad
12363 echo sind $foo .
12364 baz
12365 echo blah $foo .
12366expected-stdout:
12367 sind bad .
Thorsten Glaser811a5752013-07-25 14:24:45 +000012368 blah bad .
12369expected-stderr-pattern:
12370 /fnord: expression recurses on parameter/
Geremy Condra03ebf062011-10-12 18:17:24 -070012371---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012372name: better-parens-1a
12373description:
12374 Check support for ((…)) and $((…)) vs (…) and $(…)
12375stdin:
Geremy Condra03ebf062011-10-12 18:17:24 -070012376 if ( (echo fubar)|tr u x); then
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012377 echo ja
12378 else
12379 echo nein
12380 fi
12381expected-stdout:
12382 fxbar
12383 ja
12384---
12385name: better-parens-1b
12386description:
12387 Check support for ((…)) and $((…)) vs (…) and $(…)
12388stdin:
Geremy Condra03ebf062011-10-12 18:17:24 -070012389 echo $( (echo fubar)|tr u x) $?
12390expected-stdout:
12391 fxbar 0
12392---
12393name: better-parens-1c
12394description:
12395 Check support for ((…)) and $((…)) vs (…) and $(…)
12396stdin:
12397 x=$( (echo fubar)|tr u x); echo $x $?
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012398expected-stdout:
12399 fxbar 0
12400---
12401name: better-parens-2a
12402description:
12403 Check support for ((…)) and $((…)) vs (…) and $(…)
12404stdin:
Geremy Condra03ebf062011-10-12 18:17:24 -070012405 if ((echo fubar)|tr u x); then
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012406 echo ja
12407 else
12408 echo nein
12409 fi
12410expected-stdout:
12411 fxbar
12412 ja
12413---
12414name: better-parens-2b
12415description:
12416 Check support for ((…)) and $((…)) vs (…) and $(…)
12417stdin:
Geremy Condra03ebf062011-10-12 18:17:24 -070012418 echo $((echo fubar)|tr u x) $?
12419expected-stdout:
12420 fxbar 0
12421---
12422name: better-parens-2c
12423description:
12424 Check support for ((…)) and $((…)) vs (…) and $(…)
12425stdin:
12426 x=$((echo fubar)|tr u x); echo $x $?
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012427expected-stdout:
12428 fxbar 0
12429---
12430name: better-parens-3a
12431description:
12432 Check support for ((…)) and $((…)) vs (…) and $(…)
12433stdin:
Geremy Condra03ebf062011-10-12 18:17:24 -070012434 if ( (echo fubar)|(tr u x)); then
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012435 echo ja
12436 else
12437 echo nein
12438 fi
12439expected-stdout:
12440 fxbar
12441 ja
12442---
12443name: better-parens-3b
12444description:
12445 Check support for ((…)) and $((…)) vs (…) and $(…)
12446stdin:
Geremy Condra03ebf062011-10-12 18:17:24 -070012447 echo $( (echo fubar)|(tr u x)) $?
12448expected-stdout:
12449 fxbar 0
12450---
12451name: better-parens-3c
12452description:
12453 Check support for ((…)) and $((…)) vs (…) and $(…)
12454stdin:
12455 x=$( (echo fubar)|(tr u x)); echo $x $?
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012456expected-stdout:
12457 fxbar 0
12458---
12459name: better-parens-4a
12460description:
12461 Check support for ((…)) and $((…)) vs (…) and $(…)
12462stdin:
Geremy Condra03ebf062011-10-12 18:17:24 -070012463 if ((echo fubar)|(tr u x)); then
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012464 echo ja
12465 else
12466 echo nein
12467 fi
12468expected-stdout:
12469 fxbar
12470 ja
12471---
12472name: better-parens-4b
12473description:
12474 Check support for ((…)) and $((…)) vs (…) and $(…)
12475stdin:
Geremy Condra03ebf062011-10-12 18:17:24 -070012476 echo $((echo fubar)|(tr u x)) $?
12477expected-stdout:
12478 fxbar 0
12479---
12480name: better-parens-4c
12481description:
12482 Check support for ((…)) and $((…)) vs (…) and $(…)
12483stdin:
12484 x=$((echo fubar)|(tr u x)); echo $x $?
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012485expected-stdout:
12486 fxbar 0
12487---
Elliott Hughesfc0307d2016-02-02 15:26:47 -080012488name: better-parens-5
12489description:
12490 Another corner case
12491stdin:
12492 ( (echo 'fo o$bar' "baz\$bla\"" m\$eh) | tr a A)
12493 ((echo 'fo o$bar' "baz\$bla\"" m\$eh) | tr a A)
12494expected-stdout:
12495 fo o$bAr bAz$blA" m$eh
12496 fo o$bAr bAz$blA" m$eh
12497---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012498name: echo-test-1
12499description:
12500 Test what the echo builtin does (mksh)
12501stdin:
12502 echo -n 'foo\x40bar'
12503 echo -e '\tbaz'
12504expected-stdout:
12505 foo@bar baz
12506---
12507name: echo-test-2
12508description:
12509 Test what the echo builtin does (POSIX)
12510 Note: this follows Debian Policy 10.4 which mandates
12511 that -n shall be treated as an option, not XSI which
12512 mandates it shall be treated as string but escapes
12513 shall be expanded.
12514stdin:
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012515 test -n "$POSH_VERSION" || set -o posix
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012516 echo -n 'foo\x40bar'
12517 echo -e '\tbaz'
12518expected-stdout:
12519 foo\x40bar-e \tbaz
12520---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012521name: echo-test-3-mnbsd
12522description:
12523 Test what the echo builtin does, and test a compatibility flag.
12524category: mnbsdash
12525stdin:
12526 "$__progname" -c 'echo -n 1=\\x40$1; echo -e \\x2E' -- foo bar
12527 "$__progname" -o posix -c 'echo -n 2=\\x40$1; echo -e \\x2E' -- foo bar
12528 "$__progname" -o sh -c 'echo -n 3=\\x40$1; echo -e \\x2E' -- foo bar
12529expected-stdout:
12530 1=@foo.
12531 2=\x40foo-e \x2E
12532 3=\x40bar.
12533---
12534name: echo-test-3-normal
12535description:
12536 Test what the echo builtin does, and test a compatibility flag.
12537category: !mnbsdash
12538stdin:
12539 "$__progname" -c 'echo -n 1=\\x40$1; echo -e \\x2E' -- foo bar
12540 "$__progname" -o posix -c 'echo -n 2=\\x40$1; echo -e \\x2E' -- foo bar
12541 "$__progname" -o sh -c 'echo -n 3=\\x40$1; echo -e \\x2E' -- foo bar
12542expected-stdout:
12543 1=@foo.
12544 2=\x40foo-e \x2E
12545 3=\x40foo-e \x2E
12546---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012547name: utilities-getopts-1
12548description:
12549 getopts sets OPTIND correctly for unparsed option
12550stdin:
12551 set -- -a -a -x
12552 while getopts :a optc; do
12553 echo "OPTARG=$OPTARG, OPTIND=$OPTIND, optc=$optc."
12554 done
12555 echo done
12556expected-stdout:
12557 OPTARG=, OPTIND=2, optc=a.
12558 OPTARG=, OPTIND=3, optc=a.
12559 OPTARG=x, OPTIND=4, optc=?.
12560 done
12561---
12562name: utilities-getopts-2
12563description:
12564 Check OPTARG
12565stdin:
12566 set -- -a Mary -x
12567 while getopts a: optc; do
12568 echo "OPTARG=$OPTARG, OPTIND=$OPTIND, optc=$optc."
12569 done
12570 echo done
12571expected-stdout:
12572 OPTARG=Mary, OPTIND=3, optc=a.
12573 OPTARG=, OPTIND=4, optc=?.
12574 done
12575expected-stderr-pattern: /.*-x.*option/
12576---
Elliott Hughes77740fc2016-08-12 15:06:53 -070012577name: utilities-getopts-3
12578description:
12579 Check unsetting OPTARG
12580stdin:
12581 set -- -x arg -y
12582 getopts x:y opt && echo "${OPTARG-unset}"
12583 getopts x:y opt && echo "${OPTARG-unset}"
12584expected-stdout:
12585 arg
12586 unset
12587---
Jean-Baptiste Queru5155f1c2011-06-16 10:05:28 -070012588name: wcswidth-1
12589description:
12590 Check the new wcswidth feature
12591stdin:
12592 s=何
12593 set +U
12594 print octets: ${#s} .
12595 print 8-bit width: ${%s} .
12596 set -U
12597 print characters: ${#s} .
12598 print columns: ${%s} .
12599 s=�
12600 set +U
12601 print octets: ${#s} .
12602 print 8-bit width: ${%s} .
12603 set -U
12604 print characters: ${#s} .
12605 print columns: ${%s} .
12606expected-stdout:
12607 octets: 3 .
12608 8-bit width: -1 .
12609 characters: 1 .
12610 columns: 2 .
12611 octets: 3 .
12612 8-bit width: 3 .
12613 characters: 1 .
12614 columns: 1 .
12615---
12616name: wcswidth-2
12617description:
12618 Check some corner cases
12619stdin:
12620 print % $% .
12621 set -U
12622 x='a b'
12623 print c ${%x} .
12624 set +U
12625 x='a b'
12626 print d ${%x} .
12627expected-stdout:
12628 % $% .
12629 c -1 .
12630 d -1 .
12631---
12632name: wcswidth-3
12633description:
12634 Check some corner cases
12635stdin:
12636 print ${%} .
12637expected-stderr-pattern:
12638 /bad substitution/
12639expected-exit: 1
12640---
12641name: wcswidth-4a
12642description:
12643 Check some corner cases
12644stdin:
12645 print ${%*} .
12646expected-stderr-pattern:
12647 /bad substitution/
12648expected-exit: 1
12649---
12650name: wcswidth-4b
12651description:
12652 Check some corner cases
12653stdin:
12654 print ${%@} .
12655expected-stderr-pattern:
12656 /bad substitution/
12657expected-exit: 1
12658---
12659name: wcswidth-4c
12660description:
12661 Check some corner cases
12662stdin:
12663 :
12664 print ${%?} .
12665expected-stdout:
12666 1 .
12667---
12668name: realpath-1
12669description:
12670 Check proper return values for realpath
12671category: os:mirbsd
12672stdin:
12673 wd=$(realpath .)
12674 mkdir dir
12675 :>file
12676 :>dir/file
12677 ln -s dir lndir
12678 ln -s file lnfile
12679 ln -s nix lnnix
12680 ln -s . lnself
12681 i=0
12682 chk() {
12683 typeset x y
12684 x=$(realpath "$wd/$1" 2>&1); y=$?
12685 print $((++i)) "?$1" =${x##*$wd/} !$y
12686 }
12687 chk dir
12688 chk dir/
12689 chk dir/file
12690 chk dir/nix
12691 chk file
12692 chk file/
12693 chk file/file
12694 chk file/nix
12695 chk nix
12696 chk nix/
12697 chk nix/file
12698 chk nix/nix
12699 chk lndir
12700 chk lndir/
12701 chk lndir/file
12702 chk lndir/nix
12703 chk lnfile
12704 chk lnfile/
12705 chk lnfile/file
12706 chk lnfile/nix
12707 chk lnnix
12708 chk lnnix/
12709 chk lnnix/file
12710 chk lnnix/nix
12711 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
12712 rm lnself
12713expected-stdout:
12714 1 ?dir =dir !0
12715 2 ?dir/ =dir !0
12716 3 ?dir/file =dir/file !0
12717 4 ?dir/nix =dir/nix !0
12718 5 ?file =file !0
12719 6 ?file/ =file/: Not a directory !20
12720 7 ?file/file =file/file: Not a directory !20
12721 8 ?file/nix =file/nix: Not a directory !20
12722 9 ?nix =nix !0
12723 10 ?nix/ =nix !0
12724 11 ?nix/file =nix/file: No such file or directory !2
12725 12 ?nix/nix =nix/nix: No such file or directory !2
12726 13 ?lndir =dir !0
12727 14 ?lndir/ =dir !0
12728 15 ?lndir/file =dir/file !0
12729 16 ?lndir/nix =dir/nix !0
12730 17 ?lnfile =file !0
12731 18 ?lnfile/ =lnfile/: Not a directory !20
12732 19 ?lnfile/file =lnfile/file: Not a directory !20
12733 20 ?lnfile/nix =lnfile/nix: Not a directory !20
12734 21 ?lnnix =nix !0
12735 22 ?lnnix/ =nix !0
12736 23 ?lnnix/file =lnnix/file: No such file or directory !2
12737 24 ?lnnix/nix =lnnix/nix: No such file or directory !2
12738 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
12739---
Geremy Condra03ebf062011-10-12 18:17:24 -070012740name: realpath-2
12741description:
12742 Ensure that exactly two leading slashes are not collapsed
12743 POSIX guarantees this exception, e.g. for UNC paths on Cygwin
12744category: os:mirbsd
12745stdin:
12746 ln -s /bin t1
12747 ln -s //bin t2
12748 ln -s ///bin t3
12749 realpath /bin
12750 realpath //bin
12751 realpath ///bin
12752 realpath /usr/bin
12753 realpath /usr//bin
12754 realpath /usr///bin
12755 realpath t1
12756 realpath t2
12757 realpath t3
12758 rm -f t1 t2 t3
12759 cd //usr/bin
12760 pwd
12761 cd ../lib
12762 pwd
12763 realpath //usr/include/../bin
12764expected-stdout:
12765 /bin
12766 //bin
12767 /bin
12768 /usr/bin
12769 /usr/bin
12770 /usr/bin
12771 /bin
12772 //bin
12773 /bin
12774 //usr/bin
12775 //usr/lib
12776 //usr/bin
12777---
12778name: crash-1
12779description:
12780 Crashed during March 2011, fixed on vernal equinōx ☺
12781category: os:mirbsd,os:openbsd
12782stdin:
12783 export MALLOC_OPTIONS=FGJPRSX
12784 "$__progname" -c 'x=$(tr z r <<<baz); echo $x'
12785expected-stdout:
12786 bar
12787---
12788name: debian-117-1
12789description:
12790 Check test - bug#465250
12791stdin:
12792 test \( ! -e \) ; echo $?
12793expected-stdout:
12794 1
12795---
12796name: debian-117-2
12797description:
12798 Check test - bug#465250
12799stdin:
12800 test \( -e \) ; echo $?
12801expected-stdout:
12802 0
12803---
12804name: debian-117-3
12805description:
12806 Check test - bug#465250
12807stdin:
12808 test ! -e ; echo $?
12809expected-stdout:
12810 1
12811---
12812name: debian-117-4
12813description:
12814 Check test - bug#465250
12815stdin:
12816 test -e ; echo $?
12817expected-stdout:
12818 0
12819---
12820name: case-zsh
12821description:
12822 Check that zsh case variants work
12823stdin:
12824 case 'b' in
12825 a) echo a ;;
12826 b) echo b ;;
12827 c) echo c ;;
12828 *) echo x ;;
12829 esac
12830 echo =
12831 case 'b' in
12832 a) echo a ;&
12833 b) echo b ;&
12834 c) echo c ;&
12835 *) echo x ;&
12836 esac
12837 echo =
12838 case 'b' in
12839 a) echo a ;|
12840 b) echo b ;|
12841 c) echo c ;|
12842 *) echo x ;|
12843 esac
12844expected-stdout:
12845 b
12846 =
12847 b
12848 c
12849 x
12850 =
12851 b
12852 x
12853---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012854name: case-braces
12855description:
12856 Check that case end tokens are not mixed up (Debian #220272)
12857stdin:
12858 i=0
12859 for value in 'x' '}' 'esac'; do
12860 print -n "$((++i))($value)bourne "
12861 case $value in
12862 }) echo brace ;;
12863 *) echo no ;;
12864 esac
12865 print -n "$((++i))($value)korn "
12866 case $value {
12867 esac) echo esac ;;
12868 *) echo no ;;
12869 }
12870 done
12871expected-stdout:
12872 1(x)bourne no
12873 2(x)korn no
12874 3(})bourne brace
12875 4(})korn no
12876 5(esac)bourne no
12877 6(esac)korn esac
12878---
12879name: command-shift
12880description:
12881 Check that 'command shift' works
12882stdin:
12883 function snc {
12884 echo "before 0='$0' 1='$1' 2='$2'"
12885 shift
12886 echo "after 0='$0' 1='$1' 2='$2'"
12887 }
12888 function swc {
12889 echo "before 0='$0' 1='$1' 2='$2'"
12890 command shift
12891 echo "after 0='$0' 1='$1' 2='$2'"
12892 }
12893 echo = without command
12894 snc 一 二
12895 echo = with command
12896 swc 一 二
12897 echo = done
12898expected-stdout:
12899 = without command
12900 before 0='snc' 1='一' 2='二'
12901 after 0='snc' 1='二' 2=''
12902 = with command
12903 before 0='swc' 1='一' 2='二'
12904 after 0='swc' 1='二' 2=''
12905 = done
12906---
Elliott Hughes77740fc2016-08-12 15:06:53 -070012907name: command-pvV-posix-priorities
12908description:
12909 For POSIX compatibility, command -v should find aliases and reserved
12910 words, and command -p[vV] should find aliases, reserved words, and
12911 builtins over external commands.
12912stdin:
12913 PATH=/bin:/usr/bin
12914 alias foo="bar baz"
12915 bar() { :; }
12916 for word in 'if' 'foo' 'bar' 'set' 'true'; do
12917 command -v "$word"
12918 command -pv "$word"
12919 command -V "$word"
12920 command -pV "$word"
12921 done
12922expected-stdout:
12923 if
12924 if
12925 if is a reserved word
12926 if is a reserved word
12927 alias foo='bar baz'
12928 alias foo='bar baz'
12929 foo is an alias for 'bar baz'
12930 foo is an alias for 'bar baz'
12931 bar
12932 bar
12933 bar is a function
12934 bar is a function
12935 set
12936 set
12937 set is a special shell builtin
12938 set is a special shell builtin
12939 true
12940 true
12941 true is a shell builtin
12942 true is a shell builtin
12943---
12944name: whence-preserve-tradition
12945description:
12946 This regression test is to ensure that the POSIX compatibility
12947 changes for 'command' (see previous test) do not affect traditional
12948 'whence' behaviour.
12949category: os:mirbsd
12950stdin:
12951 PATH=/bin:/usr/bin
12952 alias foo="bar baz"
12953 bar() { :; }
12954 for word in 'if' 'foo' 'bar' 'set' 'true'; do
12955 whence "$word"
12956 whence -p "$word"
12957 whence -v "$word"
12958 whence -pv "$word"
12959 done
12960expected-stdout:
12961 if
12962 if is a reserved word
12963 if not found
12964 'bar baz'
12965 foo is an alias for 'bar baz'
12966 foo not found
12967 bar
12968 bar is a function
12969 bar not found
12970 set
12971 set is a special shell builtin
12972 set not found
12973 true
12974 /bin/true
12975 true is a shell builtin
12976 true is a tracked alias for /bin/true
12977---
Thorsten Glaserc2dc5de2013-02-18 23:02:51 +000012978name: duffs-device
12979description:
12980 Check that the compiler did not optimise-break them
12981 (lex.c has got a similar one in SHEREDELIM)
12982stdin:
12983 set +U
12984 s=
12985 typeset -i1 i=0
12986 while (( ++i < 256 )); do
12987 s+=${i#1#}
12988 done
12989 s+=$'\xC2\xA0\xE2\x82\xAC\xEF\xBF\xBD\xEF\xBF\xBE\xEF\xBF\xBF\xF0\x90\x80\x80.'
12990 typeset -p s
12991expected-stdout:
12992 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.'
12993---
12994name: stateptr-underflow
12995description:
12996 This check overflows an Xrestpos stored in a short in R40
12997category: fastbox
12998stdin:
12999 function Lb64decode {
13000 [[ -o utf8-mode ]]; local u=$?
13001 set +U
13002 local c s="$*" t=
13003 [[ -n $s ]] || { s=$(cat;print x); s=${s%x}; }
13004 local -i i=0 n=${#s} p=0 v x
13005 local -i16 o
13006
13007 while (( i < n )); do
13008 c=${s:(i++):1}
13009 case $c {
13010 (=) break ;;
13011 ([A-Z]) (( v = 1#$c - 65 )) ;;
13012 ([a-z]) (( v = 1#$c - 71 )) ;;
13013 ([0-9]) (( v = 1#$c + 4 )) ;;
13014 (+) v=62 ;;
13015 (/) v=63 ;;
13016 (*) continue ;;
13017 }
13018 (( x = (x << 6) | v ))
13019 case $((p++)) {
13020 (0) continue ;;
13021 (1) (( o = (x >> 4) & 255 )) ;;
13022 (2) (( o = (x >> 2) & 255 )) ;;
13023 (3) (( o = x & 255 ))
13024 p=0
13025 ;;
13026 }
13027 t=$t\\x${o#16#}
13028 done
13029 print -n $t
13030 (( u )) || set -U
13031 }
13032
13033 i=-1
13034 s=
13035 while (( ++i < 12120 )); do
13036 s+=a
13037 done
13038 Lb64decode $s >/dev/null
13039---
Thorsten Glaser811a5752013-07-25 14:24:45 +000013040name: xtrace-1
13041description:
13042 Check that "set -x" doesn't redirect too quickly
13043stdin:
13044 print '#!'"$__progname" >bash
13045 cat >>bash <<'EOF'
13046 echo 'GNU bash, version 2.05b.0(1)-release (i386-ecce-mirbsd10)
13047 Copyright (C) 2002 Free Software Foundation, Inc.'
13048 EOF
13049 chmod +x bash
Elliott Hughes77740fc2016-08-12 15:06:53 -070013050 "$__progname" -xc 'foo=$(./bash --version 2>&1 | sed q); echo "=$foo="'
Thorsten Glaser811a5752013-07-25 14:24:45 +000013051expected-stdout:
13052 =GNU bash, version 2.05b.0(1)-release (i386-ecce-mirbsd10)=
13053expected-stderr-pattern:
13054 /.*/
13055---
Elliott Hughes50012062015-03-10 22:22:24 -070013056name: xtrace-2
13057description:
13058 Check that "set -x" is off during PS4 expansion
13059stdin:
13060 f() {
13061 print -n "(f1:$-)"
13062 set -x
13063 print -n "(f2:$-)"
13064 }
13065 PS4='[(p:$-)$(f)] '
13066 print "(o0:$-)"
13067 set -x -o inherit-xtrace
13068 print "(o1:$-)"
13069 set +x
13070 print "(o2:$-)"
13071expected-stdout:
13072 (o0:sh)
13073 (o1:shx)
13074 (o2:sh)
13075expected-stderr:
13076 [(p:sh)(f1:sh)(f2:sh)] print '(o1:shx)'
13077 [(p:sh)(f1:sh)(f2:sh)] set +x
13078---
Elliott Hughes96b43632015-07-17 11:39:41 -070013079name: fksh-flags
13080description:
13081 Check that FKSH functions have their own shell flags
13082category: shell:legacy-no
13083stdin:
13084 [[ $KSH_VERSION = Version* ]] && set +B
13085 function foo {
13086 set +f
13087 set -e
13088 echo 2 "${-/s}" .
13089 }
13090 set -fh
13091 echo 1 "${-/s}" .
13092 foo
13093 echo 3 "${-/s}" .
13094expected-stdout:
13095 1 fh .
13096 2 eh .
13097 3 fh .
13098---
Elliott Hughesb27ce952015-04-21 13:39:18 -070013099name: fksh-flags-legacy
13100description:
13101 Check that even FKSH functions share the shell flags
Elliott Hughes96b43632015-07-17 11:39:41 -070013102category: shell:legacy-yes
Elliott Hughesb27ce952015-04-21 13:39:18 -070013103stdin:
13104 [[ $KSH_VERSION = Version* ]] && set +B
13105 foo() {
13106 set +f
13107 set -e
13108 echo 2 "${-/s}" .
13109 }
13110 set -fh
13111 echo 1 "${-/s}" .
13112 foo
13113 echo 3 "${-/s}" .
13114expected-stdout:
13115 1 fh .
13116 2 eh .
13117 3 eh .
13118---
13119name: fsh-flags
13120description:
13121 Check that !FKSH functions share the shell flags
13122stdin:
13123 [[ $KSH_VERSION = Version* ]] && set +B
13124 foo() {
13125 set +f
13126 set -e
13127 echo 2 "${-/s}" .
13128 }
13129 set -fh
13130 echo 1 "${-/s}" .
13131 foo
13132 echo 3 "${-/s}" .
13133expected-stdout:
13134 1 fh .
13135 2 eh .
13136 3 eh .
13137---