diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2017-01-06 18:46:58 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2017-01-09 21:44:23 +0300 |
commit | c55240fb05151cae046c75a793c164d72c988db2 (patch) | |
tree | 35cbba195e0fcc581944b7b098a3ea145741cf94 | |
parent | 9e2b4fd3bbc0c61bf6c84540c52869ec7d830718 (diff) |
Tests cleanup (take 2)
29 files changed, 2754 insertions, 2073 deletions
diff --git a/tests/test/script/builtin/rm.test b/tests/test/script/builtin/rm.test index 915052a..cd4a922 100644 --- a/tests/test/script/builtin/rm.test +++ b/tests/test/script/builtin/rm.test @@ -6,102 +6,118 @@ : no-args : -: Removing with no arguments fails. -: -$c <'rm 2>"rm: missing file" == 1'; -$b - -: no-args-force -: -: Removing with no arguments succeeds with -f option. -: -$c <'rm -f'; -$b +{ + : fail + : + : Removing with no arguments fails. + : + $c <'rm 2>"rm: missing file" == 1'; + $b -: empty-path -: -: Removing an empty path fails. -: -$c <<EOI; -rm '' 2>"rm: invalid path ''" == 1 -EOI -$b + : force + : + : Removing with no arguments succeeds with -f option. + : + $c <'rm -f'; + $b +} : file : -: Removing existing file succeeds. -: -$c <<EOI; -touch a &!a; -rm a -EOI -$b +{ + : exists + : + : Removing existing file succeeds. + : + $c <<EOI; + touch a &!a; + rm a + EOI + $b -: file-not-exists -: -: Removing non-existing file fails. -: -$c <<EOI; -rm a 2>>~%EOE% == 1 -%rm: unable to remove '.+[/\\]test[/\\]rm[/\\]file-not-exists[/\\]test[/\\]1[/\\]a': .+% -EOE -EOI -$b + : not-exists + : + : Removing non-existing file fails. + : + $c <<EOI; + rm a 2>>~%EOE% == 1 + %rm: unable to remove '.+[/\\]test[/\\]rm[/\\]file[/\\]not-exists[/\\]test[/\\]1[/\\]a': .+% + EOE + EOI + $b -: file-not-exists-force -: -: Removing non-existing file succeeds with -f option. -: -$c <'rm -f a'; -$b + : not-exists-force + : + : Removing non-existing file succeeds with -f option. + : + $c <'rm -f a'; + $b +} : dir : -: Removing directory fails by default. -: -$c <<EOI; -mkdir a; -rm a 2>"rm: '$normalize([path] $~/a)' is a directory" == 1 -EOI -$b +{ + : default + : + : Removing directory fails by default. + : + $c <<EOI; + mkdir a; + rm a 2>"rm: '$normalize([path] $~/a)' is a directory" == 1 + EOI + $b -: dir-recursive -: -: Removing directory succeeds with -r option. -: -$c <<EOI; -mkdir -p a/b &!a &!a/b; -rm -r a -EOI -$b + : recursive + : + : Removing directory succeeds with -r option. + : + $c <<EOI; + mkdir -p a/b &!a &!a/b; + rm -r a + EOI + $b -: scope-dir -: -: Removing scope directory fails. -: -$c <<EOI; -rm -r ./ 2>"rm: '([string] $~)' contains test working directory '$~'" == 1 -EOI -$b + : scope + : + : Removing scope directory fails. + : + $c <<EOI; + rm -r ./ 2>"rm: '([string] $~)' contains test working directory '$~'" == 1 + EOI + $b +} -: outside-scope -: -: Removing path outside the testscript working directory fails. Need to use a -: path that unlikely exists (not to remove something useful). -: -: -$c <<EOI; -rm ../../a/b/c 2>>~%EOE% == 1 -%rm: '.+[/\\]outside-scope[/\\]a[/\\]b[/\\]c' is out of working directory '.+[/\\]outside-scope[/\\]test'% -EOE -EOI -$b +: path +: +{ + : empty + : + : Removing an empty path fails. + : + $c <<EOI; + rm '' 2>"rm: invalid path ''" == 1 + EOI + $b -: outside-scope-force -: -: Removing path outside the testscript working directory succeeds with -f -: option. Need to use a path that unlikely exists (not to remove something -: useful). -: -$c <'rm -f ../../a/b/c'; -$b + : outside-scope + : + : Removing path outside the testscript working directory fails. Need to use + : a path that unlikely exists (not to remove something useful). + : + : + $c <<EOI; + rm ../../a/b/c 2>>~%EOE% == 1 + %rm: '.+[/\\]path[/\\]outside-scope[/\\]a[/\\]b[/\\]c' is out of working directory '.+[/\\]outside-scope[/\\]test'% + EOE + EOI + $b + + : outside-scope-force + : + : Removing path outside the testscript working directory succeeds with -f + : option. Need to use a path that unlikely exists (not to remove something + : useful). + : + $c <'rm -f ../../a/b/c'; + $b +} diff --git a/tests/value/reverse.test b/tests/value/reverse.test index 06de043..d667a9d 100644 --- a/tests/value/reverse.test +++ b/tests/value/reverse.test @@ -7,68 +7,76 @@ .include ../common.test -: name-dir +: name : -$* <<EOI >>EOO -x = s/foo/bar/ -print ([string] $x) -print "$x" -print -e=$x -EOI -s/foo/bar/ -s/foo/bar/ --e=s/foo/bar/ -EOO +{ + : dir + : + $* <<EOI >>EOO + x = s/foo/bar/ + print ([string] $x) + print "$x" + print -e=$x + EOI + s/foo/bar/ + s/foo/bar/ + -e=s/foo/bar/ + EOO -: name-proj -: -$* <<EOI >>EOO -print ([strings] foo%bar foo% %bar) -EOI -foo%bar foo% %bar -EOO + : proj + : + $* <<EOI >>EOO + print ([strings] foo%bar foo% %bar) + EOI + foo%bar foo% %bar + EOO -: name-pair -: -$* <<EOI >>EOO -print ([strings] foo@bar foo/@bar/ foo@ @bar @ "@@") -EOI -foo@bar foo/@bar/ foo@ @bar @ @@ -EOO + : pair + : + $* <<EOI >>EOO + print ([strings] foo@bar foo/@bar/ foo@ @bar @ "@@") + EOI + foo@bar foo/@bar/ foo@ @bar @ @@ + EOO -: name-combined -: -$* <<EOI >>EOO -print ([strings] x%foo@y%bar x%foo/@y%bar/) -EOI -x%foo@y%bar x%foo/@y%bar/ -EOO + : combined + : + $* <<EOI >>EOO + print ([strings] x%foo@y%bar x%foo/@y%bar/) + EOI + x%foo@y%bar x%foo/@y%bar/ + EOO +} : dir-path : -$* <<EOI >>"EOO" -x = [dir_path] foo/bar/ -print ([string] $x) -print "$x" -print "-I$x" -EOI -foo/bar/ -foo/bar --Ifoo/bar -EOO - -: dir-path-root -: -if ($cxx.target.class != windows) { - $* <<EOI >>EOO - x = [dir_path] / + : rel + : + $* <<EOI >>"EOO" + x = [dir_path] foo/bar/ print ([string] $x) print "$x" print "-I$x" EOI - / - / - -I/ + foo/bar/ + foo/bar + -Ifoo/bar EOO + + : root + : + if ($cxx.target.class != windows) + { + $* <<EOI >>EOO + x = [dir_path] / + print ([string] $x) + print "$x" + print "-I$x" + EOI + / + / + -I/ + EOO + } } diff --git a/unit-tests/function/call.test b/unit-tests/function/call.test index c9ef49c..e17c247 100644 --- a/unit-tests/function/call.test +++ b/unit-tests/function/call.test @@ -109,14 +109,11 @@ $* <'$bogus([uint64] 123)' 2>>EOE != 0 buildfile:1:2: error: unmatched call to bogus(uint64) EOE -#\ -@@ TMP : print-call-2 : $* <'$bogus(abc, [uint64] 123)' 2>>EOE != 0 buildfile:1:2: error: unmatched call to bogus(<untyped>, uint64) EOE -#\ : print-fovl : diff --git a/unit-tests/lexer/comment.test b/unit-tests/lexer/comment.test index 025b0a2..6840219 100644 --- a/unit-tests/lexer/comment.test +++ b/unit-tests/lexer/comment.test @@ -2,111 +2,138 @@ # copyright : Copyright (c) 2014-2017 Code Synthesis Ltd # license : MIT; see accompanying LICENSE file -# Single-line comments. +: single-line +: +{ + : only + : + $* <<EOI >>:EOO + # comment + EOI + EOO -$* <<EOI >>:EOO # single-only -# comment -EOI -EOO + : first + : + $* <<EOI >>EOO + # comment + foo + EOI + 'foo' + <newline> + EOO -$* <<EOI >>EOO # single-first -# comment -foo -EOI -'foo' -<newline> -EOO + : last + : + $* <<EOI >>EOO + foo + # comment + EOI + 'foo' + <newline> + EOO -$* <<EOI >>EOO # single-last -foo -# comment -EOI -'foo' -<newline> -EOO + : few + : + $* <<EOI >>EOO + foo + # comment + # comment + EOI + 'foo' + <newline> + EOO -$* <<EOI >>EOO # single-few -foo -# comment -# comment -EOI -'foo' -<newline> -EOO + : cont + : + $* <<EOI >>EOO + foo + # comment\\ + bar + EOI + 'foo' + <newline> + 'bar' + <newline> + EOO -$* <<EOI >>EOO # single-cont -foo -# comment\\ -bar -EOI -'foo' -<newline> -'bar' -<newline> -EOO + : same + : + $* <<EOI >>EOO + foo # comment + bar # comment + EOI + 'foo' + <newline> + 'bar' + <newline> + EOO +} -$* <<EOI >>EOO # single-same -foo # comment -bar # comment -EOI -'foo' -<newline> -'bar' -<newline> -EOO +: multi-line +: +{ + : only + : + $* <<EOI >>:EOO + #\ + comment + comment + #\ + EOI + EOO -# Multi-line comments. -# + : empty + : + $* <<EOI >>:EOO + #\ + #\ + EOI + EOO -$* <<EOI >>:EOO # multi-only -#\ -comment -comment -#\ -EOI -EOO + : start-same + : + $* <<EOI >>EOO + foo #\ + comment + comment + #\ + EOI + 'foo' + <newline> + EOO -$* <<EOI >>:EOO # multi-empty -#\ -#\ -EOI -EOO + : end-same + : + $* <<EOI >>EOO + #\ + comment + comment + foo #\ + bar + EOI + 'bar' + <newline> + EOO -$* <<EOI >>EOO # multi-start-same -foo #\ -comment -comment -#\ -EOI -'foo' -<newline> -EOO + : end-not + : + $* <<EOI >>EOO + #\ + comment + #\ not an end + foo #\ + bar + EOI + 'bar' + <newline> + EOO -$* <<EOI >>EOO # multi-end-same -#\ -comment -comment -foo #\ -bar -EOI -'bar' -<newline> -EOO - -$* <<EOI >>EOO # multi-end-not -#\ -comment -#\ not an end -foo #\ -bar -EOI -'bar' -<newline> -EOO - -$* <<EOI 2>>EOE != 0 # multi-unterm -#\ -comment -EOI -stdin:3:1: error: unterminated multi-line comment -EOE + : unterm + : + $* <<EOI 2>>EOE != 0 + #\ + comment + EOI + stdin:3:1: error: unterminated multi-line comment + EOE +} diff --git a/unit-tests/lexer/quoting.test b/unit-tests/lexer/quoting.test index 84818fc..a44d6af 100644 --- a/unit-tests/lexer/quoting.test +++ b/unit-tests/lexer/quoting.test @@ -11,81 +11,94 @@ $* <'foo' >>EOO <newline> EOO -: single-comp +: comp : -$* <":'foo':" >>EOO -: -'foo' [S/C] -: -<newline> -EOO +{ + : single + : + $* <":'foo':" >>EOO + : + 'foo' [S/C] + : + <newline> + EOO -: double-comp -: -$* <':"foo":' >>EOO -: -'foo' [D/C] -: -<newline> -EOO + : double + : + $* <':"foo":' >>EOO + : + 'foo' [D/C] + : + <newline> + EOO -: single-empty-comp -: -$* <"''" >>EOO -'' [S/C] -<newline> -EOO + : single-empty + : + $* <"''" >>EOO + '' [S/C] + <newline> + EOO -: double-empty-comp -: -$* <'""' >>EOO -'' [D/C] -<newline> -EOO + : double-empty + : + $* <'""' >>EOO + '' [D/C] + <newline> + EOO +} -: part-start-quoted -: Token start already quoted -: -$* <'"$foo"' >>EOO -'' [D/P] -$ [D/C] -'foo' [D/P] -<newline> -EOO +: part +{ + : quoted + { + : start + : Token start already quoted + : + $* <'"$foo"' >>EOO + '' [D/P] + $ [D/C] + 'foo' [D/P] + <newline> + EOO -: part-end-quoted -: Token end still quoted -: -$* <'"foo$"' >>EOO -'foo' [D/P] -$ [D/C] -'' [D/P] -<newline> -EOO + : end + : Token end still quoted + : + $* <'"foo$"' >>EOO + 'foo' [D/P] + $ [D/C] + '' [D/P] + <newline> + EOO + } -: part-start-unquoted -: Token starts with unquoted character -: -$* <'f"oo"' >>EOO -'foo' [D/P] -<newline> -EOO + : unquoted + { + : start + : Token starts with unquoted character + : + $* <'f"oo"' >>EOO + 'foo' [D/P] + <newline> + EOO -: part-unquoted -: Token continous with unquoted character -: -$* <'"fo"o' >>EOO -'foo' [D/P] -<newline> -EOO + : end + : Token continous with unquoted character + : + $* <'"fo"o' >>EOO + 'foo' [D/P] + <newline> + EOO -: part-unquoted-escape -: Token continous with unquoted escaped character -: -$* <'"fo"\"' >>EOO -'fo"' [D/P] -<newline> -EOO + : escape + : Token continous with unquoted escaped character + : + $* <'"fo"\"' >>EOO + 'fo"' [D/P] + <newline> + EOO + } +} : mixed : diff --git a/unit-tests/test/script/lexer/command-expansion.test b/unit-tests/test/script/lexer/command-expansion.test index f113846..faae29d 100644 --- a/unit-tests/test/script/lexer/command-expansion.test +++ b/unit-tests/test/script/lexer/command-expansion.test @@ -1,134 +1,230 @@ +# file : unit-tests/test/script/lexer/command-expansion.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + test.arguments = command-expansion -$* <:"0<+" >>EOO # in-pass-redirect -'0' -<+ -EOO - -$* <:"0 <+" >>EOO # arg-in-pass-redirect -'0 ' -<+ -EOO - -$* <:"1>+" >>EOO # out-pass-redirect -'1' ->+ -EOO - -$* <:"1 >+" >>EOO # arg-out-pass-redirect -'1 ' ->+ -EOO - -$* <:"0<-" >>EOO # in-null-redirect -'0' -<- -EOO - -$* <:"0 <-" >>EOO # arg-in-null-redirect -'0 ' -<- -EOO - -$* <:"1>-" >>EOO # out-null-redirect -'1' ->- -EOO - -$* <:"1 >-" >>EOO # arg-out-null-redirect -'1 ' ->- -EOO - -$* <:"1>&2" >>EOO # merge-redirect -'1' ->& -'2' -EOO - -$* <:"1 >&2" >>EOO # arg-merge-redirect -'1 ' ->& -'2' -EOO - -$* <:"0<a b" >>EOO # in-str-redirect -'0' -< -'a b' -EOO - -$* <:"1>a b" >>EOO # out-str-redirect -'1' -> -'a b' -EOO - -$* <:"0<:a b" >>EOO # in-str-nn-redirect -'0' -<: -'a b' -EOO - -$* <:"1>:a b" >>EOO # out-str-nn-redirect -'1' ->: -'a b' -EOO - -$* <:"0<<E O I" >>EOO # in-doc-redirect -'0' -<< -'E O I' -EOO - -$* <:"1>>E O O" >>EOO # out-doc-redirect -'1' ->> -'E O O' -EOO - -$* <:"0<<:E O I" >>EOO # in-doc-nn-redirect -'0' -<<: -'E O I' -EOO - -$* <:"1>>:E O O" >>EOO # out-doc-nn-redirect -'1' ->>: -'E O O' -EOO - -$* <:"0<<<a b" >>EOO # in-file-redirect -'0' -<<< -'a b' -EOO - -$* <:"1>>>a b" >>EOO # out-file-redirect -'1' ->>> -'a b' -EOO - -$* <:"1>>>&a b" >>EOO # out-file-app-redirect -'1' ->>>& -'a b' -EOO - -$* <:"&file" >>EOO # cleanup-always -& -'file' -EOO - -$* <:"&?file" >>EOO # cleanup-maybe -&? -'file' -EOO - -$* <:"&!file" >>EOO # cleanup-never -&! -'file' -EOO +: pass-redirect +: +{ + : in + : + $* <:"0<+" >>EOO + '0' + <+ + EOO + + : arg-in + : + $* <:"0 <+" >>EOO + '0 ' + <+ + EOO + + : out + : + $* <:"1>+" >>EOO + '1' + >+ + EOO + + : arg-out + : + $* <:"1 >+" >>EOO + '1 ' + >+ + EOO +} + +: null-redirect +: +{ + : in + : + $* <:"0<-" >>EOO + '0' + <- + EOO + + : arg-in + : + $* <:"0 <-" >>EOO + '0 ' + <- + EOO + + : out + : + $* <:"1>-" >>EOO + '1' + >- + EOO + + : arg-out + : + $* <:"1 >-" >>EOO + '1 ' + >- + EOO +} + +: merge-redirect +: +{ + : out + : + $* <:"1>&2" >>EOO + '1' + >& + '2' + EOO + + : arg-out + : + $* <:"1 >&2" >>EOO + '1 ' + >& + '2' + EOO +} + +: str-redirect +: +{ + : in + : + { + : newline + : + $* <:"0<a b" >>EOO + '0' + < + 'a b' + EOO + + : no-newline + : + $* <:"0<:a b" >>EOO + '0' + <: + 'a b' + EOO + } + + : out + : + { + : newline + : + $* <:"1>a b" >>EOO + '1' + > + 'a b' + EOO + + : no-newline + : + $* <:"1>:a b" >>EOO + '1' + >: + 'a b' + EOO + } +} + +: doc-redirect +: +{ + : in + : + { + : newline + : + $* <:"0<<E O I" >>EOO + '0' + << + 'E O I' + EOO + + : no-newline + : + $* <:"0<<:E O I" >>EOO + '0' + <<: + 'E O I' + EOO + } + + : out + : + { + : newline + : + $* <:"1>>E O O" >>EOO + '1' + >> + 'E O O' + EOO + + : no-newline + : + $* <:"1>>:E O O" >>EOO + '1' + >>: + 'E O O' + EOO + } +} + +: file-redirect +: +{ + : in + : + $* <:"0<<<a b" >>EOO + '0' + <<< + 'a b' + EOO + + : out + : + $* <:"1>>>a b" >>EOO + '1' + >>> + 'a b' + EOO + + : out-app + : + $* <:"1>>>&a b" >>EOO + '1' + >>>& + 'a b' + EOO +} + +: cleanup +: +{ + : always + : + $* <:"&file" >>EOO + & + 'file' + EOO + + : maybe + : + $* <:"&?file" >>EOO + &? + 'file' + EOO + + : never + : + $* <:"&!file" >>EOO + &! + 'file' + EOO +} diff --git a/unit-tests/test/script/lexer/command-line.test b/unit-tests/test/script/lexer/command-line.test index 0040cfe..8a73b3d 100644 --- a/unit-tests/test/script/lexer/command-line.test +++ b/unit-tests/test/script/lexer/command-line.test @@ -1,134 +1,187 @@ +# file : unit-tests/test/script/lexer/command-line.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + test.arguments = command-line -$* <"cmd;" >>EOO # semi -'cmd' -; -<newline> -EOO - -$* <"cmd ;" >>EOO # semi-separated -'cmd' -; -<newline> -EOO - -$* <";" >>EOO # semi-only -; -<newline> -EOO - -$* <"cmd: dsc" >>EOO # colon -'cmd' +: semi +{ + : immediate + : + $* <"cmd;" >>EOO + 'cmd' + ; + <newline> + EOO + + : separated + : + $* <"cmd ;" >>EOO + 'cmd' + ; + <newline> + EOO + + : only + : + $* <";" >>EOO + ; + <newline> + EOO +} + +: colon : -'dsc' -<newline> -EOO - -$* <"cmd :dsc" >>EOO # colon-separated -'cmd' +{ + : immediate + : + $* <"cmd: dsc" >>EOO + 'cmd' + : + 'dsc' + <newline> + EOO + + : separated + : + $* <"cmd :dsc" >>EOO + 'cmd' + : + 'dsc' + <newline> + EOO + + : only + : + $* <":" >>EOO + : + <newline> + EOO +} + +: redirect : -'dsc' -<newline> -EOO - -$* <":" >>EOO # colon-only +{ + : pass + : + $* <"cmd <+ 1>+" >>EOO + 'cmd' + <+ + '1' + >+ + <newline> + EOO + + : null + : + $* <"cmd <- 1>-" >>EOO + 'cmd' + <- + '1' + >- + <newline> + EOO + + : merge + : + $* <"cmd 1>&2" >>EOO + 'cmd' + '1' + >& + '2' + <newline> + EOO + + : str + : + $* <"cmd <a 1>b" >>EOO + 'cmd' + < + 'a' + '1' + > + 'b' + <newline> + EOO + + : str-nn + : + $* <"cmd <:a 1>:b" >>EOO + 'cmd' + <: + 'a' + '1' + >: + 'b' + <newline> + EOO + + : doc + : + $* <"cmd <<EOI 1>>EOO" >>EOO + 'cmd' + << + 'EOI' + '1' + >> + 'EOO' + <newline> + EOO + + : doc-nn + : + $* <"cmd <<:EOI 1>>:EOO" >>EOO + 'cmd' + <<: + 'EOI' + '1' + >>: + 'EOO' + <newline> + EOO + + : file + : + $* <"cmd <<<in >>>out 2>>>&err" >>EOO + 'cmd' + <<< + 'in' + >>> + 'out' + '2' + >>>& + 'err' + <newline> + EOO +} + +: cleanup : -<newline> -EOO - -$* <"cmd <+ 1>+" >>EOO # pass-redirect -'cmd' -<+ -'1' ->+ -<newline> -EOO - -$* <"cmd <- 1>-" >>EOO # null-redirect -'cmd' -<- -'1' ->- -<newline> -EOO - -$* <"cmd 1>&2" >>EOO # merge-redirect -'cmd' -'1' ->& -'2' -<newline> -EOO - -$* <"cmd <a 1>b" >>EOO # str-redirect -'cmd' -< -'a' -'1' -> -'b' -<newline> -EOO - -$* <"cmd <:a 1>:b" >>EOO # str-nn-redirect -'cmd' -<: -'a' -'1' ->: -'b' -<newline> -EOO - -$* <"cmd <<EOI 1>>EOO" >>EOO # doc-redirect -'cmd' -<< -'EOI' -'1' ->> -'EOO' -<newline> -EOO - -$* <"cmd <<:EOI 1>>:EOO" >>EOO # doc-nn-redirect -'cmd' -<<: -'EOI' -'1' ->>: -'EOO' -<newline> -EOO - -$* <"cmd <<<in >>>out 2>>>&err" >>EOO # file-redirect -'cmd' -<<< -'in' ->>> -'out' -'2' ->>>& -'err' -<newline> -EOO - -$* <"cmd &file" >>EOO # cleanup-always -'cmd' -& -'file' -<newline> -EOO - -$* <"cmd &?file" >>EOO # cleanup-maybe -'cmd' -&? -'file' -<newline> -EOO - -$* <"cmd &!file" >>EOO # cleanup-never -'cmd' -&! -'file' -<newline> -EOO +{ + : always + : + $* <"cmd &file" >>EOO + 'cmd' + & + 'file' + <newline> + EOO + + : maybe + : + $* <"cmd &?file" >>EOO + 'cmd' + &? + 'file' + <newline> + EOO + + : never + : + $* <"cmd &!file" >>EOO + 'cmd' + &! + 'file' + <newline> + EOO +} diff --git a/unit-tests/test/script/lexer/description-line.test b/unit-tests/test/script/lexer/description-line.test index 0f70e77..6b160c0 100644 --- a/unit-tests/test/script/lexer/description-line.test +++ b/unit-tests/test/script/lexer/description-line.test @@ -1,20 +1,32 @@ +# file : unit-tests/test/script/lexer/description-line.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + test.arguments = description-line -$* <" foo bar " >>EOO # full +: full +: +$* <" foo bar " >>EOO ' foo bar ' <newline> EOO -$* <" " >>EOO # space +: space +: +$* <" " >>EOO ' ' <newline> EOO -$* <"" >>EOO # empty +: empty +: +$* <"" >>EOO <newline> EOO -$* <:"foo" >>EOO 2>>EOE != 0 # eof +: eof +: +$* <:"foo" >>EOO 2>>EOE != 0 'foo' EOO stdin:1:4: error: expected newline at the end of description line diff --git a/unit-tests/test/script/lexer/first-token.test b/unit-tests/test/script/lexer/first-token.test index 8a6d39b..6044f53 100644 --- a/unit-tests/test/script/lexer/first-token.test +++ b/unit-tests/test/script/lexer/first-token.test @@ -1,68 +1,96 @@ +# file : unit-tests/test/script/lexer/first-token.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + # Note: this mode auto-expires after each token. # test.arguments = first-token -$* <"." >>EOO # dot +: dot +: +$* <"." >>EOO . <newline> EOO -$* <";" >>EOO # semi +: semi +: +$* <";" >>EOO ; <newline> EOO -$* <":" >>EOO # colon +: colon +: +$* <":" >>EOO : <newline> EOO -$* <"{" >>EOO # lcbrace +: lcbrace +: +$* <"{" >>EOO { <newline> EOO -$* <"}" >>EOO # rcbrace +: rcbrace +: +$* <"}" >>EOO } <newline> EOO -$* <"+foo" >>EOO # setup +: setup +: +$* <"+foo" >>EOO + 'foo' <newline> EOO -$* <"- foo" >>EOO # tdown +: tdown +: +$* <"- foo" >>EOO - 'foo' <newline> EOO -$* <"foo+bar" >>EOO # plus-leading +: plus-leading +: +$* <"foo+bar" >>EOO 'foo+bar' <newline> EOO -$* <"foo- x" >>EOO # minus-leading +: minus-leading +: +$* <"foo- x" >>EOO 'foo-' 'x' <newline> EOO -$* <"foo=" >>EOO # assign +: assign +: +$* <"foo=" >>EOO 'foo' '=' <newline> EOO -$* <"foo+=" >>EOO # append +: append +: +$* <"foo+=" >>EOO 'foo' '+=' <newline> EOO -$* <"foo=+" >>EOO # prepend +: prepend +: +$* <"foo=+" >>EOO 'foo' '=+' <newline> diff --git a/unit-tests/test/script/lexer/second-token.test b/unit-tests/test/script/lexer/second-token.test index 94cdf95..94ea441 100644 --- a/unit-tests/test/script/lexer/second-token.test +++ b/unit-tests/test/script/lexer/second-token.test @@ -1,47 +1,67 @@ +# file : unit-tests/test/script/lexer/second-token.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + # Note: this mode auto-expires after each token. # test.arguments = second-token -$* <";" >>EOO # semi +: semi +: +$* <";" >>EOO ; <newline> EOO -$* <":" >>EOO # colon +: colon +: +$* <":" >>EOO : <newline> EOO -$* <"=foo" >>EOO # assign +: assign +: +$* <"=foo" >>EOO = 'foo' <newline> EOO -$* <"+= foo" >>EOO # append +: append +: +$* <"+= foo" >>EOO += 'foo' <newline> EOO -$* <" =+ foo" >>EOO # prepend +: prepend +: +$* <" =+ foo" >>EOO =+ 'foo' <newline> EOO -$* <"foo=bar" >>EOO # assign-leading +: assign-leading +: +$* <"foo=bar" >>EOO 'foo=bar' <newline> EOO -$* <"foo+= bar" >>EOO # append-leading +: append-leading +: +$* <"foo+= bar" >>EOO 'foo+=' 'bar' <newline> EOO -$* <"foo =+bar" >>EOO # prepend-leading +: prepend-leading +: +$* <"foo =+bar" >>EOO 'foo' '=+bar' <newline> diff --git a/unit-tests/test/script/lexer/variable-line.test b/unit-tests/test/script/lexer/variable-line.test index 126fe54..c97981d 100644 --- a/unit-tests/test/script/lexer/variable-line.test +++ b/unit-tests/test/script/lexer/variable-line.test @@ -1,18 +1,28 @@ +# file : unit-tests/test/script/lexer/variable-line.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + test.arguments = variable-line -$* <"cmd;" >>EOO # semi +: semi +: +$* <"cmd;" >>EOO 'cmd' ; <newline> EOO -$* <"cmd ;" >>EOO # semi-separated +: semi-separated +: +$* <"cmd ;" >>EOO 'cmd' ; <newline> EOO -$* <";" >>EOO # semi-only +: semi-only +: +$* <";" >>EOO ; <newline> EOO diff --git a/unit-tests/test/script/lexer/variable.test b/unit-tests/test/script/lexer/variable.test index 0ecc6cc..15458f5 100644 --- a/unit-tests/test/script/lexer/variable.test +++ b/unit-tests/test/script/lexer/variable.test @@ -1,40 +1,70 @@ +# file : unit-tests/test/script/lexer/variable.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + # Test handling custom variable names ($*, $~, $NN). # test.arguments = variable -$* <"*" >>EOO -'*' -<newline> -EOO - -$* <"*abc" >>EOO -'*' -'abc' -<newline> -EOO - -$* <"~" >>EOO -'~' -<newline> -EOO - -$* <"~123" >>EOO -'~' -'123' -<newline> -EOO - -$* <"0" >>EOO -'0' -<newline> -EOO - -$* <"1abc" >>EOO -'1' -'abc' -<newline> -EOO - -$* <"10" 2>>EOE != 0 -stdin:1:1: error: multi-digit special variable name -EOE +: command +: +{ + : only + : + $* <"*" >>EOO + '*' + <newline> + EOO + + : followed + : + $* <"*abc" >>EOO + '*' + 'abc' + <newline> + EOO +} + +: working-dir +: +{ + : only + : + $* <"~" >>EOO + '~' + <newline> + EOO + + : followed + : + $* <"~123" >>EOO + '~' + '123' + <newline> + EOO +} + +: arg +: +{ + : only + : + $* <"0" >>EOO + '0' + <newline> + EOO + + : followed + : + $* <"1abc" >>EOO + '1' + 'abc' + <newline> + EOO + + : multi-digit + : + $* <"10" 2>>EOE != 0 + stdin:1:1: error: multi-digit special variable name + EOE +} diff --git a/unit-tests/test/script/parser/cleanup.test b/unit-tests/test/script/parser/cleanup.test index 76614e3..ac4d949 100644 --- a/unit-tests/test/script/parser/cleanup.test +++ b/unit-tests/test/script/parser/cleanup.test @@ -1,3 +1,7 @@ +# file : unit-tests/test/script/parser/cleanup.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + : always : $* <<EOI >>EOO @@ -30,20 +34,25 @@ EOI testscript:1:6: error: empty cleanup path EOE -: missed-before-token -: Path missed before command next token +: missed-before : -$* <<EOI 2>>EOE != 0 -cmd & >file -EOI -testscript:1:7: error: missing cleanup path -EOE +{ + : token + : + : Path missed before command next token + : + $* <<EOI 2>>EOE != 0 + cmd & >file + EOI + testscript:1:7: error: missing cleanup path + EOE -: missed-before-end -: Test path missed before end of command -: -$* <<EOI 2>>EOE != 0 -cmd & -EOI -testscript:1:6: error: missing cleanup path -EOE + : end + : Test path missed before end of command + : + $* <<EOI 2>>EOE != 0 + cmd & + EOI + testscript:1:6: error: missing cleanup path + EOE +} diff --git a/unit-tests/test/script/parser/command-if.test b/unit-tests/test/script/parser/command-if.test index 4bbc016..ffe2c35 100644 --- a/unit-tests/test/script/parser/command-if.test +++ b/unit-tests/test/script/parser/command-if.test @@ -1,225 +1,506 @@ -: if-true -: -$* <<EOI >>EOO -if true foo - cmd1 - cmd2 -end -EOI -? true foo -cmd1 -cmd2 -EOO +# file : unit-tests/test/script/parser/command-if.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file -: if-false +: if : -$* <<EOI >>EOO -if false foo +{ + : true + : + $* <<EOI >>EOO + if true foo + cmd1 + cmd2 + end + EOI + ? true foo cmd1 cmd2 -end -EOI -? false foo -EOO + EOO -: ifn-true -: -$* <<EOI >>EOO -if! true foo + : false + : + $* <<EOI >>EOO + if false foo + cmd1 + cmd2 + end + EOI + ? false foo + EOO + + : not-true + : + $* <<EOI >>EOO + if! true foo + cmd1 + cmd2 + end + EOI + ? true foo + EOO + + : not-false + : + $* <<EOI >>EOO + if! false foo + cmd1 + cmd2 + end + EOI + ? false foo cmd1 cmd2 -end -EOI -? true foo -EOO + EOO -: ifn-false -: -$* <<EOI >>EOO -if! false foo - cmd1 - cmd2 -end -EOI -? false foo -cmd1 -cmd2 -EOO + : without-command + : + $* <<EOI 2>>EOE != 0 + if + cmd + end + EOI + testscript:1:3: error: missing program + EOE + + : after-semi + : + $* -s <<EOI >>EOO + cmd1; + if true + cmd2 + end + EOI + { + { + cmd1 + ? true + cmd2 + } + } + EOO -: elif-true -: -$* <<EOI >>EOO -if false - cmd1 - cmd2 -elif true - cmd3 - cmd4 -end -EOI -? false -? true -cmd3 -cmd4 -EOO + : setup + : + $* -s <<EOI >>EOO + +if true + cmd + end + EOI + { + ? true + cmd + } + EOO -: elif-false -: -$* <<EOI >>EOO -if false - cmd1 - cmd2 -elif false - cmd3 - cmd4 -end -EOI -? false -? false -EOO + : tdown + : + $* -s <<EOI >>EOO + -if true + cmd + end + EOI + { + ? true + cmd + } + EOO +} -: elifn-true +: elif : -$* <<EOI >>EOO -if false - cmd1 - cmd2 -elif! true +{ + : true + : + $* <<EOI >>EOO + if false + cmd1 + cmd2 + elif true + cmd3 + cmd4 + end + EOI + ? false + ? true cmd3 cmd4 -end -EOI -? false -? true -EOO + EOO -: elifn-false -: -$* <<EOI >>EOO -if false - cmd1 - cmd2 -elif! false + : false + : + $* <<EOI >>EOO + if false + cmd1 + cmd2 + elif false + cmd3 + cmd4 + end + EOI + ? false + ? false + EOO + + : not-true + : + $* <<EOI >>EOO + if false + cmd1 + cmd2 + elif! true + cmd3 + cmd4 + end + EOI + ? false + ? true + EOO + + : not-false + : + $* <<EOI >>EOO + if false + cmd1 + cmd2 + elif! false + cmd3 + cmd4 + end + EOI + ? false + ? false cmd3 cmd4 -end -EOI -? false -? false -cmd3 -cmd4 -EOO + EOO + + : without-if + : + $* <<EOI 2>>EOE != 0 + cmd + elif true + cmd + end + EOI + testscript:2:1: error: 'elif' without preceding 'if' + EOE -: else-true + : not-without-if + : + $* <<EOI 2>>EOE != 0 + cmd + elif! true + cmd + end + EOI + testscript:2:1: error: 'elif!' without preceding 'if' + EOE + + : after-else + : + $* <<EOI 2>>EOE != 0 + if false + cmd + else + cmd + elif true + cmd + end + EOI + testscript:5:1: error: 'elif' after 'else' + EOE +} + +: else : -$* <<EOI >>EOO -if false - cmd1 - cmd2 -else +{ + : true + : + $* <<EOI >>EOO + if false + cmd1 + cmd2 + else + cmd3 + cmd4 + end + EOI + ? false cmd3 cmd4 -end -EOI -? false -cmd3 -cmd4 -EOO + EOO -: else-false -: -$* <<EOI >>EOO -if true + : false + : + $* <<EOI >>EOO + if true + cmd1 + cmd2 + else + cmd3 + cmd4 + end + EOI + ? true cmd1 cmd2 -else - cmd3 - cmd4 -end -EOI -? true -cmd1 -cmd2 -EOO + EOO -: if-chain -: -$* <<EOI >>EOO -if false - cmd - cmd -elif false - cmd - cmd -elif false - cmd - cmd -elif true + : chain + : + $* <<EOI >>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 -elif false - cmd - cmd -else - cmd + EOO + + : command-after + : + $* <<EOI 2>>EOE != 0 + if true + cmd + else cmd + cmd + end + EOI + testscript:3:6: error: expected newline instead of 'cmd' + EOE + + : without-if + : + $* <<EOI 2>>EOE != 0 cmd -end -EOI -? false -? false -? false -? true -cmd1 -cmd2 -EOO + else + cmd + end + EOI + testscript:2:1: error: 'else' without preceding 'if' + EOE -: nested-take -: -$* <<EOI >>EOO -if true - cmd1 + : after-else + : + $* <<EOI 2>>EOE != 0 if false cmd - elif false + else + cmd + else + cmd + end + EOI + testscript:5:1: error: 'else' after 'else' + EOE +} + +: end +{ + : without-if + : + $* <<EOI 2>>EOE != 0 + cmd + end + EOI + testscript:2:1: error: 'end' without preceding 'if' + EOE + + : before + { + : semi + : + $* -s <<EOI >>EOO + if true + cmd1 + end; + cmd2 + EOI + { + { + ? true + cmd1 + cmd2 + } + } + EOO + + : command + : + $* <<EOI 2>>EOE != 0 if true cmd + end cmd + EOI + testscript:3:5: error: expected newline instead of 'cmd' + EOE + + : colon + : + $* -s <<EOI >>EOO + if true + cmd1 + cmd2 + end : test + EOI + { + : id:test + { + ? true + cmd1 + cmd2 + } + } + EOO + } +} + +: nested +: +{ + : take + : + $* <<EOI >>EOO + if true + cmd1 + if false + cmd + elif false + if true + cmd + end + else + cmd2 end - else - cmd2 + cmd3 end + EOI + ? true + cmd1 + ? false + ? false + cmd2 cmd3 -end -EOI -? true -cmd1 -? false -? false -cmd2 -cmd3 -EOO + EOO -: nested-skip -: -$* <<EOI >>EOO -if false - cmd1 + : skip + : + $* <<EOI >>EOO if false - cmd - elif false - if true + cmd1 + if false cmd + elif false + if true + cmd + end + else + cmd2 end + cmd3 else - cmd2 + cmd end - cmd3 -else + EOI + ? false cmd -end -EOI -? false -cmd -EOO + EOO +} + +: contained +{ + : semi + : + $* <<EOI 2>>EOE != 0 + if + cmd; + cmd + end + EOI + testscript:2:3: error: ';' inside 'if' + EOE + + : colon-leading + : + $* <<EOI 2>>EOE != 0 + if + : foo + cmd + end + EOI + testscript:2:3: error: description inside 'if' + EOE + + : colon-trailing + : + $* <<EOI 2>>EOE != 0 + if + cmd : foo + end + EOI + testscript:2:3: error: description inside 'if' + EOE + + : eos + : + $* <<EOI 2>>EOE != 0 + if + EOI + testscript:2:1: error: expected closing 'end' + EOE + + : scope + : + $* <<EOI 2>>EOE != 0 + if + cmd + { + } + end + EOI + testscript:3:3: error: expected closing 'end' + EOE + + : setup + : + $* <<EOI 2>>EOE != 0 + if + +cmd + end + EOI + testscript:2:3: error: setup command inside 'if' + EOE + + : tdown + : + $* <<EOI 2>>EOE != 0 + if + -cmd + end + EOI + testscript:2:3: error: teardown command inside 'if' + EOE +} : line-index : @@ -255,258 +536,6 @@ EOI cmd foo EOO -: semi-inside -: -$* <<EOI 2>>EOE != 0 -if - cmd; - cmd -end -EOI -testscript:2:3: error: ';' inside 'if' -EOE - -: colon-inside-leading -: -$* <<EOI 2>>EOE != 0 -if - : foo - cmd -end -EOI -testscript:2:3: error: description inside 'if' -EOE - -: colon-inside-trailing -: -$* <<EOI 2>>EOE != 0 -if - cmd : foo -end -EOI -testscript:2:3: error: description inside 'if' -EOE - -: eos-inside -: -$* <<EOI 2>>EOE != 0 -if -EOI -testscript:2:1: error: expected closing 'end' -EOE - -: scope-inside -: -$* <<EOI 2>>EOE != 0 -if - cmd - { - } -end -EOI -testscript:3:3: error: expected closing 'end' -EOE - -: setup-inside -: -$* <<EOI 2>>EOE != 0 -if - +cmd -end -EOI -testscript:2:3: error: setup command inside 'if' -EOE - -: tdown-inside -: -$* <<EOI 2>>EOE != 0 -if - -cmd -end -EOI -testscript:2:3: error: teardown command inside 'if' -EOE - -: if-without-command -: -$* <<EOI 2>>EOE != 0 -if - cmd -end -EOI -testscript:1:3: error: missing program -EOE - -: command-after-else -: -$* <<EOI 2>>EOE != 0 -if true - cmd -else cmd - cmd -end -EOI -testscript:3:6: error: expected newline instead of 'cmd' -EOE - -: command-after-end -: -$* <<EOI 2>>EOE != 0 -if true - cmd -end cmd -EOI -testscript:3:5: error: expected newline instead of 'cmd' -EOE - -: elif-without-if -: -$* <<EOI 2>>EOE != 0 -cmd -elif true - cmd -end -EOI -testscript:2:1: error: 'elif' without preceding 'if' -EOE - -: elifn-without-if -: -$* <<EOI 2>>EOE != 0 -cmd -elif! true - cmd -end -EOI -testscript:2:1: error: 'elif!' without preceding 'if' -EOE - -: else-without-if -: -$* <<EOI 2>>EOE != 0 -cmd -else - cmd -end -EOI -testscript:2:1: error: 'else' without preceding 'if' -EOE - -: end-without-if -: -$* <<EOI 2>>EOE != 0 -cmd -end -EOI -testscript:2:1: error: 'end' without preceding 'if' -EOE - -: else-after-else -: -$* <<EOI 2>>EOE != 0 -if false - cmd -else - cmd -else - cmd -end -EOI -testscript:5:1: error: 'else' after 'else' -EOE - -: elif-after-else -: -$* <<EOI 2>>EOE != 0 -if false - cmd -else - cmd -elif true - cmd -end -EOI -testscript:5:1: error: 'elif' after 'else' -EOE - -: if-after-semi -: -$* -s <<EOI >>EOO -cmd1; -if true - cmd2 -end -EOI -{ - { - cmd1 - ? true - cmd2 - } -} -EOO - -: setup-if -: -$* -s <<EOI >>EOO -+if true - cmd -end -EOI -{ - ? true - cmd -} -EOO - -: tdown-if -: -$* -s <<EOI >>EOO --if true - cmd -end -EOI -{ - ? true - cmd -} -EOO - -: semi-after-end -: -$* -s <<EOI >>EOO -if true - cmd1 -end; -cmd2 -EOI -{ - { - ? true - cmd1 - cmd2 - } -} -EOO - -: colon-after-end -: -$* -s <<EOI >>EOO -if true - cmd1 - cmd2 -end : test -EOI -{ - : id:test - { - ? true - cmd1 - cmd2 - } -} -EOO - : leading-and-trailing-description : $* <<EOI 2>>EOE != 0 diff --git a/unit-tests/test/script/parser/command-re-parse.test b/unit-tests/test/script/parser/command-re-parse.test index 335ff69..657bf88 100644 --- a/unit-tests/test/script/parser/command-re-parse.test +++ b/unit-tests/test/script/parser/command-re-parse.test @@ -1,6 +1,9 @@ +# file : unit-tests/test/script/parser/command-re-parse.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file -# double-quote -# +: double-quote +: $* <<EOI >>EOO x = cmd \">-\" "'<-'" $x diff --git a/unit-tests/test/script/parser/description.test b/unit-tests/test/script/parser/description.test index 16ba287..3e2bb7f 100644 --- a/unit-tests/test/script/parser/description.test +++ b/unit-tests/test/script/parser/description.test @@ -1,114 +1,414 @@ -$* <<EOI >>EOO # id -: foo -cmd -EOI -: id:foo -cmd -EOO +# file : unit-tests/test/script/parser/description.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file -$* <<EOI >>EOO # trail-id -cmd : foo -EOI -: id:foo -cmd -EOO +: id +: +{ + : lead + : + $* <<EOI >>EOO + : foo + cmd + EOI + : id:foo + cmd + EOO -$* <<EOI >>EOO # summary -: foo bar -cmd -EOI -: sm:foo bar -cmd -EOO + : trail + : + $* <<EOI >>EOO + cmd : foo + EOI + : id:foo + cmd + EOO + + : dup + : Id uniqueness + : + { + : test + : + { + : test + : + $* <<EOI 2>>EOE != 0 + : foo + cmd + : foo + cmd + EOI + testscript:3:1: error: duplicate id foo + testscript:1:1: info: previously used here + EOE + + : group + : + $* <<EOI 2>>EOE != 0 + : foo + cmd + : foo + { + cmd + cmd + } + EOI + testscript:3:1: error: duplicate id foo + testscript:1:1: info: previously used here + EOE + + : derived + : + $* <<EOI 2>>EOE != 0 + : 3 + cmd + cmd + EOI + testscript:3:1: error: duplicate id 3 + testscript:1:1: info: previously used here + EOE + } -$* <<EOI >>EOO # trail-summary -cmd: foo bar -EOI -: sm:foo bar -cmd -EOO + : group + : + { + : test + : + $* <<EOI 2>>EOE != 0 + : foo + { + cmd + cmd + } + : foo + cmd + EOI + testscript:6:1: error: duplicate id foo + testscript:1:1: info: previously used here + EOE + + : group + : + $* <<EOI 2>>EOE != 0 + : foo + { + cmd + cmd + } + : foo + { + cmd + cmd + } + EOI + testscript:6:1: error: duplicate id foo + testscript:1:1: info: previously used here + EOE + + : derived + : + $* <<EOI 2>>EOE != 0 + : 3 + cmd + { + cmd + cmd + } + EOI + testscript:3:1: error: duplicate id 3 + testscript:1:1: info: previously used here + EOE + } + } +} -$* <<EOI >>EOO # id-summary -: foo-bar -: foo bar -cmd -EOI -: id:foo-bar -: sm:foo bar -cmd -EOO +: summary +{ + : lead + : + $* <<EOI >>EOO + : foo bar + cmd + EOI + : sm:foo bar + cmd + EOO -# Initially assumed summary. -# -$* <<EOI >>EOO # details-summary -: foo bar -: bar baz -cmd -EOI -: foo bar -: bar baz -cmd -EOO + : trail + : + $* <<EOI >>EOO + cmd: foo bar + EOI + : sm:foo bar + cmd + EOO -# Initially assumed id and summary. -# -$* <<EOI >>EOO # details-id-summary -: foo-bar -: bar baz -: baz fox -cmd -EOI -: foo-bar -: bar baz -: baz fox -cmd -EOO + : id + : + $* <<EOI >>EOO + : foo-bar + : foo bar + cmd + EOI + : id:foo-bar + : sm:foo bar + cmd + EOO +} -$* <<EOI >>EOO # id-details -: foo-bar +: details +{ + : id + : + $* <<EOI >>EOO + : foo-bar + : + : foo bar + : bar baz + cmd + EOI + : id:foo-bar + : + : foo bar + : bar baz + cmd + EOO + + : summary + : + { + : only + : + $* <<EOI >>EOO + : foo bar + : + : foo bar + : bar baz + cmd + EOI + : sm:foo bar + : + : foo bar + : bar baz + cmd + EOO + + : assumed + : + $* <<EOI >>EOO + : foo bar + : bar baz + cmd + EOI + : foo bar + : bar baz + cmd + EOO + + : id + : + $* <<EOI >>EOO + : foo-bar + : foo bar + : + : foo bar + : bar baz + cmd + EOI + : id:foo-bar + : sm:foo bar + : + : foo bar + : bar baz + cmd + EOO + + : id-assumed + : + $* <<EOI >>EOO + : foo-bar + : bar baz + : baz fox + cmd + EOI + : foo-bar + : bar baz + : baz fox + cmd + EOO + } +} + +: legal : -: foo bar -: bar baz -cmd -EOI -: id:foo-bar +: Legal places for description. : -: foo bar -: bar baz -cmd -EOO +{ + : var + : + $* <<EOI >>EOO + : foo bar + x = y; + cmd $x + EOI + : sm:foo bar + cmd y + EOO +} -$* <<EOI >>EOO # summary-details -: foo bar +: illegal : -: foo bar -: bar baz -cmd -EOI -: sm:foo bar +: Illegal places for description. : -: foo bar -: bar baz -cmd -EOO +{ + : eof + : + $* <": foo" 2>>EOE != 0 + testscript:2:1: error: description before <end of file> + EOE + + : rcbrace + : + $* <<EOI 2>>EOE != 0 + { + cmd + : foo + } + EOI + testscript:4:1: error: description before '}' + EOE -$* <<EOI >>EOO # id-summary-details -: foo-bar -: foo bar + : setup + : + $* <<EOI 2>>EOE != 0 + : foo + +cmd + EOI + testscript:2:1: error: description before setup command + EOE + + : tdown + : + $* <<EOI 2>>EOE != 0 + : foo + -cmd + EOI + testscript:2:1: error: description before teardown command + EOE + + : var + : + $* <<EOI 2>>EOE != 0 + : foo + x = y + EOI + testscript:2:1: error: description before setup/teardown variable + EOE + + : var-if + : + $* <<EOI 2>>EOE != 0 + : foo + if true + x = y + end + EOI + testscript:2:1: error: description before/after setup/teardown variable-if + EOE + + : var-if-after + : + $* <<EOI 2>>EOE != 0 + if true + x = y + end : foo + EOI + testscript:1:1: error: description before/after setup/teardown variable-if + EOE + + : test + : + $* <<EOI 2>>EOE != 0 + cmd1; + : foo + cmd2 + EOI + testscript:2:1: error: description inside test + EOE +} + +: test-scope : -: foo bar -: bar baz -cmd -EOI -: id:foo-bar -: sm:foo bar +: Interaction with test scope merging. : -: foo bar -: bar baz -cmd -EOO +{ + : both + : + : No merge since both have description. + : + $* -s -i <<EOI >>EOO + : foo + { + : bar + cmd + } + EOI + { + : id:foo + { # foo + : id:bar + { # foo/bar + cmd + } + } + } + EOO + + : test + : + : No merge since test has description. + : + $* -s -i <<EOI >>EOO + { + : foo-bar + : foo bar + cmd + } + EOI + { + { # 1 + : id:foo-bar + : sm:foo bar + { # 1/foo-bar + cmd + } + } + } + EOO -$* <<EOI >>EOO # blanks + : group + : + $* -s -i <<EOI >>EOO + : foo-bar + : foo bar + { + cmd + } + EOI + { + : id:foo-bar + : sm:foo bar + { # foo-bar + cmd + } + } + EOO +} + +: blanks +: +$* <<EOI >>EOO : : : foo bar @@ -126,7 +426,9 @@ EOI cmd EOO -$* <<EOI >>EOO # strip +: strip +: +$* <<EOI >>EOO : foo-bar : bar baz : @@ -145,7 +447,9 @@ EOI cmd EOO -$* <<EOI >>EOO # trail-compound +: trail-compound +: +$* <<EOI >>EOO cmd1; cmd2: foo EOI @@ -154,7 +458,9 @@ cmd1 cmd2 EOO -$* <<EOI 2>>EOE != 0 # empty +: empty +: +$* <<EOI 2>>EOE != 0 : : cmd @@ -162,225 +468,19 @@ EOI testscript:1:1: error: empty description EOE -$* <<EOI 2>>EOE != 0 # trail-empty +: trail-empty +: +$* <<EOI 2>>EOE != 0 cmd: EOI testscript:1:4: error: empty description EOE -$* <<EOI 2>>EOE != 0 # both +: both +: +$* <<EOI 2>>EOE != 0 : foo cmd : bar EOI testscript:2:1: error: both leading and trailing descriptions EOE - -# Legal places for a description. -# -$* <<EOI >>EOO # legal-var -: foo bar -x = y; -cmd $x -EOI -: sm:foo bar -cmd y -EOO - -# Illegal places for a description. -# -$* <": foo" 2>>EOE != 0 # illegal-eof -testscript:2:1: error: description before <end of file> -EOE - -$* <<EOI 2>>EOE != 0 # illegal-rcbrace -{ - cmd - : foo -} -EOI -testscript:4:1: error: description before '}' -EOE - -$* <<EOI 2>>EOE != 0 # illegal-setup -: foo -+cmd -EOI -testscript:2:1: error: description before setup command -EOE - -$* <<EOI 2>>EOE != 0 # illegal-tdown -: foo --cmd -EOI -testscript:2:1: error: description before teardown command -EOE - -$* <<EOI 2>>EOE != 0 # illegal-var -: foo -x = y -EOI -testscript:2:1: error: description before setup/teardown variable -EOE - -$* <<EOI 2>>EOE != 0 # illegal-var-if -: foo -if true - x = y -end -EOI -testscript:2:1: error: description before/after setup/teardown variable-if -EOE - -$* <<EOI 2>>EOE != 0 # illegal-var-if-after -if true - x = y -end : foo -EOI -testscript:1:1: error: description before/after setup/teardown variable-if -EOE - -$* <<EOI 2>>EOE != 0 # illegal-test -cmd1; -: foo -cmd2 -EOI -testscript:2:1: error: description inside test -EOE - -# Id uniqueness. -# -$* <<EOI 2>>EOE != 0 # id-dup-test-test -: foo -cmd -: foo -cmd -EOI -testscript:3:1: error: duplicate id foo - testscript:1:1: info: previously used here -EOE - -$* <<EOI 2>>EOE != 0 # id-dup-test-group -: foo -cmd -: foo -{ - cmd - cmd -} -EOI -testscript:3:1: error: duplicate id foo - testscript:1:1: info: previously used here -EOE - -$* <<EOI 2>>EOE != 0 # id-dup-group-test -: foo -{ - cmd - cmd -} -: foo -cmd -EOI -testscript:6:1: error: duplicate id foo - testscript:1:1: info: previously used here -EOE - -$* <<EOI 2>>EOE != 0 # id-dup-group-group -: foo -{ - cmd - cmd -} -: foo -{ - cmd - cmd -} -EOI -testscript:6:1: error: duplicate id foo - testscript:1:1: info: previously used here -EOE - -$* <<EOI 2>>EOE != 0 # id-dup-group-derived -: 3 -cmd -{ - cmd - cmd -} -EOI -testscript:3:1: error: duplicate id 3 - testscript:1:1: info: previously used here -EOE - -$* <<EOI 2>>EOE != 0 # id-dup-test-derived -: 3 -cmd -cmd -EOI -testscript:3:1: error: duplicate id 3 - testscript:1:1: info: previously used here -EOE - -# Interaction with test scope merging. -# - -: test-scope-both -: -: No merge since both have description. -: -$* -s -i <<EOI >>EOO -: foo -{ - : bar - cmd -} -EOI -{ - : id:foo - { # foo - : id:bar - { # foo/bar - cmd - } - } -} -EOO - -: test-scope-test -: -: No merge since test has description. -: -$* -s -i <<EOI >>EOO # -{ - : foo-bar - : foo bar - cmd -} -EOI -{ - { # 1 - : id:foo-bar - : sm:foo bar - { # 1/foo-bar - cmd - } - } -} -EOO - -$* -s -i <<EOI >>EOO # test-scope-group -: foo-bar -: foo bar -{ - cmd -} -EOI -{ - : id:foo-bar - : sm:foo bar - { # foo-bar - cmd - } -} -EOO diff --git a/unit-tests/test/script/parser/directive.test b/unit-tests/test/script/parser/directive.test index 07cb65c..d426d9c 100644 --- a/unit-tests/test/script/parser/directive.test +++ b/unit-tests/test/script/parser/directive.test @@ -1,3 +1,7 @@ +# file : unit-tests/test/script/parser/directive.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + : not-directive : $* <<EOI >>EOO diff --git a/unit-tests/test/script/parser/exit.test b/unit-tests/test/script/parser/exit.test index 263179b..9a4f9dc 100644 --- a/unit-tests/test/script/parser/exit.test +++ b/unit-tests/test/script/parser/exit.test @@ -1,3 +1,7 @@ +# file : unit-tests/test/script/parser/exit.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + : eq : $* <<EOI >>EOO diff --git a/unit-tests/test/script/parser/expansion.test b/unit-tests/test/script/parser/expansion.test index 1d10a63..0a40827 100644 --- a/unit-tests/test/script/parser/expansion.test +++ b/unit-tests/test/script/parser/expansion.test @@ -1,8 +1,11 @@ -# Make sure everything expanded as strings. -# +# file : unit-tests/test/script/parser/expansion.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file -# quote -# +: quote +: +: Make sure everything expanded as strings. +: $* <<EOI >>EOO x = dir/ proj% proj%name proj%proj%dir/type{name name {name}} cmd dir/ proj% proj%name proj%proj%dir/type{name name {name}} diff --git a/unit-tests/test/script/parser/here-document.test b/unit-tests/test/script/parser/here-document.test index 4afcf68..1e4f93b 100644 --- a/unit-tests/test/script/parser/here-document.test +++ b/unit-tests/test/script/parser/here-document.test @@ -1,3 +1,7 @@ +# file : unit-tests/test/script/parser/here-document.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + : end-marker : { diff --git a/unit-tests/test/script/parser/here-string.test b/unit-tests/test/script/parser/here-string.test index 9c4b68b..ab16779 100644 --- a/unit-tests/test/script/parser/here-string.test +++ b/unit-tests/test/script/parser/here-string.test @@ -1,10 +1,18 @@ -$* <<EOI >>EOO # empty +# file : unit-tests/test/script/parser/here-string.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +: empty +: +$* <<EOI >>EOO cmd <"" EOI cmd <'' EOO -$* <<EOI >>EOO # empty-nn +: empty-nn +: +$* <<EOI >>EOO cmd <:"" EOI cmd <:'' diff --git a/unit-tests/test/script/parser/include.test b/unit-tests/test/script/parser/include.test index 7910919..c810036 100644 --- a/unit-tests/test/script/parser/include.test +++ b/unit-tests/test/script/parser/include.test @@ -1,3 +1,7 @@ +# file : unit-tests/test/script/parser/include.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + : none : $* <<EOI @@ -7,7 +11,7 @@ EOI : empty : -touch foo.test &foo.test; #@@ TMP +touch foo.test; $* <<EOI .include foo.test .include --once foo.test @@ -93,8 +97,8 @@ EOE : unable-open : -: Note that the error message is platform specific. -: -$* <<EOI 2>- != 0 +$* <<EOI 2>>~/EOE/ != 0 .include foo.test EOI +/testscript:1:2: error: unable to read testscript foo.test: .+/ +EOE diff --git a/unit-tests/test/script/parser/pipe-expr.test b/unit-tests/test/script/parser/pipe-expr.test index 74077e7..cc0bd7e 100644 --- a/unit-tests/test/script/parser/pipe-expr.test +++ b/unit-tests/test/script/parser/pipe-expr.test @@ -1,3 +1,7 @@ +# file : unit-tests/test/script/parser/pipe-expr.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + : pipe : $* <<EOI >>EOO diff --git a/unit-tests/test/script/parser/pre-parse.test b/unit-tests/test/script/parser/pre-parse.test index 4057f9a..d2ae7ce 100644 --- a/unit-tests/test/script/parser/pre-parse.test +++ b/unit-tests/test/script/parser/pre-parse.test @@ -1,15 +1,23 @@ -# attribute-pair -# -$* <<EOI 2>>EOE != 0 -x = [foo=bar] -EOI -testscript:1:5: error: unknown value attribute foo=bar -EOE +# file : unit-tests/test/script/parser/pre-parse.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file -# attribute-pair-empty -# -$* <<EOI 2>>EOE != 0 -x = [foo=] -EOI -testscript:1:5: error: unknown value attribute foo -EOE +: attribute +: +{ + : pair + : + $* <<EOI 2>>EOE != 0 + x = [foo=bar] + EOI + testscript:1:5: error: unknown value attribute foo=bar + EOE + + : pair-empty + : + $* <<EOI 2>>EOE != 0 + x = [foo=] + EOI + testscript:1:5: error: unknown value attribute foo + EOE +} diff --git a/unit-tests/test/script/parser/redirect.test b/unit-tests/test/script/parser/redirect.test index 2642834..5a91354 100644 --- a/unit-tests/test/script/parser/redirect.test +++ b/unit-tests/test/script/parser/redirect.test @@ -1,117 +1,185 @@ +# file : unit-tests/test/script/parser/redirect.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + # @@ Add tests for redirects other than file and merge. # @@ Does it make sense to split into separate files - one per redirect type? # -$* <<EOI >>EOO # file -cmd 0<<<a 1>>>b 2>>>&c -EOI -cmd <<<a >>>b 2>>>&c -EOO - -$* <<EOI >>EOO # quote-file -cmd 0<<<"a f" 1>>>"b f" 2>>>&"c f" -EOI -cmd <<<'a f' >>>'b f' 2>>>&'c f' -EOO - -$* <<EOI 2>>EOE !=0 # in-file-fail1 -cmd <<< -EOI -testscript:1:8: error: missing stdin file -EOE - -$* <<EOI 2>>EOE !=0 # in-file-fail2 -cmd <<<"" -EOI -testscript:1:8: error: empty stdin redirect path -EOE - -$* <<EOI 2>>EOE !=0 # out-file-fail1 -cmd >>> -EOI -testscript:1:8: error: missing stdout file -EOE - -$* <<EOI 2>>EOE !=0 # out-file-fail2 -cmd >>>"" -EOI -testscript:1:8: error: empty stdout redirect path -EOE - -$* <<EOI 2>>EOE !=0 # err-file-fail1 -cmd 2>>> -EOI -testscript:1:9: error: missing stderr file -EOE - -$* <<EOI 2>>EOE !=0 # err-file-fail2 -cmd 2>>>"" -EOI -testscript:1:9: error: empty stderr redirect path -EOE - -$* <<EOI >>EOO # out-merge1 -cmd 1>&2 -EOI -cmd >&2 -EOO - -$* <<EOI >>EOO # out-merge2 -cmd 1>&2 2>&1 2>a -EOI -cmd >&2 2>a -EOO - -$* <<EOI 2>>EOE != 0 # out-merge-fail1 -cmd 1>&a -EOI -testscript:1:8: error: stdout merge redirect file descriptor must be 2 -EOE - -$* <<EOI 2>>EOE != 0 # out-merge-fail2 -cmd 1>&1 -EOI -testscript:1:8: error: stdout merge redirect file descriptor must be 2 -EOE - -$* <<EOI 2>>EOE != 0 # out-merge-fail3 -cmd 1>& -EOI -testscript:1:8: error: missing stdout file descriptor -EOE - -$* <<EOI >>EOO # err-merge1 -cmd 2>&1 -EOI -cmd 2>&1 -EOO - -$* <<EOI >>EOO # err-merge2 -cmd 1>&2 2>&1 >a -EOI -cmd >a 2>&1 -EOO - -$* <<EOI 2>>EOE != 0 # err-merge-fail1 -cmd 2>&2 -EOI -testscript:1:8: error: stderr merge redirect file descriptor must be 1 -EOE - -$* <<EOI 2>>EOE != 0 # err-merge-fail2 -cmd 2>&2 -EOI -testscript:1:8: error: stderr merge redirect file descriptor must be 1 -EOE - -$* <<EOI 2>>EOE != 0 # err-merge-fail3 -cmd 2>& -EOI -testscript:1:8: error: missing stderr file descriptor -EOE - -$* <<EOI 2>>EOE != 0 # merge-fail1 -cmd 1>&2 2>&1 -EOI -testscript:1:14: error: stdout and stderr redirected to each other -EOE +: file +: +{ + : not-quote + : + $* <<EOI >>EOO + cmd 0<<<a 1>>>b 2>>>&c + EOI + cmd <<<a >>>b 2>>>&c + EOO + + : quote + : + $* <<EOI >>EOO + cmd 0<<<"a f" 1>>>"b f" 2>>>&"c f" + EOI + cmd <<<'a f' >>>'b f' 2>>>&'c f' + EOO + + : in + : + { + : missed + : + $* <<EOI 2>>EOE !=0 + cmd <<< + EOI + testscript:1:8: error: missing stdin file + EOE + + : empty + : + $* <<EOI 2>>EOE !=0 + cmd <<<"" + EOI + testscript:1:8: error: empty stdin redirect path + EOE + } + + : out + : + { + : missed + : + $* <<EOI 2>>EOE !=0 + cmd >>> + EOI + testscript:1:8: error: missing stdout file + EOE + + : empty + : + $* <<EOI 2>>EOE !=0 + cmd >>>"" + EOI + testscript:1:8: error: empty stdout redirect path + EOE + } + + : err + : + { + : missed + : + $* <<EOI 2>>EOE !=0 + cmd 2>>> + EOI + testscript:1:9: error: missing stderr file + EOE + + : empty + : + $* <<EOI 2>>EOE !=0 + cmd 2>>>"" + EOI + testscript:1:9: error: empty stderr redirect path + EOE + } +} + +: merge +{ + : out + : + { + : err + : + $* <<EOI >>EOO + cmd 1>&2 + EOI + cmd >&2 + EOO + + : no-mutual + : + $* <<EOI >>EOO + cmd 1>&2 2>&1 2>a + EOI + cmd >&2 2>a + EOO + + : not-descriptor + : + $* <<EOI 2>>EOE != 0 + cmd 1>&a + EOI + testscript:1:8: error: stdout merge redirect file descriptor must be 2 + EOE + + : self + : + $* <<EOI 2>>EOE != 0 + cmd 1>&1 + EOI + testscript:1:8: error: stdout merge redirect file descriptor must be 2 + EOE + + : missed + : + $* <<EOI 2>>EOE != 0 + cmd 1>& + EOI + testscript:1:8: error: missing stdout file descriptor + EOE + } + + : err + { + : out + : + $* <<EOI >>EOO + cmd 2>&1 + EOI + cmd 2>&1 + EOO + + : no-mutual + : + $* <<EOI >>EOO + cmd 1>&2 2>&1 >a + EOI + cmd >a 2>&1 + EOO + + : not-descriptor + : + $* <<EOI 2>>EOE != 0 + cmd 2>&a + EOI + testscript:1:8: error: stderr merge redirect file descriptor must be 1 + EOE + + : self + : + $* <<EOI 2>>EOE != 0 + cmd 2>&2 + EOI + testscript:1:8: error: stderr merge redirect file descriptor must be 1 + EOE + + : missed + : + $* <<EOI 2>>EOE != 0 + cmd 2>& + EOI + testscript:1:8: error: missing stderr file descriptor + EOE + } + + : mutual + : + $* <<EOI 2>>EOE != 0 + cmd 1>&2 2>&1 + EOI + testscript:1:14: error: stdout and stderr redirected to each other + EOE +} diff --git a/unit-tests/test/script/parser/regex.test b/unit-tests/test/script/parser/regex.test index 9f2e737..f3fda75 100644 --- a/unit-tests/test/script/parser/regex.test +++ b/unit-tests/test/script/parser/regex.test @@ -8,7 +8,7 @@ : stdout : { - : missing + : missed : $* <'cmd >~' 2>>EOE != 0 testscript:1:7: error: missing stdout here-string regex @@ -67,7 +67,7 @@ : stderr : { - : missing + : missed : $* <'cmd 2>~' 2>>EOE != 0 testscript:1:8: error: missing stderr here-string regex @@ -97,7 +97,7 @@ : stdout : { - : missing + : missed : $* <'cmd >>~' 2>>EOE != 0 testscript:1:8: error: expected here-document regex end marker @@ -185,7 +185,7 @@ : stderr : { - : missing + : missed : $* <'cmd 2>>~' 2>>EOE != 0 testscript:1:9: error: expected here-document regex end marker diff --git a/unit-tests/test/script/parser/scope-if.test b/unit-tests/test/script/parser/scope-if.test index e04c47e..4f524cf 100644 --- a/unit-tests/test/script/parser/scope-if.test +++ b/unit-tests/test/script/parser/scope-if.test @@ -1,365 +1,450 @@ -: if-true +# file : unit-tests/test/script/parser/scope-if.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +: if : -$* -s <<EOI >>EOO -if true foo -{ - cmd -} -EOI { - ? true foo + : true + : + $* -s <<EOI >>EOO + if true foo { cmd } -} -EOO + EOI + { + ? true foo + { + cmd + } + } + EOO -: if-false -: -$* -s <<EOI >>EOO -if false foo -{ - cmd -} -EOI -{ - ? false foo -} -EOO + : false + : + $* -s <<EOI >>EOO + if false foo + { + cmd + } + EOI + { + ? false foo + } + EOO -: ifn-true -: -$* -s <<EOI >>EOO -if! true -{ - cmd -} -EOI -{ - ? true -} -EOO + : not-true + : + $* -s <<EOI >>EOO + if! true + { + cmd + } + EOI + { + ? true + } + EOO -: ifn-false -: -$* -s <<EOI >>EOO -if! false -{ - cmd -} -EOI -{ - ? false + : not-false + : + $* -s <<EOI >>EOO + if! false { cmd } + EOI + { + ? false + { + cmd + } + } + EOO + + : eos-inside + : + $* <<EOI 2>>EOE != 0 + if + { + EOI + testscript:3:1: error: expected '}' at the end of the scope + EOE + } -EOO -: elif-true +: elif : -$* -s <<EOI >>EOO -if false -{ - cmd -} -elif true { - cmd1 -} -EOI -{ - ? false - ? true + : true + : + $* -s <<EOI >>EOO + if false + { + cmd + } + elif true { cmd1 } -} -EOO + EOI + { + ? false + ? true + { + cmd1 + } + } + EOO -: elif-false -: -$* -s <<EOI >>EOO -if false -{ - cmd -} -elif false -{ - cmd -} -EOI -{ - ? false - ? false -} -EOO + : 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 + : not-false + : + $* -s <<EOI >>EOO + if false + { + cmd + } + elif! false { cmd1 } -} -EOO + EOI + { + ? false + ? false + { + cmd1 + } + } + EOO -: elifn-true -: -$* -s <<EOI >>EOO -if false -{ - cmd -} -elif! true -{ - cmd -} -EOI -{ - ? false - ? true -} -EOO + : not-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 + : after-else + : + $* <<EOI 2>>EOE != 0 + if false { - cmd1 + cmd + } + else + { + cmd + } + elif true + { + cmd } + EOI + testscript:9:1: error: 'elif' after 'else' + EOE } -EOO -: else-false +: else : -$* -s <<EOI >>EOO -if true -{ - cmd1 -} -else { - cmd -} -EOI -{ - ? true + : true + : + $* -s <<EOI >>EOO + if false + { + cmd + } + else { 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 + EOI { + ? false { cmd1 } + } + EOO + + : false + : + $* -s <<EOI >>EOO + if true + { + cmd1 + } + else + { + cmd + } + EOI + { + ? true { - cmd2 + cmd1 } } -} -EOO + EOO -: nested-take -: -$* -s <<EOI >>EOO -if true -{ - cmd1 + : chain + : + $* -s <<EOI >>EOO if false { cmd } elif false { - if true - { - cmd - } + cmd + cmd } - else + elif false + { + cmd + } + elif true { + cmd1 cmd2 } - cmd3 -} -EOI -{ - ? true + elif false { - { - cmd1 - } + cmd + } + else + { + cmd + cmd + } + EOI + { + ? false ? false ? false + ? true { { + cmd1 + } + { cmd2 } } - { - cmd3 - } } -} -EOO + EOO -: nested-skip -: -$* -s <<EOI >>EOO -if false -{ - cmd1 + : scope-expected + : + $* <<EOI 2>>EOE != 0 + if + { + cmd + } + else + cmd + EOI + testscript:5:1: error: expected scope after 'else' + EOE + + : after-else + : + $* <<EOI 2>>EOE != 0 if false { cmd } - elif false + else { - if true - { - cmd - } + cmd } else { - cmd2 + cmd } - cmd3 + EOI + testscript:9:1: error: 'else' after 'else' + EOE } -else -{ - cmd -} -EOI + +: nested +: { - ? false + : take + : + $* -s <<EOI >>EOO + if true { + cmd1 + if false { cmd } + elif false + { + if true + { + cmd + } + } + else + { + cmd2 + } + cmd3 } -} -EOO + EOI + { + ? true + { + { + cmd1 + } + ? false + ? false + { + { + cmd2 + } + } + { + cmd3 + } + } + } + EOO -: demote-group -: Chain remains a group -: -$* -s <<EOI >>EOO -if false -{ - cmd -} -elif true -{ - cmd1 - cmd2 -} -else -{ - cmd -} -EOI -{ - ? false - ? true + : skip + : + $* -s <<EOI >>EOO + if false { + cmd1 + if false { - cmd1 + cmd } + elif false + { + if true + { + cmd + } + } + else { cmd2 } + cmd3 + } + else + { + cmd + } + EOI + { + ? false + { + { + cmd + } + } } + EOO } -EOO -: demote-test -: Chain demoted to test +: demote : -$* -s <<EOI >>EOO -if false { - cmd -} -elif true -{ - cmd1 -} -else -{ - cmd -} -EOI -{ - ? false - ? true + : group + : Chain remains a group + : + $* -s <<EOI >>EOO + if false + { + cmd + } + elif true + { + cmd1 + cmd2 + } + else + { + cmd + } + EOI + { + ? false + ? true + { + { + cmd1 + } + { + cmd2 + } + } + } + EOO + + : test + : Chain demoted to test + : + $* -s <<EOI >>EOO + if false + { + cmd + } + elif true { cmd1 } + else + { + cmd + } + EOI + { + ? false + ? true + { + cmd1 + } + } + EOO } -EOO : line-index : Make sure command line index spans setup/if/teardown @@ -467,63 +552,3 @@ EOI } } 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 7d78aca..144dc54 100644 --- a/unit-tests/test/script/parser/scope.test +++ b/unit-tests/test/script/parser/scope.test @@ -1,5 +1,9 @@ -$* testscript <'cmd $@' >"cmd 1" # id-testscript -$* foo.test <'cmd $@' >"cmd foo/1" # id +# file : unit-tests/test/script/parser/scope.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +$* testscript <'cmd $@' >"cmd 1" : id-testscript +$* foo.test <'cmd $@' >"cmd foo/1" : id : wd-testscript : @@ -9,214 +13,268 @@ $* testscript <'cmd "$~"' >~"%cmd '?.+[/\\\\]test-driver[/\\\\]1'?%" : $* foo.test <'cmd "$~"' >~"%cmd '?.+[/\\\\]test-driver[/\\\\]foo[/\\\\]1'?%" -$* -s <<EOI # group-empty -{ -} -EOI - -$* -s <<EOI # group-empty-empty +: group +: { - { - } -} -EOI + : empty + : + $* -s <<EOI + { + } + EOI -$* -s <<EOI >>EOO # group -{ - cmd1 - cmd2 -} -EOI -{ + : empty-empty + : + $* -s <<EOI { { - cmd1 - } - { - cmd2 } } -} -EOO - -# Test scope. -# + EOI -$* -s -i <<EOI >>EOO # test-scope -{ - cmd -} -EOI -{ - { # 1 - cmd - } -} -EOO - -$* -s -i <<EOI >>EOO # test-scope-nested -{ + : non-empty + : + $* -s <<EOI >>EOO { - cmd + cmd1 + cmd2 } -} -EOI -{ - { # 1 - cmd + EOI + { + { + { + cmd1 + } + { + cmd2 + } + } } + EOO } -EOO -$* -s -i <<EOI >>EOO # test-scope-var -{ - x = abc - cmd $x -} -EOI +: test +: { - { # 1 - cmd abc - } -} -EOO + : explicit + : + { + : one-level + : + $* -s -i <<EOI >>EOO + { + cmd + } + EOI + { + { # 1 + cmd + } + } + EOO -$* -s -i <<EOI >>EOO # test-scope-setup -{ - x = abc - +setup - cmd $x -} -EOI -{ - { # 1 - setup - { # 1/4 - cmd abc + : nested + : + $* -s -i <<EOI >>EOO + { + { + cmd + } } + EOI + { + { # 1 + cmd + } + } + EOO + + : var + : + $* -s -i <<EOI >>EOO + { + x = abc + cmd $x + } + EOI + { + { # 1 + cmd abc + } + } + EOO + + : setup + : + $* -s -i <<EOI >>EOO + { + x = abc + +setup + cmd $x + } + EOI + { + { # 1 + setup + { # 1/4 + cmd abc + } + } + } + EOO } -} -EOO + : implicit + { + : one-cmd + : + $* -s <<EOI >>EOO + cmd1 + EOI + { + { + cmd1 + } + } + EOO -# -# -$* <:"{x" 2>>EOE != 0 # expected-newline-lcbrace -testscript:1:2: error: expected newline after '{' -EOE + : two-cmd + : + $* -s <<EOI >>EOO + cmd1; + cmd2 + EOI + { + { + cmd1 + cmd2 + } + } + EOO -$* <"{" 2>>EOE != 0 # expected-rcbrace -testscript:2:1: error: expected '}' at the end of the scope -EOE + : three-cmd + : + $* -s <<EOI >>EOO + cmd1; + cmd2; + cmd3 + EOI + { + { + cmd1 + cmd2 + cmd3 + } + } + EOO -$* <<EOI 2>>EOE != 0 # expected-line-rcbrace -{ - cmd; -} -EOI -testscript:3:1: error: expected another line after ';' -EOE + : var + : + $* -s <<EOI >>EOO + cmd1; + x = abc; + cmd2 $x + EOI + { + { + cmd1 + cmd2 abc + } + } + EOO -$* <<:EOI 2>>EOE != 0 # expected-newline-rcbrace -{ -} -EOI -testscript:2:2: error: expected newline after '}' -EOE + : var-first + : + $* -s <<EOI >>EOO + x = abc; + cmd $x + EOI + { + { + cmd abc + } + } + EOO -$* -s <<EOI >>EOO # test-1 -cmd1 -EOI -{ - { - cmd1 - } -} -EOO + : var-setup-tdown + : + $* -s <<EOI >>EOO + x = abc + cmd $x + y = 123 + EOI + { + { + cmd abc + } + } + EOO -$* -s <<EOI >>EOO # test-2 -cmd1; -cmd2 -EOI -{ - { + : after-tdown + : + $* <<EOI 2>>EOE != 0 cmd1 + x = abc cmd2 + EOI + testscript:3:1: error: test after teardown + testscript:2:1: info: last teardown line appears here + EOE } } -EOO -$* -s <<EOI >>EOO # test-3 -cmd1; -cmd2; -cmd3 -EOI +: expected { - { - cmd1 - cmd2 - cmd3 - } -} -EOO + : newline-lcbrace + : + $* <:"{x" 2>>EOE != 0 + testscript:1:2: error: expected newline after '{' + EOE -$* -s <<EOI >>EOO # test-var -cmd1; -x = abc; -cmd2 $x -EOI -{ - { - cmd1 - cmd2 abc - } -} -EOO + : rcbrace + : + $* <"{" 2>>EOE != 0 + testscript:2:1: error: expected '}' at the end of the scope + EOE -$* -s <<EOI >>EOO # test-var-first -x = abc; -cmd $x -EOI -{ + : line-rcbrace + : + $* <<EOI 2>>EOE != 0 { - cmd abc + cmd; } -} -EOO + EOI + testscript:3:1: error: expected another line after ';' + EOE -$* -s <<EOI >>EOO # var-setup-tdown -x = abc -cmd $x -y = 123 -EOI -{ + : newline-rcbrace + : + $* <<:EOI 2>>EOE != 0 { - cmd abc } + EOI + testscript:2:2: error: expected newline after '}' + EOE + + : line-eof + : + $* <<EOI 2>>EOE != 0 + cmd; + EOI + testscript:2:1: error: expected another line after ';' + EOE + + : newline-cmd + : + $* <<:EOI 2>>EOE != 0 + cmd; + EOI + testscript:1:5: error: expected newline instead of <end of file> + EOE + + : newline-var + : + $* <:"x = abc;" 2>>EOE != 0 + testscript:1:9: error: expected newline instead of <end of file> + EOE } -EOO - -$* <<EOI 2>>EOE != 0 # test-after-tdown -cmd1 -x = abc -cmd2 -EOI -testscript:3:1: error: test after teardown - testscript:2:1: info: last teardown line appears here -EOE - -$* <<EOI 2>>EOE != 0 # expected-line-eof -cmd; -EOI -testscript:2:1: error: expected another line after ';' -EOE - -$* <<:EOI 2>>EOE != 0 # expected-newline-cmd -cmd; -EOI -testscript:1:5: error: expected newline instead of <end of file> -EOE - -$* <:"x = abc;" 2>>EOE != 0 # expected-newline-var -testscript:1:9: error: expected newline instead of <end of file> -EOE diff --git a/unit-tests/test/script/parser/setup-teardown.test b/unit-tests/test/script/parser/setup-teardown.test index 5d30ed4..c9183ef 100644 --- a/unit-tests/test/script/parser/setup-teardown.test +++ b/unit-tests/test/script/parser/setup-teardown.test @@ -1,43 +1,83 @@ -$* <"+cmd;" 2>>EOE != 0 # semi-after-setup -testscript:1:5: error: ';' after setup command -EOE - -$* <"+cmd:" 2>>EOE != 0 # colon-after-setup -testscript:1:5: error: ':' after setup command -EOE - -$* <"-cmd;" 2>>EOE != 0 # semi-after-tdown -testscript:1:5: error: ';' after teardown command -EOE - -$* <"-cmd:" 2>>EOE != 0 # colon-after-tdown -testscript:1:5: error: ':' after teardown command -EOE - -$* <<EOI 2>>EOE != 0 # setup-in-test -cmd; -+cmd -EOI -testscript:2:1: error: setup command in test -EOE - -$* <<EOI 2>>EOE != 0 # tdown-in-test -cmd; --cmd -EOI -testscript:2:1: error: teardown command in test -EOE - -$* <<EOI 2>>EOE != 0 # setup-after-test -cmd -+cmd -EOI -testscript:2:1: error: setup command after tests -EOE - -$* <<EOI 2>>EOE != 0 # setup-after-tdownt --cmd -+cmd -EOI -testscript:2:1: error: setup command after teardown -EOE +# file : unit-tests/test/script/parser/setup-teardown.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +: setup +: +{ + : followed + : + { + : semi + : + $* <"+cmd;" 2>>EOE != 0 + testscript:1:5: error: ';' after setup command + EOE + + : colon + : + $* <"+cmd:" 2>>EOE != 0 + testscript:1:5: error: ':' after setup command + EOE + } + + : after + : + { + : test + : + $* <<EOI 2>>EOE != 0 + cmd + +cmd + EOI + testscript:2:1: error: setup command after tests + EOE + + : after-tdownt + : + $* <<EOI 2>>EOE != 0 + -cmd + +cmd + EOI + testscript:2:1: error: setup command after teardown + EOE + } + + : in-test + : + $* <<EOI 2>>EOE != 0 + cmd; + +cmd + EOI + testscript:2:1: error: setup command in test + EOE +} + +: tdown +: +{ + : followed + : + { + : semi + : + $* <"-cmd;" 2>>EOE != 0 + testscript:1:5: error: ';' after teardown command + EOE + + : colon + : + $* <"-cmd:" 2>>EOE != 0 + testscript:1:5: error: ':' after teardown command + EOE + } + + : in-test + : + $* <<EOI 2>>EOE != 0 + cmd; + -cmd + EOI + testscript:2:1: error: teardown command in test + EOE +} |