diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2016-10-22 11:59:20 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-11-04 09:26:34 +0200 |
commit | 31e16a7413813293e3cccb6799eaa08b7af5af4e (patch) | |
tree | 45f06abbcf44652b58c3a2ad7485f64108994abd /unit-tests/test/script/parser | |
parent | 8e3a8ffa6579a51f5a9351e1b99c07d3e1fbd234 (diff) |
Implement support for compound tests
Diffstat (limited to 'unit-tests/test/script/parser')
-rw-r--r-- | unit-tests/test/script/parser/driver.cxx | 54 | ||||
-rw-r--r-- | unit-tests/test/script/parser/scope.test | 107 |
2 files changed, 144 insertions, 17 deletions
diff --git a/unit-tests/test/script/parser/driver.cxx b/unit-tests/test/script/parser/driver.cxx index 4d71082..09fd6f5 100644 --- a/unit-tests/test/script/parser/driver.cxx +++ b/unit-tests/test/script/parser/driver.cxx @@ -25,25 +25,45 @@ namespace build2 { namespace script { + // Here we assume we are running serially. + // class print_runner: public runner { public: + print_runner (bool scope): scope_ (scope) {} + virtual void - enter (scope&, const location&) override {} + enter (scope&, const location&) override + { + if (scope_) + { + cout << ind_ << "{" << endl; + ind_ += " "; + } + } virtual void run (scope&, const command& t, size_t, const location&) override { - // Here we assume we are running serially. - // - cout << t << endl; + cout << ind_ << t << endl; } virtual void - leave (scope&, const location&) override {} + leave (scope&, const location&) override + { + if (scope_) + { + ind_.resize (ind_.size () - 2); + cout << ind_ << "}" << endl; + } + } + + private: + bool scope_; + string ind_; }; - // Usage: argv[0] [<testscript-name>] + // Usage: argv[0] [-s] [<testscript-name>] // int main (int argc, char* argv[]) @@ -53,9 +73,27 @@ namespace build2 init (1); // Default verbosity. reset (strings ()); // No command line variables. + bool scope (false); + path name; + + for (int i (1); i != argc; ++i) + { + string a (argv[i]); + + if (a == "-s") + scope = true; + else + { + name = path (move (a)); + break; + } + } + + if (name.empty ()) + name = path ("testscript"); + try { - path name (argc > 1 ? argv[1] : "testscript"); cin.exceptions (istream::failbit | istream::badbit); // Enter mock targets. Use fixed names and paths so that we can use @@ -83,7 +121,7 @@ namespace build2 // Parse and run. // script s (tt, st); - print_runner r; + print_runner r (scope); parser p; p.pre_parse (cin, name, s); diff --git a/unit-tests/test/script/parser/scope.test b/unit-tests/test/script/parser/scope.test index a2c6d9f..7517022 100644 --- a/unit-tests/test/script/parser/scope.test +++ b/unit-tests/test/script/parser/scope.test @@ -1,15 +1,104 @@ $* testscript <'cmd $@' >"cmd 1" # id-testscript $* foo.test <'cmd $@' >"cmd foo/1" # id -wd = [dir_path] $build.work -wd += test -wd += 1 +wd = [dir_path] $~; +wd += test; +wd += 1; $* testscript <'cmd $~' >"cmd $wd" # wd-testscript -# @@ TMP wd1 +wd = [dir_path] $~; +wd += test; +wd += foo; +wd += 1; +$* foo.test <'cmd $~' >"cmd $wd" # wd + +$* -s <<EOI >>EOO # compound-2 +cmd1; +cmd2 +EOI +{ + { + cmd1 + cmd2 + } +} +EOO + +$* -s <<EOI >>EOO # compound-3 +cmd1; +cmd2; +cmd3 +EOI +{ + { + cmd1 + cmd2 + cmd3 + } +} +EOO + +$* -s <<EOI >>EOO # compound-var +cmd1; +x = abc; +cmd2 \$x +EOI +{ + { + cmd1 + cmd2 abc + } +} +EOO + +$* -s <<EOI >>EOO # compound-var-first +x = abc; +cmd \$x +EOI +{ + { + cmd abc + } +} +EOO + +$* -s <<EOI >>EOO # var-setup-tdown +x = abc +cmd \$x +y = 123 +EOI +{ + { + cmd abc + } +} +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 +cmd; +EOI +testscript:2:1: error: expected another line after semicolon +EOE + +# @@ Need newline-less support. # -wd1 = [dir_path] $build.work -wd1 += test -wd1 += foo -wd1 += 1 -$* foo.test <'cmd $~' >"cmd $wd1" # wd +#$* <<EOI 2>>EOE != 0 # expected-newline-cmd +#cmd ;\ +#EOI +#testscript:2:1: error: expected newline instead of <end of file> +#EOE + +#$* <<EOI 2>>EOE != 0 # expected-newline-var +#x =abc;\ +#EOI +#testscript:2:1: error: expected newline instead of <end of file> +#EOE |