From 5007870b52aa549971824959a55ad3bb886f09e0 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 3 Sep 2018 16:37:32 +0200 Subject: Rename .test/test{} to .testscript/testscript{} --- tests/test/script/runner/buildfile | 4 +- tests/test/script/runner/cleanup.test | 346 ------------------ tests/test/script/runner/cleanup.testscript | 346 ++++++++++++++++++ tests/test/script/runner/exit.test | 400 -------------------- tests/test/script/runner/exit.testscript | 400 ++++++++++++++++++++ tests/test/script/runner/expr.test | 522 --------------------------- tests/test/script/runner/expr.testscript | 522 +++++++++++++++++++++++++++ tests/test/script/runner/if.test | 25 -- tests/test/script/runner/if.testscript | 25 ++ tests/test/script/runner/output.test | 87 ----- tests/test/script/runner/output.testscript | 87 +++++ tests/test/script/runner/pipe.test | 35 -- tests/test/script/runner/pipe.testscript | 35 ++ tests/test/script/runner/redirect.test | 515 -------------------------- tests/test/script/runner/redirect.testscript | 515 ++++++++++++++++++++++++++ tests/test/script/runner/regex.test | 312 ---------------- tests/test/script/runner/regex.testscript | 312 ++++++++++++++++ tests/test/script/runner/set.test | 278 -------------- tests/test/script/runner/set.testscript | 278 ++++++++++++++ tests/test/script/runner/status.test | 57 --- tests/test/script/runner/status.testscript | 57 +++ 21 files changed, 2579 insertions(+), 2579 deletions(-) delete mode 100644 tests/test/script/runner/cleanup.test create mode 100644 tests/test/script/runner/cleanup.testscript delete mode 100644 tests/test/script/runner/exit.test create mode 100644 tests/test/script/runner/exit.testscript delete mode 100644 tests/test/script/runner/expr.test create mode 100644 tests/test/script/runner/expr.testscript delete mode 100644 tests/test/script/runner/if.test create mode 100644 tests/test/script/runner/if.testscript delete mode 100644 tests/test/script/runner/output.test create mode 100644 tests/test/script/runner/output.testscript delete mode 100644 tests/test/script/runner/pipe.test create mode 100644 tests/test/script/runner/pipe.testscript delete mode 100644 tests/test/script/runner/redirect.test create mode 100644 tests/test/script/runner/redirect.testscript delete mode 100644 tests/test/script/runner/regex.test create mode 100644 tests/test/script/runner/regex.testscript delete mode 100644 tests/test/script/runner/set.test create mode 100644 tests/test/script/runner/set.testscript delete mode 100644 tests/test/script/runner/status.test create mode 100644 tests/test/script/runner/status.testscript (limited to 'tests/test/script/runner') diff --git a/tests/test/script/runner/buildfile b/tests/test/script/runner/buildfile index 0067ec1..6e8bdd3 100644 --- a/tests/test/script/runner/buildfile +++ b/tests/test/script/runner/buildfile @@ -2,9 +2,9 @@ # copyright : Copyright (c) 2014-2018 Code Synthesis Ltd # license : MIT; see accompanying LICENSE file -./: test{*} exe{driver} $b +./: testscript{*} exe{driver} $b -test{*}: target = exe{driver} +testscript{*}: target = exe{driver} import libs = libbutl%lib{butl} exe{driver}: {hxx cxx}{*} $libs diff --git a/tests/test/script/runner/cleanup.test b/tests/test/script/runner/cleanup.test deleted file mode 100644 index 2d99215..0000000 --- a/tests/test/script/runner/cleanup.test +++ /dev/null @@ -1,346 +0,0 @@ -# file : tests/test/script/runner/cleanup.test -# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -.include ../common.test - -b += --no-column - -: file -: -{ - : always - : - $c <'$* -f a &a' && $b - - : maybe - : - $c <'$* &?a' && $b - - : never - : - $c <'$* &!a' && $b - - : implicit - : - : Test that a file created out of the testscript working directory is not - : implicitly registered for cleanup. If it were, the test would fail due to - : the file absence at the cleanup time. - : - $c <+a; - rm a - EOI - - : not-exists - : - : Test cleanup of non-existing file. - : - $c <'$* &a' && $b 2>>/EOE != 0 - testscript:1: error: registered for cleanup file test/1/a does not exist - EOE - - : out-wd - : - : Test explicit cleanup of a file out of the testscript working directory. - : - $c <'$* &../../a' && $b 2>>/EOE != 0 - testscript:1: error: file cleanup ../../a is out of working directory test/ - EOE - - : in-wd - : - : Test cleanup explicit registration of a file being outside the test working - : directory but inside the script working directory. - : - $c <'$* &../a' && $b 2>>/EOE != 0 - testscript:1: error: registered for cleanup file test/a does not exist - EOE - - : not-file - : - : Test cleanup of a directory as a file. - : - $c <'$* -d a &a' && $b 2>>/~%EOE% != 0 - %error: unable to remove file test/1/a: .+% - EOE -} - -: dir -: -{ - : always - : - $c <'$* -d a &a/' && $b - - : maybe - : - $c <'$* &?a/' && $b - - : implicit - : - : Test that a directory created out of the testscript working directory is - : not implicitly registered for cleanup. If it were, the test would fail due - : to the directory absence at the cleanup time. - : - $c <>/EOE != 0 - testscript:1: error: registered for cleanup directory test/1/a/ does not exist - EOE - - : out-wd - : - : Test cleanup of a directory out of the testscript working directory. - : - $c <'$* &../../a/' && $b 2>>/EOE != 0 - testscript:1: error: directory cleanup ../../a/ is out of working directory test/ - EOE - - : in-wd - : - : Test cleanup explicit registration of a directory being outside the test - : working directory but inside the testscript working directory. - : - $c <'$* &../a/' && $b 2>>/EOE != 0 - testscript:1: error: registered for cleanup directory test/a/ does not exist - EOE - - : not-empty - : - : Test cleanup of a non-empty directory. - : - { - : files - : - $c <>/~%EOE% != 0 - $* -d a -f a/0 -f a/1 -f a/2 -f a/3 -f a/4 -f a/5 -f a/6 -f a/7 -f a/8 \ - -f a/9 -f a/a -f a/b &a/ - EOI - testscript:2: error: registered for cleanup directory test/1/a/ is not empty - %.%{10} - and 2 more file(s) - EOE - - : dir - : - $c <'$* -d a/b' && $b 2>>/EOE != 0 - testscript:1: error: registered for cleanup directory test/1/ is not empty - a/ - EOE - } - - : not-dir - : - : Test cleanup of a file as a directory. - : - $c <'$* -f a &a/' && $b 2>>/~%EOE% != 0 - %error: unable to remove directory test/1/a/: .+% - EOE -} - -: wildcard -: -{ - : self - : - { - : dirs - : - { - : always - : - $c <'$* -d a/b -d a/b/c &a/***/' && $b - - : maybe - : - $c <'$* &?a/***/' && $b - - : not-empty - : - $c <'$* -d a/b -d a/b/c -f a/c &a/***/' && $b 2>>/EOE != 0 - testscript:1: error: registered for cleanup directory test/1/a/ is not empty - c - info: wildcard: 'test/1/a/***/' - EOE - } - - : all-entries - : - : Test the trailing triple-star special case. - : - { - : always - : - $c <'$* -d a1/b -f a1/b/c -d a2/b -f a2/b/c &a?/***' && $b - - : maybe - : - $c <'$* &?a/***' && $b - - : not-exists - : - : Test cleanup of a wildcard not matching any directory. - : - $c <'$* &a/***' && $b 2>>/EOE != 0 - testscript:1: error: registered for cleanup directory test/1/a/ does not exist - EOE - - : out-wd - : - : Test cleanup of a wildcard out of the testscript working directory. - : - $c <'$* &../../a/***' && $b 2>>/EOE != 0 - testscript:1: error: wildcard cleanup ../../a/*** is out of working directory test/ - EOE - - : in-wd - : - : Test cleanup registration of a wildcard matching the directory that being - : outside the test working directory is inside the testscript working - : directory. - : - $c <'$* &../a/***' && $b 2>>/EOE != 0 - testscript:1: error: registered for cleanup directory test/a/ does not exist - EOE - - : not-dir - : - : Test cleanup of a file as a wildcard. - : - $c <'$* -f a &a/***' && $b 2>>/~%EOE% != 0 - %error: unable to remove directory test/1/a/: .*% - EOE - } - } - - : dir - : - { - : always - : - { - : immediate - : - $c <'$* -d aa/b &aa/ &a*/*/' && $b - - : recursive - : - $c <'$* -d aa/b/c &aa/ &a?/**/' && $b - } - - : maybe - : - $c <'$* &?a/**/' && $b - - : not-exists - : - : Test cleanup of a wildcard that doesn't match any directory. - : - $c <'$* &a/**/' && $b 2>>/EOE != 0 - testscript:1: error: registered for cleanup wildcard test/1/a/**/ doesn't match any directory - EOE - - : not-dir - : - : Test cleanup of a file as a directory wildcard. - : - $c <'$* -f a &a/**/' && $b 2>>/EOE != 0 - testscript:1: error: registered for cleanup wildcard test/1/a/**/ doesn't match any directory - EOE - - : not-empty - : - : Test cleanup of a non-empty directory as a wildcard. - : - $c <'$* -d a/b/c -f a/b/d &a/**/' && $b 2>>/EOE != 0 - testscript:1: error: registered for cleanup directory test/1/a/b/ is not empty - d - info: wildcard: 'test/1/a/**/' - EOE - } - - : file - : - { - : always - : - { - : immediate - : - $c <'$* -d aa -f aa/c &aa/ &a?/*' && $b - - : recursive - : - $c <'$* -d aa/b -f aa/c -f aa/b/e &aa/ &aa/b/ &a*/**' && $b - } - - : maybe - : - $c <'$* &?a/**' && $b - } -} - -: order -: -: Test that cleanup is performed in registration reversed order. -: -$c <'$* -d a/b &a/ &a/b/' && $b - -: special-order -: -: Test that special files are cleaned before others, and there is no attempt -: to remove them twice (normally and with wildcard cleanup). -: -$c <'foo'; -$* -f bar &* -EOI - -: wd-wildcard -: -: Test that there is no attempt to remove working directory twice (normally and -: with wildcard cleanup). -: -$c <=a &!a' && $b 2>>/EOE != 0 -testscript:1: error: registered for cleanup directory test/1/ is not empty -a -EOE - -: explicit-overwrite -: -: Test an explicit cleanup not being overwritten with the implicit one. -: -$c <>/EOE != 0 -$* &!a; -$* -o foo >=a -EOO -testscript:2: error: registered for cleanup directory test/1/ is not empty -a -EOE diff --git a/tests/test/script/runner/cleanup.testscript b/tests/test/script/runner/cleanup.testscript new file mode 100644 index 0000000..7ea1acd --- /dev/null +++ b/tests/test/script/runner/cleanup.testscript @@ -0,0 +1,346 @@ +# file : tests/test/script/runner/cleanup.testscript +# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +.include ../common.testscript + +b += --no-column + +: file +: +{ + : always + : + $c <'$* -f a &a' && $b + + : maybe + : + $c <'$* &?a' && $b + + : never + : + $c <'$* &!a' && $b + + : implicit + : + : Test that a file created out of the testscript working directory is not + : implicitly registered for cleanup. If it were, the test would fail due to + : the file absence at the cleanup time. + : + $c <+a; + rm a + EOI + + : not-exists + : + : Test cleanup of non-existing file. + : + $c <'$* &a' && $b 2>>/EOE != 0 + testscript:1: error: registered for cleanup file test/1/a does not exist + EOE + + : out-wd + : + : Test explicit cleanup of a file out of the testscript working directory. + : + $c <'$* &../../a' && $b 2>>/EOE != 0 + testscript:1: error: file cleanup ../../a is out of working directory test/ + EOE + + : in-wd + : + : Test cleanup explicit registration of a file being outside the test working + : directory but inside the script working directory. + : + $c <'$* &../a' && $b 2>>/EOE != 0 + testscript:1: error: registered for cleanup file test/a does not exist + EOE + + : not-file + : + : Test cleanup of a directory as a file. + : + $c <'$* -d a &a' && $b 2>>/~%EOE% != 0 + %error: unable to remove file test/1/a: .+% + EOE +} + +: dir +: +{ + : always + : + $c <'$* -d a &a/' && $b + + : maybe + : + $c <'$* &?a/' && $b + + : implicit + : + : Test that a directory created out of the testscript working directory is + : not implicitly registered for cleanup. If it were, the test would fail due + : to the directory absence at the cleanup time. + : + $c <>/EOE != 0 + testscript:1: error: registered for cleanup directory test/1/a/ does not exist + EOE + + : out-wd + : + : Test cleanup of a directory out of the testscript working directory. + : + $c <'$* &../../a/' && $b 2>>/EOE != 0 + testscript:1: error: directory cleanup ../../a/ is out of working directory test/ + EOE + + : in-wd + : + : Test cleanup explicit registration of a directory being outside the test + : working directory but inside the testscript working directory. + : + $c <'$* &../a/' && $b 2>>/EOE != 0 + testscript:1: error: registered for cleanup directory test/a/ does not exist + EOE + + : not-empty + : + : Test cleanup of a non-empty directory. + : + { + : files + : + $c <>/~%EOE% != 0 + $* -d a -f a/0 -f a/1 -f a/2 -f a/3 -f a/4 -f a/5 -f a/6 -f a/7 -f a/8 \ + -f a/9 -f a/a -f a/b &a/ + EOI + testscript:2: error: registered for cleanup directory test/1/a/ is not empty + %.%{10} + and 2 more file(s) + EOE + + : dir + : + $c <'$* -d a/b' && $b 2>>/EOE != 0 + testscript:1: error: registered for cleanup directory test/1/ is not empty + a/ + EOE + } + + : not-dir + : + : Test cleanup of a file as a directory. + : + $c <'$* -f a &a/' && $b 2>>/~%EOE% != 0 + %error: unable to remove directory test/1/a/: .+% + EOE +} + +: wildcard +: +{ + : self + : + { + : dirs + : + { + : always + : + $c <'$* -d a/b -d a/b/c &a/***/' && $b + + : maybe + : + $c <'$* &?a/***/' && $b + + : not-empty + : + $c <'$* -d a/b -d a/b/c -f a/c &a/***/' && $b 2>>/EOE != 0 + testscript:1: error: registered for cleanup directory test/1/a/ is not empty + c + info: wildcard: 'test/1/a/***/' + EOE + } + + : all-entries + : + : Test the trailing triple-star special case. + : + { + : always + : + $c <'$* -d a1/b -f a1/b/c -d a2/b -f a2/b/c &a?/***' && $b + + : maybe + : + $c <'$* &?a/***' && $b + + : not-exists + : + : Test cleanup of a wildcard not matching any directory. + : + $c <'$* &a/***' && $b 2>>/EOE != 0 + testscript:1: error: registered for cleanup directory test/1/a/ does not exist + EOE + + : out-wd + : + : Test cleanup of a wildcard out of the testscript working directory. + : + $c <'$* &../../a/***' && $b 2>>/EOE != 0 + testscript:1: error: wildcard cleanup ../../a/*** is out of working directory test/ + EOE + + : in-wd + : + : Test cleanup registration of a wildcard matching the directory that being + : outside the test working directory is inside the testscript working + : directory. + : + $c <'$* &../a/***' && $b 2>>/EOE != 0 + testscript:1: error: registered for cleanup directory test/a/ does not exist + EOE + + : not-dir + : + : Test cleanup of a file as a wildcard. + : + $c <'$* -f a &a/***' && $b 2>>/~%EOE% != 0 + %error: unable to remove directory test/1/a/: .*% + EOE + } + } + + : dir + : + { + : always + : + { + : immediate + : + $c <'$* -d aa/b &aa/ &a*/*/' && $b + + : recursive + : + $c <'$* -d aa/b/c &aa/ &a?/**/' && $b + } + + : maybe + : + $c <'$* &?a/**/' && $b + + : not-exists + : + : Test cleanup of a wildcard that doesn't match any directory. + : + $c <'$* &a/**/' && $b 2>>/EOE != 0 + testscript:1: error: registered for cleanup wildcard test/1/a/**/ doesn't match any directory + EOE + + : not-dir + : + : Test cleanup of a file as a directory wildcard. + : + $c <'$* -f a &a/**/' && $b 2>>/EOE != 0 + testscript:1: error: registered for cleanup wildcard test/1/a/**/ doesn't match any directory + EOE + + : not-empty + : + : Test cleanup of a non-empty directory as a wildcard. + : + $c <'$* -d a/b/c -f a/b/d &a/**/' && $b 2>>/EOE != 0 + testscript:1: error: registered for cleanup directory test/1/a/b/ is not empty + d + info: wildcard: 'test/1/a/**/' + EOE + } + + : file + : + { + : always + : + { + : immediate + : + $c <'$* -d aa -f aa/c &aa/ &a?/*' && $b + + : recursive + : + $c <'$* -d aa/b -f aa/c -f aa/b/e &aa/ &aa/b/ &a*/**' && $b + } + + : maybe + : + $c <'$* &?a/**' && $b + } +} + +: order +: +: Test that cleanup is performed in registration reversed order. +: +$c <'$* -d a/b &a/ &a/b/' && $b + +: special-order +: +: Test that special files are cleaned before others, and there is no attempt +: to remove them twice (normally and with wildcard cleanup). +: +$c <'foo'; +$* -f bar &* +EOI + +: wd-wildcard +: +: Test that there is no attempt to remove working directory twice (normally and +: with wildcard cleanup). +: +$c <=a &!a' && $b 2>>/EOE != 0 +testscript:1: error: registered for cleanup directory test/1/ is not empty +a +EOE + +: explicit-overwrite +: +: Test an explicit cleanup not being overwritten with the implicit one. +: +$c <>/EOE != 0 +$* &!a; +$* -o foo >=a +EOO +testscript:2: error: registered for cleanup directory test/1/ is not empty +a +EOE diff --git a/tests/test/script/runner/exit.test b/tests/test/script/runner/exit.test deleted file mode 100644 index 7933203..0000000 --- a/tests/test/script/runner/exit.test +++ /dev/null @@ -1,400 +0,0 @@ -# file : tests/test/script/runner/exit.test -# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -.include ../common.test - -: special -: -{ - : pipelining - : - { - : to - : - $c <'exit | cat' && $b 2>>EOE != 0 - testscript:1:1: error: exit builtin must be the only pipe command - EOE - - : from - : - $c <'echo "foo" | exit' && $b 2>>EOE != 0 - testscript:1:1: error: exit builtin must be the only pipe command - EOE - } - - : redirecting - : - { - : stdin - : - $c <'exit >EOE != 0 - testscript:1:1: error: exit builtin stdin cannot be redirected - EOE - - : stdout - : - $c <'exit >foo' && $b 2>>EOE != 0 - testscript:1:1: error: exit builtin stdout cannot be redirected - EOE - - : stderr - : - $c <'exit 2>foo' && $b 2>>EOE != 0 - testscript:1:1: error: exit builtin stderr cannot be redirected - EOE - } - - : exit-code - : - $c <'exit != 0' && $b 2>>EOE != 0 - testscript:1:1: error: exit builtin exit code cannot be non-zero - EOE -} - -: arguments -: -{ - : none - : - $c <'exit' && $b - - : diagnostics - : - $c <'exit "foo"' && $b 2>>EOE != 0 - testscript:1:1: error: foo - EOE - - : unexpected - : - $c <'exit "foo" "bar"' && $b 2>>EOE != 0 - testscript:1:1: error: unexpected argument - EOE -} - -: execution -: -: Test that only expected commands are executed. Note that we rely on the fact -: that their execution is performed serially (see ../common.test for details). -: -{ - : test-scope - : - { - : success - : - : Note that we also test that cleanups are executed. - : - $c <>EOO - touch -f a; - echo foo >| && exit && echo bar >|; - echo baz >| - echo box >| - EOI - foo - box - EOO - - : failure - : - : Note that we also register fake cleanup, and test that cleanups are - : not executed. If they were, there would be a diagnostics printed to - : stderr regarding non-existent file. - : - $c <>EOO 2>'testscript:1:1: error: message' != 0 - echo foo >| &b && exit 'message' && echo bar >| - echo baz >|; - echo boz >| - EOI - foo - EOO - } - - : command-if - : - { - : if-clause - : - { - : success - : - $c <| - else - echo bar >| - end; - echo baz >| - EOI - - : failure - : - $c <'testscript:2:3: error: message' != 0 - if true - exit 'message' - echo foo >| - else - echo bar >| - end - echo baz >| - EOI - } - - : else-clause - : - { - : success - : - $c <| - else - exit - echo bar >| - end; - echo baz >| - EOI - - : failure - : - $c <'testscript:4:3: error: message' != 0 - if false - echo foo >| - else - exit 'message' - echo bar >| - end - echo baz >| - EOI - } - } - - : command-if-condition - : - { - : if - : - { - : success - : - $c <| - else - echo bar >| - end; - echo baz >| - EOI - - : failure - : - $c <'testscript:1:1: error: message' != 0 - if exit 'message' - echo foo >| - else - echo bar >| - end; - echo baz >| - EOI - } - - : elif - : - { - : success - : - $c <| - else - echo bar >| - end; - echo baz >| - EOI - - : failure - : - $c <'testscript:2:1: error: message' != 0 - if false - elif exit 'message' - echo foo >| - else - echo bar >| - end; - echo baz >| - EOI - } - } - - : scope-if-condition - : - { - : if - : - { - : success - : - $c <| - } - else - { - echo bar >| - } - EOI - - : failure - : - $c <'testscript:1:1: error: message' != 0 - if exit 'message' - { - echo foo >| - } - else - { - echo bar >| - } - EOI - } - - : elif - : - { - : success - : - $c <| - } - else - { - echo bar >| - } - EOI - - : failure - : - $c <'testscript:4:1: error: message' != 0 - if false - { - } - elif exit 'message' - { - echo foo >| - } - else - { - echo bar >| - } - EOI - } - } - - : group-scope - : - { - : setup - : - { - : success - : - : Test that teardown commands are executed (the 'a' file is removed), and - : cleanups are executed as well (the 'b' file is removed). - : - $c <| - - -rm a - EOI - - : failure - : - : Test that teardown commands are not executed (the touch would fail), - : and cleanups are also not executed (they would fail due to non-existent - : file 'a'). - : - $c <'testscript:2:2: error: message' != 0 - +true &a - +exit 'message' - - echo foo >| - - -touch b/c - EOI - } - - : inner-scope - : - { - : success - : - : Test that teardown commands and cleanups are executed (see above), and - : also that the independent inner scope is still executed. - : - $c <>EOO - +touch --no-cleanup a - +touch b - - exit - - echo foo >| - - -rm a - EOI - foo - EOO - - : failure - : - : Test that teardown commands and cleanups are not executed (see above), - : as well as the independent inner scope (remember the sequential - : execution). - : - $c <'testscript:3:1: error: message' != 0 - +true &a - - exit 'message' - - echo foo >| - - -touch b/c - EOI - } - - : teardown - : - { - : success - : - : Test that cleanups are executed. - : - $c <| - EOI - - : failure - : - : Test that cleanups are not executed. - : - $c <'testscript:2:2: error: message' != 0 - -true &a - -exit 'message' - -echo foo >| - EOI - } - } -} diff --git a/tests/test/script/runner/exit.testscript b/tests/test/script/runner/exit.testscript new file mode 100644 index 0000000..9329ae4 --- /dev/null +++ b/tests/test/script/runner/exit.testscript @@ -0,0 +1,400 @@ +# file : tests/test/script/runner/exit.testscript +# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +.include ../common.testscript + +: special +: +{ + : pipelining + : + { + : to + : + $c <'exit | cat' && $b 2>>EOE != 0 + testscript:1:1: error: exit builtin must be the only pipe command + EOE + + : from + : + $c <'echo "foo" | exit' && $b 2>>EOE != 0 + testscript:1:1: error: exit builtin must be the only pipe command + EOE + } + + : redirecting + : + { + : stdin + : + $c <'exit >EOE != 0 + testscript:1:1: error: exit builtin stdin cannot be redirected + EOE + + : stdout + : + $c <'exit >foo' && $b 2>>EOE != 0 + testscript:1:1: error: exit builtin stdout cannot be redirected + EOE + + : stderr + : + $c <'exit 2>foo' && $b 2>>EOE != 0 + testscript:1:1: error: exit builtin stderr cannot be redirected + EOE + } + + : exit-code + : + $c <'exit != 0' && $b 2>>EOE != 0 + testscript:1:1: error: exit builtin exit code cannot be non-zero + EOE +} + +: arguments +: +{ + : none + : + $c <'exit' && $b + + : diagnostics + : + $c <'exit "foo"' && $b 2>>EOE != 0 + testscript:1:1: error: foo + EOE + + : unexpected + : + $c <'exit "foo" "bar"' && $b 2>>EOE != 0 + testscript:1:1: error: unexpected argument + EOE +} + +: execution +: +: Test that only expected commands are executed. Note that we rely on the fact +: that their execution is performed serially (see ../common.testscript for details). +: +{ + : test-scope + : + { + : success + : + : Note that we also test that cleanups are executed. + : + $c <>EOO + touch -f a; + echo foo >| && exit && echo bar >|; + echo baz >| + echo box >| + EOI + foo + box + EOO + + : failure + : + : Note that we also register fake cleanup, and test that cleanups are + : not executed. If they were, there would be a diagnostics printed to + : stderr regarding non-existent file. + : + $c <>EOO 2>'testscript:1:1: error: message' != 0 + echo foo >| &b && exit 'message' && echo bar >| + echo baz >|; + echo boz >| + EOI + foo + EOO + } + + : command-if + : + { + : if-clause + : + { + : success + : + $c <| + else + echo bar >| + end; + echo baz >| + EOI + + : failure + : + $c <'testscript:2:3: error: message' != 0 + if true + exit 'message' + echo foo >| + else + echo bar >| + end + echo baz >| + EOI + } + + : else-clause + : + { + : success + : + $c <| + else + exit + echo bar >| + end; + echo baz >| + EOI + + : failure + : + $c <'testscript:4:3: error: message' != 0 + if false + echo foo >| + else + exit 'message' + echo bar >| + end + echo baz >| + EOI + } + } + + : command-if-condition + : + { + : if + : + { + : success + : + $c <| + else + echo bar >| + end; + echo baz >| + EOI + + : failure + : + $c <'testscript:1:1: error: message' != 0 + if exit 'message' + echo foo >| + else + echo bar >| + end; + echo baz >| + EOI + } + + : elif + : + { + : success + : + $c <| + else + echo bar >| + end; + echo baz >| + EOI + + : failure + : + $c <'testscript:2:1: error: message' != 0 + if false + elif exit 'message' + echo foo >| + else + echo bar >| + end; + echo baz >| + EOI + } + } + + : scope-if-condition + : + { + : if + : + { + : success + : + $c <| + } + else + { + echo bar >| + } + EOI + + : failure + : + $c <'testscript:1:1: error: message' != 0 + if exit 'message' + { + echo foo >| + } + else + { + echo bar >| + } + EOI + } + + : elif + : + { + : success + : + $c <| + } + else + { + echo bar >| + } + EOI + + : failure + : + $c <'testscript:4:1: error: message' != 0 + if false + { + } + elif exit 'message' + { + echo foo >| + } + else + { + echo bar >| + } + EOI + } + } + + : group-scope + : + { + : setup + : + { + : success + : + : Test that teardown commands are executed (the 'a' file is removed), and + : cleanups are executed as well (the 'b' file is removed). + : + $c <| + + -rm a + EOI + + : failure + : + : Test that teardown commands are not executed (the touch would fail), + : and cleanups are also not executed (they would fail due to non-existent + : file 'a'). + : + $c <'testscript:2:2: error: message' != 0 + +true &a + +exit 'message' + + echo foo >| + + -touch b/c + EOI + } + + : inner-scope + : + { + : success + : + : Test that teardown commands and cleanups are executed (see above), and + : also that the independent inner scope is still executed. + : + $c <>EOO + +touch --no-cleanup a + +touch b + + exit + + echo foo >| + + -rm a + EOI + foo + EOO + + : failure + : + : Test that teardown commands and cleanups are not executed (see above), + : as well as the independent inner scope (remember the sequential + : execution). + : + $c <'testscript:3:1: error: message' != 0 + +true &a + + exit 'message' + + echo foo >| + + -touch b/c + EOI + } + + : teardown + : + { + : success + : + : Test that cleanups are executed. + : + $c <| + EOI + + : failure + : + : Test that cleanups are not executed. + : + $c <'testscript:2:2: error: message' != 0 + -true &a + -exit 'message' + -echo foo >| + EOI + } + } +} diff --git a/tests/test/script/runner/expr.test b/tests/test/script/runner/expr.test deleted file mode 100644 index cfc5277..0000000 --- a/tests/test/script/runner/expr.test +++ /dev/null @@ -1,522 +0,0 @@ -# file : tests/test/script/runner/expr.test -# copyright : Copyright (c) 2014-2018 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 code 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/expr.testscript b/tests/test/script/runner/expr.testscript new file mode 100644 index 0000000..36c15fd --- /dev/null +++ b/tests/test/script/runner/expr.testscript @@ -0,0 +1,522 @@ +# file : tests/test/script/runner/expr.testscript +# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +.include ../common.testscript + +: 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 code 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 deleted file mode 100644 index f22f761..0000000 --- a/tests/test/script/runner/if.test +++ /dev/null @@ -1,25 +0,0 @@ -# file : tests/test/script/runner/if.test -# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -.include ../common.test - -: if-branch -: -$c <'if' -if cat <'foo' >'foo' - echo 'if' >| -else - echo 'else' >| -end -EOI - -: else-branch -: -$c <'else' -if cat <'foo' >'bar' - echo 'if' >| -else - echo 'else' >| -end -EOI diff --git a/tests/test/script/runner/if.testscript b/tests/test/script/runner/if.testscript new file mode 100644 index 0000000..a625c34 --- /dev/null +++ b/tests/test/script/runner/if.testscript @@ -0,0 +1,25 @@ +# file : tests/test/script/runner/if.testscript +# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +.include ../common.testscript + +: if-branch +: +$c <'if' +if cat <'foo' >'foo' + echo 'if' >| +else + echo 'else' >| +end +EOI + +: else-branch +: +$c <'else' +if cat <'foo' >'bar' + echo 'if' >| +else + echo 'else' >| +end +EOI diff --git a/tests/test/script/runner/output.test b/tests/test/script/runner/output.test deleted file mode 100644 index a83c092..0000000 --- a/tests/test/script/runner/output.test +++ /dev/null @@ -1,87 +0,0 @@ -# file : tests/test/script/runner/output.test -# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -# Some of the tests below (*/script-wd, before/*) are probably more appropriate -# for tests/test/script/script-integration/testscript. Nevertheless let's not -# spread the feature tests among several places. -# - -.include ../common.test - -: after -: -{ - : keep - : - { - : cleanup - : - $c <'touch a' && $b config.test.output=keep; - test -f test/1/a - - : teardown - : - $c <>/EOE != 0 - error: working directory test/ exists at the beginning of the test - EOE - - : warn - : - mkdir test &!test/; - $c <'true' && $b config.test.output=warn@clean 2>>/EOE - warning: working directory test/ exists at the beginning of the test - EOE - - : clean - : - mkdir test &!test/; - $c <'true' && $b config.test.output=clean@clean -} diff --git a/tests/test/script/runner/output.testscript b/tests/test/script/runner/output.testscript new file mode 100644 index 0000000..ec9ff92 --- /dev/null +++ b/tests/test/script/runner/output.testscript @@ -0,0 +1,87 @@ +# file : tests/test/script/runner/output.testscript +# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +# Some of the tests below (*/script-wd, before/*) are probably more appropriate +# for tests/test/script/script-integration/testscript. Nevertheless let's not +# spread the feature tests among several places. +# + +.include ../common.testscript + +: after +: +{ + : keep + : + { + : cleanup + : + $c <'touch a' && $b config.test.output=keep; + test -f test/1/a + + : teardown + : + $c <>/EOE != 0 + error: working directory test/ exists at the beginning of the test + EOE + + : warn + : + mkdir test &!test/; + $c <'true' && $b config.test.output=warn@clean 2>>/EOE + warning: working directory test/ exists at the beginning of the test + EOE + + : clean + : + mkdir test &!test/; + $c <'true' && $b config.test.output=clean@clean +} diff --git a/tests/test/script/runner/pipe.test b/tests/test/script/runner/pipe.test deleted file mode 100644 index 03d8b2a..0000000 --- a/tests/test/script/runner/pipe.test +++ /dev/null @@ -1,35 +0,0 @@ -# file : tests/test/script/runner/pipe.test -# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -.include ../common.test - -$c <'cat 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 code 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 expected% - 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/pipe.testscript b/tests/test/script/runner/pipe.testscript new file mode 100644 index 0000000..7ef5893 --- /dev/null +++ b/tests/test/script/runner/pipe.testscript @@ -0,0 +1,35 @@ +# file : tests/test/script/runner/pipe.testscript +# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +.include ../common.testscript + +$c <'cat 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 code 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 expected% + 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 deleted file mode 100644 index 13d7219..0000000 --- a/tests/test/script/runner/redirect.test +++ /dev/null @@ -1,515 +0,0 @@ -# file : tests/test/script/runner/redirect.test -# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -.include ../common.test - -b += --no-column - -ps = ($cxx.target.class != 'windows' ? '/' : '\') # Path separator. -psr = ($cxx.target.class != 'windows' ? '/' : '\\') # Path separator in regex. - -: pass -: -{ - cat <'$* -i 1 -e bar <| >| 2>|' >=testscript; - cat <=buildfile; - test{testscript}: $target - EOI - $0 --serial-stop --quiet test foo 2>bar -} - -: null -: -{ - $c <'$* -o foo >-' && $b : out - $c <'$* -e foo 2>-' && $b : err -} - -: trace -: -{ - : default - : - $c <'$* -o foo -e bar >! 2>!' && $b - - : verbose - : - { - b += -v - - : out - : - $c <'$* -o foo >!' && $b >foo 2>>/~%EOE% - %test .+% - mkdir test/ - cd test/ - mkdir test/1/ - cd test/1/ - %.*/driver(.exe)? -o foo% - rmdir test/1/ - cd test/ - rmdir test/ - cd ./ - EOE - - : err - : - $c <'$* -e foo 2>!' && $b 2>>/~%EOE% - %test .+% - mkdir test/ - cd test/ - mkdir test/1/ - cd test/1/ - %.*/driver(.exe)? -e foo% - foo - rmdir test/1/ - cd test/ - rmdir test/ - cd ./ - EOE - } -} - -: str -: -{ - : literal - : - { - $c <'$* -i 0 foo' && $b : out - $c <'$* -e foo 2>foo' && $b : err - $c <'$* -i 1 foo' && $b : inout - - : inout-fail - : - $c <'$* -i 1 bar' && $b 2>>/~%EOE%d != 0 - %testscript:1: error: ../../../../../driver(.exe)? stdout doesn't match expected% - info: stdout: test/1/stdout - info: expected stdout: test/1/stdout.orig - info: stdout diff: test/1/stdout.diff - info: stdin: test/1/stdin - %--- \.*% - %\+\+\+ \.*% - %@@ \.*% - -bar - +foo - EOE - - $c <'$* -i 2 foo' && $b : inerr - $c <'$* -i 1 -e bar foo 2>bar' && $b : inout-err - $c <'$* -o "" >""' && $b : empty - $c <'$* -i 1 <:"foo" >:"foo"' && $b : no-newline - $c <'$* -i 1 <:"" >:""' && $b : no-newline-empty - - : no-newline-fail1 - : - $c <'$* -i 1 <:"foo" >"foo"' && $b 2>>~/EOE/ != 0 - /testscript:1: error: .+driver(\.exe)? stdout doesn't match expected/ - /.{7} - -foo - +foo - \ No newline at end of file - EOE - - : no-newline-fail2 - : - $c <'$* -i 1 <"foo" >:"foo"' && $b 2>>~/EOE/ != 0 - /testscript:1: error: .+driver(\.exe)? stdout doesn't match expected/ - /.{7} - -foo - \ No newline at end of file - +foo - EOE - - : merge - : - $c <>EOE 1>&2 - foo - bar - EOE - EOI - - : portable-path - : - { - $c <"\$* -i 1 'foo$ps'" && $b : in - $c <"\$* -i 1 <'foo$ps' >/'foo/'" && $b : out - $c <"\$* -i 2 <'foo$ps' 2>/'foo/'" && $b : err - } - } - - : regex - : - : Test regex matching. Note that tests that check regex parsing are located - : in regex.test testscript. - : - { - : match - : - $c <'$* -o foo >~/Foo?/i' && $b - - : mismatch - : - $c <'$* -o fooo >~/Foo?/i' && $b 2>>/~%EOE%d != 0 - %testscript:1: error: ../../../../../driver(.exe)? stdout doesn't match regex% - info: stdout: test/1/stdout - info: stdout regex: test/1/stdout.regex - fooo - EOE - - : portable-path-failure - : - : Note that we check not only build2 diagnostics being produced, but also - : the correctness of regex being saved to file (for troubleshooting). - : - { - : newline - : - $c <"\$* -i 1 <'foo' >/~%bar/%" && $b 2>>/~%EOE%d != 0; - %testscript:1: error: ../../../../../../driver(.exe)? stdout doesn't match regex% - info: stdout: test/1/stdout - info: stdout regex: test/1/stdout.regex - info: stdin: test/1/stdin - foo - EOE - cat test/1/stdout.regex >"%bar$psr%" - - : no-newline - : - $c <"\$* -i 1 <'foo' >:/~%bar/%" && $b 2>>/~%EOE%d != 0; - %testscript:1: error: ../../../../../../driver(.exe)? stdout doesn't match regex% - info: stdout: test/1/stdout - info: stdout regex: test/1/stdout.regex - info: stdin: test/1/stdin - foo - EOE - cat test/1/stdout.regex >:"%bar$psr%" - } - } -} - -: doc -: -{ - : literal - : - { - : in - : - $c <>EOO - foo - bar - EOO - EOI - - : err - : - $c <>EOO - foo - bar - EOO - EOI - - : inout - : - $c <>EOO - foo - bar - EOF - foo - bar - EOO - EOI - - : inerr - : - $c <>EOE - foo - bar - EOF - foo - bar - EOE - EOI - - : empty - : - $c <>EOO - EOF - EOO - EOI - - : shared - : - $c <>EOF - foo - bar - EOF - EOI - - : extra-newline - : - $c <>EOO - - EOF - - EOO - EOI - - : no-newline - : - $c <>:EOO - foo - EOF - foo - EOO - EOI - - : no-newline-fail1 - : - $c <>~/EOE/ != 0 - $* -i 1 <<:EOF >>EOO - foo - EOF - foo - EOO - EOI - /testscript:1: error: .+driver(\.exe)? stdout doesn't match expected/ - /.{7} - -foo - +foo - \ No newline at end of file - EOE - - : no-newline-fail2 - : - $c <>~/EOE/ != 0 - $* -i 1 <>:EOO - foo - EOF - foo - EOO - EOI - /testscript:1: error: .+driver(\.exe)? stdout doesn't match expected/ - /.{7} - -foo - \ No newline at end of file - +foo - EOE - - : no-newline-empty - : - $c <>:EOO - EOF - EOO - EOI - - : no-newline-extra-newline - : - $c <>:EOO - - EOF - - EOO - EOI - - : merge - : - $c <>EOO 2>&1 - foo - bar - EOF - foo - bar - baz - EOO - EOI - - : large-diff - : - : Make sure that the large (>4KB) expected/real output difference is not - : printed as a part of the diagnostics. - : - $c <>/~%EOE%d != 0 - s="----------------------------------------------------------------------"; - s="$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s"; - $* -i 1 <<"EOF" >>"EOO" - $s - EOF - x$s - EOO - EOI - %testscript:3: error: ../../../../../driver(.exe)? stdout doesn't match expected% - info: stdout: test/1/stdout - info: expected stdout: test/1/stdout.orig - info: stdout diff: test/1/stdout.diff - info: stdin: test/1/stdin - EOE - - : portable-path - : - { - : in - : - $c <<"EOI" && $b - \$* -i 1 <'foo$ps' - foo/ - EOF - EOI - - : out - : - $c <<"EOI" && $b - \$* -i 1 <'foo$ps' >>/EOO - foo/ - EOO - EOI - - : err - : - $c <<"EOI" && $b - \$* -i 2 <'foo$ps' 2>>/EOE - foo/ - EOE - EOI - } - } - - : regex - : - : Test regex matching. Note that tests that check regex parsing are located - : in regex.test testscript. - : - { - : match - : - $c <>~/EOO/i - /FO*/* - bar - /* - EOO - EOI - - : match-empty - : - $c <>:~/EOO/ - /.{0} - EOO - EOI - - : shared - : - $c <>~/EOF/ 2>>~/EOF/ - foo - EOF - EOI - - : mismatch - : - $c <>/~%EOE%d != 0 - $* -o foo >>~/EOO/ - bar - EOO - EOI - %testscript:1: error: ../../../../../driver(.exe)? stdout doesn't match regex% - info: stdout: test/1/stdout - info: stdout regex: test/1/stdout.regex - foo - EOE - - : mismatch-icase - : - $c <>/~%EOE%d != 0 - $* -o foo >>~/EOO/i - bar - EOO - EOI - %testscript:1: error: ../../../../../driver(.exe)? stdout doesn't match regex% - info: stdout: test/1/stdout - info: stdout regex: test/1/stdout.regex-i - foo - EOE - } -} - -: file -: -{ - : in - : - $c <=out; - $* -i 1 <<foo - EOI - - : out - : - { - : match - : - $c <=out; - $* -e bar 2>+out; - $* -i 1 <>>out - foo - bar - EOF - EOI - - : mismatch - : - $c <>/~%EOE%d != 0 - $* -o foo >=out; - $* -o bar >>>out - EOI - %testscript:2: error: ../../../../../driver(.exe)? stdout doesn't match expected% - info: stdout: test/1/stdout-2 - info: expected stdout: test/1/out - info: stdout diff: test/1/stdout-2.diff - %--- \.*% - %\+\+\+ \.*% - %@@ \.*% - -foo - +bar - EOE - } - - : merge - : - $c <&1 >=out; - $* -e baz -o biz 1>&2 2>+out; - $* -i 1 <<>EOO - foo - bar - baz - biz - EOO - EOI -} diff --git a/tests/test/script/runner/redirect.testscript b/tests/test/script/runner/redirect.testscript new file mode 100644 index 0000000..21e9d07 --- /dev/null +++ b/tests/test/script/runner/redirect.testscript @@ -0,0 +1,515 @@ +# file : tests/test/script/runner/redirect.testscript +# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +.include ../common.testscript + +b += --no-column + +ps = ($cxx.target.class != 'windows' ? '/' : '\') # Path separator. +psr = ($cxx.target.class != 'windows' ? '/' : '\\') # Path separator in regex. + +: pass +: +{ + cat <'$* -i 1 -e bar <| >| 2>|' >=testscript; + cat <=buildfile; + testscript{testscript}: $target + EOI + $0 --serial-stop --quiet test foo 2>bar +} + +: null +: +{ + $c <'$* -o foo >-' && $b : out + $c <'$* -e foo 2>-' && $b : err +} + +: trace +: +{ + : default + : + $c <'$* -o foo -e bar >! 2>!' && $b + + : verbose + : + { + b += -v + + : out + : + $c <'$* -o foo >!' && $b >foo 2>>/~%EOE% + %test .+% + mkdir test/ + cd test/ + mkdir test/1/ + cd test/1/ + %.*/driver(.exe)? -o foo% + rmdir test/1/ + cd test/ + rmdir test/ + cd ./ + EOE + + : err + : + $c <'$* -e foo 2>!' && $b 2>>/~%EOE% + %test .+% + mkdir test/ + cd test/ + mkdir test/1/ + cd test/1/ + %.*/driver(.exe)? -e foo% + foo + rmdir test/1/ + cd test/ + rmdir test/ + cd ./ + EOE + } +} + +: str +: +{ + : literal + : + { + $c <'$* -i 0 foo' && $b : out + $c <'$* -e foo 2>foo' && $b : err + $c <'$* -i 1 foo' && $b : inout + + : inout-fail + : + $c <'$* -i 1 bar' && $b 2>>/~%EOE%d != 0 + %testscript:1: error: ../../../../../driver(.exe)? stdout doesn't match expected% + info: stdout: test/1/stdout + info: expected stdout: test/1/stdout.orig + info: stdout diff: test/1/stdout.diff + info: stdin: test/1/stdin + %--- \.*% + %\+\+\+ \.*% + %@@ \.*% + -bar + +foo + EOE + + $c <'$* -i 2 foo' && $b : inerr + $c <'$* -i 1 -e bar foo 2>bar' && $b : inout-err + $c <'$* -o "" >""' && $b : empty + $c <'$* -i 1 <:"foo" >:"foo"' && $b : no-newline + $c <'$* -i 1 <:"" >:""' && $b : no-newline-empty + + : no-newline-fail1 + : + $c <'$* -i 1 <:"foo" >"foo"' && $b 2>>~/EOE/ != 0 + /testscript:1: error: .+driver(\.exe)? stdout doesn't match expected/ + /.{7} + -foo + +foo + \ No newline at end of file + EOE + + : no-newline-fail2 + : + $c <'$* -i 1 <"foo" >:"foo"' && $b 2>>~/EOE/ != 0 + /testscript:1: error: .+driver(\.exe)? stdout doesn't match expected/ + /.{7} + -foo + \ No newline at end of file + +foo + EOE + + : merge + : + $c <>EOE 1>&2 + foo + bar + EOE + EOI + + : portable-path + : + { + $c <"\$* -i 1 'foo$ps'" && $b : in + $c <"\$* -i 1 <'foo$ps' >/'foo/'" && $b : out + $c <"\$* -i 2 <'foo$ps' 2>/'foo/'" && $b : err + } + } + + : regex + : + : Test regex matching. Note that tests that check regex parsing are located + : in regex.testscript. + : + { + : match + : + $c <'$* -o foo >~/Foo?/i' && $b + + : mismatch + : + $c <'$* -o fooo >~/Foo?/i' && $b 2>>/~%EOE%d != 0 + %testscript:1: error: ../../../../../driver(.exe)? stdout doesn't match regex% + info: stdout: test/1/stdout + info: stdout regex: test/1/stdout.regex + fooo + EOE + + : portable-path-failure + : + : Note that we check not only build2 diagnostics being produced, but also + : the correctness of regex being saved to file (for troubleshooting). + : + { + : newline + : + $c <"\$* -i 1 <'foo' >/~%bar/%" && $b 2>>/~%EOE%d != 0; + %testscript:1: error: ../../../../../../driver(.exe)? stdout doesn't match regex% + info: stdout: test/1/stdout + info: stdout regex: test/1/stdout.regex + info: stdin: test/1/stdin + foo + EOE + cat test/1/stdout.regex >"%bar$psr%" + + : no-newline + : + $c <"\$* -i 1 <'foo' >:/~%bar/%" && $b 2>>/~%EOE%d != 0; + %testscript:1: error: ../../../../../../driver(.exe)? stdout doesn't match regex% + info: stdout: test/1/stdout + info: stdout regex: test/1/stdout.regex + info: stdin: test/1/stdin + foo + EOE + cat test/1/stdout.regex >:"%bar$psr%" + } + } +} + +: doc +: +{ + : literal + : + { + : in + : + $c <>EOO + foo + bar + EOO + EOI + + : err + : + $c <>EOO + foo + bar + EOO + EOI + + : inout + : + $c <>EOO + foo + bar + EOF + foo + bar + EOO + EOI + + : inerr + : + $c <>EOE + foo + bar + EOF + foo + bar + EOE + EOI + + : empty + : + $c <>EOO + EOF + EOO + EOI + + : shared + : + $c <>EOF + foo + bar + EOF + EOI + + : extra-newline + : + $c <>EOO + + EOF + + EOO + EOI + + : no-newline + : + $c <>:EOO + foo + EOF + foo + EOO + EOI + + : no-newline-fail1 + : + $c <>~/EOE/ != 0 + $* -i 1 <<:EOF >>EOO + foo + EOF + foo + EOO + EOI + /testscript:1: error: .+driver(\.exe)? stdout doesn't match expected/ + /.{7} + -foo + +foo + \ No newline at end of file + EOE + + : no-newline-fail2 + : + $c <>~/EOE/ != 0 + $* -i 1 <>:EOO + foo + EOF + foo + EOO + EOI + /testscript:1: error: .+driver(\.exe)? stdout doesn't match expected/ + /.{7} + -foo + \ No newline at end of file + +foo + EOE + + : no-newline-empty + : + $c <>:EOO + EOF + EOO + EOI + + : no-newline-extra-newline + : + $c <>:EOO + + EOF + + EOO + EOI + + : merge + : + $c <>EOO 2>&1 + foo + bar + EOF + foo + bar + baz + EOO + EOI + + : large-diff + : + : Make sure that the large (>4KB) expected/real output difference is not + : printed as a part of the diagnostics. + : + $c <>/~%EOE%d != 0 + s="----------------------------------------------------------------------"; + s="$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s"; + $* -i 1 <<"EOF" >>"EOO" + $s + EOF + x$s + EOO + EOI + %testscript:3: error: ../../../../../driver(.exe)? stdout doesn't match expected% + info: stdout: test/1/stdout + info: expected stdout: test/1/stdout.orig + info: stdout diff: test/1/stdout.diff + info: stdin: test/1/stdin + EOE + + : portable-path + : + { + : in + : + $c <<"EOI" && $b + \$* -i 1 <'foo$ps' + foo/ + EOF + EOI + + : out + : + $c <<"EOI" && $b + \$* -i 1 <'foo$ps' >>/EOO + foo/ + EOO + EOI + + : err + : + $c <<"EOI" && $b + \$* -i 2 <'foo$ps' 2>>/EOE + foo/ + EOE + EOI + } + } + + : regex + : + : Test regex matching. Note that tests that check regex parsing are located + : in regex.testscript. + : + { + : match + : + $c <>~/EOO/i + /FO*/* + bar + /* + EOO + EOI + + : match-empty + : + $c <>:~/EOO/ + /.{0} + EOO + EOI + + : shared + : + $c <>~/EOF/ 2>>~/EOF/ + foo + EOF + EOI + + : mismatch + : + $c <>/~%EOE%d != 0 + $* -o foo >>~/EOO/ + bar + EOO + EOI + %testscript:1: error: ../../../../../driver(.exe)? stdout doesn't match regex% + info: stdout: test/1/stdout + info: stdout regex: test/1/stdout.regex + foo + EOE + + : mismatch-icase + : + $c <>/~%EOE%d != 0 + $* -o foo >>~/EOO/i + bar + EOO + EOI + %testscript:1: error: ../../../../../driver(.exe)? stdout doesn't match regex% + info: stdout: test/1/stdout + info: stdout regex: test/1/stdout.regex-i + foo + EOE + } +} + +: file +: +{ + : in + : + $c <=out; + $* -i 1 <<foo + EOI + + : out + : + { + : match + : + $c <=out; + $* -e bar 2>+out; + $* -i 1 <>>out + foo + bar + EOF + EOI + + : mismatch + : + $c <>/~%EOE%d != 0 + $* -o foo >=out; + $* -o bar >>>out + EOI + %testscript:2: error: ../../../../../driver(.exe)? stdout doesn't match expected% + info: stdout: test/1/stdout-2 + info: expected stdout: test/1/out + info: stdout diff: test/1/stdout-2.diff + %--- \.*% + %\+\+\+ \.*% + %@@ \.*% + -foo + +bar + EOE + } + + : merge + : + $c <&1 >=out; + $* -e baz -o biz 1>&2 2>+out; + $* -i 1 <<>EOO + foo + bar + baz + biz + EOO + EOI +} diff --git a/tests/test/script/runner/regex.test b/tests/test/script/runner/regex.test deleted file mode 100644 index 018976c..0000000 --- a/tests/test/script/runner/regex.test +++ /dev/null @@ -1,312 +0,0 @@ -# file : tests/test/script/runner/regex.test -# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -# Here we test that regex objects are properly created by the parser/runner -# venture. The unit test approach is not of much use as regex object is not -# serializable back to string. The only way we can test their proper creation -# is via matching. -# -# Note that such a tests are separated from ones that check regex matching -# specifically (in particular matching failures), The latest ones are located -# in redirect.test testscript. -# -# Also note that the following tests are grouped by features: basic -# functionality, flags, portable-path modifier. -# - -.include ../common.test - -: basic -: -{ - : str - : - { - $c <'cat ~/fo./' && $b : out - $c <'cat &2 2>~/fo./' && $b : err - $c <'cat <:foo >:~/fo./' && $b : no-newline - - : malformed - : - : Note that old versions of libc++ (for example 1.1) do not detect some - : regex errors. For example '*' is parsed successfully. - : - $c <'cat ~/foo[/' && $b 2>>~/EOE/ != 0 - /testscript:1:12: error: invalid stdout regex redirect.*/ - info: regex: '/foo[/' - EOE - - : no-match - : - $c <'cat ~/bar/' && $b 2>>/EOE != 0 - testscript:1:1: error: cat stdout doesn't match regex - info: stdout: test/1/stdout - info: stdout regex: test/1/stdout.regex - info: stdin: test/1/stdin - foo - EOE - } - - : doc - : - { - : out - : - $c <>~/EOO/ - /foo/ - EOO - EOI - - : err - : - $c <&2 2>>~/EOO/ - /fo./ - EOO - EOI - - : no-newline - : - $c <>:~/EOO/ - /fo./ - EOO - EOI - - : line-char - : - $c <>~/EOO/ - foo - bar - baz - baz - Biz - Fox - fox - - - - - EOF - foo - /? - /bar/ - /baz/+ - /biz/i - /fox/i+ - - // - //{2} - EOO - EOI - - : expansion - : - $c <>~"/EOO/" - foo - bar - - baz - EOF - /f$(s) - baz - EOO - EOI - - : invalid-syntax-char - : - $c <>EOE != 0 - cat >~/EOO/ - /x - EOO - EOI - testscript:2:1: error: invalid syntax character 'x' in stdout regex redirect - info: regex line: '/x' - EOE - - : invalid-char-regex - : - $c <>~/EOE/ != 0 - cat >~/EOO/ - /foo[/ - EOO - EOI - /testscript:2:1: error: invalid char-regex in stdout regex redirect.*/ - info: regex line: '/foo[/' - EOE - - : invalid-line-regex - : - $c <>/~%EOE% != 0 - cat >~/EOO/ - a - /{ - EOO - EOI - %testscript:4:1: error: invalid stdout regex redirect.*% - info: stdout regex: test/1/stdout.regex - EOE - - : no-match - : - { - : leading-blank - : - $c <>/EOE != 0 - cat >~/EOO/ - - foo - EOO - EOI - testscript:1:1: error: cat stdout doesn't match regex - info: stdout: test/1/stdout - info: stdout regex: test/1/stdout.regex - info: stdin: test/1/stdin - foo - EOE - } - } -} - -:flags -: -{ - : str - : - { - : i - : - $c <'cat ~/foo/i' && $b - - : d - : - { - : escaped-dot - : - : Escaped dot becomes syntax dot and matches any character ('i' in our - : case). - : - $c <'cat ~/f\\.o/d' && $b - - : syntax-dot - : - : Syntax dot becomes escaped dot and matches only '.' and so we fail. - : - $c <'cat ~/f.o/d' && $b 2>>~/EOE/ != 0 - testscript:1:1: error: cat stdout doesn't match regex - /.+ - EOE - } - } - - : doc - { - : i - : - $c <>~/EOO/ - /foo/i - EOO - EOI - - : d - : - : All the reasonings for the /flags/str/d test group are valid for the - : current one. - : - { - : escaped-dot - : - $c <>~/EOO/ - /f\.o/d - EOO - EOI - - : syntax-dot - : - $c <>~/EOE/ != 0 - cat >~/EOO/ - /f.o/d - EOO - EOI - testscript:1:1: error: cat stdout doesn't match regex - /.+ - EOE - } - - : global - : - { - : i - : - $c <>~/EOO/i - /foo/ - EOO - EOI - - : d - : - { - : escaped-dot - : - $c <>~/EOO/d - /f\.o/ - EOO - EOI - - : syntax-dot - : - $c <>~/EOE/ != 0 - cat >~/EOO/d - /f.o/ - EOO - EOI - testscript:1:1: error: cat stdout doesn't match regex - /.+ - EOE - } - } - } -} - -: portable-path -: -{ - ps = ($cxx.target.class != 'windows' ? '/' : '\') - - : str - : - { - $c <"cat <'foo$ps' >/~%foo/%" && $b : out - $c <"cat <'foo$ps' 1>&2 2>/~%foo/%" && $b : err - } - - : doc - { - : out - : - $c <<"EOI" && $b - cat <'foo$ps' >>/~%EOO% - foo/ - EOO - EOI - - : err - : - $c <<"EOI" && $b - cat <'foo$ps' 1>&2 2>>/~%EOO% - foo/ - EOO - EOI - } -} diff --git a/tests/test/script/runner/regex.testscript b/tests/test/script/runner/regex.testscript new file mode 100644 index 0000000..46b1872 --- /dev/null +++ b/tests/test/script/runner/regex.testscript @@ -0,0 +1,312 @@ +# file : tests/test/script/runner/regex.testscript +# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +# Here we test that regex objects are properly created by the parser/runner +# venture. The unit test approach is not of much use as regex object is not +# serializable back to string. The only way we can test their proper creation +# is via matching. +# +# Note that such a tests are separated from ones that check regex matching +# specifically (in particular matching failures), The latest ones are located +# in redirect.testscript. +# +# Also note that the following tests are grouped by features: basic +# functionality, flags, portable-path modifier. +# + +.include ../common.testscript + +: basic +: +{ + : str + : + { + $c <'cat ~/fo./' && $b : out + $c <'cat &2 2>~/fo./' && $b : err + $c <'cat <:foo >:~/fo./' && $b : no-newline + + : malformed + : + : Note that old versions of libc++ (for example 1.1) do not detect some + : regex errors. For example '*' is parsed successfully. + : + $c <'cat ~/foo[/' && $b 2>>~/EOE/ != 0 + /testscript:1:12: error: invalid stdout regex redirect.*/ + info: regex: '/foo[/' + EOE + + : no-match + : + $c <'cat ~/bar/' && $b 2>>/EOE != 0 + testscript:1:1: error: cat stdout doesn't match regex + info: stdout: test/1/stdout + info: stdout regex: test/1/stdout.regex + info: stdin: test/1/stdin + foo + EOE + } + + : doc + : + { + : out + : + $c <>~/EOO/ + /foo/ + EOO + EOI + + : err + : + $c <&2 2>>~/EOO/ + /fo./ + EOO + EOI + + : no-newline + : + $c <>:~/EOO/ + /fo./ + EOO + EOI + + : line-char + : + $c <>~/EOO/ + foo + bar + baz + baz + Biz + Fox + fox + + + + + EOF + foo + /? + /bar/ + /baz/+ + /biz/i + /fox/i+ + + // + //{2} + EOO + EOI + + : expansion + : + $c <>~"/EOO/" + foo + bar + + baz + EOF + /f$(s) + baz + EOO + EOI + + : invalid-syntax-char + : + $c <>EOE != 0 + cat >~/EOO/ + /x + EOO + EOI + testscript:2:1: error: invalid syntax character 'x' in stdout regex redirect + info: regex line: '/x' + EOE + + : invalid-char-regex + : + $c <>~/EOE/ != 0 + cat >~/EOO/ + /foo[/ + EOO + EOI + /testscript:2:1: error: invalid char-regex in stdout regex redirect.*/ + info: regex line: '/foo[/' + EOE + + : invalid-line-regex + : + $c <>/~%EOE% != 0 + cat >~/EOO/ + a + /{ + EOO + EOI + %testscript:4:1: error: invalid stdout regex redirect.*% + info: stdout regex: test/1/stdout.regex + EOE + + : no-match + : + { + : leading-blank + : + $c <>/EOE != 0 + cat >~/EOO/ + + foo + EOO + EOI + testscript:1:1: error: cat stdout doesn't match regex + info: stdout: test/1/stdout + info: stdout regex: test/1/stdout.regex + info: stdin: test/1/stdin + foo + EOE + } + } +} + +:flags +: +{ + : str + : + { + : i + : + $c <'cat ~/foo/i' && $b + + : d + : + { + : escaped-dot + : + : Escaped dot becomes syntax dot and matches any character ('i' in our + : case). + : + $c <'cat ~/f\\.o/d' && $b + + : syntax-dot + : + : Syntax dot becomes escaped dot and matches only '.' and so we fail. + : + $c <'cat ~/f.o/d' && $b 2>>~/EOE/ != 0 + testscript:1:1: error: cat stdout doesn't match regex + /.+ + EOE + } + } + + : doc + { + : i + : + $c <>~/EOO/ + /foo/i + EOO + EOI + + : d + : + : All the reasonings for the /flags/str/d test group are valid for the + : current one. + : + { + : escaped-dot + : + $c <>~/EOO/ + /f\.o/d + EOO + EOI + + : syntax-dot + : + $c <>~/EOE/ != 0 + cat >~/EOO/ + /f.o/d + EOO + EOI + testscript:1:1: error: cat stdout doesn't match regex + /.+ + EOE + } + + : global + : + { + : i + : + $c <>~/EOO/i + /foo/ + EOO + EOI + + : d + : + { + : escaped-dot + : + $c <>~/EOO/d + /f\.o/ + EOO + EOI + + : syntax-dot + : + $c <>~/EOE/ != 0 + cat >~/EOO/d + /f.o/ + EOO + EOI + testscript:1:1: error: cat stdout doesn't match regex + /.+ + EOE + } + } + } +} + +: portable-path +: +{ + ps = ($cxx.target.class != 'windows' ? '/' : '\') + + : str + : + { + $c <"cat <'foo$ps' >/~%foo/%" && $b : out + $c <"cat <'foo$ps' 1>&2 2>/~%foo/%" && $b : err + } + + : doc + { + : out + : + $c <<"EOI" && $b + cat <'foo$ps' >>/~%EOO% + foo/ + EOO + EOI + + : err + : + $c <<"EOI" && $b + cat <'foo$ps' 1>&2 2>>/~%EOO% + foo/ + EOO + EOI + } +} diff --git a/tests/test/script/runner/set.test b/tests/test/script/runner/set.test deleted file mode 100644 index 2266ae9..0000000 --- a/tests/test/script/runner/set.test +++ /dev/null @@ -1,278 +0,0 @@ -# file : tests/test/script/runner/set.test -# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -.include ../common.test - -: special -: -{ - : pipelining - : - $c <'set foo | cat >bar' && $b 2>>EOE != 0 - testscript:1:1: error: set builtin must be the last pipe command - EOE - - : redirecting - : - { - : stdout - : - $c <'set foo >bar' && $b 2>>EOE != 0 - testscript:1:1: error: set builtin stdout cannot be redirected - EOE - - : stderr - : - $c <'set foo 2>bar' && $b 2>>EOE != 0 - testscript:1:1: error: set builtin stderr cannot be redirected - EOE - } - - : status - : - $c <'set foo == 1' && $b 2>>EOE != 0 - testscript:1:1: error: set builtin exit code cannot be non-zero - EOE -} - -: arguments -: -{ - : none - : - $c <'set -e' && $b 2>>EOE != 0 - testscript:1:1: error: missing variable name - EOE - - : unexpected - : - $c <'set foo bar baz' && $b 2>>EOE != 0 - testscript:1:1: error: unexpected argument - EOE - - : empty-attrs - : - $c <"set '' baz" && $b 2>>EOE != 0 - testscript:1:1: error: empty variable attributes - EOE - - : empty-var - : - $c <"set ''" && $b 2>>EOE != 0 - testscript:1:1: error: empty variable name - EOE -} - -: whitespace-separated-list -: -{ - : non-exact - : - $c <'foo bar' - EOI - - : exact - : - { - : trailing-ws - : - $c <'foo bar ' - EOI - - : no-trailing-ws - : - : Note that we need to strip the default trailing newline as well with the - : ':' modifier. - : - $c <'foo bar' - EOI - } -} - -: newline-separated-list -: -{ - : non-exact - : - $c <' foo bar ' - EOI - - : exact - : - { - : trailing-newline - : - $c <' foo bar ' - EOI - - : no-trailing-newline - : - $c <' foo bar' - EOI - } -} - -: string -: -{ - : non-exact - : - $c <>EOO - - foo - - bar - - EOO - EOI - - : roundtrip - : - echo 'foo' | set bar; - echo "$bar" >'foo' - - : exact - : - : Note that echo adds the trailing newline, so EOF and EOO here-documents - : differ by this newline. - : - { - : trailing-newline - : - $c <>EOO - - foo - - bar - - EOO - EOI - - : no-trailing-newline - : - $c <>EOO - - foo - - bar - EOO - EOI - } -} - -: attributes -: -{ - : dir_path - : - $c </'foo/' - EOI - - : null - : - $c <'' - EOI - - : none - : - $c <>EOE != 0 - set -w baz <'foo bar'; - echo "$baz" - EOI - testscript:2:8: error: concatenating variable expansion contains multiple values - EOE - - # @@ Move the following tests to build2 parser unit tests when created. - # - : empty-brackets - : - $c <>EOE != 0 - set -w '[]' baz <'foo bar'; - echo "$baz" - EOI - testscript:2:8: error: concatenating variable expansion contains multiple values - EOE - - : no-left-bracket - : - $c <>EOE != 0 - set -w x baz - EOI - :1:1: error: expected '[' instead of 'x' - testscript:1:1: info: while parsing attributes 'x' - EOE - - : unknown - : - $c <>EOE != 0 - set -w [x] baz - EOI - :1:1: error: unknown value attribute x - testscript:1:1: info: while parsing attributes '[x]' - EOE - - : junk - : - $c <>EOE != 0 - set -w '[string] x' baz - EOI - :1:10: error: trailing junk after ']' - testscript:1:1: info: while parsing attributes '[string] x' - EOE -} diff --git a/tests/test/script/runner/set.testscript b/tests/test/script/runner/set.testscript new file mode 100644 index 0000000..b10ce1e --- /dev/null +++ b/tests/test/script/runner/set.testscript @@ -0,0 +1,278 @@ +# file : tests/test/script/runner/set.testscript +# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +.include ../common.testscript + +: special +: +{ + : pipelining + : + $c <'set foo | cat >bar' && $b 2>>EOE != 0 + testscript:1:1: error: set builtin must be the last pipe command + EOE + + : redirecting + : + { + : stdout + : + $c <'set foo >bar' && $b 2>>EOE != 0 + testscript:1:1: error: set builtin stdout cannot be redirected + EOE + + : stderr + : + $c <'set foo 2>bar' && $b 2>>EOE != 0 + testscript:1:1: error: set builtin stderr cannot be redirected + EOE + } + + : status + : + $c <'set foo == 1' && $b 2>>EOE != 0 + testscript:1:1: error: set builtin exit code cannot be non-zero + EOE +} + +: arguments +: +{ + : none + : + $c <'set -e' && $b 2>>EOE != 0 + testscript:1:1: error: missing variable name + EOE + + : unexpected + : + $c <'set foo bar baz' && $b 2>>EOE != 0 + testscript:1:1: error: unexpected argument + EOE + + : empty-attrs + : + $c <"set '' baz" && $b 2>>EOE != 0 + testscript:1:1: error: empty variable attributes + EOE + + : empty-var + : + $c <"set ''" && $b 2>>EOE != 0 + testscript:1:1: error: empty variable name + EOE +} + +: whitespace-separated-list +: +{ + : non-exact + : + $c <'foo bar' + EOI + + : exact + : + { + : trailing-ws + : + $c <'foo bar ' + EOI + + : no-trailing-ws + : + : Note that we need to strip the default trailing newline as well with the + : ':' modifier. + : + $c <'foo bar' + EOI + } +} + +: newline-separated-list +: +{ + : non-exact + : + $c <' foo bar ' + EOI + + : exact + : + { + : trailing-newline + : + $c <' foo bar ' + EOI + + : no-trailing-newline + : + $c <' foo bar' + EOI + } +} + +: string +: +{ + : non-exact + : + $c <>EOO + + foo + + bar + + EOO + EOI + + : roundtrip + : + echo 'foo' | set bar; + echo "$bar" >'foo' + + : exact + : + : Note that echo adds the trailing newline, so EOF and EOO here-documents + : differ by this newline. + : + { + : trailing-newline + : + $c <>EOO + + foo + + bar + + EOO + EOI + + : no-trailing-newline + : + $c <>EOO + + foo + + bar + EOO + EOI + } +} + +: attributes +: +{ + : dir_path + : + $c </'foo/' + EOI + + : null + : + $c <'' + EOI + + : none + : + $c <>EOE != 0 + set -w baz <'foo bar'; + echo "$baz" + EOI + testscript:2:8: error: concatenating variable expansion contains multiple values + EOE + + # @@ Move the following tests to build2 parser unit tests when created. + # + : empty-brackets + : + $c <>EOE != 0 + set -w '[]' baz <'foo bar'; + echo "$baz" + EOI + testscript:2:8: error: concatenating variable expansion contains multiple values + EOE + + : no-left-bracket + : + $c <>EOE != 0 + set -w x baz + EOI + :1:1: error: expected '[' instead of 'x' + testscript:1:1: info: while parsing attributes 'x' + EOE + + : unknown + : + $c <>EOE != 0 + set -w [x] baz + EOI + :1:1: error: unknown value attribute x + testscript:1:1: info: while parsing attributes '[x]' + EOE + + : junk + : + $c <>EOE != 0 + set -w '[string] x' baz + EOI + :1:10: error: trailing junk after ']' + testscript:1:1: info: while parsing attributes '[string] x' + EOE +} diff --git a/tests/test/script/runner/status.test b/tests/test/script/runner/status.test deleted file mode 100644 index 86d9ca4..0000000 --- a/tests/test/script/runner/status.test +++ /dev/null @@ -1,57 +0,0 @@ -# file : tests/test/script/runner/status.test -# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd -# license : MIT; see accompanying LICENSE file - -.include ../common.test - -b += --no-column - -: eq -: -{ - : true - : - $c <'$* == 0' && $b - - : false - : - $c <'$* -s 1 == 0' && $b 2>>/~%EOE%d != 0 - %testscript:1: error: ../../../../driver(.exe)? exit code 1 != 0% - EOE -} - -: ne -: -{ - : true - : - $c <'$* -s 1 != 0' && $b - - : false - : - $c <'$* -s 1 != 1' && $b 2>>/~%EOE% != 0 - %testscript:1: error: ../../../../driver(.exe)? exit code 1 == 1% - EOE -} - -: error -: -$c <'$* -s 1 -e "Error"' && $b 2>>/~%EOE% != 0 -%testscript:1: error: ../../../driver(.exe)? exit code 1 != 0% - info: stderr: test/1/stderr -Error -EOE - -#\ -: segmentation-fault -: -: Can pop up dialog boxes on Windows or produce coredump on POSIX. Note that -: under Wine some extra info is printed to STDOUT. -: -$c <'$* -t m' && $b 2>>/~%EOE% != 0 -%wine: .+%? -%testscript:1: error: ../../../driver(.exe)? terminated abnormally%d -% info: .+% -% info: stdout: test\\1\\stdout%? -EOE -#\ diff --git a/tests/test/script/runner/status.testscript b/tests/test/script/runner/status.testscript new file mode 100644 index 0000000..1689a69 --- /dev/null +++ b/tests/test/script/runner/status.testscript @@ -0,0 +1,57 @@ +# file : tests/test/script/runner/status.testscript +# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +.include ../common.testscript + +b += --no-column + +: eq +: +{ + : true + : + $c <'$* == 0' && $b + + : false + : + $c <'$* -s 1 == 0' && $b 2>>/~%EOE%d != 0 + %testscript:1: error: ../../../../driver(.exe)? exit code 1 != 0% + EOE +} + +: ne +: +{ + : true + : + $c <'$* -s 1 != 0' && $b + + : false + : + $c <'$* -s 1 != 1' && $b 2>>/~%EOE% != 0 + %testscript:1: error: ../../../../driver(.exe)? exit code 1 == 1% + EOE +} + +: error +: +$c <'$* -s 1 -e "Error"' && $b 2>>/~%EOE% != 0 +%testscript:1: error: ../../../driver(.exe)? exit code 1 != 0% + info: stderr: test/1/stderr +Error +EOE + +#\ +: segmentation-fault +: +: Can pop up dialog boxes on Windows or produce coredump on POSIX. Note that +: under Wine some extra info is printed to STDOUT. +: +$c <'$* -t m' && $b 2>>/~%EOE% != 0 +%wine: .+%? +%testscript:1: error: ../../../driver(.exe)? terminated abnormally%d +% info: .+% +% info: stdout: test\\1\\stdout%? +EOE +#\ -- cgit v1.1