aboutsummaryrefslogtreecommitdiff
path: root/unit-tests/test/script/parser
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-11-10 16:33:12 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-11-10 16:33:12 +0200
commita084c6650036db9f2a8cd69e31492c5dae237793 (patch)
treeba3e34f6e85ae9e0073476b0dc46956c51039189 /unit-tests/test/script/parser
parentf1cbb7c9d5c750366fa1918a53d0682f0633b1d9 (diff)
Implement scope-if in testscript
Diffstat (limited to 'unit-tests/test/script/parser')
-rw-r--r--unit-tests/test/script/parser/buildfile6
-rw-r--r--unit-tests/test/script/parser/command-if.test (renamed from unit-tests/test/script/parser/if-else.test)3
-rw-r--r--unit-tests/test/script/parser/scope-if.test529
-rw-r--r--unit-tests/test/script/parser/scope.test10
4 files changed, 536 insertions, 12 deletions
diff --git a/unit-tests/test/script/parser/buildfile b/unit-tests/test/script/parser/buildfile
index eab5b36..2ed60ec 100644
--- a/unit-tests/test/script/parser/buildfile
+++ b/unit-tests/test/script/parser/buildfile
@@ -11,8 +11,8 @@ filesystem config/{utility init operation} dump types-parsers \
test/{target script/{token lexer parser script}}
exe{driver}: cxx{driver} ../../../../build2/cxx{$src} $libs \
-test{cleanup command-re-parse description exit expansion here-document \
- here-string if-else include pipe-expr pre-parse redirect scope \
- setup-teardown}
+test{cleanup command-if command-re-parse description exit expansion \
+ here-document here-string include pipe-expr pre-parse redirect \
+ scope scope-if setup-teardown}
include ../../../../build2/
diff --git a/unit-tests/test/script/parser/if-else.test b/unit-tests/test/script/parser/command-if.test
index 8663920..88cc7d6 100644
--- a/unit-tests/test/script/parser/if-else.test
+++ b/unit-tests/test/script/parser/command-if.test
@@ -299,11 +299,12 @@ EOE
:
$* <<EOI 2>>EOE != 0
if
+ cmd
{
}
end
EOI
-testscript:2:3: error: expected closing 'end'
+testscript:3:3: error: expected closing 'end'
EOE
: setup-inside
diff --git a/unit-tests/test/script/parser/scope-if.test b/unit-tests/test/script/parser/scope-if.test
new file mode 100644
index 0000000..e04c47e
--- /dev/null
+++ b/unit-tests/test/script/parser/scope-if.test
@@ -0,0 +1,529 @@
+: if-true
+:
+$* -s <<EOI >>EOO
+if true foo
+{
+ cmd
+}
+EOI
+{
+ ? true foo
+ {
+ cmd
+ }
+}
+EOO
+
+: if-false
+:
+$* -s <<EOI >>EOO
+if false foo
+{
+ cmd
+}
+EOI
+{
+ ? false foo
+}
+EOO
+
+: ifn-true
+:
+$* -s <<EOI >>EOO
+if! true
+{
+ cmd
+}
+EOI
+{
+ ? true
+}
+EOO
+
+: ifn-false
+:
+$* -s <<EOI >>EOO
+if! false
+{
+ cmd
+}
+EOI
+{
+ ? false
+ {
+ cmd
+ }
+}
+EOO
+
+: elif-true
+:
+$* -s <<EOI >>EOO
+if false
+{
+ cmd
+}
+elif true
+{
+ cmd1
+}
+EOI
+{
+ ? false
+ ? true
+ {
+ cmd1
+ }
+}
+EOO
+
+: elif-false
+:
+$* -s <<EOI >>EOO
+if false
+{
+ cmd
+}
+elif false
+{
+ cmd
+}
+EOI
+{
+ ? false
+ ? false
+}
+EOO
+
+: elifn-false
+:
+$* -s <<EOI >>EOO
+if false
+{
+ cmd
+}
+elif! false
+{
+ cmd1
+}
+EOI
+{
+ ? false
+ ? false
+ {
+ cmd1
+ }
+}
+EOO
+
+: elifn-true
+:
+$* -s <<EOI >>EOO
+if false
+{
+ cmd
+}
+elif! true
+{
+ cmd
+}
+EOI
+{
+ ? false
+ ? true
+}
+EOO
+
+: else-true
+:
+$* -s <<EOI >>EOO
+if false
+{
+ cmd
+}
+else
+{
+ cmd1
+}
+EOI
+{
+ ? false
+ {
+ cmd1
+ }
+}
+EOO
+
+: else-false
+:
+$* -s <<EOI >>EOO
+if true
+{
+ cmd1
+}
+else
+{
+ cmd
+}
+EOI
+{
+ ? true
+ {
+ cmd1
+ }
+}
+EOO
+
+: if-chain
+:
+$* -s <<EOI >>EOO
+if false
+{
+ cmd
+}
+elif false
+{
+ cmd
+ cmd
+}
+elif false
+{
+ cmd
+}
+elif true
+{
+ cmd1
+ cmd2
+}
+elif false
+{
+ cmd
+}
+else
+{
+ cmd
+ cmd
+}
+EOI
+{
+ ? false
+ ? false
+ ? false
+ ? true
+ {
+ {
+ cmd1
+ }
+ {
+ cmd2
+ }
+ }
+}
+EOO
+
+: nested-take
+:
+$* -s <<EOI >>EOO
+if true
+{
+ cmd1
+ if false
+ {
+ cmd
+ }
+ elif false
+ {
+ if true
+ {
+ cmd
+ }
+ }
+ else
+ {
+ cmd2
+ }
+ cmd3
+}
+EOI
+{
+ ? true
+ {
+ {
+ cmd1
+ }
+ ? false
+ ? false
+ {
+ {
+ cmd2
+ }
+ }
+ {
+ cmd3
+ }
+ }
+}
+EOO
+
+: nested-skip
+:
+$* -s <<EOI >>EOO
+if false
+{
+ cmd1
+ if false
+ {
+ cmd
+ }
+ elif false
+ {
+ if true
+ {
+ cmd
+ }
+ }
+ else
+ {
+ cmd2
+ }
+ cmd3
+}
+else
+{
+ cmd
+}
+EOI
+{
+ ? false
+ {
+ {
+ cmd
+ }
+ }
+}
+EOO
+
+: demote-group
+: Chain remains a group
+:
+$* -s <<EOI >>EOO
+if false
+{
+ cmd
+}
+elif true
+{
+ cmd1
+ cmd2
+}
+else
+{
+ cmd
+}
+EOI
+{
+ ? false
+ ? true
+ {
+ {
+ cmd1
+ }
+ {
+ cmd2
+ }
+ }
+}
+EOO
+
+: demote-test
+: Chain demoted to test
+:
+$* -s <<EOI >>EOO
+if false
+{
+ cmd
+}
+elif true
+{
+ cmd1
+}
+else
+{
+ cmd
+}
+EOI
+{
+ ? false
+ ? true
+ {
+ cmd1
+ }
+}
+EOO
+
+: line-index
+: Make sure command line index spans setup/if/teardown
+:
+$* -s -l <<EOI >>EOO
++setup # 1
+
+if false one # 2
+{
+ cmd
+}
+elif false two # 3
+{
+ cmd
+}
+elif true # 4
+{
+ cmd1
+}
+elif false # 5
+{
+ cmd
+}
+else
+{
+ cmd
+}
+
+if false one # 6
+{
+ cmd
+}
+elif false two # 7
+{
+ cmd
+}
+else
+{
+ cmd2
+}
+
+-tdown # 8
+EOI
+{
+ setup # 1
+ ? false one # 2
+ ? false two # 3
+ ? true # 4
+ {
+ cmd1 # 0
+ }
+ ? false one # 6
+ ? false two # 7
+ {
+ cmd2 # 0
+ }
+ tdown # 8
+}
+EOO
+
+: scope-comman-if
+:
+$* -s <<EOI >>EOO
+if true
+{
+ cmd
+}
+if true
+ cmd1
+ cmd2
+end
+EOI
+{
+ ? true
+ {
+ cmd
+ }
+ {
+ ? true
+ cmd1
+ cmd2
+ }
+}
+EOO
+
+: shared-id-desc
+:
+$* -s -i <<EOI >>EOO
+: test summary
+:
+if false
+{
+ cmd
+}
+else
+{
+ cmd1
+}
+EOI
+{
+ ? false
+ : sm:test summary
+ { # 3
+ cmd1
+ }
+}
+EOO
+
+: eos-inside
+:
+$* <<EOI 2>>EOE != 0
+if
+{
+EOI
+testscript:3:1: error: expected '}' at the end of the scope
+EOE
+
+: scope-expected
+:
+$* <<EOI 2>>EOE != 0
+if
+{
+ cmd
+}
+else
+cmd
+EOI
+testscript:5:1: error: expected scope after 'else'
+EOE
+
+: else-after-else
+:
+$* <<EOI 2>>EOE != 0
+if false
+{
+ cmd
+}
+else
+{
+ cmd
+}
+else
+{
+ cmd
+}
+EOI
+testscript:9:1: error: 'else' after 'else'
+EOE
+
+: elif-after-else
+:
+$* <<EOI 2>>EOE != 0
+if false
+{
+ cmd
+}
+else
+{
+ cmd
+}
+elif true
+{
+ cmd
+}
+EOI
+testscript:9:1: error: 'elif' after 'else'
+EOE
diff --git a/unit-tests/test/script/parser/scope.test b/unit-tests/test/script/parser/scope.test
index 8708b19..3b10d01 100644
--- a/unit-tests/test/script/parser/scope.test
+++ b/unit-tests/test/script/parser/scope.test
@@ -12,23 +12,17 @@ wd += foo;
wd += 1;
$* foo.test <'cmd $~' >"cmd $wd" # wd
-$* -s <<EOI >>EOO # group-empty
+$* -s <<EOI # group-empty
{
}
EOI
-{
-}
-EOO
-$* -s <<EOI >>EOO # group-empty-empty
+$* -s <<EOI # group-empty-empty
{
{
}
}
EOI
-{
-}
-EOO
$* -s <<EOI >>EOO # group
{