aboutsummaryrefslogtreecommitdiff
path: root/tests/test/script/runner
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2017-01-27 02:32:55 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2017-01-31 15:54:33 +0300
commit749f748ae6ded6e229214d2dddf3c45482bffbd3 (patch)
treec504c8b225db01c8c152b3772467d16c036a42fc /tests/test/script/runner
parente61a287832532124a1a90a8bb9cc0f61f3a4db92 (diff)
Add support for test command pipe, expression and command-if
Diffstat (limited to 'tests/test/script/runner')
-rw-r--r--tests/test/script/runner/buildfile2
-rw-r--r--tests/test/script/runner/expr.test522
-rw-r--r--tests/test/script/runner/if.test25
-rw-r--r--tests/test/script/runner/pipe.test35
-rw-r--r--tests/test/script/runner/redirect.test52
5 files changed, 593 insertions, 43 deletions
diff --git a/tests/test/script/runner/buildfile b/tests/test/script/runner/buildfile
index 86c18e2..df37c6d 100644
--- a/tests/test/script/runner/buildfile
+++ b/tests/test/script/runner/buildfile
@@ -2,7 +2,7 @@
# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
# license : MIT; see accompanying LICENSE file
-./: test{cleanup redirect regex status} exe{driver} $b
+./: test{cleanup expr if pipe redirect regex status} exe{driver} $b
test{*}: target = exe{driver}
diff --git a/tests/test/script/runner/expr.test b/tests/test/script/runner/expr.test
new file mode 100644
index 0000000..454da1e
--- /dev/null
+++ b/tests/test/script/runner/expr.test
@@ -0,0 +1,522 @@
+# file : tests/test/script/runner/expr.test
+# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+.include ../common.test
+
+: short-circuit
+:
+: Test expression result calculation and short-circuiting. We verify the
+: correctness of the above for all possible expressions of a length up to 3
+: operands. While some of tests may look redundant the full expression tree is
+: easier to maintain than the one with gaps (also much less chances that we
+: have missed something useful). Each pipe-operand has a label which is printed
+: to stdout when the pipe is executed. Pipes stdouts are pass-redirected, so we
+: just check that build2 output matches expectations.
+:
+: Note that expression evaluation goes left-to-right with AND and OR having the
+: same precedence.
+:
+{
+ true = '$* >| -o'
+ false = '$* -s 1 >| -o'
+
+ bf = $b 2>/~'%.+/driver(\.exe)? exit status 1 != 0%'
+
+ : true
+ :
+ {
+ : TERM
+ :
+ $c <"$true 1" && $b >>EOO
+ 1
+ EOO
+
+ : OR
+ :
+ {
+ : true
+ :
+ {
+ : TERM
+ :
+ $c <"$true 1 || $true 2" && $b >>EOO
+ 1
+ EOO
+
+ : OR
+ :
+ {
+ : true
+ :
+ {
+ $c <"$true 1 || $true 2 || $true 3" && $b >>EOO
+ 1
+ EOO
+ }
+
+ : false
+ :
+ {
+ $c <"$true 1 || $true 2 || $false 3" && $b >>EOO
+ 1
+ EOO
+ }
+ }
+
+ : AND
+ :
+ {
+ : true
+ :
+ {
+ $c <"$true 1 || $true 2 && $true 3" && $b >>EOO
+ 1
+ 3
+ EOO
+ }
+
+ : false
+ :
+ {
+ $c <"$true 1 || $true 2 && $false 3" && $bf >>EOO != 0
+ 1
+ 3
+ EOO
+ }
+ }
+ }
+
+ : false
+ :
+ {
+ : TERM
+ :
+ $c <"$true 1 || $false 2" && $b >>EOO
+ 1
+ EOO
+
+ : OR
+ :
+ {
+ : true
+ :
+ {
+ $c <"$true 1 || $false 2 || $true 3" && $b >>EOO
+ 1
+ EOO
+ }
+
+ : false
+ :
+ {
+ $c <"$true 1 || $false 2 || $false 3" && $b >>EOO
+ 1
+ EOO
+ }
+ }
+
+ : AND
+ :
+ {
+ : true
+ :
+ {
+ $c <"$true 1 || $false 2 && $true 3" && $b >>EOO
+ 1
+ 3
+ EOO
+ }
+
+ : false
+ :
+ {
+ $c <"$true 1 || $false 2 && $false 3" && $bf >>EOO != 0
+ 1
+ 3
+ EOO
+ }
+ }
+ }
+ }
+
+ : AND
+ :
+ {
+ : true
+ :
+ {
+ : TERM
+ :
+ $c <"$true 1 && $true 2" && $b >>EOO
+ 1
+ 2
+ EOO
+
+ : OR
+ :
+ {
+ : true
+ :
+ {
+ $c <"$true 1 && $true 2 || $true 3" && $b >>EOO
+ 1
+ 2
+ EOO
+ }
+
+ : false
+ :
+ {
+ $c <"$true 1 && $true 2 || $false 3" && $b >>EOO
+ 1
+ 2
+ EOO
+ }
+ }
+
+ : AND
+ :
+ {
+ : true
+ :
+ {
+ $c <"$true 1 && $true 2 && $true 3" && $b >>EOO
+ 1
+ 2
+ 3
+ EOO
+ }
+
+ : false
+ :
+ {
+ $c <"$true 1 && $true 2 && $false 3" && $bf >>EOO != 0
+ 1
+ 2
+ 3
+ EOO
+ }
+ }
+ }
+
+ : false
+ :
+ {
+ : TERM
+ :
+ $c <"$true 1 && $false 2" && $bf >>EOO != 0
+ 1
+ 2
+ EOO
+
+ : OR
+ :
+ {
+ : true
+ :
+ {
+ $c <"$true 1 && $false 2 || $true 3" && $b >>EOO
+ 1
+ 2
+ 3
+ EOO
+ }
+
+ : false
+ :
+ {
+ $c <"$true 1 && $false 2 || $false 3" && $bf >>EOO != 0
+ 1
+ 2
+ 3
+ EOO
+ }
+ }
+
+ : AND
+ :
+ {
+ : true
+ :
+ {
+ $c <"$true 1 && $false 2 && $true 3" && $bf >>EOO != 0
+ 1
+ 2
+ EOO
+ }
+
+ : false
+ :
+ {
+ $c <"$true 1 && $false 2 && $false 3" && $bf >>EOO != 0
+ 1
+ 2
+ EOO
+ }
+ }
+ }
+ }
+ }
+
+ : false
+ :
+ {
+ : TERM
+ :
+ $c <"$false 1" && $bf >>EOO != 0
+ 1
+ EOO
+
+ : OR
+ :
+ {
+ : true
+ :
+ {
+ : TERM
+ :
+ $c <"$false 1 || $true 2" && $b >>EOO
+ 1
+ 2
+ EOO
+
+ : OR
+ :
+ {
+ : true
+ :
+ {
+ $c <"$false 1 || $true 2 || $true 3" && $b >>EOO
+ 1
+ 2
+ EOO
+ }
+
+ : false
+ :
+ {
+ $c <"$false 1 || $true 2 || $false 3" && $b >>EOO
+ 1
+ 2
+ EOO
+ }
+ }
+
+ : AND
+ :
+ {
+ : true
+ :
+ {
+ $c <"$false 1 || $true 2 && $true 3" && $b >>EOO
+ 1
+ 2
+ 3
+ EOO
+ }
+
+ : false
+ :
+ {
+ $c <"$false 1 || $true 2 && $false 3" && $bf >>EOO != 0
+ 1
+ 2
+ 3
+ EOO
+ }
+ }
+ }
+
+ : false
+ :
+ {
+ : TERM
+ :
+ $c <"$false 1 || $false 2" && $bf >>EOO != 0
+ 1
+ 2
+ EOO
+
+ : OR
+ :
+ {
+ : true
+ :
+ {
+ $c <"$false 1 || $false 2 || $true 3" && $b >>EOO
+ 1
+ 2
+ 3
+ EOO
+ }
+
+ : false
+ :
+ {
+ $c <"$false 1 || $false 2 || $false 3" && $bf >>EOO != 0
+ 1
+ 2
+ 3
+ EOO
+ }
+ }
+
+ : AND
+ :
+ {
+ : true
+ :
+ {
+ $c <"$false 1 || $false 2 && $true 3" && $bf >>EOO != 0
+ 1
+ 2
+ EOO
+ }
+
+ : false
+ :
+ {
+ $c <"$false 1 || $false 2 && $false 3" && $bf >>EOO != 0
+ 1
+ 2
+ EOO
+ }
+ }
+ }
+ }
+
+ : AND
+ :
+ {
+ : true
+ :
+ {
+ : TERM
+ :
+ $c <"$false 1 && $true 2" && $bf >>EOO != 0
+ 1
+ EOO
+
+ : OR
+ :
+ {
+ : true
+ :
+ {
+ $c <"$false 1 && $true 2 || $true 3" && $b >>EOO
+ 1
+ 3
+ EOO
+ }
+
+ : false
+ :
+ {
+ $c <"$false 1 && $true 2 || $false 3" && $bf >>EOO != 0
+ 1
+ 3
+ EOO
+ }
+ }
+
+ : AND
+ :
+ {
+ : true
+ :
+ {
+ $c <"$false 1 && $true 2 && $true 3" && $bf >>EOO != 0
+ 1
+ EOO
+ }
+
+ : false
+ :
+ {
+ $c <"$false 1 && $true 2 && $false 3" && $bf >>EOO != 0
+ 1
+ EOO
+ }
+ }
+ }
+
+ : false
+ :
+ {
+ : TERM
+ :
+ $c <"$false 1 && $false 2" && $bf >>EOO != 0
+ 1
+ EOO
+
+ : OR
+ :
+ {
+ : true
+ :
+ {
+ $c <"$false 1 && $false 2 || $true 3" && $b >>EOO
+ 1
+ 3
+ EOO
+ }
+
+ : false
+ :
+ {
+ $c <"$false 1 && $false 2 || $false 3" && $bf >>EOO != 0
+ 1
+ 3
+ EOO
+ }
+ }
+
+ : AND
+ :
+ {
+ : true
+ :
+ {
+ $c <"$false 1 && $false 2 && $true 3" && $bf >>EOO != 0
+ 1
+ EOO
+ }
+
+ : false
+ :
+ {
+ $c <"$false 1 && $false 2 && $false 3" && $bf >>EOO != 0
+ 1
+ EOO
+ }
+ }
+ }
+ }
+ }
+}
+
+: diagnostics
+:
+: Check that the diagnostics is printed for only the last faulty pipe.
+:
+{
+ true = '$*'
+ false = '$* -s 1 2>'X' -e' # Compares stderr to value that never matches.
+
+ : trailing
+ :
+ $c <"$false 1 != 0 || $true && $false 2 != 0" && $b 2>>~/EOE/ != 0
+ /.{7}
+ -X
+ +2
+ EOE
+
+ : non-trailing
+ :
+ $c <"$false 1 != 0 || $true && $false 2 != 0 && $true" && $b 2>>~/EOE/ != 0
+ /.{7}
+ -X
+ +2
+ EOE
+}
diff --git a/tests/test/script/runner/if.test b/tests/test/script/runner/if.test
new file mode 100644
index 0000000..d9c3601
--- /dev/null
+++ b/tests/test/script/runner/if.test
@@ -0,0 +1,25 @@
+# file : tests/test/script/runner/if.test
+# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+.include ../common.test
+
+: if-branch
+:
+$c <<EOI && $b >'if'
+if cat <'foo' >'foo'
+ echo 'if' >|
+else
+ echo 'else' >|
+end
+EOI
+
+: else-branch
+:
+$c <<EOI && $b >'else'
+if cat <'foo' >'bar'
+ echo 'if' >|
+else
+ echo 'else' >|
+end
+EOI
diff --git a/tests/test/script/runner/pipe.test b/tests/test/script/runner/pipe.test
new file mode 100644
index 0000000..bfbe8cb
--- /dev/null
+++ b/tests/test/script/runner/pipe.test
@@ -0,0 +1,35 @@
+# file : tests/test/script/runner/pipe.test
+# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+.include ../common.test
+
+$c <'cat <foo | $* -i 1 >foo' && $b : builtin-to-process
+$c <'$* -o foo | cat >foo' && $b : process-to-builtin
+
+
+: failure
+:
+: Note that while both commands for the pipe are faulty the diagnostics for
+: only the last one is printed.
+:
+{
+ : exit-code
+ :
+ $c <'$* -o foo -s 1 | $* -i 1 >foo -s 2' && $b 2>>/~%EOE% != 0
+ %testscript:1:1: error: .+ exit status 2 != 0%
+ info: stdout: test/1/stdout-2
+ EOE
+
+ : stderr
+ :
+ $c <'$* -o foo -e foo 2>bar | $* -i 2 2>baz' && $b 2>>/~%EOE% != 0
+ %testscript:1:1: error: .+ stderr doesn't match the expected output%
+ info: stderr: test/1/stderr-2
+ info: expected stderr: test/1/stderr-2.orig
+ info: stderr diff: test/1/stderr-2.diff
+ %.{3}
+ -baz
+ +foo
+ EOE
+}
diff --git a/tests/test/script/runner/redirect.test b/tests/test/script/runner/redirect.test
index 7cb6316..cfc12c5 100644
--- a/tests/test/script/runner/redirect.test
+++ b/tests/test/script/runner/redirect.test
@@ -9,6 +9,16 @@ b += --no-column
ps = ($cxx.target.class != 'windows' ? '/' : '\') # Path separator.
psr = ($cxx.target.class != 'windows' ? '/' : '\\') # Path separator in regex.
+: pass
+:
+{
+ $c <'$* -i 1 -e bar <| >| 2>|';
+ cat <<EOI >=buildfile;
+ test{testscript}: $target
+ EOI
+ $0 --jobs 1 --quiet test <foo >foo 2>bar
+}
+
: null
:
{
@@ -540,45 +550,3 @@ psr = ($cxx.target.class != 'windows' ? '/' : '\\') # Path separator in regex.
EOI
$b
}
-
-# @@ That will probably become redundant when builtins and process obtain file
-# descriptors uniformly.
-#
-: builtins
-:
-{
- : out-null
- :
- $c <'echo "abc" >-';
- $b
-
- : err-null
- :
- $c <'echo "abc" 1>&2 2>-';
- $b
-
- : in-str
- :
- $c <'echo <foo 1>-';
- $b
-
- : out-str
- :
- $c <'echo "foo" >foo';
- $b
-
- : err-str
- :
- $c <'echo "foo" 2>foo 1>&2';
- $b
-
- : inout-str
- :
- $c <'cat <foo >foo';
- $b
-
- : inerr-str
- :
- $c <'cat <foo 2>foo 1>&2';
- $b
-}