From a084c6650036db9f2a8cd69e31492c5dae237793 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 10 Nov 2016 16:33:12 +0200 Subject: Implement scope-if in testscript --- unit-tests/test/script/parser/buildfile | 6 +- unit-tests/test/script/parser/command-if.test | 519 +++++++++++++++++++++++++ unit-tests/test/script/parser/if-else.test | 518 ------------------------- unit-tests/test/script/parser/scope-if.test | 529 ++++++++++++++++++++++++++ unit-tests/test/script/parser/scope.test | 10 +- 5 files changed, 1053 insertions(+), 529 deletions(-) create mode 100644 unit-tests/test/script/parser/command-if.test delete mode 100644 unit-tests/test/script/parser/if-else.test create mode 100644 unit-tests/test/script/parser/scope-if.test (limited to 'unit-tests') 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/command-if.test b/unit-tests/test/script/parser/command-if.test new file mode 100644 index 0000000..88cc7d6 --- /dev/null +++ b/unit-tests/test/script/parser/command-if.test @@ -0,0 +1,519 @@ +: if-true +: +$* <>EOO +if true foo + cmd1 + cmd2 +end +EOI +? true foo +cmd1 +cmd2 +EOO + +: if-false +: +$* <>EOO +if false foo + cmd1 + cmd2 +end +EOI +? false foo +EOO + +: ifn-true +: +$* <>EOO +if! true foo + cmd1 + cmd2 +end +EOI +? true foo +EOO + +: ifn-false +: +$* <>EOO +if! false foo + cmd1 + cmd2 +end +EOI +? false foo +cmd1 +cmd2 +EOO + +: elif-true +: +$* <>EOO +if false + cmd1 + cmd2 +elif true + cmd3 + cmd4 +end +EOI +? false +? true +cmd3 +cmd4 +EOO + +: elif-false +: +$* <>EOO +if false + cmd1 + cmd2 +elif false + cmd3 + cmd4 +end +EOI +? false +? false +EOO + +: elifn-true +: +$* <>EOO +if false + cmd1 + cmd2 +elif! true + cmd3 + cmd4 +end +EOI +? false +? true +EOO + +: elifn-false +: +$* <>EOO +if false + cmd1 + cmd2 +elif! false + cmd3 + cmd4 +end +EOI +? false +? false +cmd3 +cmd4 +EOO + +: else-true +: +$* <>EOO +if false + cmd1 + cmd2 +else + cmd3 + cmd4 +end +EOI +? false +cmd3 +cmd4 +EOO + +: else-false +: +$* <>EOO +if true + cmd1 + cmd2 +else + cmd3 + cmd4 +end +EOI +? true +cmd1 +cmd2 +EOO + +: if-chain +: +$* <>EOO +if false + cmd + cmd +elif false + cmd + cmd +elif false + cmd + cmd +elif true + cmd1 + cmd2 +elif false + cmd + cmd +else + cmd + cmd +end +EOI +? false +? false +? false +? true +cmd1 +cmd2 +EOO + +: nested-take +: +$* <>EOO +if true + cmd1 + if false + cmd + elif false + if true + cmd + end + else + cmd2 + end + cmd3 +end +EOI +? true +cmd1 +? false +? false +cmd2 +cmd3 +EOO + +: nested-skip +: +$* <>EOO +if false + cmd1 + if false + cmd + elif false + if true + cmd + end + else + cmd2 + end + cmd3 +else + cmd +end +EOI +? false +cmd +EOO + +: line-index +: +$* -l <>EOO +if false + cmd + if true + cmd + end + cmd +elif false + cmd +else + cmd +end +EOI +? false # 1 +? false # 6 +cmd # 8 +EOO + +: var +: +$* <>EOO +if true + x = foo +else + x = bar +end; +cmd \$x +EOI +? true +cmd foo +EOO + +: semi-inside +: +$* <>EOE != 0 +if + cmd; + cmd +end +EOI +testscript:2:3: error: ';' inside 'if' +EOE + +: colon-inside-leading +: +$* <>EOE != 0 +if + : foo + cmd +end +EOI +testscript:2:3: error: description inside 'if' +EOE + +: colon-inside-trailing +: +$* <>EOE != 0 +if + cmd : foo +end +EOI +testscript:2:3: error: description inside 'if' +EOE + +: eos-inside +: +$* <>EOE != 0 +if +EOI +testscript:2:1: error: expected closing 'end' +EOE + +: scope-inside +: +$* <>EOE != 0 +if + cmd + { + } +end +EOI +testscript:3:3: error: expected closing 'end' +EOE + +: setup-inside +: +$* <>EOE != 0 +if + +cmd +end +EOI +testscript:2:3: error: setup command inside 'if' +EOE + +: tdown-inside +: +$* <>EOE != 0 +if + -cmd +end +EOI +testscript:2:3: error: teardown command inside 'if' +EOE + +: if-without-command +: +$* <>EOE != 0 +if + cmd +end +EOI +testscript:1:3: error: missing program +EOE + +: command-after-else +: +$* <>EOE != 0 +if true + cmd +else cmd + cmd +end +EOI +testscript:3:6: error: expected newline instead of 'cmd' +EOE + +: command-after-end +: +$* <>EOE != 0 +if true + cmd +end cmd +EOI +testscript:3:5: error: expected newline instead of 'cmd' +EOE + +: elif-without-if +: +$* <>EOE != 0 +cmd +elif true + cmd +end +EOI +testscript:2:1: error: 'elif' without preceding 'if' +EOE + +: elifn-without-if +: +$* <>EOE != 0 +cmd +elif! true + cmd +end +EOI +testscript:2:1: error: 'elif!' without preceding 'if' +EOE + +: else-without-if +: +$* <>EOE != 0 +cmd +else + cmd +end +EOI +testscript:2:1: error: 'else' without preceding 'if' +EOE + +: end-without-if +: +$* <>EOE != 0 +cmd +end +EOI +testscript:2:1: error: 'end' without preceding 'if' +EOE + +: else-after-else +: +$* <>EOE != 0 +if false + cmd +else + cmd +else + cmd +end +EOI +testscript:5:1: error: 'else' after 'else' +EOE + +: elif-after-else +: +$* <>EOE != 0 +if false + cmd +else + cmd +elif true + cmd +end +EOI +testscript:5:1: error: 'elif' after 'else' +EOE + +: if-after-semi +: +$* -s <>EOO +cmd1; +if true + cmd2 +end +EOI +{ + { + cmd1 + ? true + cmd2 + } +} +EOO + +: setup-if +: +$* -s <>EOO ++if true + cmd +end +EOI +{ + ? true + cmd +} +EOO + +: tdown-if +: +$* -s <>EOO +-if true + cmd +end +EOI +{ + ? true + cmd +} +EOO + +: semi-after-end +: +$* -s <>EOO +if true + cmd1 +end; +cmd2 +EOI +{ + { + ? true + cmd1 + cmd2 + } +} +EOO + +: colon-after-end +: +$* -s <>EOO +if true + cmd1 + cmd2 +end : test +EOI +{ + : id:test + { + ? true + cmd1 + cmd2 + } +} +EOO + +: leading-and-trailing-description +: +$* <>EOE != 0 +: foo +if true + cmd +end : bar +EOI +testscript:4:1: error: both leading and trailing descriptions +EOE diff --git a/unit-tests/test/script/parser/if-else.test b/unit-tests/test/script/parser/if-else.test deleted file mode 100644 index 8663920..0000000 --- a/unit-tests/test/script/parser/if-else.test +++ /dev/null @@ -1,518 +0,0 @@ -: if-true -: -$* <>EOO -if true foo - cmd1 - cmd2 -end -EOI -? true foo -cmd1 -cmd2 -EOO - -: if-false -: -$* <>EOO -if false foo - cmd1 - cmd2 -end -EOI -? false foo -EOO - -: ifn-true -: -$* <>EOO -if! true foo - cmd1 - cmd2 -end -EOI -? true foo -EOO - -: ifn-false -: -$* <>EOO -if! false foo - cmd1 - cmd2 -end -EOI -? false foo -cmd1 -cmd2 -EOO - -: elif-true -: -$* <>EOO -if false - cmd1 - cmd2 -elif true - cmd3 - cmd4 -end -EOI -? false -? true -cmd3 -cmd4 -EOO - -: elif-false -: -$* <>EOO -if false - cmd1 - cmd2 -elif false - cmd3 - cmd4 -end -EOI -? false -? false -EOO - -: elifn-true -: -$* <>EOO -if false - cmd1 - cmd2 -elif! true - cmd3 - cmd4 -end -EOI -? false -? true -EOO - -: elifn-false -: -$* <>EOO -if false - cmd1 - cmd2 -elif! false - cmd3 - cmd4 -end -EOI -? false -? false -cmd3 -cmd4 -EOO - -: else-true -: -$* <>EOO -if false - cmd1 - cmd2 -else - cmd3 - cmd4 -end -EOI -? false -cmd3 -cmd4 -EOO - -: else-false -: -$* <>EOO -if true - cmd1 - cmd2 -else - cmd3 - cmd4 -end -EOI -? true -cmd1 -cmd2 -EOO - -: if-chain -: -$* <>EOO -if false - cmd - cmd -elif false - cmd - cmd -elif false - cmd - cmd -elif true - cmd1 - cmd2 -elif false - cmd - cmd -else - cmd - cmd -end -EOI -? false -? false -? false -? true -cmd1 -cmd2 -EOO - -: nested-take -: -$* <>EOO -if true - cmd1 - if false - cmd - elif false - if true - cmd - end - else - cmd2 - end - cmd3 -end -EOI -? true -cmd1 -? false -? false -cmd2 -cmd3 -EOO - -: nested-skip -: -$* <>EOO -if false - cmd1 - if false - cmd - elif false - if true - cmd - end - else - cmd2 - end - cmd3 -else - cmd -end -EOI -? false -cmd -EOO - -: line-index -: -$* -l <>EOO -if false - cmd - if true - cmd - end - cmd -elif false - cmd -else - cmd -end -EOI -? false # 1 -? false # 6 -cmd # 8 -EOO - -: var -: -$* <>EOO -if true - x = foo -else - x = bar -end; -cmd \$x -EOI -? true -cmd foo -EOO - -: semi-inside -: -$* <>EOE != 0 -if - cmd; - cmd -end -EOI -testscript:2:3: error: ';' inside 'if' -EOE - -: colon-inside-leading -: -$* <>EOE != 0 -if - : foo - cmd -end -EOI -testscript:2:3: error: description inside 'if' -EOE - -: colon-inside-trailing -: -$* <>EOE != 0 -if - cmd : foo -end -EOI -testscript:2:3: error: description inside 'if' -EOE - -: eos-inside -: -$* <>EOE != 0 -if -EOI -testscript:2:1: error: expected closing 'end' -EOE - -: scope-inside -: -$* <>EOE != 0 -if - { - } -end -EOI -testscript:2:3: error: expected closing 'end' -EOE - -: setup-inside -: -$* <>EOE != 0 -if - +cmd -end -EOI -testscript:2:3: error: setup command inside 'if' -EOE - -: tdown-inside -: -$* <>EOE != 0 -if - -cmd -end -EOI -testscript:2:3: error: teardown command inside 'if' -EOE - -: if-without-command -: -$* <>EOE != 0 -if - cmd -end -EOI -testscript:1:3: error: missing program -EOE - -: command-after-else -: -$* <>EOE != 0 -if true - cmd -else cmd - cmd -end -EOI -testscript:3:6: error: expected newline instead of 'cmd' -EOE - -: command-after-end -: -$* <>EOE != 0 -if true - cmd -end cmd -EOI -testscript:3:5: error: expected newline instead of 'cmd' -EOE - -: elif-without-if -: -$* <>EOE != 0 -cmd -elif true - cmd -end -EOI -testscript:2:1: error: 'elif' without preceding 'if' -EOE - -: elifn-without-if -: -$* <>EOE != 0 -cmd -elif! true - cmd -end -EOI -testscript:2:1: error: 'elif!' without preceding 'if' -EOE - -: else-without-if -: -$* <>EOE != 0 -cmd -else - cmd -end -EOI -testscript:2:1: error: 'else' without preceding 'if' -EOE - -: end-without-if -: -$* <>EOE != 0 -cmd -end -EOI -testscript:2:1: error: 'end' without preceding 'if' -EOE - -: else-after-else -: -$* <>EOE != 0 -if false - cmd -else - cmd -else - cmd -end -EOI -testscript:5:1: error: 'else' after 'else' -EOE - -: elif-after-else -: -$* <>EOE != 0 -if false - cmd -else - cmd -elif true - cmd -end -EOI -testscript:5:1: error: 'elif' after 'else' -EOE - -: if-after-semi -: -$* -s <>EOO -cmd1; -if true - cmd2 -end -EOI -{ - { - cmd1 - ? true - cmd2 - } -} -EOO - -: setup-if -: -$* -s <>EOO -+if true - cmd -end -EOI -{ - ? true - cmd -} -EOO - -: tdown-if -: -$* -s <>EOO --if true - cmd -end -EOI -{ - ? true - cmd -} -EOO - -: semi-after-end -: -$* -s <>EOO -if true - cmd1 -end; -cmd2 -EOI -{ - { - ? true - cmd1 - cmd2 - } -} -EOO - -: colon-after-end -: -$* -s <>EOO -if true - cmd1 - cmd2 -end : test -EOI -{ - : id:test - { - ? true - cmd1 - cmd2 - } -} -EOO - -: leading-and-trailing-description -: -$* <>EOE != 0 -: foo -if true - cmd -end : bar -EOI -testscript:4:1: error: both leading and trailing descriptions -EOE 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 <>EOO +if true foo +{ + cmd +} +EOI +{ + ? true foo + { + cmd + } +} +EOO + +: if-false +: +$* -s <>EOO +if false foo +{ + cmd +} +EOI +{ + ? false foo +} +EOO + +: ifn-true +: +$* -s <>EOO +if! true +{ + cmd +} +EOI +{ + ? true +} +EOO + +: ifn-false +: +$* -s <>EOO +if! false +{ + cmd +} +EOI +{ + ? false + { + cmd + } +} +EOO + +: elif-true +: +$* -s <>EOO +if false +{ + cmd +} +elif true +{ + cmd1 +} +EOI +{ + ? false + ? true + { + cmd1 + } +} +EOO + +: elif-false +: +$* -s <>EOO +if false +{ + cmd +} +elif false +{ + cmd +} +EOI +{ + ? false + ? false +} +EOO + +: elifn-false +: +$* -s <>EOO +if false +{ + cmd +} +elif! false +{ + cmd1 +} +EOI +{ + ? false + ? false + { + cmd1 + } +} +EOO + +: elifn-true +: +$* -s <>EOO +if false +{ + cmd +} +elif! true +{ + cmd +} +EOI +{ + ? false + ? true +} +EOO + +: else-true +: +$* -s <>EOO +if false +{ + cmd +} +else +{ + cmd1 +} +EOI +{ + ? false + { + cmd1 + } +} +EOO + +: else-false +: +$* -s <>EOO +if true +{ + cmd1 +} +else +{ + cmd +} +EOI +{ + ? true + { + cmd1 + } +} +EOO + +: if-chain +: +$* -s <>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 <>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 <>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 <>EOO +if false +{ + cmd +} +elif true +{ + cmd1 + cmd2 +} +else +{ + cmd +} +EOI +{ + ? false + ? true + { + { + cmd1 + } + { + cmd2 + } + } +} +EOO + +: demote-test +: Chain demoted to test +: +$* -s <>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 <>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 <>EOO +if true +{ + cmd +} +if true + cmd1 + cmd2 +end +EOI +{ + ? true + { + cmd + } + { + ? true + cmd1 + cmd2 + } +} +EOO + +: shared-id-desc +: +$* -s -i <>EOO +: test summary +: +if false +{ + cmd +} +else +{ + cmd1 +} +EOI +{ + ? false + : sm:test summary + { # 3 + cmd1 + } +} +EOO + +: eos-inside +: +$* <>EOE != 0 +if +{ +EOI +testscript:3:1: error: expected '}' at the end of the scope +EOE + +: scope-expected +: +$* <>EOE != 0 +if +{ + cmd +} +else +cmd +EOI +testscript:5:1: error: expected scope after 'else' +EOE + +: else-after-else +: +$* <>EOE != 0 +if false +{ + cmd +} +else +{ + cmd +} +else +{ + cmd +} +EOI +testscript:9:1: error: 'else' after 'else' +EOE + +: elif-after-else +: +$* <>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 <>EOO # group-empty +$* -s <>EOO # group-empty-empty +$* -s <>EOO # group { -- cgit v1.1