From f59d82eb8fda3ddcf790556c6c3615e40ae8b15b Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 3 Oct 2022 21:23:22 +0300 Subject: Add support for 'for' loop second (... | for x) and third (for x <...) forms in script --- tests/test/script/runner/for.testscript | 375 ++++++++++++++++++++++++++++++++ tests/test/script/runner/set.testscript | 195 +++++++++++++++++ 2 files changed, 570 insertions(+) (limited to 'tests/test') diff --git a/tests/test/script/runner/for.testscript b/tests/test/script/runner/for.testscript index 21042e5..054e9ab 100644 --- a/tests/test/script/runner/for.testscript +++ b/tests/test/script/runner/for.testscript @@ -39,4 +39,379 @@ EOI testscript:1:5: error: attempt to set '*' variable directly EOE + + : exit + : + $c <>EOO + for x: a b + echo "$x" >| + exit + end + EOI + a + EOO + + : error + : + $c <>EOO 2>>EOE != 0 + for x: a b + echo "$x" >| + exit 'fed up' + end + EOI + a + EOO + testscript:3:3: error: fed up + info: test id: 1 + EOE +} + +: form-2 +: +: ... | for x +: +{ + : whitespace-split + : + $c <>EOO + echo " a b " | for -w x + echo "'$x'" >| + end + EOI + 'a' + 'b' + EOO + + : newline-split + : + $c <>EOO + cat <| + end + EOI + '' + '' + 'a' + '' + '' + 'b' + '' + EOO + + : typed + : + $c <>/EOO + echo "a b" | for -w [dir_path] x + echo $x >| + end + EOI + a/ + b/ + EOO + + : nested + : + $c <>EOO + echo "a b" | for -w x + echo "x y" | for -w y + echo "'$x $y'" >| + end + end + EOI + 'a x' + 'a y' + 'b x' + 'b y' + EOO + + : nested-diag + : + $c <>/~%EOE% != 0 + echo "a b" | for -w x + echo "x y" | for -w y + echo "'$x $y'" >"'a x'" + end + end + EOI + testscript:3:5: error: echo stdout doesn't match expected + info: stdout: test/1/stdout-i1-i2-n3 + info: expected stdout: test/1/stdout-i1-i2-n3.orig + info: stdout diff: test/1/stdout-i1-i2-n3.diff + %.+ + EOE + + : var-value + : + $c <>EOO + x = 'x'; + echo "a b" | for -w x + end; + echo $x >| + EOI + b + EOO + + : invalid-option + : + $c <>/~%EOE% != 0 + echo "a b" | for -a x + echo $x >| + end + EOI + testscript:1:1: error: for: unknown option '-a' + %. + EOE + + + : no-variable + : + $c <>/~%EOE% != 0 + echo "a b" | for -w + echo $x >| + end + EOI + testscript:1:1: error: for: missing variable name + %. + EOE + + : special-var + : + $c <>EOE != 0 + echo "a b" | for -w * + echo $* >| + end + EOI + testscript:1:1: error: attempt to set '*' variable directly + info: test id: 1 + EOE + + : misuse + : + $c <>EOE != 0 + echo "a b" | for v: + echo $v >| + end + EOI + testscript:1:19: error: expected newline instead of ':' + EOE + + : exit + : + $c <>EOO + for x: a b + echo "$x" >| + exit + end + EOI + a + EOO + + : error + : + $c <>EOO 2>>EOE != 0 + for x: a b + echo "$x" >| + exit 'fed up' + end + EOI + a + EOO + testscript:3:3: error: fed up + info: test id: 1 + EOE +} + +: form-3 +: +: for x <... +: +{ + : whitespace-split + : + $c <>EOO + for -w x <" a b " + echo "'$x'" >| + end + EOI + 'a' + 'b' + EOO + + : newline-split + : + $c <>EOO + for -n x <| + end + EOI + '' + '' + 'a' + '' + '' + 'b' + '' + EOO + + : string-before-var + : + $c <>EOO + for <"a b" -w x + echo "'$x'" >| + end + EOI + 'a' + 'b' + EOO + + : here-doc-before-var + : + $c <>EOO + for <| + end + EOI + 'a' + 'b' + EOO + + : typed + : + $c <>/EOO + for -w [dir_path] x <"a b" + echo $x >| + end + EOI + a/ + b/ + EOO + + : typed-no-ops + : + $c <>/EOO + for [dir_path] x <"a b" + echo $x >| + end + EOI + a b/ + EOO + + : nested + : + $c <>EOO + for -w x <"a b" + for -w y <"x y" + echo "'$x $y'" >| + end + end + EOI + 'a x' + 'a y' + 'b x' + 'b y' + EOO + + : nested-diag + : + $c <>/~%EOE% != 0 + for -w x <"a b" + for -w y <"x y" + echo "'$x $y'" >"'a x'" + end + end + EOI + testscript:3:5: error: echo stdout doesn't match expected + info: stdout: test/1/stdout-i1-i2-n3 + info: expected stdout: test/1/stdout-i1-i2-n3.orig + info: stdout diff: test/1/stdout-i1-i2-n3.diff + %.+ + EOE + + : var-value + : + $c <>EOO + x = 'x'; + for -w x <"a b" + end; + echo $x >| + EOI + b + EOO + + : invalid-option + : + $c <>/~%EOE% != 0 + for -a x <"a b" + echo $x >| + end + EOI + testscript:1:1: error: for: unknown option '-a' + %. + EOE + + + : no-variable + : + $c <>/~%EOE% != 0 + for -w <"a b" + echo $x >| + end + EOI + testscript:1:1: error: for: missing variable name + %. + EOE + + : special-var + : + $c <>EOE != 0 + for * <"a b" + echo $* >| + end + EOI + testscript:1:5: error: attempt to set '*' variable directly + EOE + + : exit + : + $c <>EOO + for x: a b + echo "$x" >| + exit + end + EOI + a + EOO + + : error + : + $c <>EOO 2>>EOE != 0 + for x: a b + echo "$x" >| + exit 'fed up' + end + EOI + a + EOO + testscript:3:3: error: fed up + info: test id: 1 + EOE } diff --git a/tests/test/script/runner/set.testscript b/tests/test/script/runner/set.testscript index b2944a3..b4c8089 100644 --- a/tests/test/script/runner/set.testscript +++ b/tests/test/script/runner/set.testscript @@ -343,6 +343,201 @@ EOE EOI } + + : split + : + : Test various splitting modes as above, but now reading the stream in the + : non-blocking mode. + : + { + : whitespace-separated-list + : + { + : non-exact + : + { + : non-empty + : + $c <'"foo" "bar"' + EOI + + : empty + : + $c <'' + EOI + + : spaces + : + $c <'' + EOI + } + + : exact + : + { + : trailing-ws + : + $c <'"foo" "bar" ""' + EOI + + : no-trailing-ws + : + : Note that we need to strip the default trailing newline as well with the + : ':' modifier. + : + $c <'"foo" "bar"' + EOI + + : empty + : + $c <'' + EOI + + : spaces + : + $c <'""' + EOI + } + } + + : newline-separated-list + : + { + : non-exact + : + $c <'"" "foo" "" "bar" ""' + EOI + + : exact + : + { + : trailing-newline + : + $c <'"" "foo" "" "bar" "" ""' + EOI + + : no-trailing-newline + : + $c <'"" "foo" "" "bar"' + EOI + } + } + + : string + : + { + : non-exact + : + $c <>EOO + + foo + + bar + + EOO + EOI + + : exact + : + : Note that echo adds the trailing newline, so EOF and EOO here-documents + : differ by this newline. + : + { + : trailing-newline + : + $c <>EOO + + foo + + bar + + EOO + EOI + + : no-trailing-newline + : + $c <>EOO + + foo + + bar + EOO + EOI + } + } + } } : attributes -- cgit v1.1