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/recipe/buildscript/testscript | 693 +++++++++++++++++++++++++++++++- tests/test/script/runner/for.testscript | 375 +++++++++++++++++ tests/test/script/runner/set.testscript | 195 +++++++++ 3 files changed, 1249 insertions(+), 14 deletions(-) (limited to 'tests') diff --git a/tests/recipe/buildscript/testscript b/tests/recipe/buildscript/testscript index 0ac5d5a..531baa9 100644 --- a/tests/recipe/buildscript/testscript +++ b/tests/recipe/buildscript/testscript @@ -886,29 +886,164 @@ if $posix EOE } -: flow-control-construct +: loop : { : while : { - echo 'bar' >=bar; + : basics + : + { + echo 'bar' >=bar; - cat <=buildfile; - foo: bar - {{ - p = $path($>) - while test -f $p != 0 - cp $path($<) $p - end - }} - EOI + cat <=buildfile; + foo: bar + {{ + p = $path($>) + while test -f $p != 0 + cp $path($<) $p + end + }} + EOI - $* 2>'cp file{foo}'; + $* 2>'cp file{foo}'; - cat <<'bar'; + cat <<'bar'; - $* clean 2>- + $* clean 2>- + } + + : exit + : + { + echo 'bar' >=bar; + + cat <=buildfile; + foo: bar + {{ + diag gen ($>) + + p = $path($>) + while test -f $p != 0 + touch $p + exit + cp $path($<) $p + end + }} + EOI + + $* 2>'gen file{foo.}'; + + cat <<:''; + + $* clean 2>- + } + + : error + : + { + echo 'bar' >=bar; + + cat <=buildfile; + foo: bar + {{ + diag gen ($>) + + p = $path($>) + while test -f $p != 0 + touch $p + exit 'fed up' + cp $path($<) $p + end + }} + EOI + + $* 2>>~%EOE% != 0; + gen file{foo.} + buildfile:8:5: error: fed up + %.{3} + EOE + + $* clean 2>- + } + + : depdb + : + { + : inside + : + { + echo 'bar' >=bar; + + cat <=buildfile; + foo: bar + {{ + p = $path($>) + while test -f $p != 0 + depdb hash $p + cp $path($<) $p + end + }} + EOI + + $* 2>>EOE != 0 + buildfile:5:5: error: 'depdb' call inside flow control construct + EOE + } + + : after-commands + : + { + echo 'bar' >=bar; + + cat <=buildfile; + foo: bar + {{ + p = $path($>) + while test -f $p != 0 + cp $path($<) $p + end + + depdb hash $p + }} + EOI + + $* 2>>~%EOE% != 0; + buildfile:5:5: error: disallowed command in depdb preamble + info: only variable assignments are allowed in depdb preamble + buildfile:8:3: info: depdb preamble ends here + %.{3} + EOE + + $* clean 2>- + } + + : after-vars + : + { + echo 'bar' >=bar; + + cat <=buildfile; + foo: bar + {{ + p = $path($<) + + h = + while test -f $p != 0 + h += $p + end + + depdb hash $p + + cat $p >$path($>) + }} + EOI + + $* 2>'cat file{foo}'; + $* clean 2>- + } + } } : for @@ -947,6 +1082,85 @@ if $posix $* clean 2>- } + : special-var + : + { + echo 'bar' >=bar; + echo 'baz' >=baz; + + cat <=buildfile; + foo: bar + {{ + p = $path($>) + rm -f $p + + for ~: $< + cat $path($f) >>$p + end + }} + EOI + + $* 2>>EOE != 0 + buildfile:6:7: error: attempt to set '~' special variable + EOE + } + + : exit + : + { + echo 'bar' >=bar; + echo 'baz' >=baz; + + cat <=buildfile; + foo: bar + {{ + p = $path($>) + rm -f $p + + for f: $< + cat $path($f) >>$p + exit + end + }} + EOI + + $* 2>'cat file{foo}'; + + cat <<>EOO; + bar + EOO + + $* clean 2>- + } + + : error + : + { + echo 'bar' >=bar; + echo 'baz' >=baz; + + cat <=buildfile; + foo: bar + {{ + p = $path($>) + rm -f $p + + for f: $< + cat $path($f) >>$p + exit 'fed up' + end + }} + EOI + + $* 2>>~%EOE% != 0; + cat file{foo} + buildfile:8:5: error: fed up + %.{3} + EOE + + $* clean 2>- + } + : depdb : { @@ -1031,5 +1245,456 @@ if $posix } } } + + : form-2 + : + : ... | for x + : + { + : basics + : + { + echo 'bar' >=bar; + echo 'baz' >=baz; + + cat <=buildfile; + foo: bar baz + {{ + diag gen ($>) + + p = $path($>) + rm -f $p + + echo $path($<) | for -w f + cat $f >>$p + end + }} + EOI + + $* 2>'gen file{foo.}'; + + cat <<>EOO; + bar + baz + EOO + + $* clean 2>- + } + + : special-var + : + { + echo 'bar' >=bar; + echo 'baz' >=baz; + + cat <=buildfile; + foo: bar + {{ + diag gen ($>) + + p = $path($>) + rm -f $p + + echo $path($<) | for ~ + cat $f >>$p + end + }} + EOI + + $* 2>>~%EOE% != 0; + gen file{foo.} + buildfile:8:3: error: attempt to set '~' special variable + %.{3} + EOE + + $* clean 2>- + } + + : misuse + : + { + echo 'bar' >=bar; + echo 'baz' >=baz; + + cat <=buildfile; + foo: bar + {{ + diag gen ($>) + + p = $path($>) + rm -f $p + + echo $path($<) | for x: + cat $f >>$p + end + }} + EOI + + $* 2>>~%EOE% != 0; + gen file{foo.} + buildfile:8:3: error: for: ':' after variable name + %.{3} + EOE + + $* clean 2>- + } + + : exit + : + { + echo 'bar' >=bar; + echo 'baz' >=baz; + + cat <=buildfile; + foo: bar + {{ + diag gen ($>) + + p = $path($>) + rm -f $p + + echo $path($<) | for -w f + cat $f >>$p + exit + end + }} + EOI + + $* 2>'gen file{foo.}'; + + cat <<>EOO; + bar + EOO + + $* clean 2>- + } + + : error + : + { + echo 'bar' >=bar; + echo 'baz' >=baz; + + cat <=buildfile; + foo: bar + {{ + diag gen ($>) + + p = $path($>) + rm -f $p + + echo $path($<) | for -w f + cat $f >>$p + exit 'fed up' + end + }} + EOI + + $* 2>>~%EOE% != 0; + gen file{foo.} + buildfile:10:5: error: fed up + %.{3} + EOE + + $* clean 2>- + } + + : depdb + : + { + : inside + : + { + echo 'bar' >=bar; + + cat <=buildfile; + foo: bar + {{ + echo $path($<) | for -w f + depdb hash $f + end + + p = $path($>) + rm -f $p + + echo $path($<) | for -w f + cat $f >>$p + end + }} + EOI + + $* 2>>EOE != 0 + buildfile:4:5: error: 'depdb' call inside flow control construct + EOE + } + + : after-commands + : + { + echo 'bar' >=bar; + + cat <=buildfile; + foo: bar + {{ + echo $path($<) | for -w f + echo $f >- + end + + depdb hash $p + }} + EOI + + $* 2>>~%EOE% != 0; + buildfile:4:5: error: disallowed command in depdb preamble + info: only variable assignments are allowed in depdb preamble + buildfile:7:3: info: depdb preamble ends here + %.{3} + EOE + + $* clean 2>- + } + + : after-vars + : + { + echo 'bar' >=bar; + + cat <=buildfile; + foo: bar + {{ + h = + echo $path($<) | for -w f + h += $f + end + + depdb hash $h + + diag gen ($>) + + p = $path($>) + rm -f $p + + for f: $< + cat $path($f) >>$p + end + }} + EOI + + $* 2>'gen file{foo.}'; + $* clean 2>- + } + } + } + + : form-3 + : + : for x <... + : + { + : basics + : + { + echo 'bar' >=bar; + echo 'baz' >=baz; + + cat <=buildfile; + foo: bar baz + {{ + diag gen ($>) + + p = $path($>) + rm -f $p + + for -w f <<"EOF" + $path($<) + EOF + cat $f >>$p + end + + for <<"EOF" -w f + $path($<) + EOF + cat $f >>$p + end + }} + EOI + + $* 2>'gen file{foo.}'; + + cat <<>EOO; + bar + baz + bar + baz + EOO + + $* clean 2>- + } + + : special-var + : + { + echo 'bar' >=bar; + echo 'baz' >=baz; + + cat <=buildfile; + foo: bar + {{ + p = $path($>) + rm -f $p + + for ~ <<<$path($<) + cat $f >>$p + end + }} + EOI + + $* 2>>EOE != 0 + buildfile:6:6: error: attempt to set '~' special variable + EOE + } + + : exit + : + { + echo 'bar' >=bar; + echo 'baz' >=baz; + + cat <=buildfile; + foo: bar + {{ + p = $path($>) + rm -f $p + + for f <<<$path($<) + cat $f >>$p + exit + end + }} + EOI + + $* 2>'cat file{foo}'; + + cat <<>EOO; + bar + EOO + + $* clean 2>- + } + + : error + : + { + echo 'bar' >=bar; + echo 'baz' >=baz; + + cat <=buildfile; + foo: bar + {{ + p = $path($>) + rm -f $p + + for f <<<$path($<) + cat $f >>$p + exit 'fed up' + end + }} + EOI + + $* 2>>~%EOE% != 0; + cat file{foo} + buildfile:8:5: error: fed up + %.{3} + EOE + + $* clean 2>- + } + + : depdb + : + { + : inside + : + { + echo 'bar' >=bar; + + cat <=buildfile; + foo: bar + {{ + for -w f <<<$path($<) + depdb hash $f + end + + p = $path($>) + rm -f $p + + echo $path($<) | for -w f + cat $f >>$p + end + }} + EOI + + $* 2>>EOE != 0 + buildfile:4:5: error: 'depdb' call inside flow control construct + EOE + } + + : after-commands + : + { + echo 'bar' >=bar; + + cat <=buildfile; + foo: bar + {{ + for -w f <<<$path($<) + echo $f >- + end + + depdb hash a + }} + EOI + + $* 2>>~%EOE% != 0; + buildfile:4:5: error: disallowed command in depdb preamble + info: only variable assignments are allowed in depdb preamble + buildfile:7:3: info: depdb preamble ends here + %.{3} + EOE + + $* clean 2>- + } + + : after-vars + : + { + echo 'bar' >=bar; + + cat <=buildfile; + foo: bar + {{ + h = + for -w f <<<$path($<) + h += $f + end + + depdb hash $h + + diag gen ($>) + + p = $path($>) + rm -f $p + + for f: $< + cat $path($f) >>$p + end + }} + EOI + + $* 2>'gen file{foo.}'; + $* clean 2>- + } + } + } } } 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