Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 1 | # $MirOS: src/bin/mksh/check.t,v 1.775 2017/04/12 17:38:41 tg Exp $ |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 2 | # -*- mode: sh -*- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3 | #- |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 4 | # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 5 | # 2011, 2012, 2013, 2014, 2015, 2016, 2017 |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 6 | # mirabilos <m@mirbsd.org> |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7 | # |
| 8 | # Provided that these terms and disclaimer and all copyright notices |
| 9 | # are retained or reproduced in an accompanying document, permission |
| 10 | # is granted to deal in this work without restriction, including unâ |
| 11 | # limited rights to use, publicly perform, distribute, sell, modify, |
| 12 | # merge, give away, or sublicence. |
| 13 | # |
| 14 | # This work is provided âAS ISâ and WITHOUT WARRANTY of any kind, to |
| 15 | # the utmost extent permitted by applicable law, neither express nor |
| 16 | # implied; without malicious intent or gross negligence. In no event |
| 17 | # may a licensor, author or contributor be held liable for indirect, |
| 18 | # direct, other damage, loss, or other issues arising in any way out |
| 19 | # of dealing in the work, even if advised of the possibility of such |
| 20 | # damage or existence of a defect, except proven that it results out |
| 21 | # of said personâs immediate fault when using the work as intended. |
| 22 | #- |
| 23 | # You may also want to test IFS with the script at |
| 24 | # http://www.research.att.com/~gsf/public/ifs.sh |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 25 | # |
| 26 | # More testsuites at: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 27 | # http://svnweb.freebsd.org/base/head/bin/test/tests/legacy_test.sh?view=co&content-type=text%2Fplain |
| 28 | # |
| 29 | # Integrated testsuites from: |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 30 | # (2013/12/02 20:39:44) http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 31 | |
| 32 | expected-stdout: |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 33 | @(#)MIRBSD KSH R55 2017/04/12 |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 34 | description: |
| 35 | Check version of shell. |
| 36 | stdin: |
| 37 | echo $KSH_VERSION |
| 38 | name: KSH_VERSION |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 39 | category: !shell:legacy-yes,!shell:textmode-yes |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 40 | --- |
| 41 | expected-stdout: |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 42 | @(#)LEGACY KSH R55 2017/04/12 |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 43 | description: |
| 44 | Check version of legacy shell. |
| 45 | stdin: |
| 46 | echo $KSH_VERSION |
| 47 | name: KSH_VERSION-legacy |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 48 | category: !shell:legacy-no,!shell:textmode-yes |
| 49 | --- |
| 50 | expected-stdout: |
| 51 | @(#)MIRBSD KSH R55 2017/04/12 +TEXTMODE |
| 52 | description: |
| 53 | Check version of shell. |
| 54 | stdin: |
| 55 | echo $KSH_VERSION |
| 56 | name: KSH_VERSION-textmode |
| 57 | category: !shell:legacy-yes,!shell:textmode-no |
| 58 | --- |
| 59 | expected-stdout: |
| 60 | @(#)LEGACY KSH R55 2017/04/12 +TEXTMODE |
| 61 | description: |
| 62 | Check version of legacy shell. |
| 63 | stdin: |
| 64 | echo $KSH_VERSION |
| 65 | name: KSH_VERSION-legacy-textmode |
| 66 | category: !shell:legacy-no,!shell:textmode-no |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 67 | --- |
| 68 | name: selftest-1 |
| 69 | description: |
| 70 | Regression test self-testing |
| 71 | stdin: |
| 72 | echo ${foo:-baz} |
| 73 | expected-stdout: |
| 74 | baz |
| 75 | --- |
| 76 | name: selftest-2 |
| 77 | description: |
| 78 | Regression test self-testing |
| 79 | env-setup: !foo=bar! |
| 80 | stdin: |
| 81 | echo ${foo:-baz} |
| 82 | expected-stdout: |
| 83 | bar |
| 84 | --- |
| 85 | name: selftest-3 |
| 86 | description: |
| 87 | Regression test self-testing |
| 88 | env-setup: !ENV=fnord! |
| 89 | stdin: |
| 90 | echo "<$ENV>" |
| 91 | expected-stdout: |
| 92 | <fnord> |
| 93 | --- |
Elliott Hughes | 737fdce | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 94 | name: selftest-exec |
| 95 | description: |
| 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. |
| 99 | stdin: |
| 100 | print '#!'"$__progname"'\necho tf' >lq |
| 101 | chmod +x lq |
| 102 | ./lq |
| 103 | expected-stdout: |
| 104 | tf |
| 105 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 106 | name: selftest-env |
| 107 | description: |
| 108 | Just output the environment variables set (always fails) |
| 109 | category: disabled |
| 110 | stdin: |
| 111 | set |
| 112 | --- |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 113 | name: selftest-direct-builtin-call |
| 114 | description: |
| 115 | Check that direct builtin calls work |
| 116 | stdin: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 117 | ln -s "$__progname" cat || cp "$__progname" cat |
| 118 | ln -s "$__progname" echo || cp "$__progname" echo |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 119 | ./echo -c 'echo foo' | ./cat -u |
| 120 | expected-stdout: |
| 121 | -c echo foo |
| 122 | --- |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 123 | name: selftest-pathsep-unix |
| 124 | description: |
| 125 | Check that $PATHSEP is set correctly. |
| 126 | category: !os:os2 |
| 127 | stdin: |
| 128 | PATHSEP=.; export PATHSEP |
| 129 | "$__progname" -c 'print -r -- $PATHSEP' |
| 130 | expected-stdout: |
| 131 | : |
| 132 | --- |
| 133 | name: selftest-pathsep-dospath |
| 134 | description: |
| 135 | Check that $PATHSEP is set correctly. |
| 136 | category: os:os2 |
| 137 | stdin: |
| 138 | PATHSEP=.; export PATHSEP |
| 139 | "$__progname" -c 'print -r -- $PATHSEP' |
| 140 | expected-stdout: |
| 141 | ; |
| 142 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 143 | name: alias-1 |
| 144 | description: |
| 145 | Check that recursion is detected/avoided in aliases. |
| 146 | stdin: |
| 147 | alias fooBar=fooBar |
| 148 | fooBar |
| 149 | exit 0 |
| 150 | expected-stderr-pattern: |
| 151 | /fooBar.*not found.*/ |
| 152 | --- |
| 153 | name: alias-2 |
| 154 | description: |
| 155 | Check that recursion is detected/avoided in aliases. |
| 156 | stdin: |
| 157 | alias fooBar=barFoo |
| 158 | alias barFoo=fooBar |
| 159 | fooBar |
| 160 | barFoo |
| 161 | exit 0 |
| 162 | expected-stderr-pattern: |
| 163 | /fooBar.*not found.*\n.*barFoo.*not found/ |
| 164 | --- |
| 165 | name: alias-3 |
| 166 | description: |
| 167 | Check that recursion is detected/avoided in aliases. |
| 168 | stdin: |
| 169 | alias Echo='echo ' |
| 170 | alias fooBar=barFoo |
| 171 | alias barFoo=fooBar |
| 172 | Echo fooBar |
| 173 | unalias barFoo |
| 174 | Echo fooBar |
| 175 | expected-stdout: |
| 176 | fooBar |
| 177 | barFoo |
| 178 | --- |
| 179 | name: alias-4 |
| 180 | description: |
| 181 | Check that alias expansion isn't done on keywords (in keyword |
| 182 | postitions). |
| 183 | stdin: |
| 184 | alias Echo='echo ' |
| 185 | alias while=While |
| 186 | while false; do echo hi ; done |
| 187 | Echo while |
| 188 | expected-stdout: |
| 189 | While |
| 190 | --- |
| 191 | name: alias-5 |
| 192 | description: |
| 193 | Check that alias expansion done after alias with trailing space. |
| 194 | stdin: |
| 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 |
| 201 | expected-stdout: |
| 202 | Bar1 Bar2 Stuff Blah |
| 203 | --- |
| 204 | name: alias-6 |
| 205 | description: |
| 206 | Check that alias expansion done after alias with trailing space. |
| 207 | stdin: |
| 208 | alias Echo='echo ' |
| 209 | alias foo='bar bar' |
| 210 | alias bar='Bar ' |
| 211 | alias blah=Blah |
| 212 | Echo foo blah |
| 213 | expected-stdout: |
| 214 | Bar Bar Blah |
| 215 | --- |
| 216 | name: alias-7 |
| 217 | description: |
| 218 | Check that alias expansion done after alias with trailing space |
| 219 | after a keyword. |
| 220 | stdin: |
| 221 | alias X='case ' |
| 222 | alias Y=Z |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 223 | X Y in 'Y') echo is y ;; Z) echo is z ;; esac |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 224 | expected-stdout: |
| 225 | is z |
| 226 | --- |
| 227 | name: alias-8 |
| 228 | description: |
| 229 | Check that newlines in an alias don't cause the command to be lost. |
| 230 | stdin: |
| 231 | alias foo=' |
| 232 | |
| 233 | |
| 234 | echo hi |
| 235 | |
| 236 | |
| 237 | |
| 238 | echo there |
| 239 | |
| 240 | |
| 241 | ' |
| 242 | foo |
| 243 | expected-stdout: |
| 244 | hi |
| 245 | there |
| 246 | --- |
| 247 | name: alias-9 |
| 248 | description: |
| 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. |
| 252 | time-limit: 3 |
| 253 | stdin: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 254 | print '#!'"$__progname"'\necho tf' >lq |
| 255 | chmod +x lq |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 256 | PATH=$PWD$PATHSEP$PATH |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 257 | alias lq=lq |
| 258 | lq |
| 259 | echo = now |
| 260 | i=`lq` |
| 261 | print -r -- $i |
| 262 | echo = out |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 263 | exit 0 |
| 264 | expected-stdout: |
| 265 | tf |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 266 | = now |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 267 | tf |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 268 | = out |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 269 | --- |
| 270 | name: alias-10 |
| 271 | description: |
| 272 | Check that recursion is detected/avoided in aliases. |
| 273 | Regression, introduced during an old bugfix. |
| 274 | stdin: |
| 275 | alias foo='print hello ' |
| 276 | alias bar='foo world' |
| 277 | echo $(bar) |
| 278 | expected-stdout: |
| 279 | hello world |
| 280 | --- |
Elliott Hughes | b27ce95 | 2015-04-21 13:39:18 -0700 | [diff] [blame] | 281 | name: alias-11 |
| 282 | description: |
| 283 | Check that special argument handling still applies with escaped aliases |
| 284 | stdin: |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 285 | alias local1='\typeset' |
| 286 | alias local2='\\builtin typeset' |
| 287 | function fooa { |
| 288 | local1 x=$1 y=z |
Elliott Hughes | b27ce95 | 2015-04-21 13:39:18 -0700 | [diff] [blame] | 289 | print -r -- "$x,$y" |
| 290 | } |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 291 | 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 Hughes | b27ce95 | 2015-04-21 13:39:18 -0700 | [diff] [blame] | 297 | expected-stdout: |
| 298 | bar - baz,z |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 299 | bar - baz,z |
| 300 | --- |
| 301 | name: alias-12 |
| 302 | description: |
| 303 | Something weird from Martijn Dekker |
| 304 | stdin: |
| 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" |
| 312 | expected-stdout: |
| 313 | x() { |
| 314 | \print a |
| 315 | ( \print b ) |
| 316 | x=$(\print c ) |
| 317 | } |
| 318 | hi1 |
| 319 | hi2 |
| 320 | hi3 |
Elliott Hughes | b27ce95 | 2015-04-21 13:39:18 -0700 | [diff] [blame] | 321 | --- |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 322 | name: arith-compound |
| 323 | description: |
| 324 | Check that arithmetic expressions are compound constructs |
| 325 | stdin: |
| 326 | { ! (( 0$(cat >&2) )) <<<1; } <<<2 |
| 327 | expected-stderr: |
| 328 | 1 |
| 329 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 330 | name: arith-lazy-1 |
| 331 | description: |
| 332 | Check that only one side of ternary operator is evaluated |
| 333 | stdin: |
| 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 |
| 341 | expected-stdout: |
| 342 | 20 |
| 343 | 1,i+=2 |
| 344 | 30 |
| 345 | 1,j+=2 |
| 346 | --- |
| 347 | name: arith-lazy-2 |
| 348 | description: |
| 349 | Check that assignments not done on non-evaluated side of ternary |
| 350 | operator |
| 351 | stdin: |
| 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 |
| 359 | expected-stdout: |
| 360 | 20 |
| 361 | 1,i+=2 |
| 362 | 30 |
| 363 | 1,j+=2 |
| 364 | --- |
| 365 | name: arith-lazy-3 |
| 366 | description: |
| 367 | Check that assignments not done on non-evaluated side of ternary |
| 368 | operator and this construct is parsed correctly (Debian #445651) |
| 369 | stdin: |
| 370 | x=4 |
| 371 | y=$((0 ? x=1 : 2)) |
| 372 | echo = $x $y = |
| 373 | expected-stdout: |
| 374 | = 4 2 = |
| 375 | --- |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 376 | name: arith-lazy-4 |
| 377 | description: |
| 378 | Check that preun/postun not done on non-evaluated side of ternary |
| 379 | operator |
| 380 | stdin: |
| 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 |
| 385 | expected-stdout: |
| 386 | (1, 0) |
| 387 | 2 |
| 388 | 0 |
| 389 | 2 |
| 390 | 0 |
| 391 | --- |
Elliott Hughes | 966dd55 | 2016-12-08 15:56:04 -0800 | [diff] [blame] | 392 | name: arith-lazy-5-arr-n |
| 393 | description: Check lazy evaluation with side effects |
| 394 | stdin: |
| 395 | a=0; echo "$((0&&b[a++],a))" |
| 396 | expected-stdout: |
| 397 | 0 |
| 398 | --- |
| 399 | name: arith-lazy-5-arr-p |
| 400 | description: Check lazy evaluation with side effects |
| 401 | stdin: |
| 402 | a=0; echo "$((0&&(b[a++]),a))" |
| 403 | expected-stdout: |
| 404 | 0 |
| 405 | --- |
| 406 | name: arith-lazy-5-str-n |
| 407 | description: Check lazy evaluation with side effects |
| 408 | stdin: |
| 409 | a=0 b=a++; ((0&&b)); echo $a |
| 410 | expected-stdout: |
| 411 | 0 |
| 412 | --- |
| 413 | name: arith-lazy-5-str-p |
| 414 | description: Check lazy evaluation with side effects |
| 415 | stdin: |
| 416 | a=0 b=a++; ((0&&(b))); echo $a |
| 417 | expected-stdout: |
| 418 | 0 |
| 419 | --- |
| 420 | name: arith-lazy-5-tern-l-n |
| 421 | description: Check lazy evaluation with side effects |
| 422 | stdin: |
| 423 | a=0; echo "$((0?b[a++]:999,a))" |
| 424 | expected-stdout: |
| 425 | 0 |
| 426 | --- |
| 427 | name: arith-lazy-5-tern-l-p |
| 428 | description: Check lazy evaluation with side effects |
| 429 | stdin: |
| 430 | a=0; echo "$((0?(b[a++]):999,a))" |
| 431 | expected-stdout: |
| 432 | 0 |
| 433 | --- |
| 434 | name: arith-lazy-5-tern-r-n |
| 435 | description: Check lazy evaluation with side effects |
| 436 | stdin: |
| 437 | a=0; echo "$((1?999:b[a++],a))" |
| 438 | expected-stdout: |
| 439 | 0 |
| 440 | --- |
| 441 | name: arith-lazy-5-tern-r-p |
| 442 | description: Check lazy evaluation with side effects |
| 443 | stdin: |
| 444 | a=0; echo "$((1?999:(b[a++]),a))" |
| 445 | expected-stdout: |
| 446 | 0 |
| 447 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 448 | name: arith-ternary-prec-1 |
| 449 | description: |
| 450 | Check precedence of ternary operator vs assignment |
| 451 | stdin: |
| 452 | typeset -i x=2 |
| 453 | y=$((1 ? 20 : x+=2)) |
| 454 | expected-exit: e != 0 |
| 455 | expected-stderr-pattern: |
| 456 | /.*:.*1 \? 20 : x\+=2.*lvalue.*\n$/ |
| 457 | --- |
| 458 | name: arith-ternary-prec-2 |
| 459 | description: |
| 460 | Check precedence of ternary operator vs assignment |
| 461 | stdin: |
| 462 | typeset -i x=2 |
| 463 | echo $((0 ? x+=2 : 20)) |
| 464 | expected-stdout: |
| 465 | 20 |
| 466 | --- |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 467 | name: arith-prec-1 |
| 468 | description: |
| 469 | Prove arithmetic expressions with embedded parameter |
| 470 | substitutions cannot be parsed ahead of time |
| 471 | stdin: |
| 472 | a='3 + 4' |
| 473 | print 1 $((2 * a)) . |
| 474 | print 2 $((2 * $a)) . |
| 475 | expected-stdout: |
| 476 | 1 14 . |
| 477 | 2 10 . |
| 478 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 479 | name: arith-div-assoc-1 |
| 480 | description: |
| 481 | Check associativity of division operator |
| 482 | stdin: |
| 483 | echo $((20 / 2 / 2)) |
| 484 | expected-stdout: |
| 485 | 5 |
| 486 | --- |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 487 | name: arith-div-byzero |
| 488 | description: |
| 489 | Check division by zero errors out |
| 490 | stdin: |
| 491 | x=$(echo $((1 / 0))) |
| 492 | echo =$?:$x. |
| 493 | expected-stdout: |
| 494 | =1:. |
| 495 | expected-stderr-pattern: |
| 496 | /.*divisor/ |
| 497 | --- |
| 498 | name: arith-div-intmin-by-minusone |
| 499 | description: |
| 500 | Check division overflow wraps around silently |
| 501 | category: int:32 |
| 502 | stdin: |
| 503 | echo signed:$((-2147483648 / -1))r$((-2147483648 % -1)). |
| 504 | echo unsigned:$((# -2147483648 / -1))r$((# -2147483648 % -1)). |
| 505 | expected-stdout: |
| 506 | signed:-2147483648r0. |
| 507 | unsigned:0r2147483648. |
| 508 | --- |
| 509 | name: arith-div-intmin-by-minusone-64 |
| 510 | description: |
| 511 | Check division overflow wraps around silently |
| 512 | category: int:64 |
| 513 | stdin: |
| 514 | echo signed:$((-9223372036854775808 / -1))r$((-9223372036854775808 % -1)). |
| 515 | echo unsigned:$((# -9223372036854775808 / -1))r$((# -9223372036854775808 % -1)). |
| 516 | expected-stdout: |
| 517 | signed:-9223372036854775808r0. |
| 518 | unsigned:0r9223372036854775808. |
| 519 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 520 | name: arith-assop-assoc-1 |
| 521 | description: |
| 522 | Check associativity of assignment-operator operator |
| 523 | stdin: |
| 524 | typeset -i i=1 j=2 k=3 |
| 525 | echo $((i += j += k)) |
| 526 | echo $i,$j,$k |
| 527 | expected-stdout: |
| 528 | 6 |
| 529 | 6,5,3 |
| 530 | --- |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 531 | name: arith-mandatory |
| 532 | description: |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 533 | Passing of this test is *mandatory* for a valid mksh executable! |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 534 | category: shell:legacy-no |
| 535 | stdin: |
| 536 | typeset -i sari=0 |
| 537 | typeset -Ui uari=0 |
| 538 | typeset -i x=0 |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 539 | print -r -- $((x++)):$sari=$uari. #0 |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 540 | let --sari --uari |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 541 | print -r -- $((x++)):$sari=$uari. #1 |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 542 | sari=2147483647 uari=2147483647 |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 543 | print -r -- $((x++)):$sari=$uari. #2 |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 544 | let ++sari ++uari |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 545 | print -r -- $((x++)):$sari=$uari. #3 |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 546 | let --sari --uari |
| 547 | let 'sari *= 2' 'uari *= 2' |
| 548 | let ++sari ++uari |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 549 | print -r -- $((x++)):$sari=$uari. #4 |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 550 | let ++sari ++uari |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 551 | print -r -- $((x++)):$sari=$uari. #5 |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 552 | sari=-2147483648 uari=-2147483648 |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 553 | print -r -- $((x++)):$sari=$uari. #6 |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 554 | let --sari --uari |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 555 | 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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 562 | expected-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 Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 571 | 8:-3=2147483645. |
| 572 | 9:-2=4294967294. |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 573 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 574 | name: arith-unsigned-1 |
| 575 | description: |
| 576 | Check if unsigned arithmetics work |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 577 | category: int:32 |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 578 | stdin: |
| 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 Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 603 | # 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 606 | expected-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 Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 614 | x8 -4 0 |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 615 | --- |
| 616 | name: arith-limit32-1 |
| 617 | description: |
| 618 | Check if arithmetics are 32 bit |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 619 | category: int:32 |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 620 | stdin: |
| 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 |
| 636 | expected-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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 644 | name: arith-limit64-1 |
| 645 | description: |
| 646 | Check if arithmetics are 64 bit |
| 647 | category: int:64 |
| 648 | stdin: |
| 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 |
| 664 | expected-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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 672 | name: bksl-nl-ign-1 |
| 673 | description: |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 674 | Check that \newline is not collapsed after # |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 675 | stdin: |
| 676 | echo hi #there \ |
| 677 | echo folks |
| 678 | expected-stdout: |
| 679 | hi |
| 680 | folks |
| 681 | --- |
| 682 | name: bksl-nl-ign-2 |
| 683 | description: |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 684 | Check that \newline is not collapsed inside single quotes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 685 | stdin: |
| 686 | echo 'hi \ |
| 687 | there' |
| 688 | echo folks |
| 689 | expected-stdout: |
| 690 | hi \ |
| 691 | there |
| 692 | folks |
| 693 | --- |
| 694 | name: bksl-nl-ign-3 |
| 695 | description: |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 696 | Check that \newline is not collapsed inside single quotes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 697 | stdin: |
| 698 | cat << \EOF |
| 699 | hi \ |
| 700 | there |
| 701 | EOF |
| 702 | expected-stdout: |
| 703 | hi \ |
| 704 | there |
| 705 | --- |
| 706 | name: bksl-nl-ign-4 |
| 707 | description: |
| 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) |
| 711 | stdin: |
| 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 |
| 722 | expected-stdout: |
| 723 | hi |
| 724 | foo\ |
| 725 | bar |
| 726 | some |
| 727 | more\ |
| 728 | stuff$a |
| 729 | --- |
| 730 | name: bksl-nl-ign-5 |
| 731 | description: |
| 732 | Check what happens with backslash at end of input |
| 733 | (the old Bourne shell trashes them; so do we) |
| 734 | stdin: ! |
| 735 | echo `echo foo\\`bar |
| 736 | echo hi\ |
| 737 | expected-stdout: |
| 738 | foobar |
| 739 | hi |
| 740 | --- |
| 741 | # |
| 742 | # Places \newline should be collapsed |
| 743 | # |
| 744 | name: bksl-nl-1 |
| 745 | description: |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 746 | Check that \newline is collapsed before, in the middle of, and |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 747 | after words |
| 748 | stdin: |
| 749 | \ |
| 750 | echo hi\ |
| 751 | There, \ |
| 752 | folks |
| 753 | expected-stdout: |
| 754 | hiThere, folks |
| 755 | --- |
| 756 | name: bksl-nl-2 |
| 757 | description: |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 758 | Check that \newline is collapsed in $ sequences |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 759 | (ksh93 fails this) |
| 760 | stdin: |
| 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 | } |
| 773 | expected-stdout: |
| 774 | 12 |
| 775 | 19 |
| 776 | 12 |
| 777 | 19 |
| 778 | 19 |
| 779 | --- |
| 780 | name: bksl-nl-3 |
| 781 | description: |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 782 | Check that \newline is collapsed in $(..) and `...` sequences |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 783 | (ksh93 fails this) |
| 784 | stdin: |
| 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` |
| 797 | expected-stdout: |
| 798 | foobar1 |
| 799 | foobar2 |
| 800 | foobar3 |
| 801 | foobar4 |
| 802 | stuff1 |
| 803 | stuff2 |
| 804 | --- |
| 805 | name: bksl-nl-4 |
| 806 | description: |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 807 | Check that \newline is collapsed in $((..)) sequences |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 808 | (ksh93 fails this) |
| 809 | stdin: |
| 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 | ) |
| 820 | expected-stdout: |
| 821 | 3 |
| 822 | 6 |
| 823 | 10 |
| 824 | 15 |
| 825 | 21 |
| 826 | --- |
| 827 | name: bksl-nl-5 |
| 828 | description: |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 829 | Check that \newline is collapsed in double quoted strings |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 830 | stdin: |
| 831 | echo "\ |
| 832 | hi" |
| 833 | echo "foo\ |
| 834 | bar" |
| 835 | echo "folks\ |
| 836 | " |
| 837 | expected-stdout: |
| 838 | hi |
| 839 | foobar |
| 840 | folks |
| 841 | --- |
| 842 | name: bksl-nl-6 |
| 843 | description: |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 844 | Check that \newline is collapsed in here document delimiters |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 845 | (ksh93 fails second part of this) |
| 846 | stdin: |
| 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 |
| 859 | expected-stdout: |
| 860 | a=12 |
| 861 | foobar |
| 862 | foo |
| 863 | done |
| 864 | --- |
| 865 | name: bksl-nl-7 |
| 866 | description: |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 867 | Check that \newline is collapsed in double-quoted here-document |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 868 | delimiter. |
| 869 | stdin: |
| 870 | a=12 |
| 871 | cat << "EO\ |
| 872 | F" |
| 873 | a=$a |
| 874 | foo\ |
| 875 | bar |
| 876 | EOF |
| 877 | echo done |
| 878 | expected-stdout: |
| 879 | a=$a |
| 880 | foo\ |
| 881 | bar |
| 882 | done |
| 883 | --- |
| 884 | name: bksl-nl-8 |
| 885 | description: |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 886 | Check that \newline is collapsed in various 2+ character tokens |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 887 | delimiter. |
| 888 | (ksh93 fails this) |
| 889 | stdin: |
| 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 |
| 919 | expected-stdout: |
| 920 | hi |
| 921 | there |
| 922 | foo |
| 923 | stuff |
| 924 | more stuff |
| 925 | abcdef |
| 926 | 0 |
| 927 | hi |
| 928 | --- |
| 929 | name: bksl-nl-9 |
| 930 | description: |
| 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) |
| 934 | stdin: |
| 935 | alias x='echo hi\' |
| 936 | x |
| 937 | echo there |
| 938 | expected-stdout: |
| 939 | hiecho there |
| 940 | --- |
| 941 | name: bksl-nl-10 |
| 942 | description: |
| 943 | Check that \newline in a keyword is collapsed |
| 944 | stdin: |
| 945 | i\ |
| 946 | f true; then\ |
| 947 | echo pass; el\ |
| 948 | se echo fail; fi |
| 949 | expected-stdout: |
| 950 | pass |
| 951 | --- |
| 952 | # |
| 953 | # Places \newline should be collapsed (ksh extensions) |
| 954 | # |
| 955 | name: bksl-nl-ksh-1 |
| 956 | description: |
| 957 | Check that \newline is collapsed in extended globbing |
| 958 | (ksh93 fails this) |
| 959 | stdin: |
| 960 | xxx=foo |
| 961 | case $xxx in |
| 962 | (f*\ |
| 963 | (\ |
| 964 | o\ |
| 965 | )\ |
| 966 | ) echo ok ;; |
| 967 | *) echo bad |
| 968 | esac |
| 969 | expected-stdout: |
| 970 | ok |
| 971 | --- |
| 972 | name: bksl-nl-ksh-2 |
| 973 | description: |
| 974 | Check that \newline is collapsed in ((...)) expressions |
| 975 | (ksh93 fails this) |
| 976 | stdin: |
| 977 | i=1 |
| 978 | (\ |
| 979 | (\ |
| 980 | i=i+2\ |
| 981 | )\ |
| 982 | ) |
| 983 | echo $i |
| 984 | expected-stdout: |
| 985 | 3 |
| 986 | --- |
| 987 | name: break-1 |
| 988 | description: |
| 989 | See if break breaks out of loops |
| 990 | stdin: |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 1004 | for i in a b c; do echo $i; eval break; echo bad-$i; done |
| 1005 | echo end-4 |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 1006 | expected-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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 1018 | a |
| 1019 | end-4 |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 1020 | --- |
| 1021 | name: break-2 |
| 1022 | description: |
| 1023 | See if break breaks out of nested loops |
| 1024 | stdin: |
| 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 |
| 1034 | expected-stdout: |
| 1035 | a:x |
| 1036 | end |
| 1037 | --- |
| 1038 | name: break-3 |
| 1039 | description: |
| 1040 | What if break used outside of any loops |
| 1041 | (ksh88,ksh93 don't print error messages here) |
| 1042 | stdin: |
| 1043 | break |
| 1044 | expected-stderr-pattern: |
| 1045 | /.*break.*/ |
| 1046 | --- |
| 1047 | name: break-4 |
| 1048 | description: |
| 1049 | What if break N used when only N-1 loops |
| 1050 | (ksh88,ksh93 don't print error messages here) |
| 1051 | stdin: |
| 1052 | for i in a b c; do echo $i; break 2; echo bad-$i; done |
| 1053 | echo end |
| 1054 | expected-stdout: |
| 1055 | a |
| 1056 | end |
| 1057 | expected-stderr-pattern: |
| 1058 | /.*break.*/ |
| 1059 | --- |
| 1060 | name: break-5 |
| 1061 | description: |
| 1062 | Error if break argument isn't a number |
| 1063 | stdin: |
| 1064 | for i in a b c; do echo $i; break abc; echo more-$i; done |
| 1065 | echo end |
| 1066 | expected-stdout: |
| 1067 | a |
| 1068 | expected-exit: e != 0 |
| 1069 | expected-stderr-pattern: |
| 1070 | /.*break.*/ |
| 1071 | --- |
| 1072 | name: continue-1 |
| 1073 | description: |
| 1074 | See if continue continues loops |
| 1075 | stdin: |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 1089 | for i in a b c; do echo $i; eval continue; echo bad-$i ; done |
| 1090 | echo end-4 |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 1091 | expected-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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 1113 | a |
| 1114 | b |
| 1115 | c |
| 1116 | end-4 |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 1117 | --- |
| 1118 | name: continue-2 |
| 1119 | description: |
| 1120 | See if continue breaks out of nested loops |
| 1121 | stdin: |
| 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 |
| 1131 | expected-stdout: |
| 1132 | a:x |
| 1133 | b:x |
| 1134 | c:x |
| 1135 | end |
| 1136 | --- |
| 1137 | name: continue-3 |
| 1138 | description: |
| 1139 | What if continue used outside of any loops |
| 1140 | (ksh88,ksh93 don't print error messages here) |
| 1141 | stdin: |
| 1142 | continue |
| 1143 | expected-stderr-pattern: |
| 1144 | /.*continue.*/ |
| 1145 | --- |
| 1146 | name: continue-4 |
| 1147 | description: |
| 1148 | What if continue N used when only N-1 loops |
| 1149 | (ksh88,ksh93 don't print error messages here) |
| 1150 | stdin: |
| 1151 | for i in a b c; do echo $i; continue 2; echo bad-$i; done |
| 1152 | echo end |
| 1153 | expected-stdout: |
| 1154 | a |
| 1155 | b |
| 1156 | c |
| 1157 | end |
| 1158 | expected-stderr-pattern: |
| 1159 | /.*continue.*/ |
| 1160 | --- |
| 1161 | name: continue-5 |
| 1162 | description: |
| 1163 | Error if continue argument isn't a number |
| 1164 | stdin: |
| 1165 | for i in a b c; do echo $i; continue abc; echo more-$i; done |
| 1166 | echo end |
| 1167 | expected-stdout: |
| 1168 | a |
| 1169 | expected-exit: e != 0 |
| 1170 | expected-stderr-pattern: |
| 1171 | /.*continue.*/ |
| 1172 | --- |
| 1173 | name: cd-history |
| 1174 | description: |
| 1175 | Test someone's CD history package (uses arrays) |
| 1176 | stdin: |
| 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 |
| 1325 | expected-stdout: |
| 1326 | /bin |
| 1327 | /tmp |
| 1328 | 3 / |
| 1329 | 2 /etc |
| 1330 | 1 /bin |
| 1331 | 0 /tmp |
| 1332 | --- |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 1333 | name: cd-pe |
| 1334 | description: |
| 1335 | Check package for cd -Pe |
| 1336 | need-pass: no |
| 1337 | # the mv command fails on Cygwin |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 1338 | # Hurd aborts the testsuite (permission denied) |
| 1339 | # QNX does not find subdir to cd into |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 1340 | category: !os:cygwin,!os:gnu,!os:msys,!os:nto,!os:os390,!nosymlink |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 1341 | file-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 |
| 1360 | stdin: |
| 1361 | export TSHELL="$__progname" |
| 1362 | "$__progname" x |
| 1363 | echo "now with -e:" |
| 1364 | "$__progname" x e |
| 1365 | expected-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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 1374 | name: env-prompt |
| 1375 | description: |
| 1376 | Check that prompt not printed when processing ENV |
| 1377 | env-setup: !ENV=./foo! |
| 1378 | file-setup: file 644 "foo" |
| 1379 | XXX=_ |
| 1380 | PS1=X |
| 1381 | false && echo hmmm |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 1382 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 1383 | arguments: !-i! |
| 1384 | stdin: |
| 1385 | echo hi${XXX}there |
| 1386 | expected-stdout: |
| 1387 | hi_there |
| 1388 | expected-stderr: ! |
| 1389 | XX |
| 1390 | --- |
| 1391 | name: expand-ugly |
| 1392 | description: |
| 1393 | Check that weird ${foo+bar} constructs are parsed correctly |
| 1394 | stdin: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 1395 | 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 Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 1441 | (foo() { return 100; }; foo; echo 41 ${#+${#:+${#?}}\ \}\}\}}) 2>/dev/null || echo failed in 41 |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 1442 | expected-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 Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 1483 | 41 3 }}} |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 1484 | --- |
| 1485 | name: expand-unglob-dblq |
| 1486 | description: |
| 1487 | Check that regular "${foo+bar}" constructs are parsed correctly |
| 1488 | stdin: |
| 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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 1496 | (echo "$1 qstn norm foo ${v?'bar'} baz") 2>/dev/null || \ |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 1497 | 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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 1501 | (echo "$1 QSTN norm foo ${v:?'bar'} baz") 2>/dev/null || \ |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 1502 | 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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 1510 | (echo "$1 qstn parn foo ${v?(bar)} baz") 2>/dev/null || \ |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 1511 | 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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 1515 | (echo "$1 QSTN parn foo ${v:?(bar)} baz") 2>/dev/null || \ |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 1516 | 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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 1524 | (echo "$1 qstn brac foo ${v?a$u{{{\}b} c ${v?d{}} baz") 2>/dev/null || \ |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 1525 | 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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 1529 | (echo "$1 QSTN brac foo ${v:?a$u{{{\}b} c ${v:?d{}} baz") 2>/dev/null || \ |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 1530 | echo "$1 QSTN brac -> error" |
| 1531 | } |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 1532 | : '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 1533 | 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 |
| 1542 | expected-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 | --- |
| 1616 | name: expand-unglob-unq |
| 1617 | description: |
| 1618 | Check that regular ${foo+bar} constructs are parsed correctly |
| 1619 | stdin: |
| 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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 1627 | (echo $1 qstn norm foo ${v?'bar'} baz) 2>/dev/null || \ |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 1628 | 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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 1632 | (echo $1 QSTN norm foo ${v:?'bar'} baz) 2>/dev/null || \ |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 1633 | 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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 1641 | (echo $1 qstn parn foo ${v?\(bar')'} baz) 2>/dev/null || \ |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 1642 | 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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 1646 | (echo $1 QSTN parn foo ${v:?\(bar')'} baz) 2>/dev/null || \ |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 1647 | 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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 1655 | (echo $1 qstn brac foo ${v?a$u{{{\}b} c ${v?d{}} baz) 2>/dev/null || \ |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 1656 | 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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 1660 | (echo $1 QSTN brac foo ${v:?a$u{{{\}b} c ${v:?d{}} baz) 2>/dev/null || \ |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 1661 | echo "$1 QSTN brac -> error" |
| 1662 | } |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 1663 | : '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' '}}}' |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 1664 | 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 |
| 1673 | expected-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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 1747 | name: expand-threecolons-dblq |
| 1748 | description: |
| 1749 | Check for a particular thing that used to segfault |
| 1750 | stdin: |
| 1751 | TEST=1234 |
| 1752 | echo "${TEST:1:2:3}" |
| 1753 | echo $? but still living |
| 1754 | expected-stderr-pattern: |
| 1755 | /bad substitution/ |
| 1756 | expected-exit: 1 |
| 1757 | --- |
| 1758 | name: expand-threecolons-unq |
| 1759 | description: |
| 1760 | Check for a particular thing that used to not error out |
| 1761 | stdin: |
| 1762 | TEST=1234 |
| 1763 | echo ${TEST:1:2:3} |
| 1764 | echo $? but still living |
| 1765 | expected-stderr-pattern: |
| 1766 | /bad substitution/ |
| 1767 | expected-exit: 1 |
| 1768 | --- |
| 1769 | name: expand-weird-1 |
| 1770 | description: |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 1771 | Check corner cases of trim expansion vs. $# vs. ${#var} vs. ${var?} |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 1772 | stdin: |
| 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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 1779 | (exit 0) |
| 1780 | echo $? = ${#?} . |
| 1781 | (exit 111) |
| 1782 | echo $? = ${#?} . |
| 1783 | expected-stdout: |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 1784 | 11 |
| 1785 | 2 |
| 1786 | 1 |
| 1787 | 2 |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 1788 | 0 = 1 . |
| 1789 | 111 = 3 . |
| 1790 | --- |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 1791 | name: expand-weird-2 |
| 1792 | description: |
| 1793 | Check more substitution and extension corner cases |
| 1794 | stdin: |
| 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" |
| 1818 | expected-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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 1833 | name: expand-weird-3 |
| 1834 | description: |
| 1835 | Check that trimming works with positional parameters (Debian #48453) |
| 1836 | stdin: |
| 1837 | A=9999-02 |
| 1838 | B=9999 |
| 1839 | echo 1=${A#$B?}. |
| 1840 | set -- $A $B |
| 1841 | echo 2=${1#$2?}. |
| 1842 | expected-stdout: |
| 1843 | 1=02. |
| 1844 | 2=02. |
| 1845 | --- |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 1846 | name: expand-weird-4 |
| 1847 | description: |
| 1848 | Check that tilde expansion is enabled in ${x#~} |
| 1849 | and cases that are modelled after it (${x/~/~}) |
| 1850 | stdin: |
| 1851 | HOME=/etc |
| 1852 | a="~/x" |
| 1853 | echo "<${a#~}> <${a#\~}> <${b:-~}> <${b:-\~}> <${c:=~}><$c> <${a/~}> <${a/x/~}> <${a/x/\~}>" |
| 1854 | expected-stdout: |
| 1855 | <~/x> </x> <~> <\~> <~><~> <~/x> <~//etc> <~/~> |
| 1856 | --- |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 1857 | name: expand-bang-1 |
| 1858 | description: |
| 1859 | Check corner case of ${!?} with ! being var vs. op |
| 1860 | stdin: |
| 1861 | echo ${!?} |
| 1862 | expected-exit: 1 |
| 1863 | expected-stderr-pattern: /not set/ |
| 1864 | --- |
| 1865 | name: expand-bang-2 |
| 1866 | description: |
| 1867 | Check corner case of ${!var} vs. ${var op} with var=! |
| 1868 | stdin: |
| 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 $? . |
| 1890 | expected-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 Hughes | 737fdce | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 1901 | name: expand-number-1 |
| 1902 | description: |
| 1903 | Check that positional arguments do not overflow |
| 1904 | stdin: |
| 1905 | echo "1 ${12345678901234567890} ." |
| 1906 | expected-stdout: |
| 1907 | 1 . |
| 1908 | --- |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 1909 | name: expand-slashes-1 |
| 1910 | description: |
| 1911 | Check that side effects in substring replacement are handled correctly |
| 1912 | stdin: |
| 1913 | foo=n1n1n1n2n3 |
| 1914 | i=2 |
| 1915 | n=1 |
| 1916 | echo 1 ${foo//n$((n++))/[$((++i))]} . |
| 1917 | echo 2 $n , $i . |
| 1918 | expected-stdout: |
| 1919 | 1 [3][3][3]n2n3 . |
| 1920 | 2 2 , 3 . |
| 1921 | --- |
| 1922 | name: expand-slashes-2 |
| 1923 | description: |
| 1924 | Check that side effects in substring replacement are handled correctly |
| 1925 | stdin: |
| 1926 | foo=n1n1n1n2n3 |
| 1927 | i=2 |
| 1928 | n=1 |
| 1929 | echo 1 ${foo@/n$((n++))/[$((++i))]} . |
| 1930 | echo 2 $n , $i . |
| 1931 | expected-stdout: |
| 1932 | 1 [3]n1n1[4][5] . |
| 1933 | 2 5 , 5 . |
| 1934 | --- |
| 1935 | name: expand-slashes-3 |
| 1936 | description: |
| 1937 | Check that we can access the replaced string |
| 1938 | stdin: |
| 1939 | foo=n1n1n1n2n3 |
| 1940 | echo 1 ${foo@/n[12]/[$KSH_MATCH]} . |
| 1941 | expected-stdout: |
| 1942 | 1 [n1][n1][n1][n2]n3 . |
| 1943 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 1944 | name: eglob-bad-1 |
| 1945 | description: |
| 1946 | Check that globbing isn't done when glob has syntax error |
| 1947 | file-setup: file 644 "abcx" |
| 1948 | file-setup: file 644 "abcz" |
| 1949 | file-setup: file 644 "bbc" |
| 1950 | stdin: |
| 1951 | echo !([*)* |
| 1952 | echo +(a|b[)* |
| 1953 | expected-stdout: |
| 1954 | !([*)* |
| 1955 | +(a|b[)* |
| 1956 | --- |
| 1957 | name: eglob-bad-2 |
| 1958 | description: |
| 1959 | Check that globbing isn't done when glob has syntax error |
| 1960 | (AT&T ksh fails this test) |
| 1961 | file-setup: file 644 "abcx" |
| 1962 | file-setup: file 644 "abcz" |
| 1963 | file-setup: file 644 "bbc" |
| 1964 | stdin: |
| 1965 | echo [a*(]*)z |
| 1966 | expected-stdout: |
| 1967 | [a*(]*)z |
| 1968 | --- |
| 1969 | name: eglob-infinite-plus |
| 1970 | description: |
| 1971 | Check that shell doesn't go into infinite loop expanding +(...) |
| 1972 | expressions. |
| 1973 | file-setup: file 644 "abc" |
| 1974 | time-limit: 3 |
| 1975 | stdin: |
| 1976 | echo +()c |
| 1977 | echo +()x |
| 1978 | echo +(*)c |
| 1979 | echo +(*)x |
| 1980 | expected-stdout: |
| 1981 | +()c |
| 1982 | +()x |
| 1983 | abc |
| 1984 | +(*)x |
| 1985 | --- |
| 1986 | name: eglob-subst-1 |
| 1987 | description: |
| 1988 | Check that eglobbing isn't done on substitution results |
| 1989 | file-setup: file 644 "abc" |
| 1990 | stdin: |
| 1991 | x='@(*)' |
| 1992 | echo $x |
| 1993 | expected-stdout: |
| 1994 | @(*) |
| 1995 | --- |
| 1996 | name: eglob-nomatch-1 |
| 1997 | description: |
| 1998 | Check that the pattern doesn't match |
| 1999 | stdin: |
| 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 |
| 2003 | expected-stdout: |
| 2004 | 1: no-file+(a|b)stuff |
| 2005 | 2: no-file+(a*(c)|b)stuff |
| 2006 | 3: no-file+((((c)))|b)stuff |
| 2007 | --- |
| 2008 | name: eglob-match-1 |
| 2009 | description: |
| 2010 | Check that the pattern matches correctly |
| 2011 | file-setup: file 644 "abd" |
| 2012 | file-setup: file 644 "acd" |
| 2013 | file-setup: file 644 "abac" |
| 2014 | stdin: |
| 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 [...] |
| 2019 | expected-stdout: |
| 2020 | 1: abd acd |
| 2021 | 2: acd |
| 2022 | 3: abac |
| 2023 | 4: abd |
| 2024 | --- |
| 2025 | name: eglob-case-1 |
| 2026 | description: |
| 2027 | Simple negation tests |
| 2028 | stdin: |
| 2029 | case foo in !(foo|bar)) echo yes;; *) echo no;; esac |
| 2030 | case bar in !(foo|bar)) echo yes;; *) echo no;; esac |
| 2031 | expected-stdout: |
| 2032 | no |
| 2033 | no |
| 2034 | --- |
| 2035 | name: eglob-case-2 |
| 2036 | description: |
| 2037 | Simple kleene tests |
| 2038 | stdin: |
| 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 |
| 2042 | expected-stdout: |
| 2043 | no |
| 2044 | yes |
| 2045 | yes |
| 2046 | --- |
| 2047 | name: eglob-trim-1 |
| 2048 | description: |
| 2049 | Eglobbing in trim expressions... |
| 2050 | (AT&T ksh fails this - docs say # matches shortest string, ## matches |
| 2051 | longest...) |
| 2052 | stdin: |
| 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} |
| 2058 | expected-stdout: |
| 2059 | 1: bcdef |
| 2060 | 2: def |
| 2061 | 3: abcde |
| 2062 | 4: abc |
| 2063 | --- |
| 2064 | name: eglob-trim-2 |
| 2065 | description: |
| 2066 | Check eglobbing works in trims... |
| 2067 | stdin: |
| 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)} |
| 2073 | expected-stdout: |
| 2074 | 1: ef |
| 2075 | 2: ef |
| 2076 | 3: abcdef |
| 2077 | 4: cdef |
| 2078 | --- |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 2079 | name: eglob-trim-3 |
| 2080 | description: |
| 2081 | Check eglobbing works in trims, for Korn Shell |
| 2082 | Ensure eglobbing does not work for reduced-feature /bin/sh |
| 2083 | stdin: |
| 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%(*}>" |
| 2094 | expected-stdout: |
| 2095 | <foo,foo,fooba> |
| 2096 | <foo,foo> |
| 2097 | <foobar,foobaz,fooba> |
| 2098 | <foo> |
| 2099 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2100 | name: eglob-substrpl-1 |
| 2101 | description: |
| 2102 | Check eglobbing works in substs... and they work at all |
| 2103 | stdin: |
| 2104 | [[ -n $BASH_VERSION ]] && shopt -s extglob |
| 2105 | x=1222321_ab/cde_b/c_1221 |
| 2106 | y=xyz |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 2107 | echo 1: ${x/2} . ${x/} |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2108 | 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 Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 2129 | 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2138 | expected-stdout: |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 2139 | 1: 122321_ab/cde_b/c_1221 . 1222321_ab/cde_b/c_1221 |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2140 | 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 Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 2162 | 24: 1222321_ab/cde_b/c_1221 |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2163 | 25: 1222321_ab/cde_b/c_1229 |
| 2164 | 26: 1222321_ab/cde_b/c_1221 |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 2165 | 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2170 | --- |
| 2171 | name: eglob-substrpl-2 |
| 2172 | description: |
| 2173 | Check anchored substring replacement works, corner cases |
| 2174 | stdin: |
| 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/%} |
| 2182 | expected-stdout: |
| 2183 | 1: x123 |
| 2184 | 2: 123x |
| 2185 | 3: 123 |
| 2186 | 4: 123 |
| 2187 | 5: 123 |
| 2188 | 6: 123 |
| 2189 | --- |
| 2190 | name: eglob-substrpl-3a |
| 2191 | description: |
| 2192 | Check substring replacement works with variables and slashes, too |
| 2193 | stdin: |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 2194 | HOME=/etc |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2195 | 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'/~}" |
| 2203 | expected-stdout: |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 2204 | /etc/tmp |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2205 | /home/user/tmp |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 2206 | /etc/tmp |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2207 | /home/user/tmp |
| 2208 | /home/user/tmp |
| 2209 | /home/user/tmp |
| 2210 | --- |
| 2211 | name: eglob-substrpl-3b |
| 2212 | description: |
| 2213 | More of this, bash fails it (bash4 passes) |
| 2214 | stdin: |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 2215 | HOME=/etc |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2216 | 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)'/~}" |
| 2221 | expected-stdout: |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 2222 | /etc/tmp |
| 2223 | /etc/tmp |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2224 | /home/user/tmp |
| 2225 | --- |
| 2226 | name: eglob-substrpl-3c |
| 2227 | description: |
| 2228 | Even more weird cases |
| 2229 | stdin: |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 2230 | HOME=/etc |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2231 | 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 Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 2256 | 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2266 | tp="+($tp)" |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 2267 | echo 30: ${ts/$tp/$tr} |
| 2268 | echo 31: ${ts//$tp/$tr} |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2269 | expected-stdout: |
| 2270 | 1: $pfx/tmp |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 2271 | 2: /etc/tmp |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2272 | 3: $pfx/tmp |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 2273 | 4: /etc/tmp |
| 2274 | 5: /etc/tmp |
| 2275 | 6: $pfx/tmp |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2276 | 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 Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 2280 | 11: a/ba/b$tp$tp_a/b$tp_*(a/b)_*($tp) |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2281 | 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 Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 2289 | 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2301 | # This is what GNU bash does: |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 2302 | # 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2304 | --- |
| 2305 | name: eglob-utf8-1 |
| 2306 | description: |
| 2307 | UTF-8 mode differences for eglobbing |
| 2308 | stdin: |
| 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%%?} . |
| 2326 | expected-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 | --- |
| 2337 | name: glob-bad-1 |
| 2338 | description: |
| 2339 | Check that globbing isn't done when glob has syntax error |
| 2340 | file-setup: dir 755 "[x" |
| 2341 | file-setup: file 644 "[x/foo" |
| 2342 | stdin: |
| 2343 | echo [* |
| 2344 | echo *[x |
| 2345 | echo [x/* |
| 2346 | expected-stdout: |
| 2347 | [* |
| 2348 | *[x |
| 2349 | [x/foo |
| 2350 | --- |
| 2351 | name: glob-bad-2 |
| 2352 | description: |
| 2353 | Check that symbolic links aren't stat()'d |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 2354 | # breaks on Dell UNIX 4.0 R2.2 (SVR4) where unlink also fails |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 2355 | # breaks on FreeMiNT (cannot unlink dangling symlinks) |
| 2356 | # breaks on MSYS, OS/2 (do not support symlinks) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 2357 | category: !os:mint,!os:msys,!os:svr4.0,!nosymlink |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2358 | file-setup: dir 755 "dir" |
| 2359 | file-setup: symlink 644 "dir/abc" |
| 2360 | non-existent-file |
| 2361 | stdin: |
| 2362 | echo d*/* |
| 2363 | echo d*/abc |
| 2364 | expected-stdout: |
| 2365 | dir/abc |
| 2366 | dir/abc |
| 2367 | --- |
| 2368 | name: glob-range-1 |
| 2369 | description: |
| 2370 | Test range matching |
| 2371 | file-setup: file 644 ".bc" |
| 2372 | file-setup: file 644 "abc" |
| 2373 | file-setup: file 644 "bbc" |
| 2374 | file-setup: file 644 "cbc" |
| 2375 | file-setup: file 644 "-bc" |
| 2376 | stdin: |
| 2377 | echo [ab-]* |
| 2378 | echo [-ab]* |
| 2379 | echo [!-ab]* |
| 2380 | echo [!ab]* |
| 2381 | echo []ab]* |
Elliott Hughes | 737fdce | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 2382 | :>'./!bc' |
| 2383 | :>'./^bc' |
| 2384 | echo [^ab]* |
| 2385 | echo [!ab]* |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2386 | expected-stdout: |
| 2387 | -bc abc bbc |
| 2388 | -bc abc bbc |
| 2389 | cbc |
| 2390 | -bc cbc |
| 2391 | abc bbc |
Elliott Hughes | 737fdce | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 2392 | ^bc abc bbc |
| 2393 | !bc -bc ^bc cbc |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2394 | --- |
| 2395 | name: glob-range-2 |
| 2396 | description: |
| 2397 | Test range matching |
| 2398 | (AT&T ksh fails this; POSIX says invalid) |
| 2399 | file-setup: file 644 "abc" |
| 2400 | stdin: |
| 2401 | echo [a--]* |
| 2402 | expected-stdout: |
| 2403 | [a--]* |
| 2404 | --- |
| 2405 | name: glob-range-3 |
| 2406 | description: |
| 2407 | Check that globbing matches the right things... |
| 2408 | # breaks on Mac OSX (HFS+ non-standard Unicode canonical decomposition) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 2409 | # breaks on Cygwin 1.7 (files are now UTF-16 or something) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 2410 | # breaks on QNX 6.4.1 (says RT) |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 2411 | category: !os:cygwin,!os:darwin,!os:msys,!os:nto,!os:os2 |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 2412 | need-pass: no |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2413 | file-setup: file 644 "aÂc" |
| 2414 | stdin: |
| 2415 | echo a[Á-Ú]* |
| 2416 | expected-stdout: |
| 2417 | aÂc |
| 2418 | --- |
| 2419 | name: glob-range-4 |
| 2420 | description: |
| 2421 | Results unspecified according to POSIX |
| 2422 | file-setup: file 644 ".bc" |
| 2423 | stdin: |
| 2424 | echo [a.]* |
| 2425 | expected-stdout: |
| 2426 | [a.]* |
| 2427 | --- |
| 2428 | name: glob-range-5 |
| 2429 | description: |
| 2430 | Results unspecified according to POSIX |
| 2431 | (AT&T ksh treats this like [a-cc-e]*) |
| 2432 | file-setup: file 644 "abc" |
| 2433 | file-setup: file 644 "bbc" |
| 2434 | file-setup: file 644 "cbc" |
| 2435 | file-setup: file 644 "dbc" |
| 2436 | file-setup: file 644 "ebc" |
| 2437 | file-setup: file 644 "-bc" |
| 2438 | stdin: |
| 2439 | echo [a-c-e]* |
| 2440 | expected-stdout: |
| 2441 | -bc abc bbc cbc ebc |
| 2442 | --- |
Elliott Hughes | 737fdce | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 2443 | name: glob-trim-1 |
| 2444 | description: |
| 2445 | Check against a regression from fixing IFS-subst-2 |
| 2446 | stdin: |
| 2447 | x='#foo' |
| 2448 | print -r "before='$x'" |
| 2449 | x=${x%%#*} |
| 2450 | print -r "after ='$x'" |
| 2451 | expected-stdout: |
| 2452 | before='#foo' |
| 2453 | after ='' |
| 2454 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2455 | name: heredoc-1 |
| 2456 | description: |
| 2457 | Check ordering/content of redundent here documents. |
| 2458 | stdin: |
| 2459 | cat << EOF1 << EOF2 |
| 2460 | hi |
| 2461 | EOF1 |
| 2462 | there |
| 2463 | EOF2 |
| 2464 | expected-stdout: |
| 2465 | there |
| 2466 | --- |
| 2467 | name: heredoc-2 |
| 2468 | description: |
| 2469 | Check quoted here-doc is protected. |
| 2470 | stdin: |
| 2471 | a=foo |
| 2472 | cat << 'EOF' |
| 2473 | hi\ |
| 2474 | there$a |
| 2475 | stuff |
| 2476 | EO\ |
| 2477 | F |
| 2478 | EOF |
| 2479 | expected-stdout: |
| 2480 | hi\ |
| 2481 | there$a |
| 2482 | stuff |
| 2483 | EO\ |
| 2484 | F |
| 2485 | --- |
| 2486 | name: heredoc-3 |
| 2487 | description: |
| 2488 | Check that newline isn't needed after heredoc-delimiter marker. |
| 2489 | stdin: ! |
| 2490 | cat << EOF |
| 2491 | hi |
| 2492 | there |
| 2493 | EOF |
| 2494 | expected-stdout: |
| 2495 | hi |
| 2496 | there |
| 2497 | --- |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 2498 | name: heredoc-4a |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2499 | description: |
| 2500 | Check that an error occurs if the heredoc-delimiter is missing. |
| 2501 | stdin: ! |
| 2502 | cat << EOF |
| 2503 | hi |
| 2504 | there |
| 2505 | expected-exit: e > 0 |
| 2506 | expected-stderr-pattern: /.*/ |
| 2507 | --- |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 2508 | name: heredoc-4an |
| 2509 | description: |
| 2510 | Check that an error occurs if the heredoc-delimiter is missing. |
| 2511 | arguments: !-n! |
| 2512 | stdin: ! |
| 2513 | cat << EOF |
| 2514 | hi |
| 2515 | there |
| 2516 | expected-exit: e > 0 |
| 2517 | expected-stderr-pattern: /.*/ |
| 2518 | --- |
| 2519 | name: heredoc-4b |
| 2520 | description: |
| 2521 | Check that an error occurs if the heredoc is missing. |
| 2522 | stdin: ! |
| 2523 | cat << EOF |
| 2524 | expected-exit: e > 0 |
| 2525 | expected-stderr-pattern: /.*/ |
| 2526 | --- |
| 2527 | name: heredoc-4bn |
| 2528 | description: |
| 2529 | Check that an error occurs if the heredoc is missing. |
| 2530 | arguments: !-n! |
| 2531 | stdin: ! |
| 2532 | cat << EOF |
| 2533 | expected-exit: e > 0 |
| 2534 | expected-stderr-pattern: /.*/ |
| 2535 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2536 | name: heredoc-5 |
| 2537 | description: |
| 2538 | Check that backslash quotes a $, ` and \ and kills a \newline |
| 2539 | stdin: |
| 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 |
| 2552 | expected-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 | --- |
| 2561 | name: heredoc-6 |
| 2562 | description: |
| 2563 | Check that \newline in initial here-delim word doesn't imply |
| 2564 | a quoted here-doc. |
| 2565 | stdin: |
| 2566 | a=i |
| 2567 | cat << EO\ |
| 2568 | F |
| 2569 | h$a |
| 2570 | there |
| 2571 | EOF |
| 2572 | expected-stdout: |
| 2573 | hi |
| 2574 | there |
| 2575 | --- |
| 2576 | name: heredoc-7 |
| 2577 | description: |
| 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. |
| 2581 | stdin: |
| 2582 | a=b |
| 2583 | cat << "E$a" |
| 2584 | hi |
| 2585 | h$a |
| 2586 | hb |
| 2587 | E$a |
| 2588 | echo done |
| 2589 | expected-stdout: |
| 2590 | hi |
| 2591 | h$a |
| 2592 | hb |
| 2593 | done |
| 2594 | --- |
| 2595 | name: heredoc-8 |
| 2596 | description: |
| 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). |
| 2601 | stdin: |
| 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 |
| 2611 | expected-stdout: |
| 2612 | hi |
| 2613 | h$a |
| 2614 | h\$a |
| 2615 | hb |
| 2616 | h\b |
| 2617 | done |
| 2618 | --- |
| 2619 | name: heredoc-9a |
| 2620 | description: |
| 2621 | Check that here strings work. |
| 2622 | stdin: |
| 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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 2631 | tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"$(echo "foo bar")" |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 2632 | tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<"A $(echo "foo bar") B" |
| 2633 | tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<\$b\$b$bar |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2634 | expected-stdout: |
| 2635 | sbb |
| 2636 | sbb |
| 2637 | one |
| 2638 | onm |
| 2639 | $one |
| 2640 | $one |
| 2641 | -sbb |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 2642 | sbb one |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 2643 | A sbb one B |
| 2644 | $o$oone |
| 2645 | onm |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 2646 | --- |
| 2647 | name: heredoc-9b |
| 2648 | description: |
| 2649 | Check that a corner case of here strings works like bash |
| 2650 | stdin: |
| 2651 | fnord=42 |
| 2652 | bar="bar |
| 2653 | \$fnord baz" |
| 2654 | tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<$bar |
| 2655 | expected-stdout: |
| 2656 | one $sabeq onm |
| 2657 | category: bash |
| 2658 | --- |
| 2659 | name: heredoc-9c |
| 2660 | description: |
| 2661 | Check that a corner case of here strings works like ksh93, zsh |
| 2662 | stdin: |
| 2663 | fnord=42 |
| 2664 | bar="bar |
| 2665 | \$fnord baz" |
| 2666 | tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<<$bar |
| 2667 | expected-stdout: |
| 2668 | one |
| 2669 | $sabeq onm |
| 2670 | --- |
| 2671 | name: heredoc-9d |
| 2672 | description: |
| 2673 | Check another corner case of here strings |
| 2674 | stdin: |
| 2675 | tr abcdefghijklmnopqrstuvwxyz nopqrstuvwxyzabcdefghijklm <<< bar |
| 2676 | expected-stdout: |
| 2677 | one |
| 2678 | --- |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 2679 | name: heredoc-9e |
| 2680 | description: |
| 2681 | Check here string related regression with multiple iops |
| 2682 | stdin: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 2683 | echo $(tr r z <<<'bar' 2>/dev/null) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 2684 | expected-stdout: |
| 2685 | baz |
| 2686 | --- |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 2687 | name: heredoc-9f |
| 2688 | description: |
| 2689 | Check long here strings |
| 2690 | stdin: |
| 2691 | cat <<< "$( : )aa" |
| 2692 | expected-stdout: |
| 2693 | aa |
| 2694 | --- |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 2695 | name: heredoc-10 |
| 2696 | description: |
| 2697 | Check direct here document assignment |
| 2698 | stdin: |
| 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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 2711 | fnd=$(typeset -f foo) |
| 2712 | print -r -- "$fnd" |
| 2713 | function foo { |
| 2714 | echo blub |
| 2715 | } |
| 2716 | foo |
| 2717 | eval "$fnd" |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 2718 | 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 Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 2725 | # check append |
| 2726 | v=<<-EOF |
| 2727 | vapp1 |
| 2728 | EOF |
| 2729 | v+=<<-EOF |
| 2730 | vapp2 |
| 2731 | EOF |
| 2732 | print -r -- "| ${v//$'\n'/^} |" |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 2733 | expected-stdout: |
| 2734 | function foo { |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 2735 | vc=<<-EOF |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 2736 | =c $x \x40= |
| 2737 | EOF |
| 2738 | |
| 2739 | } |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 2740 | blub |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 2741 | | 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 Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 2748 | | vapp1^vapp2^ | |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 2749 | --- |
| 2750 | name: heredoc-11 |
| 2751 | description: |
| 2752 | Check here documents with no or empty delimiter |
| 2753 | stdin: |
| 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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 2769 | fnd=$(typeset -f foo) |
| 2770 | print -r -- "$fnd" |
| 2771 | function foo { |
| 2772 | echo blub |
| 2773 | } |
| 2774 | foo |
| 2775 | eval "$fnd" |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 2776 | foo |
| 2777 | print -r -- "| va={$va} vb={$vb} vc={$vc} vd={$vd} |" |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 2778 | x=y |
| 2779 | foo |
| 2780 | typeset -f foo |
| 2781 | print -r -- "| vc={$vc} vd={$vd} |" |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 2782 | # check append |
| 2783 | v=<<- |
| 2784 | vapp1 |
| 2785 | << |
| 2786 | v+=<<-'' |
| 2787 | vapp2 |
| 2788 | |
| 2789 | print -r -- "| ${v//$'\n'/^} |" |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 2790 | expected-stdout: |
| 2791 | function foo { |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 2792 | vc=<<- |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 2793 | =c $x \x40= |
| 2794 | << |
| 2795 | |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 2796 | vd=<<-"" |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 2797 | =d $x \x40= |
| 2798 | |
| 2799 | |
| 2800 | } |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 2801 | blub |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 2802 | | va={=a u \x40= |
| 2803 | } vb={=b $x \x40= |
| 2804 | } vc={=c u \x40= |
| 2805 | } vd={=d $x \x40= |
| 2806 | } | |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 2807 | 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 Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 2820 | | vapp1^vapp2^ | |
| 2821 | --- |
| 2822 | name: heredoc-12 |
| 2823 | description: |
| 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 |
| 2828 | stdin: |
| 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 |
| 2853 | expected-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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 2866 | --- |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 2867 | name: heredoc-14 |
| 2868 | description: |
| 2869 | Check that using multiple here documents works |
| 2870 | stdin: |
| 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 |
| 2891 | expected-stdout: |
| 2892 | 0 |
| 2893 | bar() { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 2894 | \foo 4<<-a <<-b 5<<-c |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 2895 | 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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 2907 | name: heredoc-comsub-1 |
| 2908 | description: |
| 2909 | Tests for here documents in COMSUB, taken from Austin ML |
| 2910 | stdin: |
| 2911 | text=$(cat <<EOF |
| 2912 | here is the text |
| 2913 | EOF) |
| 2914 | echo = $text = |
| 2915 | expected-stdout: |
| 2916 | = here is the text = |
| 2917 | --- |
| 2918 | name: heredoc-comsub-2 |
| 2919 | description: |
| 2920 | Tests for here documents in COMSUB, taken from Austin ML |
| 2921 | stdin: |
| 2922 | unbalanced=$(cat <<EOF |
| 2923 | this paren ) is a problem |
| 2924 | EOF) |
| 2925 | echo = $unbalanced = |
| 2926 | expected-stdout: |
| 2927 | = this paren ) is a problem = |
| 2928 | --- |
| 2929 | name: heredoc-comsub-3 |
| 2930 | description: |
| 2931 | Tests for here documents in COMSUB, taken from Austin ML |
| 2932 | stdin: |
| 2933 | balanced=$(cat <<EOF |
| 2934 | these parens ( ) are not a problem |
| 2935 | EOF) |
| 2936 | echo = $balanced = |
| 2937 | expected-stdout: |
| 2938 | = these parens ( ) are not a problem = |
| 2939 | --- |
| 2940 | name: heredoc-comsub-4 |
| 2941 | description: |
| 2942 | Tests for here documents in COMSUB, taken from Austin ML |
| 2943 | stdin: |
| 2944 | balanced=$(cat <<EOF |
| 2945 | these parens \( ) are a problem |
| 2946 | EOF) |
| 2947 | echo = $balanced = |
| 2948 | expected-stdout: |
| 2949 | = these parens \( ) are a problem = |
| 2950 | --- |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 2951 | name: heredoc-comsub-5 |
| 2952 | description: |
| 2953 | Check heredoc and COMSUB mixture in input |
| 2954 | stdin: |
| 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 |
| 2969 | expected-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 | --- |
| 2977 | name: heredoc-comsub-6 |
| 2978 | description: |
| 2979 | Check here documents and here strings can be used |
| 2980 | without a specific command, like $(<â¦) (extension) |
| 2981 | stdin: |
| 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>" |
| 2993 | expected-stdout: |
| 2994 | 3<EObarF> |
| 2995 | 7<hi! |
| 2996 | |
| 2997 | bar) is not a problem> |
| 2998 | --- |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 2999 | name: heredoc-subshell-1 |
| 3000 | description: |
| 3001 | Tests for here documents in subshells, taken from Austin ML |
| 3002 | stdin: |
| 3003 | (cat <<EOF |
| 3004 | some text |
| 3005 | EOF) |
| 3006 | echo end |
| 3007 | expected-stdout: |
| 3008 | some text |
| 3009 | end |
| 3010 | --- |
| 3011 | name: heredoc-subshell-2 |
| 3012 | description: |
| 3013 | Tests for here documents in subshells, taken from Austin ML |
| 3014 | stdin: |
| 3015 | (cat <<EOF |
| 3016 | some text |
| 3017 | EOF |
| 3018 | ) |
| 3019 | echo end |
| 3020 | expected-stdout: |
| 3021 | some text |
| 3022 | end |
| 3023 | --- |
| 3024 | name: heredoc-subshell-3 |
| 3025 | description: |
| 3026 | Tests for here documents in subshells, taken from Austin ML |
| 3027 | stdin: |
| 3028 | (cat <<EOF; ) |
| 3029 | some text |
| 3030 | EOF |
| 3031 | echo end |
| 3032 | expected-stdout: |
| 3033 | some text |
| 3034 | end |
| 3035 | --- |
| 3036 | name: heredoc-weird-1 |
| 3037 | description: |
| 3038 | Tests for here documents, taken from Austin ML |
| 3039 | Documents current state in mksh, *NOT* necessarily correct! |
| 3040 | stdin: |
| 3041 | cat <<END |
| 3042 | hello |
| 3043 | END\ |
| 3044 | END |
| 3045 | END |
| 3046 | echo end |
| 3047 | expected-stdout: |
| 3048 | hello |
| 3049 | ENDEND |
| 3050 | end |
| 3051 | --- |
| 3052 | name: heredoc-weird-2 |
| 3053 | description: |
| 3054 | Tests for here documents, taken from Austin ML |
| 3055 | stdin: |
| 3056 | cat <<' END ' |
| 3057 | hello |
| 3058 | END |
| 3059 | echo end |
| 3060 | expected-stdout: |
| 3061 | hello |
| 3062 | end |
| 3063 | --- |
| 3064 | name: heredoc-weird-4 |
| 3065 | description: |
| 3066 | Tests for here documents, taken from Austin ML |
| 3067 | Documents current state in mksh, *NOT* necessarily correct! |
| 3068 | stdin: |
| 3069 | cat <<END |
| 3070 | hello\ |
| 3071 | END |
| 3072 | END |
| 3073 | echo end |
| 3074 | expected-stdout: |
| 3075 | helloEND |
| 3076 | end |
| 3077 | --- |
| 3078 | name: heredoc-weird-5 |
| 3079 | description: |
| 3080 | Tests for here documents, taken from Austin ML |
| 3081 | Documents current state in mksh, *NOT* necessarily correct! |
| 3082 | stdin: |
| 3083 | cat <<END |
| 3084 | hello |
| 3085 | \END |
| 3086 | END |
| 3087 | echo end |
| 3088 | expected-stdout: |
| 3089 | hello |
| 3090 | \END |
| 3091 | end |
| 3092 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3093 | name: heredoc-tmpfile-1 |
| 3094 | description: |
| 3095 | Check that heredoc temp files aren't removed too soon or too late. |
| 3096 | Heredoc in simple command. |
| 3097 | stdin: |
| 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: * |
| 3111 | expected-stdout: |
| 3112 | hi |
| 3113 | more |
| 3114 | more |
| 3115 | Left overs: * |
| 3116 | --- |
| 3117 | name: heredoc-tmpfile-2 |
| 3118 | description: |
| 3119 | Check that heredoc temp files aren't removed too soon or too late. |
| 3120 | Heredoc in function, multiple calls to function. |
| 3121 | stdin: |
| 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: * |
| 3134 | expected-stdout: |
| 3135 | hi |
| 3136 | hi |
| 3137 | Left overs: * |
| 3138 | --- |
| 3139 | name: heredoc-tmpfile-3 |
| 3140 | description: |
| 3141 | Check that heredoc temp files aren't removed too soon or too late. |
| 3142 | Heredoc in function in loop, multiple calls to function. |
| 3143 | stdin: |
| 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: * |
| 3163 | expected-stdout: |
| 3164 | hi |
| 3165 | folks b |
| 3166 | folks b |
| 3167 | Left overs: * |
| 3168 | --- |
| 3169 | name: heredoc-tmpfile-4 |
| 3170 | description: |
| 3171 | Check that heredoc temp files aren't removed too soon or too late. |
| 3172 | Backgrounded simple command with here doc |
| 3173 | stdin: |
| 3174 | TMPDIR=$PWD |
| 3175 | eval ' |
| 3176 | cat <<- EOF & |
| 3177 | hi |
| 3178 | EOF |
| 3179 | ' & |
| 3180 | sleep 1 |
| 3181 | echo Left overs: * |
| 3182 | expected-stdout: |
| 3183 | hi |
| 3184 | Left overs: * |
| 3185 | --- |
| 3186 | name: heredoc-tmpfile-5 |
| 3187 | description: |
| 3188 | Check that heredoc temp files aren't removed too soon or too late. |
| 3189 | Backgrounded subshell command with here doc |
| 3190 | stdin: |
| 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: * |
| 3204 | expected-stdout: |
| 3205 | A |
| 3206 | hi |
| 3207 | B |
| 3208 | Left overs: * |
| 3209 | --- |
| 3210 | name: heredoc-tmpfile-6 |
| 3211 | description: |
| 3212 | Check that heredoc temp files aren't removed too soon or too late. |
| 3213 | Heredoc in pipeline. |
| 3214 | stdin: |
| 3215 | TMPDIR=$PWD |
| 3216 | eval ' |
| 3217 | cat <<- EOF | sed "s/hi/HI/" |
| 3218 | hi |
| 3219 | EOF |
| 3220 | ' & |
| 3221 | sleep 1 |
| 3222 | echo Left overs: * |
| 3223 | expected-stdout: |
| 3224 | HI |
| 3225 | Left overs: * |
| 3226 | --- |
| 3227 | name: heredoc-tmpfile-7 |
| 3228 | description: |
| 3229 | Check that heredoc temp files aren't removed too soon or too late. |
| 3230 | Heredoc in backgrounded pipeline. |
| 3231 | stdin: |
| 3232 | TMPDIR=$PWD |
| 3233 | eval ' |
| 3234 | cat <<- EOF | sed 's/hi/HI/' & |
| 3235 | hi |
| 3236 | EOF |
| 3237 | ' & |
| 3238 | sleep 1 |
| 3239 | echo Left overs: * |
| 3240 | expected-stdout: |
| 3241 | HI |
| 3242 | Left overs: * |
| 3243 | --- |
| 3244 | name: heredoc-tmpfile-8 |
| 3245 | description: |
| 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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 3250 | need-pass: no |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3251 | stdin: |
| 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: * |
| 3268 | expected-stdout: |
| 3269 | hi |
| 3270 | hi |
| 3271 | hi |
| 3272 | hi |
| 3273 | Left overs: * |
| 3274 | --- |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 3275 | name: heredoc-quoting-unsubst |
| 3276 | description: |
| 3277 | Check for correct handling of quoted characters in |
| 3278 | here documents without substitution (marker is quoted). |
| 3279 | stdin: |
| 3280 | foo=bar |
| 3281 | cat <<-'EOF' |
| 3282 | x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x |
| 3283 | EOF |
| 3284 | expected-stdout: |
| 3285 | x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x |
| 3286 | --- |
| 3287 | name: heredoc-quoting-subst |
| 3288 | description: |
| 3289 | Check for correct handling of quoted characters in |
| 3290 | here documents with substitution (marker is not quoted). |
| 3291 | stdin: |
| 3292 | foo=bar |
| 3293 | cat <<-EOF |
| 3294 | x " \" \ \\ $ \$ `echo baz` \`echo baz\` $foo \$foo x |
| 3295 | EOF |
| 3296 | expected-stdout: |
| 3297 | x " \" \ \ $ $ baz `echo baz` bar $foo x |
| 3298 | --- |
| 3299 | name: single-quotes-in-braces |
| 3300 | description: |
| 3301 | Check that single quotes inside unquoted {} are treated as quotes |
| 3302 | stdin: |
| 3303 | foo=1 |
| 3304 | echo ${foo:+'blah $foo'} |
| 3305 | expected-stdout: |
| 3306 | blah $foo |
| 3307 | --- |
| 3308 | name: single-quotes-in-quoted-braces |
| 3309 | description: |
| 3310 | Check that single quotes inside quoted {} are treated as |
| 3311 | normal char |
| 3312 | stdin: |
| 3313 | foo=1 |
| 3314 | echo "${foo:+'blah $foo'}" |
| 3315 | expected-stdout: |
| 3316 | 'blah 1' |
| 3317 | --- |
| 3318 | name: single-quotes-in-braces-nested |
| 3319 | description: |
| 3320 | Check that single quotes inside unquoted {} are treated as quotes, |
| 3321 | even if that's inside a double-quoted command expansion |
| 3322 | stdin: |
| 3323 | foo=1 |
| 3324 | echo "$( echo ${foo:+'blah $foo'})" |
| 3325 | expected-stdout: |
| 3326 | blah $foo |
| 3327 | --- |
| 3328 | name: single-quotes-in-brace-pattern |
| 3329 | description: |
| 3330 | Check that single quotes inside {} pattern are treated as quotes |
| 3331 | stdin: |
| 3332 | foo=1234 |
| 3333 | echo ${foo%'2'*} "${foo%'2'*}" ${foo%2'*'} "${foo%2'*'}" |
| 3334 | expected-stdout: |
| 3335 | 1 1 1234 1234 |
| 3336 | --- |
| 3337 | name: single-quotes-in-heredoc-braces |
| 3338 | description: |
| 3339 | Check that single quotes inside {} in heredoc are treated |
| 3340 | as normal char |
| 3341 | stdin: |
| 3342 | foo=1 |
| 3343 | cat <<EOM |
| 3344 | ${foo:+'blah $foo'} |
| 3345 | EOM |
| 3346 | expected-stdout: |
| 3347 | 'blah 1' |
| 3348 | --- |
| 3349 | name: single-quotes-in-nested-braces |
| 3350 | description: |
| 3351 | Check that single quotes inside nested unquoted {} are |
| 3352 | treated as quotes |
| 3353 | stdin: |
| 3354 | foo=1 |
| 3355 | echo ${foo:+${foo:+'blah $foo'}} |
| 3356 | expected-stdout: |
| 3357 | blah $foo |
| 3358 | --- |
| 3359 | name: single-quotes-in-nested-quoted-braces |
| 3360 | description: |
| 3361 | Check that single quotes inside nested quoted {} are treated |
| 3362 | as normal char |
| 3363 | stdin: |
| 3364 | foo=1 |
| 3365 | echo "${foo:+${foo:+'blah $foo'}}" |
| 3366 | expected-stdout: |
| 3367 | 'blah 1' |
| 3368 | --- |
| 3369 | name: single-quotes-in-nested-braces-nested |
| 3370 | description: |
| 3371 | Check that single quotes inside nested unquoted {} are treated |
| 3372 | as quotes, even if that's inside a double-quoted command expansion |
| 3373 | stdin: |
| 3374 | foo=1 |
| 3375 | echo "$( echo ${foo:+${foo:+'blah $foo'}})" |
| 3376 | expected-stdout: |
| 3377 | blah $foo |
| 3378 | --- |
| 3379 | name: single-quotes-in-nested-brace-pattern |
| 3380 | description: |
| 3381 | Check that single quotes inside nested {} pattern are treated as quotes |
| 3382 | stdin: |
| 3383 | foo=1234 |
| 3384 | echo ${foo:+${foo%'2'*}} "${foo:+${foo%'2'*}}" ${foo:+${foo%2'*'}} "${foo:+${foo%2'*'}}" |
| 3385 | expected-stdout: |
| 3386 | 1 1 1234 1234 |
| 3387 | --- |
| 3388 | name: single-quotes-in-heredoc-nested-braces |
| 3389 | description: |
| 3390 | Check that single quotes inside nested {} in heredoc are treated |
| 3391 | as normal char |
| 3392 | stdin: |
| 3393 | foo=1 |
| 3394 | cat <<EOM |
| 3395 | ${foo:+${foo:+'blah $foo'}} |
| 3396 | EOM |
| 3397 | expected-stdout: |
| 3398 | 'blah 1' |
| 3399 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3400 | name: history-basic |
| 3401 | description: |
| 3402 | See if we can test history at all |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 3403 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3404 | arguments: !-i! |
| 3405 | env-setup: !ENV=./Env!HISTFILE=hist.file! |
| 3406 | file-setup: file 644 "Env" |
| 3407 | PS1=X |
| 3408 | stdin: |
| 3409 | echo hi |
| 3410 | fc -l |
| 3411 | expected-stdout: |
| 3412 | hi |
| 3413 | 1 echo hi |
| 3414 | expected-stderr-pattern: |
| 3415 | /^X*$/ |
| 3416 | --- |
| 3417 | name: history-dups |
| 3418 | description: |
| 3419 | Verify duplicates and spaces are not entered |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 3420 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3421 | arguments: !-i! |
| 3422 | env-setup: !ENV=./Env!HISTFILE=hist.file! |
| 3423 | file-setup: file 644 "Env" |
| 3424 | PS1=X |
| 3425 | stdin: |
| 3426 | echo hi |
| 3427 | echo yo |
| 3428 | echo hi |
| 3429 | fc -l |
| 3430 | expected-stdout: |
| 3431 | hi |
| 3432 | yo |
| 3433 | hi |
| 3434 | 1 echo hi |
| 3435 | expected-stderr-pattern: |
| 3436 | /^X*$/ |
| 3437 | --- |
| 3438 | name: history-unlink |
| 3439 | description: |
| 3440 | Check if broken HISTFILEs do not cause trouble |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 3441 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3442 | arguments: !-i! |
| 3443 | env-setup: !ENV=./Env!HISTFILE=foo/hist.file! |
| 3444 | file-setup: file 644 "Env" |
| 3445 | PS1=X |
| 3446 | file-setup: dir 755 "foo" |
| 3447 | file-setup: file 644 "foo/hist.file" |
| 3448 | sometext |
| 3449 | time-limit: 5 |
| 3450 | perl-setup: chmod(0555, "foo"); |
| 3451 | stdin: |
| 3452 | echo hi |
| 3453 | fc -l |
| 3454 | chmod 0755 foo |
| 3455 | expected-stdout: |
| 3456 | hi |
| 3457 | 1 echo hi |
| 3458 | expected-stderr-pattern: |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 3459 | /(.*can't unlink HISTFILE.*\n)?X*$/ |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3460 | --- |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 3461 | name: history-multiline |
| 3462 | description: |
| 3463 | Check correct multiline history, Debian #783978 |
| 3464 | need-ctty: yes |
| 3465 | arguments: !-i! |
| 3466 | env-setup: !ENV=./Env! |
| 3467 | file-setup: file 644 "Env" |
| 3468 | PS1=X |
| 3469 | PS2=Y |
| 3470 | stdin: |
| 3471 | for i in A B C |
| 3472 | do |
| 3473 | print $i |
| 3474 | print $i |
| 3475 | done |
| 3476 | fc -l |
| 3477 | expected-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 |
| 3489 | expected-stderr-pattern: |
| 3490 | /^XYYYYXX$/ |
| 3491 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3492 | name: history-e-minus-1 |
| 3493 | description: |
| 3494 | Check if more recent command is executed |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 3495 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3496 | arguments: !-i! |
| 3497 | env-setup: !ENV=./Env!HISTFILE=hist.file! |
| 3498 | file-setup: file 644 "Env" |
| 3499 | PS1=X |
| 3500 | stdin: |
| 3501 | echo hi |
| 3502 | echo there |
| 3503 | fc -e - |
| 3504 | expected-stdout: |
| 3505 | hi |
| 3506 | there |
| 3507 | there |
| 3508 | expected-stderr-pattern: |
| 3509 | /^X*echo there\nX*$/ |
| 3510 | --- |
| 3511 | name: history-e-minus-2 |
| 3512 | description: |
| 3513 | Check that repeated command is printed before command |
| 3514 | is re-executed. |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 3515 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3516 | arguments: !-i! |
| 3517 | env-setup: !ENV=./Env!HISTFILE=hist.file! |
| 3518 | file-setup: file 644 "Env" |
| 3519 | PS1=X |
| 3520 | stdin: |
| 3521 | exec 2>&1 |
| 3522 | echo hi |
| 3523 | echo there |
| 3524 | fc -e - |
| 3525 | expected-stdout-pattern: |
| 3526 | /X*hi\nX*there\nX*echo there\nthere\nX*/ |
| 3527 | expected-stderr-pattern: |
| 3528 | /^X*$/ |
| 3529 | --- |
| 3530 | name: history-e-minus-3 |
| 3531 | description: |
| 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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 3535 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3536 | arguments: !-i! |
| 3537 | env-setup: !ENV=./Env!HISTFILE=hist.file! |
| 3538 | file-setup: file 644 "Env" |
| 3539 | PS1=X |
| 3540 | stdin: |
| 3541 | fc -e - |
| 3542 | echo ok |
| 3543 | expected-stdout: |
| 3544 | ok |
| 3545 | expected-stderr-pattern: |
| 3546 | /^X*.*:.*history.*\nX*$/ |
| 3547 | --- |
| 3548 | name: history-e-minus-4 |
| 3549 | description: |
| 3550 | Check if "fc -e -" command output goes to stdout. |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 3551 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3552 | arguments: !-i! |
| 3553 | env-setup: !ENV=./Env!HISTFILE=hist.file! |
| 3554 | file-setup: file 644 "Env" |
| 3555 | PS1=X |
| 3556 | stdin: |
| 3557 | echo abc |
| 3558 | fc -e - | (read x; echo "A $x") |
| 3559 | echo ok |
| 3560 | expected-stdout: |
| 3561 | abc |
| 3562 | A abc |
| 3563 | ok |
| 3564 | expected-stderr-pattern: |
| 3565 | /^X*echo abc\nX*/ |
| 3566 | --- |
| 3567 | name: history-e-minus-5 |
| 3568 | description: |
| 3569 | fc is replaced in history by new command. |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 3570 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3571 | arguments: !-i! |
| 3572 | env-setup: !ENV=./Env!HISTFILE=hist.file! |
| 3573 | file-setup: file 644 "Env" |
| 3574 | PS1=X |
| 3575 | stdin: |
| 3576 | echo abc def |
| 3577 | echo ghi jkl |
| 3578 | : |
| 3579 | fc -e - echo |
| 3580 | fc -l 2 5 |
| 3581 | expected-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 |
| 3589 | expected-stderr-pattern: |
| 3590 | /^X*echo ghi jkl\nX*$/ |
| 3591 | --- |
| 3592 | name: history-list-1 |
| 3593 | description: |
| 3594 | List lists correct range |
| 3595 | (ksh88 fails 'cause it lists the fc command) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 3596 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3597 | arguments: !-i! |
| 3598 | env-setup: !ENV=./Env!HISTFILE=hist.file! |
| 3599 | file-setup: file 644 "Env" |
| 3600 | PS1=X |
| 3601 | stdin: |
| 3602 | echo line 1 |
| 3603 | echo line 2 |
| 3604 | echo line 3 |
| 3605 | fc -l -- -2 |
| 3606 | expected-stdout: |
| 3607 | line 1 |
| 3608 | line 2 |
| 3609 | line 3 |
| 3610 | 2 echo line 2 |
| 3611 | 3 echo line 3 |
| 3612 | expected-stderr-pattern: |
| 3613 | /^X*$/ |
| 3614 | --- |
| 3615 | name: history-list-2 |
| 3616 | description: |
| 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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 3620 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3621 | arguments: !-i! |
| 3622 | env-setup: !ENV=./Env!HISTFILE=hist.file! |
| 3623 | file-setup: file 644 "Env" |
| 3624 | PS1=X |
| 3625 | stdin: |
| 3626 | echo line 1 |
| 3627 | echo line 2 |
| 3628 | echo line 3 |
| 3629 | fc -l -- -40 |
| 3630 | expected-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 |
| 3637 | expected-stderr-pattern: |
| 3638 | /^X*$/ |
| 3639 | --- |
| 3640 | name: history-list-3 |
| 3641 | description: |
| 3642 | Can give number 'options' to fc |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 3643 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3644 | arguments: !-i! |
| 3645 | env-setup: !ENV=./Env!HISTFILE=hist.file! |
| 3646 | file-setup: file 644 "Env" |
| 3647 | PS1=X |
| 3648 | stdin: |
| 3649 | echo line 1 |
| 3650 | echo line 2 |
| 3651 | echo line 3 |
| 3652 | echo line 4 |
| 3653 | fc -l -3 -2 |
| 3654 | expected-stdout: |
| 3655 | line 1 |
| 3656 | line 2 |
| 3657 | line 3 |
| 3658 | line 4 |
| 3659 | 2 echo line 2 |
| 3660 | 3 echo line 3 |
| 3661 | expected-stderr-pattern: |
| 3662 | /^X*$/ |
| 3663 | --- |
| 3664 | name: history-list-4 |
| 3665 | description: |
| 3666 | -1 refers to previous command |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 3667 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3668 | arguments: !-i! |
| 3669 | env-setup: !ENV=./Env!HISTFILE=hist.file! |
| 3670 | file-setup: file 644 "Env" |
| 3671 | PS1=X |
| 3672 | stdin: |
| 3673 | echo line 1 |
| 3674 | echo line 2 |
| 3675 | echo line 3 |
| 3676 | echo line 4 |
| 3677 | fc -l -1 -1 |
| 3678 | expected-stdout: |
| 3679 | line 1 |
| 3680 | line 2 |
| 3681 | line 3 |
| 3682 | line 4 |
| 3683 | 4 echo line 4 |
| 3684 | expected-stderr-pattern: |
| 3685 | /^X*$/ |
| 3686 | --- |
| 3687 | name: history-list-5 |
| 3688 | description: |
| 3689 | List command stays in history |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 3690 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3691 | arguments: !-i! |
| 3692 | env-setup: !ENV=./Env!HISTFILE=hist.file! |
| 3693 | file-setup: file 644 "Env" |
| 3694 | PS1=X |
| 3695 | stdin: |
| 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 |
| 3702 | expected-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 |
| 3710 | expected-stderr-pattern: |
| 3711 | /^X*$/ |
| 3712 | --- |
| 3713 | name: history-list-6 |
| 3714 | description: |
| 3715 | HISTSIZE limits about of history kept. |
| 3716 | (ksh88 fails 'cause it lists the fc command) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 3717 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3718 | arguments: !-i! |
| 3719 | env-setup: !ENV=./Env!HISTFILE=hist.file!HISTSIZE=3! |
| 3720 | file-setup: file 644 "Env" |
| 3721 | PS1=X |
| 3722 | stdin: |
| 3723 | echo line 1 |
| 3724 | echo line 2 |
| 3725 | echo line 3 |
| 3726 | echo line 4 |
| 3727 | echo line 5 |
| 3728 | fc -l |
| 3729 | expected-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 |
| 3737 | expected-stderr-pattern: |
| 3738 | /^X*$/ |
| 3739 | --- |
| 3740 | name: history-list-7 |
| 3741 | description: |
| 3742 | fc allows too old/new errors in range specification |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 3743 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3744 | arguments: !-i! |
| 3745 | env-setup: !ENV=./Env!HISTFILE=hist.file!HISTSIZE=3! |
| 3746 | file-setup: file 644 "Env" |
| 3747 | PS1=X |
| 3748 | stdin: |
| 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 |
| 3755 | expected-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 |
| 3764 | expected-stderr-pattern: |
| 3765 | /^X*$/ |
| 3766 | --- |
| 3767 | name: history-list-r-1 |
| 3768 | description: |
| 3769 | test -r flag in history |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 3770 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3771 | arguments: !-i! |
| 3772 | env-setup: !ENV=./Env!HISTFILE=hist.file! |
| 3773 | file-setup: file 644 "Env" |
| 3774 | PS1=X |
| 3775 | stdin: |
| 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 |
| 3782 | expected-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 |
| 3791 | expected-stderr-pattern: |
| 3792 | /^X*$/ |
| 3793 | --- |
| 3794 | name: history-list-r-2 |
| 3795 | description: |
| 3796 | If first is newer than last, -r is implied. |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 3797 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3798 | arguments: !-i! |
| 3799 | env-setup: !ENV=./Env!HISTFILE=hist.file! |
| 3800 | file-setup: file 644 "Env" |
| 3801 | PS1=X |
| 3802 | stdin: |
| 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 |
| 3809 | expected-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 |
| 3818 | expected-stderr-pattern: |
| 3819 | /^X*$/ |
| 3820 | --- |
| 3821 | name: history-list-r-3 |
| 3822 | description: |
| 3823 | If first is newer than last, -r is cancelled. |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 3824 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3825 | arguments: !-i! |
| 3826 | env-setup: !ENV=./Env!HISTFILE=hist.file! |
| 3827 | file-setup: file 644 "Env" |
| 3828 | PS1=X |
| 3829 | stdin: |
| 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 |
| 3836 | expected-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 |
| 3845 | expected-stderr-pattern: |
| 3846 | /^X*$/ |
| 3847 | --- |
| 3848 | name: history-subst-1 |
| 3849 | description: |
| 3850 | Basic substitution |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 3851 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3852 | arguments: !-i! |
| 3853 | env-setup: !ENV=./Env!HISTFILE=hist.file! |
| 3854 | file-setup: file 644 "Env" |
| 3855 | PS1=X |
| 3856 | stdin: |
| 3857 | echo abc def |
| 3858 | echo ghi jkl |
| 3859 | fc -e - abc=AB 'echo a' |
| 3860 | expected-stdout: |
| 3861 | abc def |
| 3862 | ghi jkl |
| 3863 | AB def |
| 3864 | expected-stderr-pattern: |
| 3865 | /^X*echo AB def\nX*$/ |
| 3866 | --- |
| 3867 | name: history-subst-2 |
| 3868 | description: |
| 3869 | Does subst find previous command? |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 3870 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3871 | arguments: !-i! |
| 3872 | env-setup: !ENV=./Env!HISTFILE=hist.file! |
| 3873 | file-setup: file 644 "Env" |
| 3874 | PS1=X |
| 3875 | stdin: |
| 3876 | echo abc def |
| 3877 | echo ghi jkl |
| 3878 | fc -e - jkl=XYZQRT 'echo g' |
| 3879 | expected-stdout: |
| 3880 | abc def |
| 3881 | ghi jkl |
| 3882 | ghi XYZQRT |
| 3883 | expected-stderr-pattern: |
| 3884 | /^X*echo ghi XYZQRT\nX*$/ |
| 3885 | --- |
| 3886 | name: history-subst-3 |
| 3887 | description: |
| 3888 | Does subst find previous command when no arguments given |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 3889 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3890 | arguments: !-i! |
| 3891 | env-setup: !ENV=./Env!HISTFILE=hist.file! |
| 3892 | file-setup: file 644 "Env" |
| 3893 | PS1=X |
| 3894 | stdin: |
| 3895 | echo abc def |
| 3896 | echo ghi jkl |
| 3897 | fc -e - jkl=XYZQRT |
| 3898 | expected-stdout: |
| 3899 | abc def |
| 3900 | ghi jkl |
| 3901 | ghi XYZQRT |
| 3902 | expected-stderr-pattern: |
| 3903 | /^X*echo ghi XYZQRT\nX*$/ |
| 3904 | --- |
| 3905 | name: history-subst-4 |
| 3906 | description: |
| 3907 | Global substitutions work |
| 3908 | (ksh88 and ksh93 do not have -g option) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 3909 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3910 | arguments: !-i! |
| 3911 | env-setup: !ENV=./Env!HISTFILE=hist.file! |
| 3912 | file-setup: file 644 "Env" |
| 3913 | PS1=X |
| 3914 | stdin: |
| 3915 | echo abc def asjj sadjhasdjh asdjhasd |
| 3916 | fc -e - -g a=FooBAR |
| 3917 | expected-stdout: |
| 3918 | abc def asjj sadjhasdjh asdjhasd |
| 3919 | FooBARbc def FooBARsjj sFooBARdjhFooBARsdjh FooBARsdjhFooBARsd |
| 3920 | expected-stderr-pattern: |
| 3921 | /^X*echo FooBARbc def FooBARsjj sFooBARdjhFooBARsdjh FooBARsdjhFooBARsd\nX*$/ |
| 3922 | --- |
| 3923 | name: history-subst-5 |
| 3924 | description: |
| 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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 3927 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3928 | arguments: !-i! |
| 3929 | env-setup: !ENV=./Env!HISTFILE=hist.file! |
| 3930 | file-setup: file 644 "Env" |
| 3931 | PS1=X |
| 3932 | stdin: |
| 3933 | echo abc def |
| 3934 | echo ghi jkl |
| 3935 | fc -e - abc=AB \?abc |
| 3936 | expected-stdout: |
| 3937 | abc def |
| 3938 | ghi jkl |
| 3939 | AB def |
| 3940 | expected-stderr-pattern: |
| 3941 | /^X*echo AB def\nX*$/ |
| 3942 | --- |
| 3943 | name: history-ed-1-old |
| 3944 | description: |
| 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. |
| 3948 | category: stdout-ed |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 3949 | need-ctty: yes |
| 3950 | need-pass: no |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3951 | arguments: !-i! |
| 3952 | env-setup: !ENV=./Env!HISTFILE=hist.file! |
| 3953 | file-setup: file 644 "Env" |
| 3954 | PS1=X |
| 3955 | stdin: |
| 3956 | echo abc def |
| 3957 | fc echo |
| 3958 | s/abc/FOOBAR/ |
| 3959 | w |
| 3960 | q |
| 3961 | expected-stdout: |
| 3962 | abc def |
| 3963 | 13 |
| 3964 | 16 |
| 3965 | FOOBAR def |
| 3966 | expected-stderr-pattern: |
| 3967 | /^X*echo FOOBAR def\nX*$/ |
| 3968 | --- |
| 3969 | name: history-ed-2-old |
| 3970 | description: |
| 3971 | Correct command is edited when number given |
| 3972 | category: stdout-ed |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 3973 | need-ctty: yes |
| 3974 | need-pass: no |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 3975 | arguments: !-i! |
| 3976 | env-setup: !ENV=./Env!HISTFILE=hist.file! |
| 3977 | file-setup: file 644 "Env" |
| 3978 | PS1=X |
| 3979 | stdin: |
| 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 |
| 3988 | expected-stdout: |
| 3989 | line 1 |
| 3990 | line 2 is here |
| 3991 | line 3 |
| 3992 | line 4 |
| 3993 | 20 |
| 3994 | 23 |
| 3995 | line 2 is changed |
| 3996 | expected-stderr-pattern: |
| 3997 | /^X*echo line 2 is changed\nX*$/ |
| 3998 | --- |
| 3999 | name: history-ed-3-old |
| 4000 | description: |
| 4001 | Newly created multi line commands show up as single command |
| 4002 | in history. |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4003 | (ksh88 fails 'cause it lists the fc command) |
| 4004 | category: stdout-ed |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 4005 | need-ctty: yes |
| 4006 | need-pass: no |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4007 | arguments: !-i! |
| 4008 | env-setup: !ENV=./Env!HISTFILE=hist.file! |
| 4009 | file-setup: file 644 "Env" |
| 4010 | PS1=X |
| 4011 | stdin: |
| 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 |
| 4021 | expected-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 Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 4029 | echo a new line |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4030 | expected-stderr-pattern: |
| 4031 | /^X*echo FOOBAR def\necho a new line\nX*$/ |
| 4032 | --- |
| 4033 | name: history-ed-1 |
| 4034 | description: |
| 4035 | Basic (ed) editing works (assumes you have generic ed editor |
| 4036 | that prints no prompts). This is for newish ed(1) and stderr. |
| 4037 | category: !no-stderr-ed |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 4038 | need-ctty: yes |
| 4039 | need-pass: no |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4040 | arguments: !-i! |
| 4041 | env-setup: !ENV=./Env!HISTFILE=hist.file! |
| 4042 | file-setup: file 644 "Env" |
| 4043 | PS1=X |
| 4044 | stdin: |
| 4045 | echo abc def |
| 4046 | fc echo |
| 4047 | s/abc/FOOBAR/ |
| 4048 | w |
| 4049 | q |
| 4050 | expected-stdout: |
| 4051 | abc def |
| 4052 | FOOBAR def |
| 4053 | expected-stderr-pattern: |
| 4054 | /^X*13\n16\necho FOOBAR def\nX*$/ |
| 4055 | --- |
| 4056 | name: history-ed-2 |
| 4057 | description: |
| 4058 | Correct command is edited when number given |
| 4059 | category: !no-stderr-ed |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 4060 | need-ctty: yes |
| 4061 | need-pass: no |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4062 | arguments: !-i! |
| 4063 | env-setup: !ENV=./Env!HISTFILE=hist.file! |
| 4064 | file-setup: file 644 "Env" |
| 4065 | PS1=X |
| 4066 | stdin: |
| 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 |
| 4075 | expected-stdout: |
| 4076 | line 1 |
| 4077 | line 2 is here |
| 4078 | line 3 |
| 4079 | line 4 |
| 4080 | line 2 is changed |
| 4081 | expected-stderr-pattern: |
| 4082 | /^X*20\n23\necho line 2 is changed\nX*$/ |
| 4083 | --- |
| 4084 | name: history-ed-3 |
| 4085 | description: |
| 4086 | Newly created multi line commands show up as single command |
| 4087 | in history. |
| 4088 | category: !no-stderr-ed |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 4089 | need-ctty: yes |
| 4090 | need-pass: no |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4091 | arguments: !-i! |
| 4092 | env-setup: !ENV=./Env!HISTFILE=hist.file! |
| 4093 | file-setup: file 644 "Env" |
| 4094 | PS1=X |
| 4095 | stdin: |
| 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 |
| 4105 | expected-stdout: |
| 4106 | abc def |
| 4107 | FOOBAR def |
| 4108 | a new line |
| 4109 | 1 echo abc def |
| 4110 | 2 echo FOOBAR def |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 4111 | echo a new line |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4112 | expected-stderr-pattern: |
| 4113 | /^X*13\n32\necho FOOBAR def\necho a new line\nX*$/ |
| 4114 | --- |
| 4115 | name: IFS-space-1 |
| 4116 | description: |
| 4117 | Simple test, default IFS |
| 4118 | stdin: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4119 | showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4120 | set -- A B C |
| 4121 | showargs 1 $* |
| 4122 | showargs 2 "$*" |
| 4123 | showargs 3 $@ |
| 4124 | showargs 4 "$@" |
| 4125 | expected-stdout: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4126 | <1> <A> <B> <C> . |
| 4127 | <2> <A B C> . |
| 4128 | <3> <A> <B> <C> . |
| 4129 | <4> <A> <B> <C> . |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4130 | --- |
| 4131 | name: IFS-colon-1 |
| 4132 | description: |
| 4133 | Simple test, IFS=: |
| 4134 | stdin: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4135 | showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4136 | IFS=: |
| 4137 | set -- A B C |
| 4138 | showargs 1 $* |
| 4139 | showargs 2 "$*" |
| 4140 | showargs 3 $@ |
| 4141 | showargs 4 "$@" |
| 4142 | expected-stdout: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4143 | <1> <A> <B> <C> . |
| 4144 | <2> <A:B:C> . |
| 4145 | <3> <A> <B> <C> . |
| 4146 | <4> <A> <B> <C> . |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4147 | --- |
| 4148 | name: IFS-null-1 |
| 4149 | description: |
| 4150 | Simple test, IFS="" |
| 4151 | stdin: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4152 | showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4153 | IFS="" |
| 4154 | set -- A B C |
| 4155 | showargs 1 $* |
| 4156 | showargs 2 "$*" |
| 4157 | showargs 3 $@ |
| 4158 | showargs 4 "$@" |
| 4159 | expected-stdout: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4160 | <1> <A> <B> <C> . |
| 4161 | <2> <ABC> . |
| 4162 | <3> <A> <B> <C> . |
| 4163 | <4> <A> <B> <C> . |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4164 | --- |
| 4165 | name: IFS-space-colon-1 |
| 4166 | description: |
| 4167 | Simple test, IFS=<white-space>: |
| 4168 | stdin: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4169 | showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4170 | IFS="$IFS:" |
| 4171 | set -- |
| 4172 | showargs 1 $* |
| 4173 | showargs 2 "$*" |
| 4174 | showargs 3 $@ |
| 4175 | showargs 4 "$@" |
| 4176 | showargs 5 : "$@" |
| 4177 | expected-stdout: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4178 | <1> . |
| 4179 | <2> <> . |
| 4180 | <3> . |
| 4181 | <4> . |
| 4182 | <5> <:> . |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4183 | --- |
| 4184 | name: IFS-space-colon-2 |
| 4185 | description: |
| 4186 | Simple test, IFS=<white-space>: |
| 4187 | AT&T ksh fails this, POSIX says the test is correct. |
| 4188 | stdin: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4189 | showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4190 | IFS="$IFS:" |
| 4191 | set -- |
| 4192 | showargs :"$@" |
| 4193 | expected-stdout: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4194 | <:> . |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4195 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4196 | name: IFS-space-colon-4 |
| 4197 | description: |
| 4198 | Simple test, IFS=<white-space>: |
| 4199 | stdin: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4200 | showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4201 | IFS="$IFS:" |
| 4202 | set -- |
| 4203 | showargs "$@$@" |
| 4204 | expected-stdout: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4205 | . |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4206 | --- |
| 4207 | name: IFS-space-colon-5 |
| 4208 | description: |
| 4209 | Simple test, IFS=<white-space>: |
| 4210 | Don't know what POSIX thinks of this. AT&T ksh does not do this. |
| 4211 | stdin: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4212 | showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4213 | IFS="$IFS:" |
| 4214 | set -- |
| 4215 | showargs "${@:-}" |
| 4216 | expected-stdout: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4217 | <> . |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4218 | --- |
| 4219 | name: IFS-subst-1 |
| 4220 | description: |
| 4221 | Simple test, IFS=<white-space>: |
| 4222 | stdin: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4223 | showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4224 | 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 |
| 4242 | expected-stdout: |
| 4243 | 1: [] [b] [] |
| 4244 | 2: [:b::] |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4245 | <3> <> <b> <> . |
| 4246 | <4> <:b::> . |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4247 | 5: [a] [b] |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4248 | <6> <a> <b> . |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4249 | 7: [a] [] [c] |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4250 | <8> <a> <> <c> . |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4251 | 9: [h] [ith] [ere] |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4252 | <10> <h> <ith> <ere> . |
| 4253 | <11> <h:ith:ere> . |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4254 | 12: [A] [B] [] [D] |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4255 | <13> <A> <B> <> <D> . |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4256 | --- |
Elliott Hughes | 737fdce | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 4257 | name: IFS-subst-2 |
| 4258 | description: |
| 4259 | Check leading whitespace after trim does not make a field |
| 4260 | stdin: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4261 | showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } |
Elliott Hughes | 737fdce | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 4262 | x="X 1 2" |
| 4263 | showargs 1 shift ${x#X} |
| 4264 | expected-stdout: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4265 | <1> <shift> <1> <2> . |
Elliott Hughes | 737fdce | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 4266 | --- |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4267 | name: IFS-subst-3-arr |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4268 | description: |
| 4269 | Check leading IFS non-whitespace after trim does make a field |
Elliott Hughes | f7f7956 | 2014-10-07 15:04:14 -0700 | [diff] [blame] | 4270 | but leading IFS whitespace does not, nor empty replacements |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4271 | stdin: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4272 | showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } |
Elliott Hughes | f7f7956 | 2014-10-07 15:04:14 -0700 | [diff] [blame] | 4273 | showargs 0 ${-+} |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4274 | IFS=: |
| 4275 | showargs 1 ${-+:foo:bar} |
Elliott Hughes | f7f7956 | 2014-10-07 15:04:14 -0700 | [diff] [blame] | 4276 | IFS=' ' |
| 4277 | showargs 2 ${-+ foo bar} |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4278 | expected-stdout: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4279 | <0> . |
| 4280 | <1> <> <foo> <bar> . |
| 4281 | <2> <foo> <bar> . |
| 4282 | --- |
| 4283 | name: IFS-subst-3-ass |
| 4284 | description: |
| 4285 | Check non-field semantics |
| 4286 | stdin: |
| 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} |
| 4293 | expected-stdout: |
| 4294 | <0> <x=> . |
| 4295 | <1> <x=> <foo> <bar> . |
| 4296 | <2> <x=> <foo> <bar> . |
| 4297 | --- |
| 4298 | name: IFS-subst-3-lcl |
| 4299 | description: |
| 4300 | Check non-field semantics, smaller corner case (LP#1381965) |
| 4301 | stdin: |
| 4302 | set -x |
| 4303 | local regex=${2:-} |
| 4304 | exit 1 |
| 4305 | expected-exit: e != 0 |
| 4306 | expected-stderr-pattern: |
| 4307 | /regex=/ |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4308 | --- |
| 4309 | name: IFS-subst-4-1 |
| 4310 | description: |
| 4311 | reported by mikeserv |
| 4312 | stdin: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4313 | pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; } |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4314 | a='space divded argument |
| 4315 | here' |
| 4316 | IFS=\ ; set -- $a |
| 4317 | IFS= ; q="$*" ; nq=$* |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4318 | pfn "$*" $* "$q" "$nq" |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4319 | [ "$q" = "$nq" ] && echo =true || echo =false |
| 4320 | expected-stdout: |
| 4321 | <spacedivdedargument |
| 4322 | here> |
| 4323 | <space> |
| 4324 | <divded> |
| 4325 | <argument |
| 4326 | here> |
| 4327 | <spacedivdedargument |
| 4328 | here> |
| 4329 | <spacedivdedargument |
| 4330 | here> |
| 4331 | =true |
| 4332 | --- |
| 4333 | name: IFS-subst-4-2 |
| 4334 | description: |
| 4335 | extended testsuite based on problem by mikeserv |
| 4336 | stdin: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4337 | pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; } |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4338 | a='space divded argument |
| 4339 | here' |
| 4340 | IFS=\ ; set -- $a |
| 4341 | IFS= ; q="$@" ; nq=$@ |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4342 | pfn "$*" $* "$q" "$nq" |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4343 | [ "$q" = "$nq" ] && echo =true || echo =false |
| 4344 | expected-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 | --- |
| 4357 | name: IFS-subst-4-3 |
| 4358 | description: |
| 4359 | extended testsuite based on problem by mikeserv |
| 4360 | stdin: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4361 | pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; } |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4362 | a='space divded argument |
| 4363 | here' |
| 4364 | IFS=\ ; set -- $a; IFS= |
| 4365 | qs="$*" |
| 4366 | nqs=$* |
| 4367 | qk="$@" |
| 4368 | nqk=$@ |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4369 | 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 Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4377 | expected-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 | --- |
| 4401 | name: IFS-subst-4-4 |
| 4402 | description: |
| 4403 | extended testsuite based on problem by mikeserv |
| 4404 | stdin: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4405 | pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; } |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4406 | a='space divded argument |
| 4407 | here' |
| 4408 | IFS=\ ; set -- $a; IFS= |
| 4409 | qs="$*" |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4410 | print -nr -- '= qs '; pfn "$qs" |
| 4411 | print -nr -- '~ qs '; pfn "$*" |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4412 | nqs=$* |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4413 | print -nr -- '=nqs '; pfn "$nqs" |
| 4414 | print -nr -- '~nqs '; pfn $* |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4415 | qk="$@" |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4416 | print -nr -- '= qk '; pfn "$qk" |
| 4417 | print -nr -- '~ qk '; pfn "$@" |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4418 | nqk=$@ |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4419 | print -nr -- '=nqk '; pfn "$nqk" |
| 4420 | print -nr -- '~nqk '; pfn $@ |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4421 | expected-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 | --- |
| 4445 | name: IFS-subst-4-4p |
| 4446 | description: |
| 4447 | extended testsuite based on problem by mikeserv |
| 4448 | stdin: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4449 | pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; } |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4450 | a='space divded argument |
| 4451 | here' |
| 4452 | IFS=\ ; set -- $a; IFS= |
| 4453 | unset v |
| 4454 | qs=${v:-"$*"} |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4455 | print -nr -- '= qs '; pfn "$qs" |
| 4456 | print -nr -- '~ qs '; pfn ${v:-"$*"} |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4457 | nqs=${v:-$*} |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4458 | print -nr -- '=nqs '; pfn "$nqs" |
| 4459 | print -nr -- '~nqs '; pfn ${v:-$*} |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4460 | qk=${v:-"$@"} |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4461 | print -nr -- '= qk '; pfn "$qk" |
| 4462 | print -nr -- '~ qk '; pfn ${v:-"$@"} |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4463 | nqk=${v:-$@} |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4464 | print -nr -- '=nqk '; pfn "$nqk" |
| 4465 | print -nr -- '~nqk '; pfn ${v:-$@} |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4466 | expected-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 | --- |
| 4490 | name: IFS-subst-4-5 |
| 4491 | description: |
| 4492 | extended testsuite based on problem by mikeserv |
| 4493 | stdin: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4494 | pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; } |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4495 | a='space divded argument |
| 4496 | here' |
| 4497 | IFS=\ ; set -- $a; IFS=, |
| 4498 | qs="$*" |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4499 | print -nr -- '= qs '; pfn "$qs" |
| 4500 | print -nr -- '~ qs '; pfn "$*" |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4501 | nqs=$* |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4502 | print -nr -- '=nqs '; pfn "$nqs" |
| 4503 | print -nr -- '~nqs '; pfn $* |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4504 | qk="$@" |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4505 | print -nr -- '= qk '; pfn "$qk" |
| 4506 | print -nr -- '~ qk '; pfn "$@" |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4507 | nqk=$@ |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4508 | print -nr -- '=nqk '; pfn "$nqk" |
| 4509 | print -nr -- '~nqk '; pfn $@ |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4510 | expected-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 | --- |
| 4534 | name: IFS-subst-4-5p |
| 4535 | description: |
| 4536 | extended testsuite based on problem by mikeserv |
| 4537 | stdin: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4538 | pfn() { for s_arg in "$@"; do print -r -- "<$s_arg>"; done; } |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4539 | a='space divded argument |
| 4540 | here' |
| 4541 | IFS=\ ; set -- $a; IFS=, |
| 4542 | unset v |
| 4543 | qs=${v:-"$*"} |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4544 | print -nr -- '= qs '; pfn "$qs" |
| 4545 | print -nr -- '~ qs '; pfn ${v:-"$*"} |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4546 | nqs=${v:-$*} |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4547 | print -nr -- '=nqs '; pfn "$nqs" |
| 4548 | print -nr -- '~nqs '; pfn ${v:-$*} |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4549 | qk=${v:-"$@"} |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4550 | print -nr -- '= qk '; pfn "$qk" |
| 4551 | print -nr -- '~ qk '; pfn ${v:-"$@"} |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4552 | nqk=${v:-$@} |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4553 | print -nr -- '=nqk '; pfn "$nqk" |
| 4554 | print -nr -- '~nqk '; pfn ${v:-$@} |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4555 | expected-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 | --- |
| 4579 | name: IFS-subst-5 |
| 4580 | description: |
| 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 Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4593 | !!WARNING!! more to come: http://austingroupbugs.net/view.php?id=888 |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4594 | stdin: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4595 | "$__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 Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4597 | echo '=a1zns' |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4598 | "$__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 Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4600 | echo '=a2zqs' |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4601 | "$__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 Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4603 | echo '=a3zna' |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4604 | "$__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 Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4606 | echo '=a4zqa' |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4607 | "$__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 Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4609 | echo '=a5ins' |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4610 | "$__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 Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4612 | echo '=a6iqs' |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4613 | "$__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 Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4615 | echo '=a7ina' |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4616 | "$__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 Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4618 | echo '=a8iqa' |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4619 | "$__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 Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4621 | echo '=b1zns' |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4622 | "$__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 Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4624 | echo '=b2zqs' |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4625 | "$__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 Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4627 | echo '=b3zna' |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4628 | "$__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 Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4630 | echo '=b4zqa' |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4631 | "$__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 Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4633 | echo '=b5ins' |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4634 | "$__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 Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4636 | echo '=b6iqs' |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4637 | "$__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 Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4639 | echo '=b7ina' |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4640 | "$__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 Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 4642 | echo '=b8iqa' |
| 4643 | expected-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 Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4717 | name: IFS-subst-6 |
| 4718 | description: |
| 4719 | Regression wrt. vector expansion in trim |
| 4720 | stdin: |
| 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#$*} |
| 4726 | expected-stdout: |
| 4727 | <c> . |
| 4728 | --- |
| 4729 | name: IFS-subst-7 |
| 4730 | description: |
| 4731 | ksh93 bug wrt. vector expansion in trim |
| 4732 | stdin: |
| 4733 | showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } |
| 4734 | IFS="*" |
| 4735 | a=abcd |
| 4736 | set -- '' c |
| 4737 | showargs "$*" ${a##"$*"} |
| 4738 | expected-stdout: |
| 4739 | <*c> <abcd> . |
| 4740 | --- |
| 4741 | name: IFS-subst-8 |
| 4742 | description: |
| 4743 | http://austingroupbugs.net/view.php?id=221 |
| 4744 | stdin: |
| 4745 | n() { echo "$#"; }; n "${foo-$@}" |
| 4746 | expected-stdout: |
| 4747 | 1 |
| 4748 | --- |
| 4749 | name: IFS-subst-9 |
| 4750 | description: |
| 4751 | Scalar context for $*/$@ in [[ and case |
| 4752 | stdin: |
| 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 |
| 4762 | expected-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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 4773 | name: IFS-subst-10 |
| 4774 | description: |
| 4775 | Scalar context in ${var=$subst} |
| 4776 | stdin: |
| 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 "$@" |
| 4786 | expected-stdout: |
| 4787 | var=onetwo threefour |
| 4788 | <onetwo threefour> . |
| 4789 | --- |
Elliott Hughes | 737fdce | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 4790 | name: IFS-arith-1 |
| 4791 | description: |
| 4792 | http://austingroupbugs.net/view.php?id=832 |
| 4793 | stdin: |
| 4794 | ${ZSH_VERSION+false} || emulate sh |
| 4795 | ${BASH_VERSION+set -o posix} |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 4796 | showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } |
Elliott Hughes | 737fdce | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 4797 | IFS=0 |
| 4798 | showargs $((1230456)) |
| 4799 | expected-stdout: |
| 4800 | <123> <456> . |
| 4801 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4802 | name: integer-base-err-1 |
| 4803 | description: |
| 4804 | Can't have 0 base (causes shell to exit) |
| 4805 | expected-exit: e != 0 |
| 4806 | stdin: |
| 4807 | typeset -i i |
| 4808 | i=3 |
| 4809 | i=0#4 |
| 4810 | echo $i |
| 4811 | expected-stderr-pattern: |
| 4812 | /^.*:.*0#4.*\n$/ |
| 4813 | --- |
| 4814 | name: integer-base-err-2 |
| 4815 | description: |
| 4816 | Can't have multiple bases in a 'constant' (causes shell to exit) |
| 4817 | (ksh88 fails this test) |
| 4818 | expected-exit: e != 0 |
| 4819 | stdin: |
| 4820 | typeset -i i |
| 4821 | i=3 |
| 4822 | i=2#110#11 |
| 4823 | echo $i |
| 4824 | expected-stderr-pattern: |
| 4825 | /^.*:.*2#110#11.*\n$/ |
| 4826 | --- |
| 4827 | name: integer-base-err-3 |
| 4828 | description: |
| 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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 4832 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 4833 | arguments: !-i! |
| 4834 | stdin: |
| 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 |
| 4842 | expected-stderr-pattern: |
| 4843 | /^([#\$] )?.*:.*2+.*\n.*:.*2+.*\n$/ |
| 4844 | expected-stdout: |
| 4845 | 4#22 |
| 4846 | 4#22 |
| 4847 | --- |
| 4848 | name: integer-base-err-4 |
| 4849 | description: |
| 4850 | Are invalid digits (according to base) errors? |
| 4851 | (ksh93 fails this test) |
| 4852 | expected-exit: e != 0 |
| 4853 | stdin: |
| 4854 | typeset -i i; |
| 4855 | i=3#4 |
| 4856 | expected-stderr-pattern: |
| 4857 | /^([#\$] )?.*:.*3#4.*\n$/ |
| 4858 | --- |
| 4859 | name: integer-base-1 |
| 4860 | description: |
| 4861 | Missing number after base is treated as 0. |
| 4862 | stdin: |
| 4863 | typeset -i i |
| 4864 | i=3 |
| 4865 | i=2# |
| 4866 | echo $i |
| 4867 | expected-stdout: |
| 4868 | 0 |
| 4869 | --- |
| 4870 | name: integer-base-2 |
| 4871 | description: |
| 4872 | Check 'stickyness' of base in various situations |
| 4873 | stdin: |
| 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 |
| 4905 | expected-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 | --- |
| 4923 | name: integer-base-3 |
| 4924 | description: |
| 4925 | More base parsing (hmm doesn't test much..) |
| 4926 | stdin: |
| 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 |
| 4939 | expected-stdout: |
| 4940 | 15 |
| 4941 | 16 |
| 4942 | 15 |
| 4943 | 15 |
| 4944 | --- |
| 4945 | name: integer-base-4 |
| 4946 | description: |
| 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) |
| 4950 | stdin: |
| 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 |
| 4957 | expected-stdout: |
| 4958 | 4#110 |
| 4959 | --- |
| 4960 | name: integer-base-5 |
| 4961 | description: |
| 4962 | More base stuff |
| 4963 | stdin: |
| 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 |
| 4977 | expected-stdout: |
| 4978 | 4#3 |
| 4979 | -- |
| 4980 | -4 |
| 4981 | -- |
| 4982 | 2 |
| 4983 | -- |
| 4984 | 1 |
| 4985 | 5 |
| 4986 | 4 |
| 4987 | --- |
| 4988 | name: integer-base-6 |
| 4989 | description: |
| 4990 | Even more base stuff |
| 4991 | (ksh93 fails this test - prints 0) |
| 4992 | stdin: |
| 4993 | typeset -i7 i |
| 4994 | i= |
| 4995 | echo $i |
| 4996 | expected-stdout: |
| 4997 | 7#0 |
| 4998 | --- |
| 4999 | name: integer-base-7 |
| 5000 | description: |
| 5001 | Check that non-integer parameters don't get bases assigned |
| 5002 | stdin: |
| 5003 | echo $(( zz = 8#100 )) |
| 5004 | echo $zz |
| 5005 | expected-stdout: |
| 5006 | 64 |
| 5007 | 64 |
| 5008 | --- |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 5009 | name: integer-base-8 |
| 5010 | description: |
| 5011 | Check that base-36 works (full span) |
| 5012 | stdin: |
| 5013 | echo 1:$((36#109AZ)). |
| 5014 | typeset -i36 x=1691675 |
| 5015 | echo 2:$x. |
| 5016 | typeset -Uui36 x |
| 5017 | echo 3:$x. |
| 5018 | expected-stdout: |
| 5019 | 1:1691675. |
| 5020 | 2:36#109az. |
| 5021 | 3:36#109AZ. |
| 5022 | --- |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 5023 | name: integer-base-check-flat |
| 5024 | description: |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 5025 | Check behaviour does not match POSuX (except if set -o posix), |
| 5026 | because a not type-safe scripting language has *no* business |
Elliott Hughes | 966dd55 | 2016-12-08 15:56:04 -0800 | [diff] [blame] | 5027 | interpreting the string "010" as octal number eight (dangerous). |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 5028 | stdin: |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 5029 | 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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 5032 | expected-stdout: |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 5033 | 1 :10/10,16: . |
| 5034 | 2 :10/8,16: . |
| 5035 | 3 :10/10,16: . |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 5036 | --- |
| 5037 | name: integer-base-check-numeric-from |
| 5038 | description: |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 5039 | Check behaviour for base one to 36, and that 37 degrades to 10 |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 5040 | stdin: |
| 5041 | echo 1:$((1#1))0. |
| 5042 | i=1 |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 5043 | while (( ++i <= 37 )); do |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 5044 | eval 'echo '$i':$(('$i'#10)).' |
| 5045 | done |
| 5046 | echo 37:$($__progname -c 'echo $((37#10))').$?: |
| 5047 | expected-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 Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 5084 | 37:10. |
| 5085 | 37:10.0: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 5086 | --- |
| 5087 | name: integer-base-check-numeric-to |
| 5088 | description: |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 5089 | Check behaviour for base one to 36, and that 37 degrades to 10 |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 5090 | stdin: |
| 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 |
| 5097 | expected-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 Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 5134 | 37:64.64. |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 5135 | --- |
| 5136 | name: integer-arithmetic-span |
| 5137 | description: |
| 5138 | Check wraparound and size that is defined in mksh |
| 5139 | category: int:32 |
| 5140 | stdin: |
| 5141 | echo s:$((2147483647+1)).$(((2147483647*2)+1)).$(((2147483647*2)+2)). |
| 5142 | echo u:$((#2147483647+1)).$((#(2147483647*2)+1)).$((#(2147483647*2)+2)). |
| 5143 | expected-stdout: |
| 5144 | s:-2147483648.-1.0. |
| 5145 | u:2147483648.4294967295.0. |
| 5146 | --- |
| 5147 | name: integer-arithmetic-span-64 |
| 5148 | description: |
| 5149 | Check wraparound and size that is defined in mksh |
| 5150 | category: int:64 |
| 5151 | stdin: |
| 5152 | echo s:$((9223372036854775807+1)).$(((9223372036854775807*2)+1)).$(((9223372036854775807*2)+2)). |
| 5153 | echo u:$((#9223372036854775807+1)).$((#(9223372036854775807*2)+1)).$((#(9223372036854775807*2)+2)). |
| 5154 | expected-stdout: |
| 5155 | s:-9223372036854775808.-1.0. |
| 5156 | u:9223372036854775808.18446744073709551615.0. |
| 5157 | --- |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 5158 | name: integer-size-FAIL-to-detect |
| 5159 | description: |
| 5160 | Notify the user that their ints are not 32 or 64 bit |
| 5161 | category: int:u |
| 5162 | stdin: |
| 5163 | : |
| 5164 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 5165 | name: lineno-stdin |
| 5166 | description: |
| 5167 | See if $LINENO is updated and can be modified. |
| 5168 | stdin: |
| 5169 | echo A $LINENO |
| 5170 | echo B $LINENO |
| 5171 | LINENO=20 |
| 5172 | echo C $LINENO |
| 5173 | expected-stdout: |
| 5174 | A 1 |
| 5175 | B 2 |
| 5176 | C 20 |
| 5177 | --- |
| 5178 | name: lineno-inc |
| 5179 | description: |
| 5180 | See if $LINENO is set for .'d files. |
| 5181 | file-setup: file 644 "dotfile" |
| 5182 | echo dot A $LINENO |
| 5183 | echo dot B $LINENO |
| 5184 | LINENO=20 |
| 5185 | echo dot C $LINENO |
| 5186 | stdin: |
| 5187 | echo A $LINENO |
| 5188 | echo B $LINENO |
| 5189 | . ./dotfile |
| 5190 | expected-stdout: |
| 5191 | A 1 |
| 5192 | B 2 |
| 5193 | dot A 1 |
| 5194 | dot B 2 |
| 5195 | dot C 20 |
| 5196 | --- |
| 5197 | name: lineno-func |
| 5198 | description: |
| 5199 | See if $LINENO is set for commands in a function. |
| 5200 | stdin: |
| 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 |
| 5209 | expected-stdout: |
| 5210 | A 1 |
| 5211 | B 2 |
| 5212 | func A 4 |
| 5213 | func B 5 |
| 5214 | C 8 |
| 5215 | --- |
| 5216 | name: lineno-unset |
| 5217 | description: |
| 5218 | See if unsetting LINENO makes it non-magic. |
| 5219 | file-setup: file 644 "dotfile" |
| 5220 | echo dot A $LINENO |
| 5221 | echo dot B $LINENO |
| 5222 | stdin: |
| 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 |
| 5233 | expected-stdout: |
| 5234 | A |
| 5235 | B |
| 5236 | func A |
| 5237 | func B |
| 5238 | dot A |
| 5239 | dot B |
| 5240 | C |
| 5241 | --- |
| 5242 | name: lineno-unset-use |
| 5243 | description: |
| 5244 | See if unsetting LINENO makes it non-magic even |
| 5245 | when it is re-used. |
| 5246 | file-setup: file 644 "dotfile" |
| 5247 | echo dot A $LINENO |
| 5248 | echo dot B $LINENO |
| 5249 | stdin: |
| 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 |
| 5261 | expected-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 | --- |
| 5270 | name: lineno-trap |
| 5271 | description: |
| 5272 | Check if LINENO is tracked in traps |
| 5273 | stdin: |
| 5274 | fail() { |
| 5275 | echo "line <$1>" |
| 5276 | exit 1 |
| 5277 | } |
| 5278 | trap 'fail $LINENO' INT ERR |
| 5279 | false |
| 5280 | expected-stdout: |
| 5281 | line <6> |
| 5282 | expected-exit: 1 |
| 5283 | --- |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 5284 | name: lineno-eval-alias |
| 5285 | description: |
| 5286 | Check if LINENO is trapped in eval and aliases |
| 5287 | stdin: |
| 5288 | ${ZSH_VERSION+false} || emulate sh; echo $LINENO |
| 5289 | echo $LINENO |
| 5290 | eval ' echo $LINENO |
| 5291 | echo $LINENO |
| 5292 | echo $LINENO' |
| 5293 | echo $LINENO |
| 5294 | expected-stdout: |
| 5295 | 1 |
| 5296 | 2 |
| 5297 | 3 |
| 5298 | 3 |
| 5299 | 3 |
| 5300 | 6 |
| 5301 | --- |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 5302 | name: unknown-trap |
| 5303 | description: |
| 5304 | Ensure unknown traps are not a syntax error |
| 5305 | stdin: |
| 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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 5311 | ) 2>&1 | sed "s^${__progname%.exe}\.*e*x*e*: <stdin>\[[0-9]*]PROG" |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 5312 | expected-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 Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 5319 | = 1 |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 5320 | trap 2 executed |
| 5321 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 5322 | name: read-IFS-1 |
| 5323 | description: |
| 5324 | Simple test, default IFS |
| 5325 | stdin: |
| 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]" |
| 5333 | expected-stdout: |
| 5334 | 1: x[A] y[B] z[] |
| 5335 | 1a: |
| 5336 | 2: x[A B] |
| 5337 | --- |
Elliott Hughes | b27ce95 | 2015-04-21 13:39:18 -0700 | [diff] [blame] | 5338 | name: read-IFS-2 |
| 5339 | description: |
| 5340 | Complex tests, IFS either colon (IFS-NWS) or backslash (tricky) |
| 5341 | stdin: |
| 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") |
| 5370 | expected-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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 5398 | name: read-ksh-1 |
| 5399 | description: |
| 5400 | If no var specified, REPLY is used |
| 5401 | stdin: |
| 5402 | echo "abc" > IN |
| 5403 | read < IN |
| 5404 | echo "[$REPLY]"; |
| 5405 | expected-stdout: |
| 5406 | [abc] |
| 5407 | --- |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 5408 | name: read-regress-1 |
| 5409 | description: |
| 5410 | Check a regression of read |
| 5411 | file-setup: file 644 "foo" |
| 5412 | foo bar |
| 5413 | baz |
| 5414 | blah |
| 5415 | stdin: |
| 5416 | while read a b c; do |
| 5417 | read d |
| 5418 | break |
| 5419 | done <foo |
| 5420 | echo "<$a|$b|$c><$d>" |
| 5421 | expected-stdout: |
| 5422 | <foo|bar|><baz> |
| 5423 | --- |
| 5424 | name: read-delim-1 |
| 5425 | description: |
| 5426 | Check read with delimiters |
| 5427 | stdin: |
| 5428 | emit() { |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 5429 | print -n 'foo bar\tbaz\nblah \0blub\tblech\nmyok meck \0' |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 5430 | } |
| 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 |
| 5434 | expected-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 | --- |
| 5448 | name: read-ext-1 |
| 5449 | description: |
| 5450 | Check read with number of bytes specified, and -A |
| 5451 | stdin: |
| 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]}>" |
| 5467 | expected-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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 5476 | name: regression-1 |
| 5477 | description: |
| 5478 | Lex array code had problems with this. |
| 5479 | stdin: |
| 5480 | echo foo[ |
| 5481 | n=bar |
| 5482 | echo "hi[ $n ]=1" |
| 5483 | expected-stdout: |
| 5484 | foo[ |
| 5485 | hi[ bar ]=1 |
| 5486 | --- |
| 5487 | name: regression-2 |
| 5488 | description: |
| 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. |
| 5500 | stdin: |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 5501 | : "${PWD:-`pwd 2> /dev/null`}" |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 5502 | : "${PWD:?"PWD not set - cannot do test"}" |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 5503 | 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 $? |
| 5516 | expected-stdout: |
| 5517 | hi |
| 5518 | --- |
| 5519 | name: regression-6 |
| 5520 | description: |
| 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... |
| 5534 | stdin: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 5535 | echo $(echo \( ) |
| 5536 | echo $(echo "(" ) |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 5537 | expected-stdout: |
| 5538 | ( |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 5539 | ( |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 5540 | --- |
| 5541 | name: regression-9 |
| 5542 | description: |
| 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... |
| 5551 | stdin: |
| 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 |
| 5564 | expected-stdout: |
| 5565 | bye |
| 5566 | --- |
| 5567 | name: regression-10 |
| 5568 | description: |
| 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 Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 5575 | We honour POSIX except when -o sh is set. |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 5576 | category: shell:legacy-no |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 5577 | stdin: |
| 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 Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 5595 | set -o posix -o sh |
| 5596 | showf |
| 5597 | set -- `false` |
| 5598 | echo rv=$? |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 5599 | expected-stdout: |
| 5600 | FPOSIX=0 FSH=0 rv=0 |
| 5601 | FPOSIX=0 FSH=1 rv=1 |
| 5602 | FPOSIX=1 FSH=0 rv=0 |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 5603 | FPOSIX=1 FSH=1 rv=0 |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 5604 | --- |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 5605 | name: regression-10-legacy |
| 5606 | description: |
| 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). |
| 5613 | category: shell:legacy-yes |
| 5614 | stdin: |
| 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 Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 5632 | set -o posix -o sh |
| 5633 | showf |
| 5634 | set -- `false` |
| 5635 | echo rv=$? |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 5636 | expected-stdout: |
| 5637 | FPOSIX=0 FSH=0 rv=1 |
| 5638 | FPOSIX=0 FSH=1 rv=1 |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 5639 | FPOSIX=1 FSH=0 rv=0 |
| 5640 | FPOSIX=1 FSH=1 rv=0 |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 5641 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 5642 | name: regression-11 |
| 5643 | description: |
| 5644 | The following: |
| 5645 | x=/foo/bar/blah |
| 5646 | echo ${x##*/} |
| 5647 | should echo blah but on some machines echos /foo/bar/blah. |
| 5648 | stdin: |
| 5649 | x=/foo/bar/blah |
| 5650 | echo ${x##*/} |
| 5651 | expected-stdout: |
| 5652 | blah |
| 5653 | --- |
| 5654 | name: regression-12 |
| 5655 | description: |
| 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) |
| 5662 | stdin: |
| 5663 | x="foo bar" |
| 5664 | echo "`echo \"$x\"`" |
| 5665 | echo "`echo "$x"`" |
| 5666 | expected-stdout: |
| 5667 | foo bar |
| 5668 | foo bar |
| 5669 | --- |
| 5670 | name: regression-13 |
| 5671 | description: |
| 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..) |
| 5681 | time-limit: 10 |
| 5682 | stdin: |
| 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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 5687 | (: ; cat t2 2>/dev/null) | sleep 1 |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 5688 | --- |
| 5689 | name: regression-14 |
| 5690 | description: |
| 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). |
| 5699 | stdin: |
| 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 | --- |
| 5704 | name: regression-15 |
| 5705 | description: |
| 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). |
| 5714 | stdin: |
| 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) |
| 5719 | expected-stdout: |
| 5720 | 1: 1 |
| 5721 | 2: 0 |
| 5722 | 3: 0 |
| 5723 | --- |
| 5724 | name: regression-16 |
| 5725 | description: |
| 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... |
| 5738 | script: |
| 5739 | read x |
| 5740 | y=$x |
| 5741 | echo ${x%%:*} |
| 5742 | echo $x |
| 5743 | stdin: |
| 5744 | root:asdjhasdasjhs:0:1:Root:/:/bin/sh |
| 5745 | expected-stdout: |
| 5746 | root |
| 5747 | root:asdjhasdasjhs:0:1:Root:/:/bin/sh |
| 5748 | --- |
| 5749 | name: regression-17 |
| 5750 | description: |
| 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 |
| 5755 | stdin: |
| 5756 | . does/not/exist |
| 5757 | expected-exit: e != 0 |
| 5758 | expected-stderr-pattern: /.?/ |
| 5759 | --- |
| 5760 | name: regression-19 |
| 5761 | description: |
| 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 |
| 5768 | stdin: |
| 5769 | x=foo/bar |
| 5770 | echo "${x%/*}" |
| 5771 | expected-stdout: |
| 5772 | foo |
| 5773 | --- |
| 5774 | name: regression-21 |
| 5775 | description: |
| 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 | $ |
| 5788 | stdin: |
| 5789 | case -x in |
| 5790 | -\?) echo fail |
| 5791 | esac |
| 5792 | --- |
| 5793 | name: regression-22 |
| 5794 | description: |
| 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 |
| 5799 | stdin: |
| 5800 | echo `echo hi \`echo there\` folks` |
| 5801 | expected-stdout: |
| 5802 | hi there folks |
| 5803 | --- |
| 5804 | name: regression-23 |
| 5805 | description: |
| 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 | $ |
| 5816 | stdin: |
| 5817 | ( : ; ( : ; echo hi)) |
| 5818 | expected-stdout: |
| 5819 | hi |
| 5820 | --- |
| 5821 | name: regression-25 |
| 5822 | description: |
| 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. |
| 5826 | stdin: |
| 5827 | (echo a; echo b) | while read x ; do |
| 5828 | echo $x |
| 5829 | cat > /dev/null |
| 5830 | done |
| 5831 | expected-stdout: |
| 5832 | a |
| 5833 | --- |
| 5834 | name: regression-26 |
| 5835 | description: |
| 5836 | Check reading stdin in a while loop. The read should read both |
| 5837 | lines, not just the first. |
| 5838 | script: |
| 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 |
| 5847 | stdin: |
| 5848 | a |
| 5849 | b |
| 5850 | expected-stdout: |
| 5851 | b |
| 5852 | --- |
| 5853 | name: regression-27 |
| 5854 | description: |
| 5855 | The command |
| 5856 | . /does/not/exist |
| 5857 | should cause a script to exit. |
| 5858 | stdin: |
| 5859 | . does/not/exist |
| 5860 | echo hi |
| 5861 | expected-exit: e != 0 |
| 5862 | expected-stderr-pattern: /does\/not\/exist/ |
| 5863 | --- |
| 5864 | name: regression-28 |
| 5865 | description: |
| 5866 | variable assignements not detected well |
| 5867 | stdin: |
| 5868 | a.x=1 echo hi |
| 5869 | expected-exit: e != 0 |
| 5870 | expected-stderr-pattern: /a\.x=1/ |
| 5871 | --- |
| 5872 | name: regression-29 |
| 5873 | description: |
| 5874 | alias expansion different from AT&T ksh88 |
| 5875 | stdin: |
| 5876 | alias a='for ' b='i in' |
| 5877 | a b hi ; do echo $i ; done |
| 5878 | expected-stdout: |
| 5879 | hi |
| 5880 | --- |
| 5881 | name: regression-30 |
| 5882 | description: |
| 5883 | strange characters allowed inside ${...} |
| 5884 | stdin: |
| 5885 | echo ${a{b}} |
| 5886 | expected-exit: e != 0 |
| 5887 | expected-stderr-pattern: /.?/ |
| 5888 | --- |
| 5889 | name: regression-31 |
| 5890 | description: |
| 5891 | Does read handle partial lines correctly |
| 5892 | script: |
| 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 |
| 5901 | stdin: ! |
| 5902 | a A aA |
| 5903 | b B Bb |
| 5904 | c |
| 5905 | expected-stdout: |
| 5906 | [c] |
| 5907 | 1 |
| 5908 | --- |
| 5909 | name: regression-32 |
| 5910 | description: |
| 5911 | Does read set variables to null at eof? |
| 5912 | script: |
| 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} |
| 5920 | stdin: |
| 5921 | a A Aa |
| 5922 | b B Bb |
| 5923 | expected-stdout: |
| 5924 | 1: |
| 5925 | 2: |
| 5926 | --- |
| 5927 | name: regression-33 |
| 5928 | description: |
| 5929 | Does umask print a leading 0 when umask is 3 digits? |
| 5930 | stdin: |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 5931 | # on MiNT, the first umask call seems to fail |
| 5932 | umask 022 |
| 5933 | # now, the test proper |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 5934 | umask 222 |
| 5935 | umask |
| 5936 | expected-stdout: |
| 5937 | 0222 |
| 5938 | --- |
| 5939 | name: regression-35 |
| 5940 | description: |
| 5941 | Tempory files used for here-docs in functions get trashed after |
| 5942 | the function is parsed (before it is executed) |
| 5943 | stdin: |
| 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 |
| 5958 | expected-stdout: |
| 5959 | F1 |
| 5960 | F2 |
| 5961 | F2 |
| 5962 | --- |
| 5963 | name: regression-36 |
| 5964 | description: |
| 5965 | Command substitution breaks reading in while loop |
| 5966 | (test from <sjg@void.zen.oz.au>) |
| 5967 | stdin: |
| 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 |
| 5975 | expected-stdout: |
| 5976 | 7 |
| 5977 | 1 |
| 5978 | 4 |
| 5979 | --- |
| 5980 | name: regression-37 |
| 5981 | description: |
| 5982 | Machines with broken times() (reported by <sjg@void.zen.oz.au>) |
| 5983 | time does not report correct real time |
| 5984 | stdin: |
| 5985 | time sleep 1 |
| 5986 | expected-stderr-pattern: !/^\s*0\.0[\s\d]+real|^\s*real[\s]+0+\.0/ |
| 5987 | --- |
| 5988 | name: regression-38 |
| 5989 | description: |
| 5990 | set -e doesn't ignore exit codes for if/while/until/&&/||/!. |
| 5991 | arguments: !-e! |
| 5992 | stdin: |
| 5993 | if false; then echo hi ; fi |
| 5994 | false || true |
| 5995 | false && true |
| 5996 | while false; do echo hi; done |
| 5997 | echo ok |
| 5998 | expected-stdout: |
| 5999 | ok |
| 6000 | --- |
| 6001 | name: regression-39 |
| 6002 | description: |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 6003 | 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 6006 | stdin: |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 6007 | set -e |
Elliott Hughes | 737fdce | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 6008 | echo `false; echo hi` $(<this-file-does-not-exist) |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 6009 | echo $? |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 6010 | expected-stdout: |
| 6011 | |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 6012 | 0 |
Elliott Hughes | 737fdce | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 6013 | expected-stderr-pattern: /this-file-does-not-exist/ |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 6014 | --- |
| 6015 | name: regression-40 |
| 6016 | description: |
| 6017 | This used to cause a core dump |
| 6018 | env-setup: !RANDOM=12! |
| 6019 | stdin: |
| 6020 | echo hi |
| 6021 | expected-stdout: |
| 6022 | hi |
| 6023 | --- |
| 6024 | name: regression-41 |
| 6025 | description: |
| 6026 | foo should be set to bar (should not be empty) |
| 6027 | stdin: |
| 6028 | foo=` |
| 6029 | echo bar` |
| 6030 | echo "($foo)" |
| 6031 | expected-stdout: |
| 6032 | (bar) |
| 6033 | --- |
| 6034 | name: regression-42 |
| 6035 | description: |
| 6036 | Can't use command line assignments to assign readonly parameters. |
| 6037 | stdin: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 6038 | print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \ |
| 6039 | 'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \ |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 6040 | done >env; chmod +x env; PATH=.$PATHSEP$PATH |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 6041 | foo=bar |
| 6042 | readonly foo |
| 6043 | foo=stuff env | grep '^foo' |
| 6044 | expected-exit: e != 0 |
| 6045 | expected-stderr-pattern: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 6046 | /read-only/ |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 6047 | --- |
| 6048 | name: regression-43 |
| 6049 | description: |
| 6050 | Can subshells be prefixed by redirections (historical shells allow |
| 6051 | this) |
| 6052 | stdin: |
| 6053 | < /dev/null (sed 's/^/X/') |
| 6054 | --- |
| 6055 | name: regression-45 |
| 6056 | description: |
| 6057 | Parameter assignments with [] recognised correctly |
| 6058 | stdin: |
| 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>" |
| 6067 | expected-stdout: |
| 6068 | <*[12]> |
| 6069 | <abc[> |
| 6070 | <[abc]> |
| 6071 | <a[bc> |
| 6072 | --- |
| 6073 | name: regression-46 |
| 6074 | description: |
| 6075 | Check that alias expansion works in command substitutions and |
| 6076 | at the end of file. |
| 6077 | stdin: |
| 6078 | alias x='echo hi' |
| 6079 | FOO="`x` " |
| 6080 | echo "[$FOO]" |
| 6081 | x |
| 6082 | expected-stdout: |
| 6083 | [hi ] |
| 6084 | hi |
| 6085 | --- |
| 6086 | name: regression-47 |
| 6087 | description: |
| 6088 | Check that aliases are fully read. |
| 6089 | stdin: |
| 6090 | alias x='echo hi; |
| 6091 | echo there' |
| 6092 | x |
| 6093 | echo done |
| 6094 | expected-stdout: |
| 6095 | hi |
| 6096 | there |
| 6097 | done |
| 6098 | --- |
| 6099 | name: regression-48 |
| 6100 | description: |
| 6101 | Check that (here doc) temp files are not left behind after an exec. |
| 6102 | stdin: |
| 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/* |
| 6126 | expected-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 | --- |
| 6135 | name: regression-49 |
| 6136 | description: |
| 6137 | Check that unset params with attributes are reported by set, those |
| 6138 | sans attributes are not. |
| 6139 | stdin: |
| 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 |
| 6147 | expected-stdout: |
| 6148 | X |
| 6149 | BAR |
| 6150 | BLAH |
| 6151 | --- |
| 6152 | name: regression-50 |
| 6153 | description: |
| 6154 | Check that aliases do not use continuation prompt after trailing |
| 6155 | semi-colon. |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 6156 | file-setup: file 644 "envf" |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 6157 | PS1=Y |
| 6158 | PS2=X |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 6159 | env-setup: !ENV=./envf! |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 6160 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 6161 | arguments: !-i! |
| 6162 | stdin: |
| 6163 | alias foo='echo hi ; ' |
| 6164 | foo |
| 6165 | foo echo there |
| 6166 | expected-stdout: |
| 6167 | hi |
| 6168 | hi |
| 6169 | there |
| 6170 | expected-stderr: ! |
| 6171 | YYYY |
| 6172 | --- |
| 6173 | name: regression-51 |
| 6174 | description: |
| 6175 | Check that set allows both +o and -o options on same command line. |
| 6176 | stdin: |
| 6177 | set a b c |
| 6178 | set -o noglob +o allexport |
| 6179 | echo A: $*, * |
| 6180 | expected-stdout: |
| 6181 | A: a b c, * |
| 6182 | --- |
| 6183 | name: regression-52 |
| 6184 | description: |
| 6185 | Check that globbing works in pipelined commands |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 6186 | file-setup: file 644 "envf" |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 6187 | PS1=P |
| 6188 | file-setup: file 644 "abc" |
| 6189 | stuff |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 6190 | env-setup: !ENV=./envf! |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 6191 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 6192 | arguments: !-i! |
| 6193 | stdin: |
| 6194 | sed 's/^/X /' < ab* |
| 6195 | echo mark 1 |
| 6196 | sed 's/^/X /' < ab* | sed 's/^/Y /' |
| 6197 | echo mark 2 |
| 6198 | expected-stdout: |
| 6199 | X stuff |
| 6200 | mark 1 |
| 6201 | Y X stuff |
| 6202 | mark 2 |
| 6203 | expected-stderr: ! |
| 6204 | PPPPP |
| 6205 | --- |
| 6206 | name: regression-53 |
| 6207 | description: |
| 6208 | Check that getopts works in functions |
| 6209 | stdin: |
| 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" |
| 6267 | expected-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 | --- |
| 6300 | name: regression-54 |
| 6301 | description: |
| 6302 | Check that ; is not required before the then in if (( ... )) then ... |
| 6303 | stdin: |
| 6304 | if (( 1 )) then |
| 6305 | echo ok dparen |
| 6306 | fi |
| 6307 | if [[ -n 1 ]] then |
| 6308 | echo ok dbrackets |
| 6309 | fi |
| 6310 | expected-stdout: |
| 6311 | ok dparen |
| 6312 | ok dbrackets |
| 6313 | --- |
| 6314 | name: regression-55 |
| 6315 | description: |
| 6316 | Check ${foo:%bar} is allowed (ksh88 allows it...) |
| 6317 | stdin: |
| 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} |
| 6327 | expected-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 | --- |
| 6337 | name: regression-57 |
| 6338 | description: |
| 6339 | Check if typeset output is correct for |
| 6340 | uninitialised array elements. |
| 6341 | stdin: |
| 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/^/ /' |
| 6353 | expected-stdout: |
| 6354 | A |
| 6355 | xxx |
| 6356 | B |
| 6357 | typeset -i xxx |
| 6358 | M |
| 6359 | xxx[1]=7 |
| 6360 | N |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 6361 | set -A xxx |
| 6362 | typeset -i xxx[1] |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 6363 | --- |
| 6364 | name: regression-58 |
| 6365 | description: |
| 6366 | Check if trap exit is ok (exit not mistaken for signal name) |
| 6367 | stdin: |
| 6368 | trap 'echo hi' exit |
| 6369 | trap exit 1 |
| 6370 | expected-stdout: |
| 6371 | hi |
| 6372 | --- |
| 6373 | name: regression-59 |
| 6374 | description: |
| 6375 | Check if ${#array[*]} is calculated correctly. |
| 6376 | stdin: |
| 6377 | a[12]=hi |
| 6378 | a[8]=there |
| 6379 | echo ${#a[*]} |
| 6380 | expected-stdout: |
| 6381 | 2 |
| 6382 | --- |
| 6383 | name: regression-60 |
| 6384 | description: |
| 6385 | Check if default exit status is previous command |
| 6386 | stdin: |
| 6387 | (true; exit) |
| 6388 | echo A $? |
| 6389 | (false; exit) |
| 6390 | echo B $? |
| 6391 | ( (exit 103) ; exit) |
| 6392 | echo C $? |
| 6393 | expected-stdout: |
| 6394 | A 0 |
| 6395 | B 1 |
| 6396 | C 103 |
| 6397 | --- |
| 6398 | name: regression-61 |
| 6399 | description: |
| 6400 | Check if EXIT trap is executed for sub shells. |
| 6401 | stdin: |
| 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 |
| 6408 | expected-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 | --- |
| 6419 | name: regression-62 |
| 6420 | description: |
| 6421 | Check if test -nt/-ot succeeds if second(first) file is missing. |
| 6422 | stdin: |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 6423 | :>a |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 6424 | test a -nt b && echo nt OK || echo nt BAD |
| 6425 | test b -ot a && echo ot OK || echo ot BAD |
| 6426 | expected-stdout: |
| 6427 | nt OK |
| 6428 | ot OK |
| 6429 | --- |
| 6430 | name: regression-63 |
| 6431 | description: |
| 6432 | Check if typeset, export, and readonly work |
| 6433 | stdin: |
| 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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 6463 | fnord=(42 23) |
| 6464 | typeset -p fnord |
| 6465 | echo FNORD-9 |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 6466 | expected-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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 6516 | set -A fnord |
| 6517 | typeset fnord[0]=42 |
| 6518 | typeset fnord[1]=23 |
| 6519 | FNORD-9 |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 6520 | --- |
| 6521 | name: regression-64 |
| 6522 | description: |
| 6523 | Check that we can redefine functions calling time builtin |
| 6524 | stdin: |
| 6525 | t() { |
| 6526 | time >/dev/null |
| 6527 | } |
| 6528 | t 2>/dev/null |
| 6529 | t() { |
| 6530 | time |
| 6531 | } |
| 6532 | --- |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 6533 | name: regression-65 |
| 6534 | description: |
| 6535 | check for a regression with sleep builtin and signal mask |
| 6536 | category: !nojsig |
| 6537 | time-limit: 3 |
| 6538 | stdin: |
| 6539 | sleep 1 |
| 6540 | echo blub |& |
| 6541 | while read -p line; do :; done |
| 6542 | echo ok |
| 6543 | expected-stdout: |
| 6544 | ok |
| 6545 | --- |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 6546 | name: regression-66 |
| 6547 | description: |
| 6548 | Check that quoting is sane |
| 6549 | category: !nojsig |
| 6550 | stdin: |
| 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 |
| 6566 | expected-stdout: |
| 6567 | ac_space=' ' |
| 6568 | ac_newline=$'\n' |
| 6569 | --- |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 6570 | name: regression-67 |
| 6571 | description: |
| 6572 | Check that we can both break and use source on the same line |
| 6573 | stdin: |
| 6574 | for s in s; do break; done; print -s s |
| 6575 | --- |
| 6576 | name: regression-68 |
| 6577 | description: |
| 6578 | Check that all common arithmetic operators work as expected |
| 6579 | stdin: |
| 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) )) . |
| 6616 | expected-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 | --- |
| 6654 | name: regression-69 |
| 6655 | description: |
| 6656 | Check that all non-lksh arithmetic operators work as expected |
| 6657 | category: shell:legacy-no |
| 6658 | stdin: |
| 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 )) . |
| 6664 | expected-stdout: |
| 6665 | 1 10 , 11 . |
| 6666 | 2 -2147483646 , -1073741822 . |
| 6667 | 3 10 . |
| 6668 | 4 -2147483646 . |
| 6669 | --- |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 6670 | name: readonly-0 |
| 6671 | description: |
| 6672 | Ensure readonly is honoured for assignments and unset |
| 6673 | stdin: |
| 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, $? |
| 6679 | expected-stdout: |
| 6680 | 0 x . |
| 6681 | = |
| 6682 | aborted, 2 |
| 6683 | = |
| 6684 | 1 x . |
| 6685 | expected-stderr-pattern: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 6686 | /read-only/ |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 6687 | --- |
| 6688 | name: readonly-1 |
| 6689 | description: |
| 6690 | http://austingroupbugs.net/view.php?id=367 for export |
| 6691 | stdin: |
| 6692 | "$__progname" -c 'readonly foo; export foo=a; echo $?' || echo aborted, $? |
| 6693 | expected-stdout: |
| 6694 | aborted, 2 |
| 6695 | expected-stderr-pattern: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 6696 | /read-only/ |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 6697 | --- |
| 6698 | name: readonly-2a |
| 6699 | description: |
| 6700 | Check that getopts works as intended, for readonly-2b to be valid |
| 6701 | stdin: |
| 6702 | "$__progname" -c 'set -- -a b; getopts a c; echo $? $c .; getopts a c; echo $? $c .' || echo aborted, $? |
| 6703 | expected-stdout: |
| 6704 | 0 a . |
| 6705 | 1 ? . |
| 6706 | --- |
| 6707 | name: readonly-2b |
| 6708 | description: |
| 6709 | http://austingroupbugs.net/view.php?id=367 for getopts |
| 6710 | stdin: |
| 6711 | "$__progname" -c 'readonly c; set -- -a b; getopts a c; echo $? $c .' || echo aborted, $? |
| 6712 | expected-stdout: |
| 6713 | 2 . |
| 6714 | expected-stderr-pattern: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 6715 | /read-only/ |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 6716 | --- |
| 6717 | name: readonly-3 |
| 6718 | description: |
| 6719 | http://austingroupbugs.net/view.php?id=367 for read |
| 6720 | stdin: |
| 6721 | echo x | "$__progname" -c 'read s; echo $? $s .' || echo aborted, $? |
| 6722 | echo y | "$__progname" -c 'readonly s; read s; echo $? $s .' || echo aborted, $? |
| 6723 | expected-stdout: |
| 6724 | 0 x . |
| 6725 | 2 . |
| 6726 | expected-stderr-pattern: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 6727 | /read-only/ |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 6728 | --- |
Elliott Hughes | 737fdce | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 6729 | name: readonly-4 |
| 6730 | description: |
| 6731 | Do not permit bypassing readonly for first array item |
| 6732 | stdin: |
| 6733 | set -A arr -- foo bar |
| 6734 | readonly arr |
| 6735 | arr=baz |
| 6736 | print -r -- "${arr[@]}" |
| 6737 | expected-exit: e != 0 |
| 6738 | expected-stderr-pattern: |
| 6739 | /read[ -]?only/ |
| 6740 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 6741 | name: syntax-1 |
| 6742 | description: |
| 6743 | Check that lone ampersand is a syntax error |
| 6744 | stdin: |
| 6745 | & |
| 6746 | expected-exit: e != 0 |
| 6747 | expected-stderr-pattern: |
| 6748 | /syntax error/ |
| 6749 | --- |
| 6750 | name: xxx-quoted-newline-1 |
| 6751 | description: |
| 6752 | Check that \<newline> works inside of ${} |
| 6753 | stdin: |
| 6754 | abc=2 |
| 6755 | echo ${ab\ |
| 6756 | c} |
| 6757 | expected-stdout: |
| 6758 | 2 |
| 6759 | --- |
| 6760 | name: xxx-quoted-newline-2 |
| 6761 | description: |
| 6762 | Check that \<newline> works at the start of a here document |
| 6763 | stdin: |
| 6764 | cat << EO\ |
| 6765 | F |
| 6766 | hi |
| 6767 | EOF |
| 6768 | expected-stdout: |
| 6769 | hi |
| 6770 | --- |
| 6771 | name: xxx-quoted-newline-3 |
| 6772 | description: |
| 6773 | Check that \<newline> works at the end of a here document |
| 6774 | stdin: |
| 6775 | cat << EOF |
| 6776 | hi |
| 6777 | EO\ |
| 6778 | F |
| 6779 | expected-stdout: |
| 6780 | hi |
| 6781 | --- |
| 6782 | name: xxx-multi-assignment-cmd |
| 6783 | description: |
| 6784 | Check that assignments in a command affect subsequent assignments |
| 6785 | in the same command |
| 6786 | stdin: |
| 6787 | FOO=abc |
| 6788 | FOO=123 BAR=$FOO |
| 6789 | echo $BAR |
| 6790 | expected-stdout: |
| 6791 | 123 |
| 6792 | --- |
| 6793 | name: xxx-multi-assignment-posix-cmd |
| 6794 | description: |
| 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 |
| 6798 | stdin: |
| 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 . |
| 6804 | expected-stdout: |
| 6805 | 1 b a . |
| 6806 | 2 a b . |
| 6807 | 3 b . |
| 6808 | 4 a . |
| 6809 | --- |
| 6810 | name: xxx-multi-assignment-posix-nocmd |
| 6811 | description: |
| 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 |
| 6815 | stdin: |
| 6816 | X=a Y=b; X=$Y Y=$X; echo 1 $X $Y . |
| 6817 | expected-stdout: |
| 6818 | 1 b b . |
| 6819 | --- |
| 6820 | name: xxx-multi-assignment-posix-subassign |
| 6821 | description: |
| 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. |
| 6826 | stdin: |
| 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/ |
| 6834 | expected-stdout: |
| 6835 | ++ +b+ +a+ |
| 6836 | /b/ |
| 6837 | ++ +b+ |
| 6838 | /b/ |
| 6839 | --- |
| 6840 | name: xxx-exec-environment-1 |
| 6841 | description: |
| 6842 | Check to see if exec sets it's environment correctly |
| 6843 | stdin: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 6844 | print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \ |
| 6845 | 'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \ |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 6846 | done >env; chmod +x env; PATH=.$PATHSEP$PATH |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 6847 | FOO=bar exec env |
| 6848 | expected-stdout-pattern: |
| 6849 | /(^|.*\n)FOO=bar\n/ |
| 6850 | --- |
| 6851 | name: xxx-exec-environment-2 |
| 6852 | description: |
| 6853 | Check to make sure exec doesn't change environment if a program |
| 6854 | isn't exec-ed |
| 6855 | stdin: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 6856 | print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \ |
| 6857 | 'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \ |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 6858 | done >env; chmod +x env; PATH=.$PATHSEP$PATH |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 6859 | env >bar1 |
| 6860 | FOO=bar exec; env >bar2 |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 6861 | cmp -s bar1 bar2 |
| 6862 | --- |
| 6863 | name: exec-function-environment-1 |
| 6864 | description: |
| 6865 | Check assignments in function calls and whether they affect |
| 6866 | the current execution environment (ksh93, SUSv4) |
| 6867 | stdin: |
| 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- |
| 6870 | expected-stdout: |
| 6871 | y1- |
| 6872 | x2-3- z1- |
| 6873 | --- |
| 6874 | name: xxx-what-do-you-call-this-1 |
| 6875 | stdin: |
| 6876 | echo "${foo:-"a"}*" |
| 6877 | expected-stdout: |
| 6878 | a* |
| 6879 | --- |
| 6880 | name: xxx-prefix-strip-1 |
| 6881 | stdin: |
| 6882 | foo='a cdef' |
| 6883 | echo ${foo#a c} |
| 6884 | expected-stdout: |
| 6885 | def |
| 6886 | --- |
| 6887 | name: xxx-prefix-strip-2 |
| 6888 | stdin: |
| 6889 | set a c |
| 6890 | x='a cdef' |
| 6891 | echo ${x#$*} |
| 6892 | expected-stdout: |
| 6893 | def |
| 6894 | --- |
| 6895 | name: xxx-variable-syntax-1 |
| 6896 | stdin: |
| 6897 | echo ${:} |
| 6898 | expected-stderr-pattern: |
| 6899 | /bad substitution/ |
| 6900 | expected-exit: 1 |
| 6901 | --- |
| 6902 | name: xxx-variable-syntax-2 |
| 6903 | stdin: |
| 6904 | set 0 |
| 6905 | echo ${*:0} |
| 6906 | expected-stderr-pattern: |
| 6907 | /bad substitution/ |
| 6908 | expected-exit: 1 |
| 6909 | --- |
| 6910 | name: xxx-variable-syntax-3 |
| 6911 | stdin: |
| 6912 | set -A foo 0 |
| 6913 | echo ${foo[*]:0} |
| 6914 | expected-stderr-pattern: |
| 6915 | /bad substitution/ |
| 6916 | expected-exit: 1 |
| 6917 | --- |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 6918 | name: xxx-variable-syntax-4 |
| 6919 | description: |
| 6920 | Not all kinds of trims are currently impossible, check those who do |
| 6921 | stdin: |
| 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 "" "" |
| 6939 | expected-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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 6953 | name: xxx-substitution-eval-order |
| 6954 | description: |
| 6955 | Check order of evaluation of expressions |
| 6956 | stdin: |
| 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 |
| 6961 | expected-stdout: |
| 6962 | HI |
| 6963 | 2 4 |
| 6964 | --- |
| 6965 | name: xxx-set-option-1 |
| 6966 | description: |
| 6967 | Check option parsing in set |
| 6968 | stdin: |
| 6969 | set -vsA foo -- A 1 3 2 |
| 6970 | echo ${foo[*]} |
| 6971 | expected-stderr: |
| 6972 | echo ${foo[*]} |
| 6973 | expected-stdout: |
| 6974 | 1 2 3 A |
| 6975 | --- |
| 6976 | name: xxx-exec-1 |
| 6977 | description: |
| 6978 | Check that exec exits for built-ins |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 6979 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 6980 | arguments: !-i! |
| 6981 | stdin: |
| 6982 | exec echo hi |
| 6983 | echo still herre |
| 6984 | expected-stdout: |
| 6985 | hi |
| 6986 | expected-stderr-pattern: /.*/ |
| 6987 | --- |
| 6988 | name: xxx-while-1 |
| 6989 | description: |
| 6990 | Check the return value of while loops |
| 6991 | XXX need to do same for for/select/until loops |
| 6992 | stdin: |
| 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=$? |
| 7019 | expected-stdout: |
| 7020 | loop1=0 |
| 7021 | loop2=0 |
| 7022 | loop3=1 |
| 7023 | --- |
| 7024 | name: xxx-status-1 |
| 7025 | description: |
| 7026 | Check that blank lines don't clear $? |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 7027 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7028 | arguments: !-i! |
| 7029 | stdin: |
| 7030 | (exit 1) |
| 7031 | echo $? |
| 7032 | (exit 1) |
| 7033 | |
| 7034 | echo $? |
| 7035 | true |
| 7036 | expected-stdout: |
| 7037 | 1 |
| 7038 | 1 |
| 7039 | expected-stderr-pattern: /.*/ |
| 7040 | --- |
| 7041 | name: xxx-status-2 |
| 7042 | description: |
| 7043 | Check that $? is preserved in subshells, includes, traps. |
| 7044 | stdin: |
| 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: $? |
| 7059 | expected-stdout: |
| 7060 | blank: 1 |
| 7061 | subshell: 2 |
| 7062 | include: 3 |
| 7063 | trap: 4 |
| 7064 | exit: 4 |
| 7065 | --- |
| 7066 | name: xxx-clean-chars-1 |
| 7067 | description: |
| 7068 | Check MAGIC character is stuffed correctly |
| 7069 | stdin: |
| 7070 | echo `echo [£` |
| 7071 | expected-stdout: |
| 7072 | [£ |
| 7073 | --- |
| 7074 | name: xxx-param-subst-qmark-1 |
| 7075 | description: |
| 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 Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 7078 | ksh88/93, Solaris /bin/sh and /usr/xpg4/bin/sh all print the error. |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7079 | stdin: |
| 7080 | unset foo |
| 7081 | x= |
| 7082 | echo x${foo?$x} |
| 7083 | expected-exit: 1 |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 7084 | expected-stderr-pattern: !/not set/ |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7085 | --- |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 7086 | name: xxx-param-subst-qmark-namespec |
| 7087 | description: |
| 7088 | Check special names are output correctly |
| 7089 | stdin: |
| 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 "" |
| 7103 | expected-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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7117 | name: xxx-param-_-1 |
| 7118 | # fails due to weirdness of execv stuff |
| 7119 | category: !os:uwin-nt |
| 7120 | description: |
| 7121 | Check c flag is set. |
| 7122 | arguments: !-c!echo "[$-]"! |
| 7123 | expected-stdout-pattern: /^\[.*c.*\]$/ |
| 7124 | --- |
| 7125 | name: tilde-expand-1 |
| 7126 | description: |
| 7127 | Check tilde expansion after equal signs |
| 7128 | env-setup: !HOME=/sweet! |
| 7129 | stdin: |
| 7130 | echo ${A=a=}~ b=~ c=d~ ~ |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 7131 | 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7137 | echo ${A=a=}~ b=~ c=d~ ~ |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 7138 | export e=~ f=d~ |
| 7139 | command command export g=~ h=d~ |
| 7140 | echo ". $e . $f ." |
| 7141 | echo ". $g . $h ." |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7142 | expected-stdout: |
| 7143 | a=/sweet b=/sweet c=d~ /sweet |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 7144 | . /sweet . d~ . |
| 7145 | . /sweet . d~ . |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7146 | a=~ b=~ c=d~ /sweet |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 7147 | . /sweet . d~ . |
| 7148 | . /sweet . d~ . |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7149 | --- |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 7150 | name: tilde-expand-2 |
| 7151 | description: |
| 7152 | Check tilde expansion works |
| 7153 | env-setup: !HOME=/sweet! |
| 7154 | stdin: |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 7155 | :>'c=a' |
| 7156 | typeset c=[ab] |
| 7157 | :>'d=a' |
| 7158 | x=typeset; $x d=[ab] |
| 7159 | echo "<$c>" "<$d>" |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 7160 | 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 $? . |
| 7168 | expected-stdout: |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 7169 | <[ab]> <a> |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 7170 | one 0 . |
| 7171 | two 0 . |
| 7172 | nix 0 . |
| 7173 | --- |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 7174 | name: tilde-expand-3 |
| 7175 | description: |
| 7176 | Check mostly Austin 351 stuff |
| 7177 | stdin: |
| 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 "=~ |
| 7246 | expected-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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7269 | name: exit-err-1 |
| 7270 | description: |
| 7271 | Check some "exit on error" conditions |
| 7272 | stdin: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 7273 | print '#!'"$__progname"'\nexec "$1"' >env |
| 7274 | print '#!'"$__progname"'\nexit 1' >false |
| 7275 | chmod +x env false |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 7276 | PATH=.$PATHSEP$PATH |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7277 | set -ex |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 7278 | env false && echo something |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7279 | echo END |
| 7280 | expected-stdout: |
| 7281 | END |
| 7282 | expected-stderr: |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 7283 | + env false |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7284 | + echo END |
| 7285 | --- |
| 7286 | name: exit-err-2 |
| 7287 | description: |
| 7288 | Check some "exit on error" edge conditions (POSIXly) |
| 7289 | stdin: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 7290 | print '#!'"$__progname"'\nexec "$1"' >env |
| 7291 | print '#!'"$__progname"'\nexit 1' >false |
| 7292 | print '#!'"$__progname"'\nexit 0' >true |
| 7293 | chmod +x env false |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 7294 | PATH=.$PATHSEP$PATH |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7295 | set -ex |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 7296 | if env true; then |
| 7297 | env false && echo something |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7298 | fi |
| 7299 | echo END |
| 7300 | expected-stdout: |
| 7301 | END |
| 7302 | expected-stderr: |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 7303 | + env true |
| 7304 | + env false |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7305 | + echo END |
| 7306 | --- |
| 7307 | name: exit-err-3 |
| 7308 | description: |
| 7309 | pdksh regression which AT&T ksh does right |
| 7310 | TFM says: [set] -e | errexit |
| 7311 | Exit (after executing the ERR trap) ... |
| 7312 | stdin: |
| 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 |
| 7319 | expected-stdout: |
| 7320 | ERR |
| 7321 | EXIT |
| 7322 | expected-exit: e != 0 |
| 7323 | --- |
| 7324 | name: exit-err-4 |
| 7325 | description: |
| 7326 | "set -e" test suite (POSIX) |
| 7327 | stdin: |
| 7328 | set -e |
| 7329 | echo pre |
| 7330 | if true ; then |
| 7331 | false && echo foo |
| 7332 | fi |
| 7333 | echo bar |
| 7334 | expected-stdout: |
| 7335 | pre |
| 7336 | bar |
| 7337 | --- |
| 7338 | name: exit-err-5 |
| 7339 | description: |
| 7340 | "set -e" test suite (POSIX) |
| 7341 | stdin: |
| 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 |
| 7356 | expected-stdout: |
| 7357 | pre |
| 7358 | a b c |
| 7359 | post |
| 7360 | --- |
| 7361 | name: exit-err-6 |
| 7362 | description: |
| 7363 | "set -e" test suite (BSD make) |
| 7364 | category: os:mirbsd |
| 7365 | stdin: |
| 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" |
| 7372 | expected-stdout: |
| 7373 | ===> a |
| 7374 | eins |
| 7375 | *** Error code 42 |
| 7376 | |
| 7377 | Stop in WD/zd/a (line 2 of Makefile). |
| 7378 | --- |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 7379 | name: exit-err-7 |
| 7380 | description: |
| 7381 | "set -e" regression (LP#1104543) |
| 7382 | stdin: |
| 7383 | set -e |
| 7384 | bla() { |
| 7385 | [ -x $PWD/nonexistant ] && $PWD/nonexistant |
| 7386 | } |
| 7387 | echo x |
| 7388 | bla |
| 7389 | echo y$? |
| 7390 | expected-stdout: |
| 7391 | x |
| 7392 | expected-exit: 1 |
| 7393 | --- |
| 7394 | name: exit-err-8 |
| 7395 | description: |
| 7396 | "set -e" regression (Debian #700526) |
| 7397 | stdin: |
| 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 Hughes | 966dd55 | 2016-12-08 15:56:04 -0800 | [diff] [blame] | 7406 | name: exit-err-9 |
| 7407 | description: |
| 7408 | "set -e" versus bang pipelines |
| 7409 | stdin: |
| 7410 | set -e |
| 7411 | ! false | false |
| 7412 | echo 1 ok |
| 7413 | ! false && false |
| 7414 | echo 2 wrong |
| 7415 | expected-stdout: |
| 7416 | 1 ok |
| 7417 | expected-exit: 1 |
| 7418 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7419 | name: exit-enoent-1 |
| 7420 | description: |
| 7421 | SUSv4 says that the shell should exit with 126/127 in some situations |
| 7422 | stdin: |
| 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 . |
| 7433 | expected-stdout: |
| 7434 | 0 0 . |
| 7435 | 1 126 . |
| 7436 | 2 42 . |
| 7437 | 3 126 . |
| 7438 | 4 127 . |
| 7439 | 5 127 . |
| 7440 | --- |
| 7441 | name: exit-eval-1 |
| 7442 | description: |
| 7443 | Check eval vs substitution exit codes (ksh93 alike) |
| 7444 | stdin: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 7445 | (exit 12) |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7446 | eval $(false) |
| 7447 | echo A $? |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 7448 | (exit 12) |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7449 | eval ' $(false)' |
| 7450 | echo B $? |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 7451 | (exit 12) |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7452 | eval " $(false)" |
| 7453 | echo C $? |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 7454 | (exit 12) |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7455 | eval "eval $(false)" |
| 7456 | echo D $? |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 7457 | (exit 12) |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7458 | eval 'eval '"$(false)" |
| 7459 | echo E $? |
| 7460 | IFS="$IFS:" |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 7461 | (exit 12) |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7462 | eval $(echo :; false) |
| 7463 | echo F $? |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 7464 | echo -n "G " |
| 7465 | (exit 12) |
| 7466 | eval 'echo $?' |
| 7467 | echo H $? |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7468 | expected-stdout: |
| 7469 | A 0 |
| 7470 | B 1 |
| 7471 | C 0 |
| 7472 | D 0 |
| 7473 | E 0 |
| 7474 | F 0 |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 7475 | G 12 |
| 7476 | H 0 |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7477 | --- |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 7478 | name: exit-trap-1 |
| 7479 | description: |
| 7480 | Check that "exit" with no arguments behaves SUSv4 conformant. |
| 7481 | stdin: |
| 7482 | trap 'echo hi; exit' EXIT |
| 7483 | exit 9 |
| 7484 | expected-stdout: |
| 7485 | hi |
| 7486 | expected-exit: 9 |
| 7487 | --- |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 7488 | name: exit-trap-2 |
| 7489 | description: |
| 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. |
| 7495 | file-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 |
| 7503 | file-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 |
| 7511 | file-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 |
| 7519 | file-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 |
| 7527 | stdin: |
| 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) . |
| 7566 | expected-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 Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 7622 | name: exit-trap-interactive |
| 7623 | description: |
| 7624 | Check that interactive shell doesn't exit via EXIT trap on syntax error |
| 7625 | arguments: !-i! |
| 7626 | stdin: |
| 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' |
| 7636 | expected-stdout: |
| 7637 | After error 1 |
| 7638 | After error 2 |
| 7639 | Exit trap |
| 7640 | expected-stderr-pattern: |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 7641 | /syntax error: unexpected 'newline'/ |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 7642 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7643 | name: test-stlt-1 |
| 7644 | description: |
| 7645 | Check that test also can handle string1 < string2 etc. |
| 7646 | stdin: |
| 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 |
| 7651 | expected-stdout: |
| 7652 | nein |
| 7653 | ja |
| 7654 | ja |
| 7655 | nein |
| 7656 | expected-stderr-pattern: !/unexpected op/ |
| 7657 | --- |
| 7658 | name: test-precedence-1 |
| 7659 | description: |
| 7660 | Check a weird precedence case (and POSIX echo) |
| 7661 | stdin: |
| 7662 | test \( -f = -f \) |
| 7663 | rv=$? |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 7664 | echo $rv |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7665 | expected-stdout: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 7666 | 0 |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7667 | --- |
| 7668 | name: test-option-1 |
| 7669 | description: |
| 7670 | Test the test -o operator |
| 7671 | stdin: |
| 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) = |
| 7718 | expected-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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 7751 | name: test-varset-1 |
| 7752 | description: |
| 7753 | Test the test -v operator |
| 7754 | stdin: |
| 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 |
| 7781 | expected-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 | --- |
| 7793 | name: test-varset-2 |
| 7794 | description: |
| 7795 | test -v works only on scalars |
| 7796 | stdin: |
| 7797 | [[ -v x[*] ]] |
| 7798 | echo ok |
| 7799 | expected-exit: e != 0 |
| 7800 | expected-stderr-pattern: |
| 7801 | /unexpected '\*'/ |
| 7802 | --- |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 7803 | name: test-stnze-1 |
| 7804 | description: |
| 7805 | Check that the short form [ $x ] works |
| 7806 | stdin: |
| 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 |
| 7834 | expected-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 | --- |
| 7848 | name: test-stnze-2 |
| 7849 | description: |
| 7850 | Check that the short form [[ $x ]] works (ksh93 extension) |
| 7851 | stdin: |
| 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 |
| 7879 | expected-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 | --- |
| 7893 | name: test-numeq |
| 7894 | description: |
| 7895 | Check numeric -eq works (R40d regression); spotted by Martijn Dekker |
| 7896 | stdin: |
| 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' |
| 7915 | expected-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 |
| 7925 | expected-stderr-pattern: |
| 7926 | /bad number/ |
| 7927 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7928 | name: mkshrc-1 |
| 7929 | description: |
| 7930 | Check that ~/.mkshrc works correctly. |
| 7931 | Part 1: verify user environment is not read (internal) |
| 7932 | stdin: |
| 7933 | echo x $FNORD |
| 7934 | expected-stdout: |
| 7935 | x |
| 7936 | --- |
| 7937 | name: mkshrc-2a |
| 7938 | description: |
| 7939 | Check that ~/.mkshrc works correctly. |
| 7940 | Part 2: verify mkshrc is not read (non-interactive shells) |
| 7941 | file-setup: file 644 ".mkshrc" |
| 7942 | FNORD=42 |
| 7943 | env-setup: !HOME=.!ENV=! |
| 7944 | stdin: |
| 7945 | echo x $FNORD |
| 7946 | expected-stdout: |
| 7947 | x |
| 7948 | --- |
| 7949 | name: mkshrc-2b |
| 7950 | description: |
| 7951 | Check that ~/.mkshrc works correctly. |
| 7952 | Part 2: verify mkshrc can be read (interactive shells) |
| 7953 | file-setup: file 644 ".mkshrc" |
| 7954 | FNORD=42 |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 7955 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 7956 | arguments: !-i! |
| 7957 | env-setup: !HOME=.!ENV=!PS1=! |
| 7958 | stdin: |
| 7959 | echo x $FNORD |
| 7960 | expected-stdout: |
| 7961 | x 42 |
| 7962 | expected-stderr-pattern: |
| 7963 | /(# )*/ |
| 7964 | --- |
| 7965 | name: mkshrc-3 |
| 7966 | description: |
| 7967 | Check that ~/.mkshrc works correctly. |
| 7968 | Part 3: verify mkshrc can be turned off |
| 7969 | file-setup: file 644 ".mkshrc" |
| 7970 | FNORD=42 |
| 7971 | env-setup: !HOME=.!ENV=nonexistant! |
| 7972 | stdin: |
| 7973 | echo x $FNORD |
| 7974 | expected-stdout: |
| 7975 | x |
| 7976 | --- |
| 7977 | name: sh-mode-1 |
| 7978 | description: |
| 7979 | Check that sh mode turns braceexpand off |
| 7980 | and that that works correctly |
| 7981 | stdin: |
| 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 |
| 7999 | expected-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 | --- |
| 8012 | name: sh-mode-2a |
| 8013 | description: |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 8014 | Check that posix or sh mode is *not* automatically turned on |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8015 | category: !binsh |
| 8016 | stdin: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 8017 | 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8021 | for shell in {,-}{,k}sh; do |
| 8022 | print -- $shell $(./$shell +l -c \ |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 8023 | '[[ $(set +o) == *"-o "@(sh|posix)@(| *) ]] && echo sh || echo nosh') |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8024 | done |
| 8025 | expected-stdout: |
| 8026 | sh nosh |
| 8027 | ksh nosh |
| 8028 | -sh nosh |
| 8029 | -ksh nosh |
| 8030 | --- |
| 8031 | name: sh-mode-2b |
| 8032 | description: |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 8033 | Check that posix or sh mode *is* automatically turned on |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8034 | category: binsh |
| 8035 | stdin: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 8036 | 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8040 | for shell in {,-}{,k}sh; do |
| 8041 | print -- $shell $(./$shell +l -c \ |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 8042 | '[[ $(set +o) == *"-o "@(sh|posix)@(| *) ]] && echo sh || echo nosh') |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8043 | done |
| 8044 | expected-stdout: |
| 8045 | sh sh |
| 8046 | ksh nosh |
| 8047 | -sh sh |
| 8048 | -ksh nosh |
| 8049 | --- |
| 8050 | name: pipeline-1 |
| 8051 | description: |
| 8052 | pdksh bug: last command of a pipeline is executed in a |
| 8053 | subshell - make sure it still is, scripts depend on it |
| 8054 | file-setup: file 644 "abcx" |
| 8055 | file-setup: file 644 "abcy" |
| 8056 | stdin: |
| 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 * |
| 8067 | expected-stdout: |
| 8068 | abcx abcy |
| 8069 | a |
| 8070 | abcx abcy |
| 8071 | abcx abcy |
| 8072 | a* |
| 8073 | * |
| 8074 | abcx abcy |
| 8075 | --- |
| 8076 | name: pipeline-2 |
| 8077 | description: |
| 8078 | check that co-processes work with TCOMs, TPIPEs and TPARENs |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8079 | category: !nojsig |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8080 | stdin: |
| 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' |
| 8084 | expected-stdout: |
| 8085 | 100 hi |
| 8086 | 200 hi |
| 8087 | 300 hi |
| 8088 | --- |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8089 | name: pipeline-3 |
| 8090 | description: |
| 8091 | Check that PIPESTATUS does what it's supposed to |
| 8092 | stdin: |
| 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) . |
| 8101 | expected-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 Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 8111 | name: pipeline-4 |
| 8112 | description: |
| 8113 | Check that "set -o pipefail" does what it's supposed to |
| 8114 | stdin: |
| 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 Hughes | 737fdce | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 8123 | echo 9 "$("$__progname" -o pipefail -c 'x=$( (exit 23) | (exit 42) | :); echo $?')" . |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 8124 | expected-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 Hughes | 737fdce | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 8133 | 9 42 . |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 8134 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8135 | name: persist-history-1 |
| 8136 | description: |
| 8137 | Check if persistent history saving works |
| 8138 | category: !no-histfile |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8139 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8140 | arguments: !-i! |
| 8141 | env-setup: !ENV=./Env!HISTFILE=hist.file! |
| 8142 | file-setup: file 644 "Env" |
| 8143 | PS1=X |
| 8144 | stdin: |
| 8145 | cat hist.file |
| 8146 | expected-stdout-pattern: |
| 8147 | /cat hist.file/ |
| 8148 | expected-stderr-pattern: |
| 8149 | /^X*$/ |
| 8150 | --- |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8151 | name: typeset-1 |
| 8152 | description: |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 8153 | Check that typeset -g works correctly |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8154 | stdin: |
| 8155 | set -A arrfoo 65 |
| 8156 | foo() { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 8157 | typeset -g -Uui16 arrfoo[*] |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8158 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 8167 | typeset -g -Uui16 arrbar[*] |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8168 | 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]} . |
| 8175 | expected-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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 8185 | name: typeset-2 |
| 8186 | description: |
| 8187 | Check that typeset -p on arrays works correctly |
| 8188 | stdin: |
| 8189 | set -A x -- a b c |
| 8190 | echo = |
| 8191 | typeset -p x |
| 8192 | echo = |
| 8193 | typeset -p x[1] |
| 8194 | expected-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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8203 | name: typeset-padding-1 |
| 8204 | description: |
| 8205 | Check if left/right justification works as per TFM |
| 8206 | stdin: |
| 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>" |
| 8213 | expected-stdout: |
| 8214 | <0hall0 > < 0hall0> <hall0 > <00000hall0> <0000 hallo> |
| 8215 | --- |
| 8216 | name: typeset-padding-2 |
| 8217 | description: |
| 8218 | Check if base-!10 integers are padded right |
| 8219 | stdin: |
| 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>" |
| 8227 | expected-stdout: |
| 8228 | <16#1 > < 16#1> <16#000001> <16#1 > < 16#1> <0000016#1> |
| 8229 | --- |
| 8230 | name: utf8bom-1 |
| 8231 | description: |
| 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) |
| 8236 | category: !os:darwin |
| 8237 | stdin: |
| 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 Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 8246 | export PATH=$(pwd)/foo$PATHSEP$PATH |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8247 | "$__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 |
| 8259 | expected-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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8283 | : ohne |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8284 | --- |
| 8285 | name: utf8bom-2 |
| 8286 | description: |
| 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 Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 8291 | XXX fails when LD_PRELOAD is set with -e and Perl chokes it (ASan) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8292 | need-pass: no |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 8293 | category: !os:cygwin,!os:msys,!os:ultrix,!os:uwin-nt,!smksh |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8294 | env-setup: !FOO=BAR! |
| 8295 | stdin: |
| 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 |
| 8305 | expected-stdout: |
| 8306 | 1 a=/nonexistant{FOO} |
| 8307 | 2 a=/nonexistant{FOO} |
| 8308 | 3 a=BAR |
| 8309 | 4 a=BAR |
| 8310 | expected-stderr-pattern: |
| 8311 | /(Unrecognized character .... ignored at \..t4 line 1)*/ |
| 8312 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8313 | name: utf8opt-1a |
| 8314 | description: |
| 8315 | Check that the utf8-mode flag is not set at non-interactive startup |
| 8316 | category: !os:hpux |
| 8317 | env-setup: !PS1=!PS2=!LC_CTYPE=en_US.UTF-8! |
| 8318 | stdin: |
| 8319 | if [[ $- = *U* ]]; then |
| 8320 | echo is set |
| 8321 | else |
| 8322 | echo is not set |
| 8323 | fi |
| 8324 | expected-stdout: |
| 8325 | is not set |
| 8326 | --- |
| 8327 | name: utf8opt-1b |
| 8328 | description: |
| 8329 | Check that the utf8-mode flag is not set at non-interactive startup |
| 8330 | category: os:hpux |
| 8331 | env-setup: !PS1=!PS2=!LC_CTYPE=en_US.utf8! |
| 8332 | stdin: |
| 8333 | if [[ $- = *U* ]]; then |
| 8334 | echo is set |
| 8335 | else |
| 8336 | echo is not set |
| 8337 | fi |
| 8338 | expected-stdout: |
| 8339 | is not set |
| 8340 | --- |
| 8341 | name: utf8opt-2a |
| 8342 | description: |
| 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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8348 | need-pass: no |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 8349 | category: !os:hpux,!os:msys,!os:os2 |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8350 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8351 | arguments: !-i! |
| 8352 | env-setup: !PS1=!PS2=!LC_CTYPE=en_US.UTF-8! |
| 8353 | stdin: |
| 8354 | if [[ $- = *U* ]]; then |
| 8355 | echo is set |
| 8356 | else |
| 8357 | echo is not set |
| 8358 | fi |
| 8359 | expected-stdout: |
| 8360 | is set |
| 8361 | expected-stderr-pattern: |
| 8362 | /(# )*/ |
| 8363 | --- |
| 8364 | name: utf8opt-2b |
| 8365 | description: |
| 8366 | Check that the utf8-mode flag is set at interactive startup |
| 8367 | Expected failure if -DMKSH_ASSUME_UTF8=0 |
| 8368 | category: os:hpux |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8369 | need-ctty: yes |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8370 | arguments: !-i! |
| 8371 | env-setup: !PS1=!PS2=!LC_CTYPE=en_US.utf8! |
| 8372 | stdin: |
| 8373 | if [[ $- = *U* ]]; then |
| 8374 | echo is set |
| 8375 | else |
| 8376 | echo is not set |
| 8377 | fi |
| 8378 | expected-stdout: |
| 8379 | is set |
| 8380 | expected-stderr-pattern: |
| 8381 | /(# )*/ |
| 8382 | --- |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8383 | name: utf8opt-3a |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8384 | description: |
| 8385 | Ensure ±U on the command line is honoured |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8386 | (these two tests may pass falsely depending on CPPFLAGS) |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8387 | stdin: |
| 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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8392 | echo $((++i)) done |
| 8393 | expected-stdout: |
| 8394 | 1 on |
| 8395 | 2 off |
| 8396 | 3 done |
| 8397 | --- |
| 8398 | name: utf8opt-3b |
| 8399 | description: |
| 8400 | Ensure ±U on the command line is honoured, interactive shells |
| 8401 | need-ctty: yes |
| 8402 | stdin: |
| 8403 | export i=0 |
| 8404 | code='if [[ $- = *U* ]]; then echo $i on; else echo $i off; fi' |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8405 | let i++; "$__progname" -U -ic "$code" |
| 8406 | let i++; "$__progname" +U -ic "$code" |
| 8407 | echo $((++i)) done |
| 8408 | expected-stdout: |
| 8409 | 1 on |
| 8410 | 2 off |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8411 | 3 done |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8412 | --- |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 8413 | name: utf8bug-1 |
| 8414 | description: |
| 8415 | Ensure trailing combining characters are not lost |
| 8416 | stdin: |
| 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>" |
| 8429 | expected-stdout: |
| 8430 | <eaÌ> |
| 8431 | <eaÌ> |
| 8432 | <eaÌb> |
| 8433 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8434 | name: aliases-1 |
| 8435 | description: |
| 8436 | Check if built-in shell aliases are okay |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8437 | stdin: |
| 8438 | alias |
| 8439 | typeset -f |
| 8440 | expected-stdout: |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 8441 | 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8449 | nohup='nohup ' |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 8450 | r='\\builtin fc -e -' |
| 8451 | type='\\builtin whence -v' |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8452 | --- |
| 8453 | name: aliases-2b |
| 8454 | description: |
| 8455 | Check if âset -o shâ does not influence built-in aliases |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8456 | arguments: !-o!sh! |
| 8457 | stdin: |
| 8458 | alias |
| 8459 | typeset -f |
| 8460 | expected-stdout: |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 8461 | 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8469 | nohup='nohup ' |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 8470 | r='\\builtin fc -e -' |
| 8471 | type='\\builtin whence -v' |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8472 | --- |
| 8473 | name: aliases-3b |
| 8474 | description: |
| 8475 | Check if running as sh does not influence built-in aliases |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8476 | stdin: |
| 8477 | cp "$__progname" sh |
| 8478 | ./sh -c 'alias; typeset -f' |
| 8479 | rm -f sh |
| 8480 | expected-stdout: |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 8481 | 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8489 | nohup='nohup ' |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 8490 | r='\\builtin fc -e -' |
| 8491 | type='\\builtin whence -v' |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8492 | --- |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 8493 | name: aliases-cmdline |
| 8494 | description: |
| 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. |
| 8499 | stdin: |
| 8500 | "$__progname" -c $'alias a="echo OK"\na' |
| 8501 | expected-stdout: |
| 8502 | OK |
| 8503 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8504 | name: aliases-funcdef-1 |
| 8505 | description: |
| 8506 | Check if POSIX functions take precedences over aliases |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 8507 | stdin: |
| 8508 | alias foo='echo makro' |
| 8509 | foo() { |
| 8510 | echo funktion |
| 8511 | } |
| 8512 | foo |
| 8513 | expected-stdout: |
| 8514 | makro |
| 8515 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8516 | name: aliases-funcdef-2 |
| 8517 | description: |
| 8518 | Check if POSIX functions take precedences over aliases |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 8519 | stdin: |
| 8520 | alias foo='echo makro' |
| 8521 | foo () { |
| 8522 | echo funktion |
| 8523 | } |
| 8524 | foo |
| 8525 | expected-stdout: |
| 8526 | makro |
| 8527 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8528 | name: aliases-funcdef-3 |
| 8529 | description: |
| 8530 | Check if aliases take precedences over Korn functions |
| 8531 | stdin: |
| 8532 | alias foo='echo makro' |
| 8533 | function foo { |
| 8534 | echo funktion |
| 8535 | } |
| 8536 | foo |
| 8537 | expected-stdout: |
| 8538 | makro |
| 8539 | --- |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8540 | name: aliases-funcdef-4 |
| 8541 | description: |
| 8542 | Functions should only take over if actually being defined |
| 8543 | stdin: |
| 8544 | alias local |
| 8545 | :|| local() { :; } |
| 8546 | alias local |
| 8547 | expected-stdout: |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 8548 | local='\\builtin typeset' |
| 8549 | local='\\builtin typeset' |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8550 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8551 | name: arrays-1 |
| 8552 | description: |
| 8553 | Check if Korn Shell arrays work as expected |
| 8554 | stdin: |
| 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]}|" |
| 8558 | expected-stdout: |
| 8559 | 5|a|$v|c d|$v|b| |
| 8560 | --- |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8561 | name: arrays-2a |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8562 | description: |
| 8563 | Check if bash-style arrays work as expected |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8564 | stdin: |
| 8565 | v="c d" |
| 8566 | foo=(a \$v "$v" '$v' b) |
| 8567 | echo "${#foo[*]}|${foo[0]}|${foo[1]}|${foo[2]}|${foo[3]}|${foo[4]}|" |
| 8568 | expected-stdout: |
| 8569 | 5|a|$v|c d|$v|b| |
| 8570 | --- |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8571 | name: arrays-2b |
| 8572 | description: |
| 8573 | Check if bash-style arrays work as expected, with newlines |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8574 | stdin: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 8575 | print '#!'"$__progname"'\nfor x in "$@"; do print -nr -- "$x|"; done' >pfp |
| 8576 | chmod +x pfp |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8577 | test -n "$ZSH_VERSION" && setopt KSH_ARRAYS |
| 8578 | v="e f" |
| 8579 | foo=(a |
| 8580 | bc |
| 8581 | d \$v "$v" '$v' g |
| 8582 | ) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 8583 | ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8584 | foo=(a\ |
| 8585 | bc |
| 8586 | d \$v "$v" '$v' g |
| 8587 | ) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 8588 | ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8589 | foo=(a\ |
| 8590 | bc\\ |
| 8591 | d \$v "$v" '$v' |
| 8592 | g) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 8593 | ./pfp "${#foo[*]}" "${foo[0]}" "${foo[1]}" "${foo[2]}" "${foo[3]}" "${foo[4]}" "${foo[5]}" "${foo[6]}"; echo |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8594 | expected-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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8599 | name: arrays-3 |
| 8600 | description: |
| 8601 | Check if array bounds are uint32_t |
| 8602 | stdin: |
| 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[*]} |
| 8609 | expected-stdout: |
| 8610 | a b c d e |
| 8611 | f g a b c d e f |
| 8612 | --- |
| 8613 | name: arrays-4 |
| 8614 | description: |
| 8615 | Check if Korn Shell arrays with specified indices work as expected |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8616 | stdin: |
| 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 Hughes | 737fdce | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 8620 | # 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8624 | expected-stdout: |
Elliott Hughes | 737fdce | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 8625 | 5|[1]=$v|[2]=c d|[4]=$v|[0]=a|[5]=b|| |
| 8626 | <[5]=meh><> |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8627 | --- |
| 8628 | name: arrays-5 |
| 8629 | description: |
| 8630 | Check if bash-style arrays with specified indices work as expected |
Elliott Hughes | 737fdce | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 8631 | (taken out temporarily to fix arrays-4; see also arrays-9a comment) |
| 8632 | category: disabled |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8633 | stdin: |
| 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 Hughes | 737fdce | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 8640 | # 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8646 | expected-stdout: |
| 8647 | 5|a|$v|c d||$v|b| |
| 8648 | k= 128 129 130 . |
| 8649 | v= foo bar baz . |
Elliott Hughes | 737fdce | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 8650 | <><blah> |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8651 | --- |
| 8652 | name: arrays-6 |
| 8653 | description: |
| 8654 | Check if we can get the array keys (indices) for indexed arrays, |
| 8655 | Korn shell style |
| 8656 | stdin: |
| 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 |
| 8679 | expected-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 | --- |
| 8695 | name: arrays-7 |
| 8696 | description: |
| 8697 | Check if we can get the array keys (indices) for indexed arrays, |
| 8698 | Korn shell style, in some corner cases |
| 8699 | stdin: |
| 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]} |
| 8711 | expected-stdout: |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8712 | !arz: arz |
Elliott Hughes | 737fdce | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 8713 | !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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 8721 | --- |
| 8722 | name: arrays-8 |
| 8723 | description: |
| 8724 | Check some behavioural rules for arrays. |
| 8725 | stdin: |
| 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[*]} . |
| 8787 | expected-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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8805 | name: arrays-9a |
| 8806 | description: |
| 8807 | Check that we can concatenate arrays |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8808 | stdin: |
| 8809 | unset foo; foo=(bar); foo+=(baz); echo 1 ${!foo[*]} : ${foo[*]} . |
| 8810 | unset foo; foo=(foo bar); foo+=(baz); echo 2 ${!foo[*]} : ${foo[*]} . |
Elliott Hughes | 737fdce | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 8811 | # unset foo; foo=([2]=foo [0]=bar); foo+=(baz [5]=quux); echo 3 ${!foo[*]} : ${foo[*]} . |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8812 | expected-stdout: |
| 8813 | 1 0 1 : bar baz . |
| 8814 | 2 0 1 2 : foo bar baz . |
Elliott Hughes | 737fdce | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 8815 | # 3 0 2 3 5 : bar foo baz quux . |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 8816 | --- |
| 8817 | name: arrays-9b |
| 8818 | description: |
| 8819 | Check that we can concatenate parameters too |
| 8820 | stdin: |
| 8821 | unset foo; foo=bar; foo+=baz; echo 1 $foo . |
| 8822 | unset foo; typeset -i16 foo=10; foo+=20; echo 2 $foo . |
| 8823 | expected-stdout: |
| 8824 | 1 barbaz . |
| 8825 | 2 16#a20 . |
| 8826 | --- |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 8827 | name: arrassign-basic |
| 8828 | description: |
| 8829 | Check basic whitespace conserving properties of wdarrassign |
| 8830 | stdin: |
| 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]}:" |
| 8843 | expected-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 | --- |
| 8849 | name: arrassign-fnc-none |
| 8850 | description: |
| 8851 | Check locality of array access inside a function |
| 8852 | stdin: |
| 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]}:" |
| 8878 | expected-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 | --- |
| 8890 | name: arrassign-fnc-local |
| 8891 | description: |
| 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) |
| 8895 | stdin: |
| 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]}:" |
| 8939 | expected-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 | --- |
| 8956 | name: arrassign-fnc-global |
| 8957 | description: |
| 8958 | Check locality of array access inside a function |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 8959 | with the bash4/mksh/yash/zsh typeset -g keyword |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 8960 | stdin: |
| 8961 | function fn { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 8962 | typeset -g x |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 8963 | x+=(f) |
| 8964 | echo ".fn:${x[0]}.${x[1]}.${x[2]}.${x[3]}:" |
| 8965 | } |
| 8966 | function rfn { |
| 8967 | set -A y |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 8968 | typeset -g y |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 8969 | y+=(f) |
| 8970 | echo ".rfn:${y[0]}.${y[1]}.${y[2]}.${y[3]}:" |
| 8971 | } |
| 8972 | function fnr { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 8973 | typeset -g z |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 8974 | 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]}:" |
| 8996 | expected-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 | --- |
| 9013 | name: strassign-fnc-none |
| 9014 | description: |
| 9015 | Check locality of string access inside a function |
| 9016 | stdin: |
| 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:" |
| 9038 | expected-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 | --- |
| 9050 | name: strassign-fnc-local |
| 9051 | description: |
| 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) |
| 9055 | stdin: |
| 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:" |
| 9091 | expected-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 | --- |
| 9108 | name: strassign-fnc-global |
| 9109 | description: |
| 9110 | Check locality of string access inside a function |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 9111 | with the bash4/mksh/yash/zsh typeset -g keyword |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 9112 | stdin: |
| 9113 | function fn { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 9114 | typeset -g x |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 9115 | x+=f |
| 9116 | echo ".fn:$x:" |
| 9117 | } |
| 9118 | function rfn { |
| 9119 | y= |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 9120 | typeset -g y |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 9121 | y+=f |
| 9122 | echo ".rfn:$y:" |
| 9123 | } |
| 9124 | function fnr { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 9125 | typeset -g z |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 9126 | 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:" |
| 9148 | expected-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 Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 9165 | name: unset-fnc-local-ksh |
| 9166 | description: |
| 9167 | Check that âunsetâ removes a previous âlocalâ |
| 9168 | (ksh93 syntax compatible version); apparently, |
| 9169 | there are shells which fail this? |
| 9170 | stdin: |
| 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 |
| 9186 | expected-stdout: |
| 9187 | before: o |
| 9188 | f0: o |
| 9189 | f1: |
| 9190 | f2: fa |
| 9191 | f3: o |
| 9192 | f4: fb |
| 9193 | after: fb |
| 9194 | --- |
| 9195 | name: unset-fnc-local-sh |
| 9196 | description: |
| 9197 | Check that âunsetâ removes a previous âlocalâ |
| 9198 | (Debian Policy §10.4 sh version); apparently, |
| 9199 | there are shells which fail this? |
| 9200 | stdin: |
| 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 |
| 9216 | expected-stdout: |
| 9217 | before: o |
| 9218 | f0: o |
| 9219 | f1: |
| 9220 | f2: fa |
| 9221 | f3: o |
| 9222 | f4: fb |
| 9223 | after: fb |
| 9224 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9225 | name: varexpand-substr-1 |
| 9226 | description: |
| 9227 | Check if bash-style substring expansion works |
| 9228 | when using positive numerics |
| 9229 | stdin: |
| 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 |
| 9240 | expected-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 | --- |
| 9249 | name: varexpand-substr-2 |
| 9250 | description: |
| 9251 | Check if bash-style substring expansion works |
| 9252 | when using negative numerics or expressions |
| 9253 | stdin: |
| 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 |
| 9262 | expected-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 | --- |
| 9268 | name: varexpand-substr-3 |
| 9269 | description: |
| 9270 | Check that some things that work in bash fail. |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 9271 | This is by design. Oh and vice versa, nowadays. |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9272 | stdin: |
| 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 Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 9279 | # next fails only in bash |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9280 | "$__progname" -c 'x=abcdef;y=123;echo ${x:${y:2:1}:2}' >/dev/null 2>&1; echo $? |
| 9281 | expected-stdout: |
| 9282 | vcdefghix |
| 9283 | wcdefghix |
| 9284 | zabcdefghix |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 9285 | 0 |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9286 | expected-stderr-pattern: |
| 9287 | /x:n.*bad substitution.*\n.*bad substitution/ |
| 9288 | --- |
| 9289 | name: varexpand-substr-4 |
| 9290 | description: |
| 9291 | Check corner cases for substring expansion |
| 9292 | stdin: |
| 9293 | x=abcdefghi |
| 9294 | integer y=2 |
| 9295 | echo a ${x:(y == 1 ? 2 : 3):4} a |
| 9296 | expected-stdout: |
| 9297 | a defg a |
| 9298 | --- |
| 9299 | name: varexpand-substr-5A |
| 9300 | description: |
| 9301 | Check that substring expansions work on characters |
| 9302 | stdin: |
| 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 |
| 9309 | expected-stdout: |
| 9310 | a m h a |
| 9311 | b mä äh b |
| 9312 | c ä ä c |
| 9313 | d 4 d |
| 9314 | --- |
| 9315 | name: varexpand-substr-5W |
| 9316 | description: |
| 9317 | Check that substring expansions work on characters |
| 9318 | stdin: |
| 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 |
| 9325 | expected-stdout: |
| 9326 | a m h a |
| 9327 | b mä äh b |
| 9328 | c ä ä c |
| 9329 | d 3 d |
| 9330 | --- |
| 9331 | name: varexpand-substr-6 |
| 9332 | description: |
| 9333 | Check that string substitution works correctly |
| 9334 | stdin: |
| 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} |
| 9342 | expected-stdout: |
| 9343 | a we |
| 9344 | b we |
| 9345 | c we |
| 9346 | d we |
| 9347 | --- |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 9348 | name: varexpand-special-hash |
| 9349 | description: |
| 9350 | Check special ${var@x} expansion for x=hash |
| 9351 | stdin: |
| 9352 | typeset -i8 foo=10 |
| 9353 | bar=baz |
| 9354 | unset baz |
| 9355 | print ${foo@#} ${bar@#} ${baz@#} . |
| 9356 | expected-stdout: |
Elliott Hughes | 737fdce | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 9357 | 9B15FBFB CFBDD32B 00000000 . |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 9358 | --- |
| 9359 | name: varexpand-special-quote |
| 9360 | description: |
| 9361 | Check special ${var@Q} expansion for quoted strings |
| 9362 | stdin: |
| 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 |
| 9373 | expected-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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 9380 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9381 | name: varexpand-null-1 |
| 9382 | description: |
| 9383 | Ensure empty strings expand emptily |
| 9384 | stdin: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 9385 | 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9392 | expected-stdout: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 9393 | s . S |
| 9394 | t . T |
| 9395 | r . R |
| 9396 | q |
| 9397 | s . S |
| 9398 | t . T |
| 9399 | r . R |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9400 | --- |
| 9401 | name: varexpand-null-2 |
| 9402 | description: |
| 9403 | Ensure empty strings, when quoted, are expanded as empty strings |
| 9404 | stdin: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 9405 | 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9408 | echo . |
| 9409 | expected-stdout: |
| 9410 | <1> <> <2> <> <+> <> <3> <> <+> <> . |
| 9411 | --- |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 9412 | name: varexpand-null-3 |
| 9413 | description: |
| 9414 | Ensure concatenating behaviour matches other shells |
Elliott Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 9415 | stdin: |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 9416 | showargs() { for s_arg in "$@"; do echo -n "<$s_arg> "; done; echo .; } |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 9417 | showargs 0 ""$@ |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 9418 | 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 Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 9436 | expected-stdout: |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 9437 | <0> <> . |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 9438 | <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 Hughes | 56b517d | 2014-10-06 11:30:44 -0700 | [diff] [blame] | 9452 | --- |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 9453 | name: varexpand-funny-chars |
| 9454 | description: |
| 9455 | Check some characters |
| 9456 | XXX \uEF80 is asymmetric, possibly buggy so we donât check this |
| 9457 | stdin: |
| 9458 | x=$'<\x00>'; typeset -p x |
| 9459 | x=$'<\x01>'; typeset -p x |
| 9460 | x=$'<\u0000>'; typeset -p x |
| 9461 | x=$'<\u0001>'; typeset -p x |
| 9462 | expected-stdout: |
| 9463 | typeset x='<' |
| 9464 | typeset x=$'<\001>' |
| 9465 | typeset x='<' |
| 9466 | typeset x=$'<\001>' |
| 9467 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9468 | name: print-funny-chars |
| 9469 | description: |
| 9470 | Check print builtin's capability to output designated characters |
| 9471 | stdin: |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 9472 | { |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 9489 | (( pos )) && print -r -- "$dasc|" |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 9490 | 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 9506 | (( hv == 2147483647 )) || print -r -- "$dasc|" |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 9507 | } |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9508 | expected-stdout: |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 9509 | 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9511 | --- |
| 9512 | name: print-bksl-c |
| 9513 | description: |
| 9514 | Check print builtin's \c escape |
| 9515 | stdin: |
| 9516 | print '\ca'; print b |
| 9517 | expected-stdout: |
| 9518 | ab |
| 9519 | --- |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 9520 | name: print-cr |
| 9521 | description: |
| 9522 | Check that CR+LF is not collapsed into LF as some MSYS shells wrongly do |
| 9523 | stdin: |
| 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 |
| 9534 | expected-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 Hughes | b27ce95 | 2015-04-21 13:39:18 -0700 | [diff] [blame] | 9542 | name: print-crlf |
| 9543 | description: |
| 9544 | Check that CR+LF is shown and read as-is |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 9545 | category: shell:textmode-no |
Elliott Hughes | b27ce95 | 2015-04-21 13:39:18 -0700 | [diff] [blame] | 9546 | stdin: |
| 9547 | cat >foo <<-'EOF' |
| 9548 | x='bar
|
| 9549 | ' #
|
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 9550 | echo .${#x} #
|
Elliott Hughes | b27ce95 | 2015-04-21 13:39:18 -0700 | [diff] [blame] | 9551 | 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 |
| 9561 | expected-stdout: |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 9562 | [.5 |
| 9563 | <bar
|
Elliott Hughes | b27ce95 | 2015-04-21 13:39:18 -0700 | [diff] [blame] | 9564 | >] |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 9565 | {.5} |
Elliott Hughes | b27ce95 | 2015-04-21 13:39:18 -0700 | [diff] [blame] | 9566 | {<bar
} |
| 9567 | --- |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 9568 | name: print-crlf-textmode |
| 9569 | description: |
| 9570 | Check that CR+LF is treated as newline |
| 9571 | category: shell:textmode-yes |
| 9572 | stdin: |
| 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 |
| 9587 | expected-stdout: |
| 9588 | [.4 |
| 9589 | <bar |
| 9590 | >] |
| 9591 | {.4} |
| 9592 | {<bar} |
| 9593 | --- |
Elliott Hughes | b27ce95 | 2015-04-21 13:39:18 -0700 | [diff] [blame] | 9594 | name: print-lf |
| 9595 | description: |
| 9596 | Check that LF-only is shown and read as-is |
| 9597 | stdin: |
| 9598 | cat >foo <<-'EOF' |
| 9599 | x='bar |
| 9600 | ' # |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 9601 | echo .${#x} # |
Elliott Hughes | b27ce95 | 2015-04-21 13:39:18 -0700 | [diff] [blame] | 9602 | 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 |
| 9612 | expected-stdout: |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 9613 | [.4 |
| 9614 | <bar |
Elliott Hughes | b27ce95 | 2015-04-21 13:39:18 -0700 | [diff] [blame] | 9615 | >] |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 9616 | {.4} |
Elliott Hughes | b27ce95 | 2015-04-21 13:39:18 -0700 | [diff] [blame] | 9617 | {<bar} |
| 9618 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9619 | name: print-nul-chars |
| 9620 | description: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 9621 | Check handling of NUL characters for print and COMSUB |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9622 | stdin: |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9623 | x=$(print '<\0>') |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 9624 | print $(($(print '<\0>' | wc -c))) $(($(print "$x" | wc -c))) \ |
| 9625 | ${#x} "$x" '<\0>' |
| 9626 | expected-stdout-pattern: |
| 9627 | /^4 3 2 <> <\0>$/ |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9628 | --- |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 9629 | name: print-array |
| 9630 | description: |
| 9631 | Check that print -A works as expected |
| 9632 | stdin: |
| 9633 | print -An 0x20AC 0xC3 0xBC 8#101 |
| 9634 | set -U |
| 9635 | print -A 0x20AC 0xC3 0xBC 8#102 |
| 9636 | expected-stdout: |
| 9637 | ¬Ã¼Aâ¬Ã¼B |
| 9638 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9639 | name: print-escapes |
| 9640 | description: |
| 9641 | Check backslash expansion by the print builtin |
| 9642 | stdin: |
| 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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 9648 | # integer-base-one-3As |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9649 | typeset -Uui16 -Z11 pos=0 |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 9650 | typeset -Uui16 -Z5 hv=2147483647 |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9651 | 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 9659 | (( pos )) && print -r -- "$dasc|" |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9660 | 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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 9673 | while (( pos & 15 )); do |
| 9674 | print -n ' ' |
| 9675 | (( (pos++ & 15) == 7 )) && print -n -- '- ' |
| 9676 | done |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 9677 | (( hv == 2147483647 )) || print -r -- "$dasc|" |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9678 | } |
| 9679 | expected-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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 9686 | 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9693 | --- |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 9694 | name: dollar-doublequoted-strings |
| 9695 | description: |
| 9696 | Check that a $ preceding "â¦" is ignored |
| 9697 | stdin: |
| 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 |
| 9705 | expected-stdout: |
| 9706 | Localise me! |
| 9707 | Me too! |
| 9708 | I do not take a $V for a V! |
| 9709 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9710 | name: dollar-quoted-strings |
| 9711 | description: |
| 9712 | Check backslash expansion by $'â¦' strings |
| 9713 | stdin: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 9714 | 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9717 | $'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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 9723 | # integer-base-one-3As |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9724 | typeset -Uui16 -Z11 pos=0 |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 9725 | typeset -Uui16 -Z5 hv=2147483647 |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9726 | 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 9734 | (( pos )) && print -r -- "$dasc|" |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9735 | 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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 9748 | while (( pos & 15 )); do |
| 9749 | print -n ' ' |
| 9750 | (( (pos++ & 15) == 7 )) && print -n -- '- ' |
| 9751 | done |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 9752 | (( hv == 2147483647 )) || print -r -- "$dasc|" |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9753 | } |
| 9754 | expected-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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 9765 | name: dollar-quotes-in-heredocs-strings |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9766 | description: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 9767 | 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9770 | stdin: |
| 9771 | cat <<EOF |
| 9772 | dollar = strchr(s, '$'); /* ' */ |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 9773 | foo " bar \" baz |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9774 | EOF |
| 9775 | cat <<$'a\tb' |
| 9776 | a\tb |
| 9777 | a b |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9778 | cat <<<"dollar = strchr(s, '$'); /* ' */" |
| 9779 | cat <<<'dollar = strchr(s, '\''$'\''); /* '\'' */' |
| 9780 | x="dollar = strchr(s, '$'); /* ' */" |
| 9781 | cat <<<"$x" |
| 9782 | cat <<<$'a\E[0m\tb' |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 9783 | 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9797 | expected-stdout: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 9798 | dollar = strchr(s, '$'); /* ' */ |
| 9799 | foo " bar \" baz |
| 9800 | a\tb |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9801 | dollar = strchr(s, '$'); /* ' */ |
| 9802 | dollar = strchr(s, '$'); /* ' */ |
| 9803 | dollar = strchr(s, '$'); /* ' */ |
| 9804 | a[0m b |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 9805 | 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9814 | --- |
| 9815 | name: dot-needs-argument |
| 9816 | description: |
| 9817 | check Debian #415167 solution: '.' without arguments should fail |
| 9818 | stdin: |
| 9819 | "$__progname" -c . |
| 9820 | "$__progname" -c source |
| 9821 | expected-exit: e != 0 |
| 9822 | expected-stderr-pattern: |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 9823 | /\.: missing argument.*\n.*source: missing argument/ |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9824 | --- |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 9825 | name: dot-errorlevel |
| 9826 | description: |
| 9827 | Ensure dot resets $? |
| 9828 | stdin: |
| 9829 | :>dotfile |
| 9830 | (exit 42) |
| 9831 | . ./dotfile |
| 9832 | echo 1 $? . |
| 9833 | expected-stdout: |
| 9834 | 1 0 . |
| 9835 | --- |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 9836 | name: alias-function-no-conflict |
| 9837 | description: |
| 9838 | make aliases not conflict with function definitions |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 9839 | stdin: |
| 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 |
| 9865 | expected-stdout: |
| 9866 | bar |
| 9867 | bar |
| 9868 | bar |
| 9869 | bar |
| 9870 | bar |
| 9871 | bfn |
| 9872 | bal |
| 9873 | bfn |
| 9874 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9875 | name: bash-function-parens |
| 9876 | description: |
| 9877 | ensure the keyword function is ignored when preceding |
| 9878 | POSIX style function declarations (bashism) |
| 9879 | stdin: |
| 9880 | mk() { |
| 9881 | echo '#!'"$__progname" |
| 9882 | echo "$1 {" |
| 9883 | echo ' echo "bar='\''$0'\'\" |
| 9884 | echo '}' |
Elliott Hughes | b27ce95 | 2015-04-21 13:39:18 -0700 | [diff] [blame] | 9885 | print -r -- "${2:-foo}" |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9886 | } |
| 9887 | mk 'function foo' >f-korn |
| 9888 | mk 'foo ()' >f-dash |
| 9889 | mk 'function foo ()' >f-bash |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 9890 | print '#!'"$__progname"'\nprint -r -- "${0%/f-argh}"' >f-argh |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9891 | chmod +x f-* |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 9892 | 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9896 | expected-stdout: |
| 9897 | korn: bar='foo' |
| 9898 | dash: bar='./f-dash' |
| 9899 | bash: bar='./f-bash' |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 9900 | --- |
| 9901 | name: integer-base-one-1 |
| 9902 | description: |
| 9903 | check if the use of fake integer base 1 works |
| 9904 | stdin: |
| 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#}>" |
| 9922 | expected-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 | --- |
| 9930 | name: integer-base-one-2a |
| 9931 | description: |
| 9932 | check if the use of fake integer base 1 stops at correct characters |
| 9933 | stdin: |
| 9934 | set -U |
| 9935 | integer x=1#foo |
| 9936 | echo /$x/ |
| 9937 | expected-stderr-pattern: |
| 9938 | /1#foo: unexpected 'oo'/ |
| 9939 | expected-exit: e != 0 |
| 9940 | --- |
| 9941 | name: integer-base-one-2b |
| 9942 | description: |
| 9943 | check if the use of fake integer base 1 stops at correct characters |
| 9944 | stdin: |
| 9945 | set -U |
| 9946 | integer x=1#À |
| 9947 | echo /$x/ |
| 9948 | expected-stderr-pattern: |
| 9949 | /1#À: unexpected ''/ |
| 9950 | expected-exit: e != 0 |
| 9951 | --- |
| 9952 | name: integer-base-one-2c1 |
| 9953 | description: |
| 9954 | check if the use of fake integer base 1 stops at correct characters |
| 9955 | stdin: |
| 9956 | set -U |
| 9957 | integer x=1#⦠|
| 9958 | echo /$x/ |
| 9959 | expected-stdout: |
| 9960 | /1#â¦/ |
| 9961 | --- |
| 9962 | name: integer-base-one-2c2 |
| 9963 | description: |
| 9964 | check if the use of fake integer base 1 stops at correct characters |
| 9965 | stdin: |
| 9966 | set +U |
| 9967 | integer x=1#⦠|
| 9968 | echo /$x/ |
| 9969 | expected-stderr-pattern: |
| 9970 | /1#â¦: unexpected ''/ |
| 9971 | expected-exit: e != 0 |
| 9972 | --- |
| 9973 | name: integer-base-one-2d1 |
| 9974 | description: |
| 9975 | check if the use of fake integer base 1 handles octets okay |
| 9976 | stdin: |
| 9977 | set -U |
| 9978 | typeset -i16 x=1#ÿ |
| 9979 | echo /$x/ # invalid utf-8 |
| 9980 | expected-stdout: |
| 9981 | /16#efff/ |
| 9982 | --- |
| 9983 | name: integer-base-one-2d2 |
| 9984 | description: |
| 9985 | check if the use of fake integer base 1 handles octets |
| 9986 | stdin: |
| 9987 | set -U |
| 9988 | typeset -i16 x=1#Â |
| 9989 | echo /$x/ # invalid 2-byte |
| 9990 | expected-stdout: |
| 9991 | /16#efc2/ |
| 9992 | --- |
| 9993 | name: integer-base-one-2d3 |
| 9994 | description: |
| 9995 | check if the use of fake integer base 1 handles octets |
| 9996 | stdin: |
| 9997 | set -U |
| 9998 | typeset -i16 x=1#ï |
| 9999 | echo /$x/ # invalid 2-byte |
| 10000 | expected-stdout: |
| 10001 | /16#efef/ |
| 10002 | --- |
| 10003 | name: integer-base-one-2d4 |
| 10004 | description: |
| 10005 | check if the use of fake integer base 1 stops at invalid input |
| 10006 | stdin: |
| 10007 | set -U |
| 10008 | typeset -i16 x=1#ï¿À |
| 10009 | echo /$x/ # invalid 3-byte |
| 10010 | expected-stderr-pattern: |
| 10011 | /1#ï¿À: unexpected '¿'/ |
| 10012 | expected-exit: e != 0 |
| 10013 | --- |
| 10014 | name: integer-base-one-2d5 |
| 10015 | description: |
| 10016 | check if the use of fake integer base 1 stops at invalid input |
| 10017 | stdin: |
| 10018 | set -U |
| 10019 | typeset -i16 x=1#À |
| 10020 | echo /$x/ # non-minimalistic |
| 10021 | expected-stderr-pattern: |
| 10022 | /1#À: unexpected ''/ |
| 10023 | expected-exit: e != 0 |
| 10024 | --- |
| 10025 | name: integer-base-one-2d6 |
| 10026 | description: |
| 10027 | check if the use of fake integer base 1 stops at invalid input |
| 10028 | stdin: |
| 10029 | set -U |
| 10030 | typeset -i16 x=1#à |
| 10031 | echo /$x/ # non-minimalistic |
| 10032 | expected-stderr-pattern: |
| 10033 | /1#à: unexpected ''/ |
| 10034 | expected-exit: e != 0 |
| 10035 | --- |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10036 | name: integer-base-one-3As |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10037 | description: |
| 10038 | some sample code for hexdumping |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10039 | not NUL safe; input lines must be NL terminated |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10040 | stdin: |
| 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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10049 | print '\0z' |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10050 | } | { |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10051 | # integer-base-one-3As |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10052 | typeset -Uui16 -Z11 pos=0 |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10053 | typeset -Uui16 -Z5 hv=2147483647 |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10054 | 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 10062 | (( pos )) && print -r -- "$dasc|" |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10063 | 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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10076 | while (( pos & 15 )); do |
| 10077 | print -n ' ' |
| 10078 | (( (pos++ & 15) == 7 )) && print -n -- '- ' |
| 10079 | done |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 10080 | (( hv == 2147483647 )) || print -r -- "$dasc|" |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10081 | } |
| 10082 | expected-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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10101 | 00000120 FF 7A 0A - |.z.| |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10102 | --- |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10103 | name: integer-base-one-3Ws |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10104 | description: |
| 10105 | some sample code for hexdumping Unicode |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10106 | not NUL safe; input lines must be NL terminated |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10107 | stdin: |
| 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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10124 | print '\0z' # embedded NUL |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10125 | } | { |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10126 | # integer-base-one-3Ws |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10127 | 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 10150 | (( pos )) && print -r -- "$dasc|" |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10151 | 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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10161 | while (( pos & 7 )); do |
| 10162 | print -n ' ' |
| 10163 | (( (pos++ & 7) == 3 )) && print -n -- '- ' |
| 10164 | done |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 10165 | (( hv == 2147483647 )) || print -r -- "$dasc|" |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10166 | } |
| 10167 | expected-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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10205 | 00000128 EFBE EFEF EFBF EFBF - 000A 007A 000A |����.z.| |
| 10206 | --- |
| 10207 | name: integer-base-one-3Ar |
| 10208 | description: |
| 10209 | some sample code for hexdumping; NUL and binary safe |
| 10210 | stdin: |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 10231 | (( pos )) && print -r -- "$dasc|" |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10232 | 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 10248 | (( hv == 2147483647 )) || print -r -- "$dasc|" |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10249 | } |
| 10250 | expected-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 | --- |
| 10271 | name: integer-base-one-3Wr |
| 10272 | description: |
| 10273 | some sample code for hexdumping Unicode; NUL and binary safe |
| 10274 | stdin: |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 10314 | (( pos )) && print -r -- "$dasc|" |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10315 | 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 10328 | (( hv == 2147483647 )) || print -r -- "$dasc|" |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10329 | } |
| 10330 | expected-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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10369 | --- |
| 10370 | name: integer-base-one-4 |
| 10371 | description: |
| 10372 | Check if ksh93-style base-one integers work |
| 10373 | category: !smksh |
| 10374 | stdin: |
| 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)) |
| 10383 | expected-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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10391 | name: integer-base-one-5A |
| 10392 | description: |
| 10393 | Check to see that weâre NUL and Unicode safe |
| 10394 | stdin: |
| 10395 | set +U |
| 10396 | print 'a\0b\xfdz' >x |
| 10397 | read -a y <x |
| 10398 | set -U |
| 10399 | typeset -Uui16 y |
| 10400 | print ${y[*]} . |
| 10401 | expected-stdout: |
| 10402 | 16#61 16#0 16#62 16#FD 16#7A . |
| 10403 | --- |
| 10404 | name: integer-base-one-5W |
| 10405 | description: |
| 10406 | Check to see that weâre NUL and Unicode safe |
| 10407 | stdin: |
| 10408 | set -U |
| 10409 | print 'a\0bâ¬c' >x |
| 10410 | read -a y <x |
| 10411 | set +U |
| 10412 | typeset -Uui16 y |
| 10413 | print ${y[*]} . |
| 10414 | expected-stdout: |
| 10415 | 16#61 16#0 16#62 16#20AC 16#63 . |
| 10416 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10417 | name: ulimit-1 |
| 10418 | description: |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 10419 | Check that ulimit as used in dot.mksh works or is stubbed |
| 10420 | stdin: |
| 10421 | ulimit -c 0 |
| 10422 | --- |
| 10423 | name: ulimit-2 |
| 10424 | description: |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10425 | Check if we can use a specific syntax idiom for ulimit |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 10426 | XXX Haiku works, but only for -n and -V |
| 10427 | category: !os:haiku,!os:syllable |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10428 | stdin: |
| 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 |
| 10435 | expected-stdout: |
| 10436 | okay |
| 10437 | --- |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 10438 | name: redir-1 |
| 10439 | description: |
| 10440 | Check some of the most basic invariants of I/O redirection |
| 10441 | stdin: |
| 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= |
| 10457 | expected-stdout: |
| 10458 | =1= |
| 10459 | o0. |
| 10460 | =2= |
| 10461 | e0. |
| 10462 | =3= |
| 10463 | e1. |
| 10464 | =4= |
| 10465 | o1. |
| 10466 | =5= |
| 10467 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10468 | name: bashiop-1 |
| 10469 | description: |
| 10470 | Check if GNU bash-like I/O redirection works |
| 10471 | Part 1: this is also supported by GNU bash |
| 10472 | stdin: |
| 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 |
| 10482 | expected-stdout: |
| 10483 | tri |
| 10484 | === |
| 10485 | ras |
| 10486 | dwa |
| 10487 | --- |
| 10488 | name: bashiop-2a |
| 10489 | description: |
| 10490 | Check if GNU bash-like I/O redirection works |
| 10491 | Part 2: this is *not* supported by GNU bash |
| 10492 | stdin: |
| 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 |
| 10502 | expected-stdout: |
| 10503 | ras |
| 10504 | === |
| 10505 | dwa |
| 10506 | tri |
| 10507 | --- |
| 10508 | name: bashiop-2b |
| 10509 | description: |
| 10510 | Check if GNU bash-like I/O redirection works |
| 10511 | Part 2: this is *not* supported by GNU bash |
| 10512 | stdin: |
| 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 |
| 10522 | expected-stdout: |
| 10523 | === |
| 10524 | ras |
| 10525 | dwa |
| 10526 | tri |
| 10527 | --- |
| 10528 | name: bashiop-2c |
| 10529 | description: |
| 10530 | Check if GNU bash-like I/O redirection works |
| 10531 | Part 2: this is supported by GNU bash 4 only |
| 10532 | stdin: |
| 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 |
| 10544 | expected-stdout: |
| 10545 | tri |
| 10546 | === |
| 10547 | mir |
| 10548 | ras |
| 10549 | dwa |
| 10550 | --- |
| 10551 | name: bashiop-3a |
| 10552 | description: |
| 10553 | Check if GNU bash-like I/O redirection fails correctly |
| 10554 | Part 1: this is also supported by GNU bash |
| 10555 | stdin: |
| 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 |
| 10567 | expected-stdout: |
| 10568 | === |
| 10569 | mir |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10570 | expected-stderr-pattern: /.*: can't (create|overwrite) .*/ |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10571 | --- |
| 10572 | name: bashiop-3b |
| 10573 | description: |
| 10574 | Check if GNU bash-like I/O redirection fails correctly |
| 10575 | Part 2: this is *not* supported by GNU bash |
| 10576 | stdin: |
| 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 |
| 10588 | expected-stdout: |
| 10589 | tri |
| 10590 | === |
| 10591 | ras |
| 10592 | dwa |
| 10593 | --- |
| 10594 | name: bashiop-4 |
| 10595 | description: |
| 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 |
| 10599 | stdin: |
| 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 |
| 10614 | expected-stdout: |
| 10615 | tri |
| 10616 | === |
| 10617 | ras |
| 10618 | dwa |
| 10619 | --- |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 10620 | name: bashiop-5 |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 10621 | description: |
| 10622 | Check if GNU bash-like I/O redirection is only supported |
| 10623 | in !POSIX !sh mode as it breaks existing scripts' syntax |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 10624 | stdin: |
| 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)" . |
| 10628 | expected-stdout: |
| 10629 | 1 = foo echo bar . |
| 10630 | 2 = bar . |
| 10631 | 3 = bar . |
| 10632 | --- |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 10633 | name: oksh-eval |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10634 | description: |
Elliott Hughes | 737fdce | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 10635 | Check expansions. |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10636 | stdin: |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 10637 | 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 |
| 10646 | expected-stdout: |
| 10647 | 1hq . |
| 10648 | 2hq . |
| 10649 | 1pq . |
| 10650 | 2pq . |
| 10651 | --- |
| 10652 | name: oksh-and-list-error-1 |
| 10653 | description: |
| 10654 | Test exit status of rightmost element in 2 element && list in -e mode |
| 10655 | stdin: |
| 10656 | true && false |
| 10657 | echo "should not print" |
| 10658 | arguments: !-e! |
| 10659 | expected-exit: e != 0 |
| 10660 | --- |
| 10661 | name: oksh-and-list-error-2 |
| 10662 | description: |
| 10663 | Test exit status of rightmost element in 3 element && list in -e mode |
| 10664 | stdin: |
| 10665 | true && true && false |
| 10666 | echo "should not print" |
| 10667 | arguments: !-e! |
| 10668 | expected-exit: e != 0 |
| 10669 | --- |
| 10670 | name: oksh-or-list-error-1 |
| 10671 | description: |
| 10672 | Test exit status of || list in -e mode |
| 10673 | stdin: |
| 10674 | false || false |
| 10675 | echo "should not print" |
| 10676 | arguments: !-e! |
| 10677 | expected-exit: e != 0 |
| 10678 | --- |
| 10679 | name: oksh-longline-crash |
| 10680 | description: |
| 10681 | This used to cause a core dump |
| 10682 | stdin: |
| 10683 | ulimit -c 0 |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10684 | 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 Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 10700 | name: oksh-seterror-1 |
| 10701 | description: |
| 10702 | The -e flag should be ignored when executing a compound list |
| 10703 | followed by an if statement. |
| 10704 | stdin: |
| 10705 | if true; then false && false; fi |
| 10706 | true |
| 10707 | arguments: !-e! |
| 10708 | expected-exit: e == 0 |
| 10709 | --- |
| 10710 | name: oksh-seterror-2 |
| 10711 | description: |
| 10712 | The -e flag should be ignored when executing a compound list |
| 10713 | followed by an if statement. |
| 10714 | stdin: |
| 10715 | if true; then if true; then false && false; fi; fi |
| 10716 | true |
| 10717 | arguments: !-e! |
| 10718 | expected-exit: e == 0 |
| 10719 | --- |
| 10720 | name: oksh-seterror-3 |
| 10721 | description: |
| 10722 | The -e flag should be ignored when executing a compound list |
| 10723 | followed by an elif statement. |
| 10724 | stdin: |
| 10725 | if true; then :; elif true; then false && false; fi |
| 10726 | arguments: !-e! |
| 10727 | expected-exit: e == 0 |
| 10728 | --- |
| 10729 | name: oksh-seterror-4 |
| 10730 | description: |
| 10731 | The -e flag should be ignored when executing a pipeline |
| 10732 | beginning with '!' |
| 10733 | stdin: |
| 10734 | for i in 1 2 3 |
| 10735 | do |
| 10736 | false && false |
| 10737 | true || false |
| 10738 | done |
| 10739 | arguments: !-e! |
| 10740 | expected-exit: e == 0 |
| 10741 | --- |
| 10742 | name: oksh-seterror-5 |
| 10743 | description: |
| 10744 | The -e flag should be ignored when executing a pipeline |
| 10745 | beginning with '!' |
| 10746 | stdin: |
| 10747 | ! true | false |
| 10748 | true |
| 10749 | arguments: !-e! |
| 10750 | expected-exit: e == 0 |
| 10751 | --- |
| 10752 | name: oksh-seterror-6 |
| 10753 | description: |
| 10754 | When trapping ERR and EXIT, both traps should run in -e mode |
| 10755 | when an error occurs. |
| 10756 | stdin: |
| 10757 | trap 'echo EXIT' EXIT |
| 10758 | trap 'echo ERR' ERR |
| 10759 | set -e |
| 10760 | false |
| 10761 | echo DONE |
| 10762 | exit 0 |
| 10763 | arguments: !-e! |
| 10764 | expected-exit: e != 0 |
| 10765 | expected-stdout: |
| 10766 | ERR |
| 10767 | EXIT |
| 10768 | --- |
| 10769 | name: oksh-seterror-7 |
| 10770 | description: |
| 10771 | The -e flag within a command substitution should be honored |
| 10772 | stdin: |
| 10773 | echo $( set -e; false; echo foo ) |
| 10774 | arguments: !-e! |
| 10775 | expected-stdout: |
| 10776 | |
| 10777 | --- |
| 10778 | name: oksh-input-comsub |
| 10779 | description: |
| 10780 | A command substitution using input redirection should exit with |
| 10781 | failure if the input file does not exist. |
| 10782 | stdin: |
| 10783 | var=$(< non-existent) |
| 10784 | expected-exit: e != 0 |
| 10785 | expected-stderr-pattern: /non-existent/ |
| 10786 | --- |
| 10787 | name: oksh-empty-for-list |
| 10788 | description: |
| 10789 | A for list which expands to zero items should not execute the body. |
| 10790 | stdin: |
| 10791 | set foo bar baz ; for out in ; do echo $out ; done |
| 10792 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10793 | name: oksh-varfunction-mod1 |
| 10794 | description: |
Elliott Hughes | 737fdce | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 10795 | (Inspired by PR 2450 on OpenBSD.) Calling |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10796 | 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10803 | stdin: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 10804 | print '#!'"$__progname"'\nunset RANDOM\nexport | while IFS= read -r' \ |
| 10805 | 'RANDOM; do eval '\''print -r -- "$RANDOM=$'\''"$RANDOM"'\'\"\'\; \ |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 10806 | done >env; chmod +x env; PATH=.$PATHSEP$PATH |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10807 | 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 | --- |
| 10863 | name: fd-cloexec-1 |
| 10864 | description: |
| 10865 | Verify that file descriptors > 2 are private for Korn shells |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10866 | AT&T ksh93 does this still, which means we must keep it as well |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 10867 | XXX fails on some old Perl installations |
| 10868 | need-pass: no |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10869 | stdin: |
Elliott Hughes | b27ce95 | 2015-04-21 13:39:18 -0700 | [diff] [blame] | 10870 | 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10878 | expected-exit: e != 0 |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10879 | expected-stderr-pattern: |
Elliott Hughes | b27ce95 | 2015-04-21 13:39:18 -0700 | [diff] [blame] | 10880 | /E: open / |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10881 | --- |
| 10882 | name: fd-cloexec-2 |
| 10883 | description: |
| 10884 | Verify that file descriptors > 2 are not private for POSIX shells |
| 10885 | See Debian Bug #154540, Closes: #499139 |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 10886 | XXX fails on some old Perl installations |
| 10887 | need-pass: no |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10888 | stdin: |
Elliott Hughes | b27ce95 | 2015-04-21 13:39:18 -0700 | [diff] [blame] | 10889 | 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10898 | expected-stdout: |
| 10899 | Fowl |
| 10900 | --- |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10901 | name: comsub-1a |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10902 | description: |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10903 | 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10907 | stdin: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 10908 | 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10914 | expected-stdout: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 10915 | 1 yes . |
| 10916 | 2 yes . |
| 10917 | 3 234 . |
| 10918 | 4 678 . |
| 10919 | 5 1 . |
| 10920 | 6 1 . |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10921 | --- |
| 10922 | name: comsub-1b |
| 10923 | description: |
| 10924 | COMSUB are now parsed recursively, so this works |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 10925 | Fails on: pdksh bash2 bash3 bash4 zsh |
| 10926 | Passes on: ksh93 mksh(20110313+) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10927 | stdin: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 10928 | 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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10934 | expected-stdout: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 10935 | 1 11 . |
| 10936 | 2 21 . |
| 10937 | 3 1 . |
| 10938 | 4 1 . |
| 10939 | 5 11 . |
| 10940 | 6 21 . |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10941 | --- |
| 10942 | name: comsub-2 |
| 10943 | description: |
| 10944 | RedHat BZ#496791 â another case of missing recursion |
| 10945 | in parsing COMSUB expressions |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10946 | Fails on: pdksh bash2 bash3¹ bash4¹ zsh |
| 10947 | Passes on: ksh93 mksh(20110305+) |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10948 | â bash[34] seem to choke on comment ending with backslash-newline |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 10949 | stdin: |
| 10950 | # a comment with " ' \ |
| 10951 | x=$( |
| 10952 | echo yes |
| 10953 | # a comment with " ' \ |
| 10954 | ) |
| 10955 | echo $x |
| 10956 | expected-stdout: |
| 10957 | yes |
| 10958 | --- |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10959 | name: comsub-3 |
| 10960 | description: |
| 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) |
| 10964 | stdin: |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 10965 | print '#!'"$__progname"'\necho 1234' >id; chmod +x id; PATH=.$PATHSEP$PATH |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10966 | 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) |
| 10973 | expected-stdout: |
| 10974 | 32 |
| 10975 | . |
| 10976 | 16#4F68 16#24 2 1 |
| 10977 | --- |
| 10978 | name: comsub-4 |
| 10979 | description: |
| 10980 | Check the tree dump functions for !MKSH_SMALL functionality |
| 10981 | category: !smksh |
| 10982 | stdin: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 10983 | x() { case $1 in u) echo x ;;& *) echo $1 ;; esac; } |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10984 | typeset -f x |
| 10985 | expected-stdout: |
| 10986 | x() { |
| 10987 | case $1 in |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 10988 | (u) |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 10989 | \echo x |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10990 | ;| |
| 10991 | (*) |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 10992 | \echo $1 |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 10993 | ;; |
| 10994 | esac |
| 10995 | } |
| 10996 | --- |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 10997 | name: comsub-5 |
| 10998 | description: |
| 10999 | Check COMSUB works with aliases (does not expand them twice) |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11000 | and reentrancy safety |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11001 | stdin: |
| 11002 | print '#!'"$__progname"'\nfor x in "$@"; do print -r -- "$x"; done' >pfn |
| 11003 | chmod +x pfn |
| 11004 | alias echo='echo a' |
| 11005 | foo() { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11006 | echo moo |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11007 | ./pfn "$(echo foo)" |
| 11008 | } |
| 11009 | ./pfn "$(echo b)" |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11010 | typeset -f foo >x |
| 11011 | cat x |
| 11012 | foo |
| 11013 | . ./x |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11014 | typeset -f foo |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11015 | foo |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11016 | expected-stdout: |
| 11017 | a b |
| 11018 | foo() { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11019 | \echo a moo |
| 11020 | ./pfn "$(\echo a foo )" |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11021 | } |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11022 | a moo |
| 11023 | a foo |
| 11024 | foo() { |
| 11025 | \echo a moo |
| 11026 | ./pfn "$(\echo a foo )" |
| 11027 | } |
| 11028 | a moo |
| 11029 | a foo |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11030 | --- |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11031 | name: comsub-torture |
| 11032 | description: |
| 11033 | Check the tree dump functions work correctly |
| 11034 | stdin: |
| 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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11072 | time for i in {1,2,3} ; do echo $i ; done |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11073 | #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 Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 11098 | #COMSUB_EXPRSUB_FUNSUB_VALSUB |
| 11099 | echo $(true) $((1+ 2)) ${ :;} ${| REPLY=x;} |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11100 | #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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11129 | #wdarrassign |
| 11130 | case x in |
| 11131 | x) a+=b; c+=(d e) |
| 11132 | esac |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11133 | #0 |
| 11134 | EOD |
| 11135 | expected-stdout: |
| 11136 | inline_TCOM() { |
| 11137 | vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4" |
| 11138 | } |
| 11139 | inline_TCOM() { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11140 | vara=1 varb="2 3" \cmd arg1 $arg2 "$arg3 4" |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11141 | } |
| 11142 | function comsub_TCOM { x=$( |
| 11143 | vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4" |
| 11144 | ); } |
| 11145 | function comsub_TCOM { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11146 | x=$(vara=1 varb="2 3" \cmd arg1 $arg2 "$arg3 4" ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11147 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11152 | x=$( ( vara=1 varb="2 3" \cmd arg1 $arg2 "$arg3 4" ) | \tr u x ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11153 | } |
| 11154 | inline_TPAREN_TPIPE_TLIST() { |
| 11155 | (echo $foo | tr -dc 0-9; echo) |
| 11156 | } |
| 11157 | inline_TPAREN_TPIPE_TLIST() { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11158 | ( \echo $foo | \tr -dc 0-9 |
| 11159 | \echo ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11160 | } |
| 11161 | function comsub_TPAREN_TPIPE_TLIST { x=$( |
| 11162 | (echo $foo | tr -dc 0-9; echo) |
| 11163 | ); } |
| 11164 | function comsub_TPAREN_TPIPE_TLIST { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11165 | x=$( ( \echo $foo | \tr -dc 0-9 ; \echo ) ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11166 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11171 | x=$( ( ( \echo $foo | \tr -dc 0-9 ; \echo ) ) | \tr u x ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11172 | } |
| 11173 | inline_TAND_TOR() { |
| 11174 | cmd && echo ja || echo nein |
| 11175 | } |
| 11176 | inline_TAND_TOR() { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11177 | \cmd && \echo ja || \echo nein |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11178 | } |
| 11179 | function comsub_TAND_TOR { x=$( |
| 11180 | cmd && echo ja || echo nein |
| 11181 | ); } |
| 11182 | function comsub_TAND_TOR { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11183 | x=$(\cmd && \echo ja || \echo nein ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11184 | } |
| 11185 | function reread_TAND_TOR { x=$(( |
| 11186 | cmd && echo ja || echo nein |
| 11187 | )|tr u x); } |
| 11188 | function reread_TAND_TOR { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11189 | x=$( ( \cmd && \echo ja || \echo nein ) | \tr u x ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11190 | } |
| 11191 | inline_TSELECT() { |
| 11192 | select file in *; do echo "<$file>" ; break ; done |
| 11193 | } |
| 11194 | inline_TSELECT() { |
| 11195 | select file in * |
| 11196 | do |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11197 | \echo "<$file>" |
| 11198 | \break |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11199 | done |
| 11200 | } |
| 11201 | function comsub_TSELECT { x=$( |
| 11202 | select file in *; do echo "<$file>" ; break ; done |
| 11203 | ); } |
| 11204 | function comsub_TSELECT { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11205 | x=$(select file in * ; do \echo "<$file>" ; \break ; done ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11206 | } |
| 11207 | function reread_TSELECT { x=$(( |
| 11208 | select file in *; do echo "<$file>" ; break ; done |
| 11209 | )|tr u x); } |
| 11210 | function reread_TSELECT { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11211 | x=$( ( select file in * ; do \echo "<$file>" ; \break ; done ) | \tr u x ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11212 | } |
| 11213 | inline_TFOR_TTIME() { |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11214 | time for i in {1,2,3} ; do echo $i ; done |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11215 | } |
| 11216 | inline_TFOR_TTIME() { |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11217 | time for i in {1,2,3} |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11218 | do |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11219 | \echo $i |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11220 | done |
| 11221 | } |
| 11222 | function comsub_TFOR_TTIME { x=$( |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11223 | time for i in {1,2,3} ; do echo $i ; done |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11224 | ); } |
| 11225 | function comsub_TFOR_TTIME { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11226 | x=$(time for i in {1,2,3} ; do \echo $i ; done ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11227 | } |
| 11228 | function reread_TFOR_TTIME { x=$(( |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11229 | time for i in {1,2,3} ; do echo $i ; done |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11230 | )|tr u x); } |
| 11231 | function reread_TFOR_TTIME { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11232 | x=$( ( time for i in {1,2,3} ; do \echo $i ; done ) | \tr u x ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11233 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11240 | \echo eins |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11241 | ;& |
| 11242 | (2) |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11243 | \echo zwei |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11244 | ;| |
| 11245 | (*) |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11246 | \echo kann net bis drei zählen |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11247 | ;; |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11254 | x=$(case $foo in (1) \echo eins ;& (2) \echo zwei ;| (*) \echo kann net bis drei zählen ;; esac ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11255 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11260 | x=$( ( case $foo in (1) \echo eins ;& (2) \echo zwei ;| (*) \echo kann net bis drei zählen ;; esac ) | \tr u x ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11261 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11268 | \echo eins |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11269 | elif [[ 1 = 2 ]] |
| 11270 | then |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11271 | \echo zwei |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11272 | else |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11273 | \echo drei |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11274 | 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11280 | x=$(if ! [[ 1 = 1 ]] ; then \echo eins ; elif [[ 1 = 2 ]] ; then \echo zwei ; else \echo drei ; fi ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11281 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11286 | x=$( ( if ! [[ 1 = 1 ]] ; then \echo eins ; elif [[ 1 = 2 ]] ; then \echo zwei ; else \echo drei ; fi ) | \tr u x ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11287 | } |
| 11288 | inline_TWHILE() { |
| 11289 | i=1; while (( i < 10 )); do echo $i; let ++i; done |
| 11290 | } |
| 11291 | inline_TWHILE() { |
| 11292 | i=1 |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 11293 | while { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11294 | \\builtin let " i < 10 " |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 11295 | } |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11296 | do |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11297 | \echo $i |
| 11298 | \let ++i |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11299 | 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11305 | x=$(i=1 ; while { \\builtin let " i < 10 " ; } ; do \echo $i ; \let ++i ; done ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11306 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11311 | x=$( ( i=1 ; while { \\builtin let " i < 10 " ; } ; do \echo $i ; \let ++i ; done ) | \tr u x ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11312 | } |
| 11313 | inline_TUNTIL() { |
| 11314 | i=10; until (( !--i )) ; do echo $i; done |
| 11315 | } |
| 11316 | inline_TUNTIL() { |
| 11317 | i=10 |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 11318 | until { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11319 | \\builtin let " !--i " |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 11320 | } |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11321 | do |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11322 | \echo $i |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11323 | done |
| 11324 | } |
| 11325 | function comsub_TUNTIL { x=$( |
| 11326 | i=10; until (( !--i )) ; do echo $i; done |
| 11327 | ); } |
| 11328 | function comsub_TUNTIL { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11329 | x=$(i=10 ; until { \\builtin let " !--i " ; } ; do \echo $i ; done ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11330 | } |
| 11331 | function reread_TUNTIL { x=$(( |
| 11332 | i=10; until (( !--i )) ; do echo $i; done |
| 11333 | )|tr u x); } |
| 11334 | function reread_TUNTIL { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11335 | x=$( ( i=10 ; until { \\builtin let " !--i " ; } ; do \echo $i ; done ) | \tr u x ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11336 | } |
| 11337 | inline_TCOPROC() { |
| 11338 | cat * |& ls |
| 11339 | } |
| 11340 | inline_TCOPROC() { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11341 | \cat * |& |
| 11342 | \ls |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11343 | } |
| 11344 | function comsub_TCOPROC { x=$( |
| 11345 | cat * |& ls |
| 11346 | ); } |
| 11347 | function comsub_TCOPROC { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11348 | x=$(\cat * |& \ls ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11349 | } |
| 11350 | function reread_TCOPROC { x=$(( |
| 11351 | cat * |& ls |
| 11352 | )|tr u x); } |
| 11353 | function reread_TCOPROC { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11354 | x=$( ( \cat * |& \ls ) | \tr u x ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11355 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11362 | \echo eins |
| 11363 | \echo zwei |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11364 | } |
| 11365 | bourne() { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11366 | \logger * & |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11367 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11374 | x=$(function korn { \echo eins ; \echo zwei ; } ; bourne() { \logger * & } ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11375 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11381 | x=$( ( function korn { \echo eins ; \echo zwei ; } ; bourne() { \logger * & } ) | \tr u x ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11382 | } |
| 11383 | inline_IOREAD_IOCAT() { |
| 11384 | tr x u 0<foo >>bar |
| 11385 | } |
| 11386 | inline_IOREAD_IOCAT() { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11387 | \tr x u <foo >>bar |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11388 | } |
| 11389 | function comsub_IOREAD_IOCAT { x=$( |
| 11390 | tr x u 0<foo >>bar |
| 11391 | ); } |
| 11392 | function comsub_IOREAD_IOCAT { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11393 | x=$(\tr x u <foo >>bar ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11394 | } |
| 11395 | function reread_IOREAD_IOCAT { x=$(( |
| 11396 | tr x u 0<foo >>bar |
| 11397 | )|tr u x); } |
| 11398 | function reread_IOREAD_IOCAT { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11399 | x=$( ( \tr x u <foo >>bar ) | \tr u x ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11400 | } |
| 11401 | inline_IOWRITE_IOCLOB_IOHERE_noIOSKIP() { |
| 11402 | cat >|bar <<'EOFN' |
| 11403 | foo |
| 11404 | EOFN |
| 11405 | } |
| 11406 | inline_IOWRITE_IOCLOB_IOHERE_noIOSKIP() { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11407 | \cat >|bar <<"EOFN" |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11408 | 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11418 | x=$(\cat >|bar <<"EOFN" |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11419 | 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11429 | x=$( ( \cat >|bar <<"EOFN" |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11430 | foo |
| 11431 | EOFN |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11432 | ) | \tr u x ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11433 | } |
| 11434 | inline_IOWRITE_noIOCLOB_IOHERE_IOSKIP() { |
| 11435 | cat 1>bar <<-EOFI |
| 11436 | foo |
| 11437 | EOFI |
| 11438 | } |
| 11439 | inline_IOWRITE_noIOCLOB_IOHERE_IOSKIP() { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11440 | \cat >bar <<-EOFI |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11441 | 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11451 | x=$(\cat >bar <<-EOFI |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11452 | 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11462 | x=$( ( \cat >bar <<-EOFI |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11463 | foo |
| 11464 | EOFI |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11465 | ) | \tr u x ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11466 | } |
| 11467 | inline_IORDWR_IODUP() { |
| 11468 | sh 1<>/dev/console 0<&1 2>&1 |
| 11469 | } |
| 11470 | inline_IORDWR_IODUP() { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11471 | \sh 1<>/dev/console <&1 2>&1 |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11472 | } |
| 11473 | function comsub_IORDWR_IODUP { x=$( |
| 11474 | sh 1<>/dev/console 0<&1 2>&1 |
| 11475 | ); } |
| 11476 | function comsub_IORDWR_IODUP { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11477 | x=$(\sh 1<>/dev/console <&1 2>&1 ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11478 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11483 | x=$( ( \sh 1<>/dev/console <&1 2>&1 ) | \tr u x ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11484 | } |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 11485 | inline_COMSUB_EXPRSUB_FUNSUB_VALSUB() { |
| 11486 | echo $(true) $((1+ 2)) ${ :;} ${| REPLY=x;} |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11487 | } |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 11488 | inline_COMSUB_EXPRSUB_FUNSUB_VALSUB() { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11489 | \echo $(\true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11490 | } |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 11491 | function comsub_COMSUB_EXPRSUB_FUNSUB_VALSUB { x=$( |
| 11492 | echo $(true) $((1+ 2)) ${ :;} ${| REPLY=x;} |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11493 | ); } |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 11494 | function comsub_COMSUB_EXPRSUB_FUNSUB_VALSUB { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11495 | x=$(\echo $(\true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11496 | } |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 11497 | function reread_COMSUB_EXPRSUB_FUNSUB_VALSUB { x=$(( |
| 11498 | echo $(true) $((1+ 2)) ${ :;} ${| REPLY=x;} |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11499 | )|tr u x); } |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 11500 | function reread_COMSUB_EXPRSUB_FUNSUB_VALSUB { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11501 | x=$( ( \echo $(\true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} ) | \tr u x ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11502 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11509 | \echo fo\ob\"a\`r\'b\$az |
| 11510 | \echo "fo\ob\"a\`r\'b\$az" |
| 11511 | \echo "fo\\ob\\\"a\\\`r"\'"b\\\$az" |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11512 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11519 | x=$(\echo fo\ob\"a\`r\'b\$az ; \echo "fo\ob\"a\`r\'b\$az" ; \echo "fo\\ob\\\"a\\\`r"\'"b\\\$az" ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11520 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11527 | 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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11528 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11545 | x=$( ( [[ ${foo#bl\(u\)b} = @(bar|baz) ]] ) | \tr u x ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11546 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11553 | x=$(\cat <<EOFN |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11554 | note there must be no space between EOFN and ) |
| 11555 | EOFN |
| 11556 | ) |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11557 | \echo $x |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11558 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11565 | x=$(x=$(\cat <<EOFN |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11566 | note there must be no space between EOFN and ) |
| 11567 | EOFN |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11568 | ) ; \echo $x ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11569 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11576 | x=$( ( x=$(\cat <<EOFN |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11577 | note there must be no space between EOFN and ) |
| 11578 | EOFN |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11579 | ) ; \echo $x ) | \tr u x ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11580 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11587 | x=$(\cat <<EOFN\ |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11588 | note the space between EOFN and ) is actually part of the here document marker |
| 11589 | EOFN |
| 11590 | ) |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11591 | \echo $x |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11592 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11599 | x=$(x=$(\cat <<EOFN\ |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11600 | note the space between EOFN and ) is actually part of the here document marker |
| 11601 | EOFN |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11602 | ) ; \echo $x ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11603 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11610 | x=$( ( x=$(\cat <<EOFN\ |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11611 | note the space between EOFN and ) is actually part of the here document marker |
| 11612 | EOFN |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11613 | ) ; \echo $x ) | \tr u x ) |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11614 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11632 | x=$(\sysctl -n kern.version | \sed 1q ) |
| 11633 | [[ -s /etc/motd && "$([[ "$(\head -1 /etc/motd )" != $x ]] && \ed -s /etc/motd 2>&1 <<-EOF |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11634 | 1,/^\$/d |
| 11635 | 0a |
| 11636 | $x |
| 11637 | |
| 11638 | . |
| 11639 | wq |
| 11640 | EOF |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11641 | )" = @(?) ]] && \rm -f /etc/motd |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11642 | if [[ ! -s /etc/motd ]] |
| 11643 | then |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11644 | \install -c -o root -g wheel -m 664 /dev/null /etc/motd |
| 11645 | \print -- "$x\n" >/etc/motd |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11646 | 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11665 | x=$(x=$(\sysctl -n kern.version | \sed 1q ) ; [[ -s /etc/motd && "$([[ "$(\head -1 /etc/motd )" != $x ]] && \ed -s /etc/motd 2>&1 <<-EOF |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11666 | 1,/^\$/d |
| 11667 | 0a |
| 11668 | $x |
| 11669 | |
| 11670 | . |
| 11671 | wq |
| 11672 | EOF |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11673 | )" = @(?) ]] && \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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11674 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11692 | x=$( ( x=$(\sysctl -n kern.version | \sed 1q ) ; [[ -s /etc/motd && "$([[ "$(\head -1 /etc/motd )" != $x ]] && \ed -s /etc/motd 2>&1 <<-EOF |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11693 | 1,/^\$/d |
| 11694 | 0a |
| 11695 | $x |
| 11696 | |
| 11697 | . |
| 11698 | wq |
| 11699 | EOF |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11700 | )" = @(?) ]] && \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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 11701 | } |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11702 | 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11711 | \\builtin set -A c+ -- d e |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11712 | ;; |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11721 | x=$(case x in (x) a+=b ; \\builtin set -A c+ -- d e ;; esac ) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11722 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11729 | x=$( ( case x in (x) a+=b ; \\builtin set -A c+ -- d e ;; esac ) | \tr u x ) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11730 | } |
| 11731 | --- |
| 11732 | name: comsub-torture-io |
| 11733 | description: |
| 11734 | Check the tree dump functions work correctly with I/O redirection |
| 11735 | stdin: |
| 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 |
| 11791 | expected-stdout: |
| 11792 | inline_TCOM() { |
| 11793 | vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4" >&3 |
| 11794 | } |
| 11795 | inline_TCOM() { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11796 | vara=1 varb="2 3" \cmd arg1 $arg2 "$arg3 4" >&3 |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11797 | } |
| 11798 | function comsub_TCOM { x=$( |
| 11799 | vara=1 varb='2 3' cmd arg1 $arg2 "$arg3 4" >&3 |
| 11800 | ); } |
| 11801 | function comsub_TCOM { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11802 | x=$(vara=1 varb="2 3" \cmd arg1 $arg2 "$arg3 4" >&3 ) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11803 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11808 | x=$( ( vara=1 varb="2 3" \cmd arg1 $arg2 "$arg3 4" >&3 ) | \tr u x ) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11809 | } |
| 11810 | inline_TPAREN_TPIPE_TLIST() { |
| 11811 | (echo $foo | tr -dc 0-9 >&3; echo >&3) >&3 |
| 11812 | } |
| 11813 | inline_TPAREN_TPIPE_TLIST() { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11814 | ( \echo $foo | \tr -dc 0-9 >&3 |
| 11815 | \echo >&3 ) >&3 |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11816 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11821 | x=$( ( \echo $foo | \tr -dc 0-9 >&3 ; \echo >&3 ) >&3 ) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11822 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11827 | x=$( ( ( \echo $foo | \tr -dc 0-9 >&3 ; \echo >&3 ) >&3 ) | \tr u x ) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11828 | } |
| 11829 | inline_TAND_TOR() { |
| 11830 | cmd >&3 && >&3 echo ja || echo >&3 nein |
| 11831 | } |
| 11832 | inline_TAND_TOR() { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11833 | \cmd >&3 && \echo ja >&3 || \echo nein >&3 |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11834 | } |
| 11835 | function comsub_TAND_TOR { x=$( |
| 11836 | cmd >&3 && >&3 echo ja || echo >&3 nein |
| 11837 | ); } |
| 11838 | function comsub_TAND_TOR { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11839 | x=$(\cmd >&3 && \echo ja >&3 || \echo nein >&3 ) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11840 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11845 | x=$( ( \cmd >&3 && \echo ja >&3 || \echo nein >&3 ) | \tr u x ) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11846 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11853 | \echo "<$file>" |
| 11854 | \break >&3 |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11855 | 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11861 | x=$(select file in * ; do \echo "<$file>" ; \break >&3 ; done >&3 ) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11862 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11867 | x=$( ( select file in * ; do \echo "<$file>" ; \break >&3 ; done >&3 ) | \tr u x ) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11868 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11875 | time \echo $i >&3 |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11876 | 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11882 | x=$(for i in {1,2,3} ; do time \echo $i >&3 ; done >&3 ) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11883 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11888 | x=$( ( for i in {1,2,3} ; do time \echo $i >&3 ; done >&3 ) | \tr u x ) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11889 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11896 | \echo eins >&3 |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11897 | ;& |
| 11898 | (2) |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11899 | \echo zwei >&3 |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11900 | ;| |
| 11901 | (*) |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11902 | \echo kann net bis drei zählen >&3 |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11903 | ;; |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11910 | x=$(case $foo in (1) \echo eins >&3 ;& (2) \echo zwei >&3 ;| (*) \echo kann net bis drei zählen >&3 ;; esac >&3 ) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11911 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11916 | 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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11917 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11924 | \echo eins |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11925 | elif [[ 1 = 2 ]] >&3 |
| 11926 | then |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11927 | \echo zwei |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11928 | else |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11929 | \echo drei |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11930 | 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11936 | x=$(if ! [[ 1 = 1 ]] >&3 ; then \echo eins ; elif [[ 1 = 2 ]] >&3 ; then \echo zwei ; else \echo drei ; fi >&3 ) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11937 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11942 | x=$( ( if ! [[ 1 = 1 ]] >&3 ; then \echo eins ; elif [[ 1 = 2 ]] >&3 ; then \echo zwei ; else \echo drei ; fi >&3 ) | \tr u x ) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11943 | } |
| 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 Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 11949 | while { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11950 | \\builtin let " i < 10 " |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 11951 | } >&3 |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11952 | do |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11953 | \echo $i |
| 11954 | \let ++i |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11955 | 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11961 | x=$(i=1 ; while { \\builtin let " i < 10 " ; } >&3 ; do \echo $i ; \let ++i ; done >&3 ) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11962 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11967 | x=$( ( i=1 ; while { \\builtin let " i < 10 " ; } >&3 ; do \echo $i ; \let ++i ; done >&3 ) | \tr u x ) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11968 | } |
| 11969 | inline_TUNTIL() { |
| 11970 | i=10; until (( !--i )) >&3 ; do echo $i; done >&3 |
| 11971 | } |
| 11972 | inline_TUNTIL() { |
| 11973 | i=10 |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 11974 | until { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11975 | \\builtin let " !--i " |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 11976 | } >&3 |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11977 | do |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11978 | \echo $i |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11979 | 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11985 | x=$(i=10 ; until { \\builtin let " !--i " ; } >&3 ; do \echo $i ; done >&3 ) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11986 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11991 | x=$( ( i=10 ; until { \\builtin let " !--i " ; } >&3 ; do \echo $i ; done >&3 ) | \tr u x ) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11992 | } |
| 11993 | inline_TCOPROC() { |
| 11994 | cat * >&3 |& >&3 ls |
| 11995 | } |
| 11996 | inline_TCOPROC() { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 11997 | \cat * >&3 |& |
| 11998 | \ls >&3 |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 11999 | } |
| 12000 | function comsub_TCOPROC { x=$( |
| 12001 | cat * >&3 |& >&3 ls |
| 12002 | ); } |
| 12003 | function comsub_TCOPROC { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 12004 | x=$(\cat * >&3 |& \ls >&3 ) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 12005 | } |
| 12006 | function reread_TCOPROC { x=$(( |
| 12007 | cat * >&3 |& >&3 ls |
| 12008 | )|tr u x); } |
| 12009 | function reread_TCOPROC { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 12010 | x=$( ( \cat * >&3 |& \ls >&3 ) | \tr u x ) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 12011 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 12018 | \echo eins |
| 12019 | \echo zwei >&3 |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 12020 | } |
| 12021 | bourne() { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 12022 | \logger * >&3 & |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 12023 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 12030 | x=$(function korn { \echo eins ; \echo zwei >&3 ; } ; bourne() { \logger * >&3 & } ) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 12031 | } |
| 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 Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 12037 | x=$( ( function korn { \echo eins ; \echo zwei >&3 ; } ; bourne() { \logger * >&3 & } ) | \tr u x ) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 12038 | } |
| 12039 | inline_COMSUB_EXPRSUB() { |
| 12040 | echo $(true >&3) $((1+ 2)) |
| 12041 | } |
| 12042 | inline_COMSUB_EXPRSUB() { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 12043 | \echo $(\true >&3 ) $((1+ 2)) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 12044 | } |
| 12045 | function comsub_COMSUB_EXPRSUB { x=$( |
| 12046 | echo $(true >&3) $((1+ 2)) |
| 12047 | ); } |
| 12048 | function comsub_COMSUB_EXPRSUB { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 12049 | x=$(\echo $(\true >&3 ) $((1+ 2)) ) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 12050 | } |
| 12051 | function reread_COMSUB_EXPRSUB { x=$(( |
| 12052 | echo $(true >&3) $((1+ 2)) |
| 12053 | )|tr u x); } |
| 12054 | function reread_COMSUB_EXPRSUB { |
Elliott Hughes | a3c3f96 | 2017-04-12 16:52:30 -0700 | [diff] [blame] | 12055 | x=$( ( \echo $(\true >&3 ) $((1+ 2)) ) | \tr u x ) |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 12056 | } |
| 12057 | --- |
| 12058 | name: funsub-1 |
| 12059 | description: |
| 12060 | Check that non-subenvironment command substitution works |
| 12061 | stdin: |
| 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 ." |
| 12072 | expected-stdout: |
| 12073 | ob bar . |
| 12074 | ib bar : |
| 12075 | ia baz : . |
| 12076 | oa baz . |
| 12077 | --- |
| 12078 | name: funsub-2 |
| 12079 | description: |
| 12080 | You can now reliably use local and return in funsubs |
| 12081 | (not exit though) |
| 12082 | stdin: |
| 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,$?. |
| 12086 | expected-stdout: |
| 12087 | 1:ya x2,2,0. |
| 12088 | 2:ya x2,1,0. |
| 12089 | 3:ya,1,3. |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 12090 | --- |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 12091 | name: valsub-1 |
| 12092 | description: |
| 12093 | Check that "value substitutions" work as advertised |
| 12094 | stdin: |
| 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 Hughes | 966dd55 | 2016-12-08 15:56:04 -0800 | [diff] [blame] | 12102 | echo "start: x<$x> y<$y> z<$z> R<$REPLY>" |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 12103 | 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). |
| 12115 | expected-stdout: |
| 12116 | before: x<1> y<2> z<3> R<4> |
Elliott Hughes | 966dd55 | 2016-12-08 15:56:04 -0800 | [diff] [blame] | 12117 | start: x<1> y<> z<3> R<> |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 12118 | 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 Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 12123 | name: event-subst-3 |
| 12124 | description: |
| 12125 | Check that '!' substitution in noninteractive mode is ignored |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 12126 | file-setup: file 755 "falsetto" |
| 12127 | #! /bin/sh |
| 12128 | echo molto bene |
| 12129 | exit 42 |
| 12130 | file-setup: file 755 "!false" |
| 12131 | #! /bin/sh |
| 12132 | echo si |
| 12133 | stdin: |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 12134 | export PATH=.$PATHSEP$PATH |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 12135 | falsetto |
| 12136 | echo yeap |
| 12137 | !false |
| 12138 | echo meow |
| 12139 | ! false |
| 12140 | echo = $? |
| 12141 | if |
| 12142 | ! false; then echo foo; else echo bar; fi |
| 12143 | expected-stdout: |
| 12144 | molto bene |
| 12145 | yeap |
| 12146 | si |
| 12147 | meow |
| 12148 | = 0 |
| 12149 | foo |
| 12150 | --- |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 12151 | name: event-subst-0 |
| 12152 | description: |
| 12153 | Check that '!' substitution in interactive mode is ignored |
| 12154 | need-ctty: yes |
| 12155 | arguments: !-i! |
| 12156 | file-setup: file 755 "falsetto" |
| 12157 | #! /bin/sh |
| 12158 | echo molto bene |
| 12159 | exit 42 |
| 12160 | file-setup: file 755 "!false" |
| 12161 | #! /bin/sh |
| 12162 | echo si |
| 12163 | stdin: |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 12164 | export PATH=.$PATHSEP$PATH |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 12165 | falsetto |
| 12166 | echo yeap |
| 12167 | !false |
| 12168 | echo meow |
| 12169 | ! false |
| 12170 | echo = $? |
| 12171 | if |
| 12172 | ! false; then echo foo; else echo bar; fi |
| 12173 | expected-stdout: |
| 12174 | molto bene |
| 12175 | yeap |
| 12176 | si |
| 12177 | meow |
| 12178 | = 0 |
| 12179 | foo |
| 12180 | expected-stderr-pattern: |
| 12181 | /.*/ |
| 12182 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 12183 | name: nounset-1 |
| 12184 | description: |
| 12185 | Check that "set -u" matches (future) SUSv4 requirement |
| 12186 | stdin: |
| 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 Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 12229 | exit ${PIPESTATUS[0]} |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 12230 | expected-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 | --- |
| 12260 | name: nameref-1 |
| 12261 | description: |
| 12262 | Testsuite for nameref (bound variables) |
| 12263 | stdin: |
| 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 |
| 12286 | expected-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 Hughes | 737fdce | 2014-08-07 12:59:26 -0700 | [diff] [blame] | 12297 | !ind[1]: blub[1] |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 12298 | !ir2: ir2 |
| 12299 | ind[1]: e2 |
| 12300 | ir2: e3 |
| 12301 | --- |
| 12302 | name: nameref-2da |
| 12303 | description: |
| 12304 | Testsuite for nameref (bound variables) |
| 12305 | Functions, argument given directly, after local |
| 12306 | stdin: |
| 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 |
| 12325 | expected-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 | --- |
| 12338 | name: nameref-3 |
| 12339 | description: |
| 12340 | Advanced testsuite for bound variables (ksh93 fails this) |
| 12341 | stdin: |
| 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 |
| 12347 | expected-stdout: |
| 12348 | 0 b . |
| 12349 | 1 c . |
| 12350 | 2 a . |
| 12351 | 3 . |
| 12352 | --- |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 12353 | name: nameref-4 |
| 12354 | description: |
| 12355 | Ensure we don't run in an infinite loop |
| 12356 | time-limit: 3 |
| 12357 | stdin: |
| 12358 | baz() { |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 12359 | typeset -n foo=fnord fnord=foo |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 12360 | foo[0]=bar |
| 12361 | } |
| 12362 | set -A foo bad |
| 12363 | echo sind $foo . |
| 12364 | baz |
| 12365 | echo blah $foo . |
| 12366 | expected-stdout: |
| 12367 | sind bad . |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 12368 | blah bad . |
| 12369 | expected-stderr-pattern: |
| 12370 | /fnord: expression recurses on parameter/ |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 12371 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 12372 | name: better-parens-1a |
| 12373 | description: |
| 12374 | Check support for ((â¦)) and $((â¦)) vs (â¦) and $(â¦) |
| 12375 | stdin: |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 12376 | if ( (echo fubar)|tr u x); then |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 12377 | echo ja |
| 12378 | else |
| 12379 | echo nein |
| 12380 | fi |
| 12381 | expected-stdout: |
| 12382 | fxbar |
| 12383 | ja |
| 12384 | --- |
| 12385 | name: better-parens-1b |
| 12386 | description: |
| 12387 | Check support for ((â¦)) and $((â¦)) vs (â¦) and $(â¦) |
| 12388 | stdin: |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 12389 | echo $( (echo fubar)|tr u x) $? |
| 12390 | expected-stdout: |
| 12391 | fxbar 0 |
| 12392 | --- |
| 12393 | name: better-parens-1c |
| 12394 | description: |
| 12395 | Check support for ((â¦)) and $((â¦)) vs (â¦) and $(â¦) |
| 12396 | stdin: |
| 12397 | x=$( (echo fubar)|tr u x); echo $x $? |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 12398 | expected-stdout: |
| 12399 | fxbar 0 |
| 12400 | --- |
| 12401 | name: better-parens-2a |
| 12402 | description: |
| 12403 | Check support for ((â¦)) and $((â¦)) vs (â¦) and $(â¦) |
| 12404 | stdin: |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 12405 | if ((echo fubar)|tr u x); then |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 12406 | echo ja |
| 12407 | else |
| 12408 | echo nein |
| 12409 | fi |
| 12410 | expected-stdout: |
| 12411 | fxbar |
| 12412 | ja |
| 12413 | --- |
| 12414 | name: better-parens-2b |
| 12415 | description: |
| 12416 | Check support for ((â¦)) and $((â¦)) vs (â¦) and $(â¦) |
| 12417 | stdin: |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 12418 | echo $((echo fubar)|tr u x) $? |
| 12419 | expected-stdout: |
| 12420 | fxbar 0 |
| 12421 | --- |
| 12422 | name: better-parens-2c |
| 12423 | description: |
| 12424 | Check support for ((â¦)) and $((â¦)) vs (â¦) and $(â¦) |
| 12425 | stdin: |
| 12426 | x=$((echo fubar)|tr u x); echo $x $? |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 12427 | expected-stdout: |
| 12428 | fxbar 0 |
| 12429 | --- |
| 12430 | name: better-parens-3a |
| 12431 | description: |
| 12432 | Check support for ((â¦)) and $((â¦)) vs (â¦) and $(â¦) |
| 12433 | stdin: |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 12434 | if ( (echo fubar)|(tr u x)); then |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 12435 | echo ja |
| 12436 | else |
| 12437 | echo nein |
| 12438 | fi |
| 12439 | expected-stdout: |
| 12440 | fxbar |
| 12441 | ja |
| 12442 | --- |
| 12443 | name: better-parens-3b |
| 12444 | description: |
| 12445 | Check support for ((â¦)) and $((â¦)) vs (â¦) and $(â¦) |
| 12446 | stdin: |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 12447 | echo $( (echo fubar)|(tr u x)) $? |
| 12448 | expected-stdout: |
| 12449 | fxbar 0 |
| 12450 | --- |
| 12451 | name: better-parens-3c |
| 12452 | description: |
| 12453 | Check support for ((â¦)) and $((â¦)) vs (â¦) and $(â¦) |
| 12454 | stdin: |
| 12455 | x=$( (echo fubar)|(tr u x)); echo $x $? |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 12456 | expected-stdout: |
| 12457 | fxbar 0 |
| 12458 | --- |
| 12459 | name: better-parens-4a |
| 12460 | description: |
| 12461 | Check support for ((â¦)) and $((â¦)) vs (â¦) and $(â¦) |
| 12462 | stdin: |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 12463 | if ((echo fubar)|(tr u x)); then |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 12464 | echo ja |
| 12465 | else |
| 12466 | echo nein |
| 12467 | fi |
| 12468 | expected-stdout: |
| 12469 | fxbar |
| 12470 | ja |
| 12471 | --- |
| 12472 | name: better-parens-4b |
| 12473 | description: |
| 12474 | Check support for ((â¦)) and $((â¦)) vs (â¦) and $(â¦) |
| 12475 | stdin: |
Geremy Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 12476 | echo $((echo fubar)|(tr u x)) $? |
| 12477 | expected-stdout: |
| 12478 | fxbar 0 |
| 12479 | --- |
| 12480 | name: better-parens-4c |
| 12481 | description: |
| 12482 | Check support for ((â¦)) and $((â¦)) vs (â¦) and $(â¦) |
| 12483 | stdin: |
| 12484 | x=$((echo fubar)|(tr u x)); echo $x $? |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 12485 | expected-stdout: |
| 12486 | fxbar 0 |
| 12487 | --- |
Elliott Hughes | fc0307d | 2016-02-02 15:26:47 -0800 | [diff] [blame] | 12488 | name: better-parens-5 |
| 12489 | description: |
| 12490 | Another corner case |
| 12491 | stdin: |
| 12492 | ( (echo 'fo o$bar' "baz\$bla\"" m\$eh) | tr a A) |
| 12493 | ((echo 'fo o$bar' "baz\$bla\"" m\$eh) | tr a A) |
| 12494 | expected-stdout: |
| 12495 | fo o$bAr bAz$blA" m$eh |
| 12496 | fo o$bAr bAz$blA" m$eh |
| 12497 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 12498 | name: echo-test-1 |
| 12499 | description: |
| 12500 | Test what the echo builtin does (mksh) |
| 12501 | stdin: |
| 12502 | echo -n 'foo\x40bar' |
| 12503 | echo -e '\tbaz' |
| 12504 | expected-stdout: |
| 12505 | foo@bar baz |
| 12506 | --- |
| 12507 | name: echo-test-2 |
| 12508 | description: |
| 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. |
| 12514 | stdin: |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 12515 | test -n "$POSH_VERSION" || set -o posix |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 12516 | echo -n 'foo\x40bar' |
| 12517 | echo -e '\tbaz' |
| 12518 | expected-stdout: |
| 12519 | foo\x40bar-e \tbaz |
| 12520 | --- |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 12521 | name: echo-test-3-mnbsd |
| 12522 | description: |
| 12523 | Test what the echo builtin does, and test a compatibility flag. |
| 12524 | category: mnbsdash |
| 12525 | stdin: |
| 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 |
| 12529 | expected-stdout: |
| 12530 | 1=@foo. |
| 12531 | 2=\x40foo-e \x2E |
| 12532 | 3=\x40bar. |
| 12533 | --- |
| 12534 | name: echo-test-3-normal |
| 12535 | description: |
| 12536 | Test what the echo builtin does, and test a compatibility flag. |
| 12537 | category: !mnbsdash |
| 12538 | stdin: |
| 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 |
| 12542 | expected-stdout: |
| 12543 | 1=@foo. |
| 12544 | 2=\x40foo-e \x2E |
| 12545 | 3=\x40foo-e \x2E |
| 12546 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 12547 | name: utilities-getopts-1 |
| 12548 | description: |
| 12549 | getopts sets OPTIND correctly for unparsed option |
| 12550 | stdin: |
| 12551 | set -- -a -a -x |
| 12552 | while getopts :a optc; do |
| 12553 | echo "OPTARG=$OPTARG, OPTIND=$OPTIND, optc=$optc." |
| 12554 | done |
| 12555 | echo done |
| 12556 | expected-stdout: |
| 12557 | OPTARG=, OPTIND=2, optc=a. |
| 12558 | OPTARG=, OPTIND=3, optc=a. |
| 12559 | OPTARG=x, OPTIND=4, optc=?. |
| 12560 | done |
| 12561 | --- |
| 12562 | name: utilities-getopts-2 |
| 12563 | description: |
| 12564 | Check OPTARG |
| 12565 | stdin: |
| 12566 | set -- -a Mary -x |
| 12567 | while getopts a: optc; do |
| 12568 | echo "OPTARG=$OPTARG, OPTIND=$OPTIND, optc=$optc." |
| 12569 | done |
| 12570 | echo done |
| 12571 | expected-stdout: |
| 12572 | OPTARG=Mary, OPTIND=3, optc=a. |
| 12573 | OPTARG=, OPTIND=4, optc=?. |
| 12574 | done |
| 12575 | expected-stderr-pattern: /.*-x.*option/ |
| 12576 | --- |
Elliott Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 12577 | name: utilities-getopts-3 |
| 12578 | description: |
| 12579 | Check unsetting OPTARG |
| 12580 | stdin: |
| 12581 | set -- -x arg -y |
| 12582 | getopts x:y opt && echo "${OPTARG-unset}" |
| 12583 | getopts x:y opt && echo "${OPTARG-unset}" |
| 12584 | expected-stdout: |
| 12585 | arg |
| 12586 | unset |
| 12587 | --- |
Jean-Baptiste Queru | 5155f1c | 2011-06-16 10:05:28 -0700 | [diff] [blame] | 12588 | name: wcswidth-1 |
| 12589 | description: |
| 12590 | Check the new wcswidth feature |
| 12591 | stdin: |
| 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} . |
| 12606 | expected-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 | --- |
| 12616 | name: wcswidth-2 |
| 12617 | description: |
| 12618 | Check some corner cases |
| 12619 | stdin: |
| 12620 | print % $% . |
| 12621 | set -U |
| 12622 | x='a b' |
| 12623 | print c ${%x} . |
| 12624 | set +U |
| 12625 | x='a b' |
| 12626 | print d ${%x} . |
| 12627 | expected-stdout: |
| 12628 | % $% . |
| 12629 | c -1 . |
| 12630 | d -1 . |
| 12631 | --- |
| 12632 | name: wcswidth-3 |
| 12633 | description: |
| 12634 | Check some corner cases |
| 12635 | stdin: |
| 12636 | print ${%} . |
| 12637 | expected-stderr-pattern: |
| 12638 | /bad substitution/ |
| 12639 | expected-exit: 1 |
| 12640 | --- |
| 12641 | name: wcswidth-4a |
| 12642 | description: |
| 12643 | Check some corner cases |
| 12644 | stdin: |
| 12645 | print ${%*} . |
| 12646 | expected-stderr-pattern: |
| 12647 | /bad substitution/ |
| 12648 | expected-exit: 1 |
| 12649 | --- |
| 12650 | name: wcswidth-4b |
| 12651 | description: |
| 12652 | Check some corner cases |
| 12653 | stdin: |
| 12654 | print ${%@} . |
| 12655 | expected-stderr-pattern: |
| 12656 | /bad substitution/ |
| 12657 | expected-exit: 1 |
| 12658 | --- |
| 12659 | name: wcswidth-4c |
| 12660 | description: |
| 12661 | Check some corner cases |
| 12662 | stdin: |
| 12663 | : |
| 12664 | print ${%?} . |
| 12665 | expected-stdout: |
| 12666 | 1 . |
| 12667 | --- |
| 12668 | name: realpath-1 |
| 12669 | description: |
| 12670 | Check proper return values for realpath |
| 12671 | category: os:mirbsd |
| 12672 | stdin: |
| 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 |
| 12713 | expected-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 Condra | 03ebf06 | 2011-10-12 18:17:24 -0700 | [diff] [blame] | 12740 | name: realpath-2 |
| 12741 | description: |
| 12742 | Ensure that exactly two leading slashes are not collapsed |
| 12743 | POSIX guarantees this exception, e.g. for UNC paths on Cygwin |
| 12744 | category: os:mirbsd |
| 12745 | stdin: |
| 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 |
| 12764 | expected-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 | --- |
| 12778 | name: crash-1 |
| 12779 | description: |
| 12780 | Crashed during March 2011, fixed on vernal equinÅx ⺠|
| 12781 | category: os:mirbsd,os:openbsd |
| 12782 | stdin: |
| 12783 | export MALLOC_OPTIONS=FGJPRSX |
| 12784 | "$__progname" -c 'x=$(tr z r <<<baz); echo $x' |
| 12785 | expected-stdout: |
| 12786 | bar |
| 12787 | --- |
| 12788 | name: debian-117-1 |
| 12789 | description: |
| 12790 | Check test - bug#465250 |
| 12791 | stdin: |
| 12792 | test \( ! -e \) ; echo $? |
| 12793 | expected-stdout: |
| 12794 | 1 |
| 12795 | --- |
| 12796 | name: debian-117-2 |
| 12797 | description: |
| 12798 | Check test - bug#465250 |
| 12799 | stdin: |
| 12800 | test \( -e \) ; echo $? |
| 12801 | expected-stdout: |
| 12802 | 0 |
| 12803 | --- |
| 12804 | name: debian-117-3 |
| 12805 | description: |
| 12806 | Check test - bug#465250 |
| 12807 | stdin: |
| 12808 | test ! -e ; echo $? |
| 12809 | expected-stdout: |
| 12810 | 1 |
| 12811 | --- |
| 12812 | name: debian-117-4 |
| 12813 | description: |
| 12814 | Check test - bug#465250 |
| 12815 | stdin: |
| 12816 | test -e ; echo $? |
| 12817 | expected-stdout: |
| 12818 | 0 |
| 12819 | --- |
| 12820 | name: case-zsh |
| 12821 | description: |
| 12822 | Check that zsh case variants work |
| 12823 | stdin: |
| 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 |
| 12844 | expected-stdout: |
| 12845 | b |
| 12846 | = |
| 12847 | b |
| 12848 | c |
| 12849 | x |
| 12850 | = |
| 12851 | b |
| 12852 | x |
| 12853 | --- |
Thorsten Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 12854 | name: case-braces |
| 12855 | description: |
| 12856 | Check that case end tokens are not mixed up (Debian #220272) |
| 12857 | stdin: |
| 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 |
| 12871 | expected-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 | --- |
| 12879 | name: command-shift |
| 12880 | description: |
| 12881 | Check that 'command shift' works |
| 12882 | stdin: |
| 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 |
| 12898 | expected-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 Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 12907 | name: command-pvV-posix-priorities |
| 12908 | description: |
| 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. |
| 12912 | stdin: |
| 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 |
| 12922 | expected-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 | --- |
| 12944 | name: whence-preserve-tradition |
| 12945 | description: |
| 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. |
| 12949 | category: os:mirbsd |
| 12950 | stdin: |
| 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 |
| 12960 | expected-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 Glaser | c2dc5de | 2013-02-18 23:02:51 +0000 | [diff] [blame] | 12978 | name: duffs-device |
| 12979 | description: |
| 12980 | Check that the compiler did not optimise-break them |
| 12981 | (lex.c has got a similar one in SHEREDELIM) |
| 12982 | stdin: |
| 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 |
| 12991 | expected-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 | --- |
| 12994 | name: stateptr-underflow |
| 12995 | description: |
| 12996 | This check overflows an Xrestpos stored in a short in R40 |
| 12997 | category: fastbox |
| 12998 | stdin: |
| 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 Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 13040 | name: xtrace-1 |
| 13041 | description: |
| 13042 | Check that "set -x" doesn't redirect too quickly |
| 13043 | stdin: |
| 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 Hughes | 77740fc | 2016-08-12 15:06:53 -0700 | [diff] [blame] | 13050 | "$__progname" -xc 'foo=$(./bash --version 2>&1 | sed q); echo "=$foo="' |
Thorsten Glaser | 811a575 | 2013-07-25 14:24:45 +0000 | [diff] [blame] | 13051 | expected-stdout: |
| 13052 | =GNU bash, version 2.05b.0(1)-release (i386-ecce-mirbsd10)= |
| 13053 | expected-stderr-pattern: |
| 13054 | /.*/ |
| 13055 | --- |
Elliott Hughes | 5001206 | 2015-03-10 22:22:24 -0700 | [diff] [blame] | 13056 | name: xtrace-2 |
| 13057 | description: |
| 13058 | Check that "set -x" is off during PS4 expansion |
| 13059 | stdin: |
| 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:$-)" |
| 13071 | expected-stdout: |
| 13072 | (o0:sh) |
| 13073 | (o1:shx) |
| 13074 | (o2:sh) |
| 13075 | expected-stderr: |
| 13076 | [(p:sh)(f1:sh)(f2:sh)] print '(o1:shx)' |
| 13077 | [(p:sh)(f1:sh)(f2:sh)] set +x |
| 13078 | --- |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 13079 | name: fksh-flags |
| 13080 | description: |
| 13081 | Check that FKSH functions have their own shell flags |
| 13082 | category: shell:legacy-no |
| 13083 | stdin: |
| 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}" . |
| 13094 | expected-stdout: |
| 13095 | 1 fh . |
| 13096 | 2 eh . |
| 13097 | 3 fh . |
| 13098 | --- |
Elliott Hughes | b27ce95 | 2015-04-21 13:39:18 -0700 | [diff] [blame] | 13099 | name: fksh-flags-legacy |
| 13100 | description: |
| 13101 | Check that even FKSH functions share the shell flags |
Elliott Hughes | 96b4363 | 2015-07-17 11:39:41 -0700 | [diff] [blame] | 13102 | category: shell:legacy-yes |
Elliott Hughes | b27ce95 | 2015-04-21 13:39:18 -0700 | [diff] [blame] | 13103 | stdin: |
| 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}" . |
| 13114 | expected-stdout: |
| 13115 | 1 fh . |
| 13116 | 2 eh . |
| 13117 | 3 eh . |
| 13118 | --- |
| 13119 | name: fsh-flags |
| 13120 | description: |
| 13121 | Check that !FKSH functions share the shell flags |
| 13122 | stdin: |
| 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}" . |
| 13133 | expected-stdout: |
| 13134 | 1 fh . |
| 13135 | 2 eh . |
| 13136 | 3 eh . |
| 13137 | --- |