From 31e16a7413813293e3cccb6799eaa08b7af5af4e Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 22 Oct 2016 11:59:20 +0200 Subject: Implement support for compound tests --- unit-tests/test/script/parser/driver.cxx | 54 +++++++++++++--- unit-tests/test/script/parser/scope.test | 107 ++++++++++++++++++++++++++++--- 2 files changed, 144 insertions(+), 17 deletions(-) (limited to 'unit-tests/test/script/parser') 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] [] + // Usage: argv[0] [-s] [] // 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 <>EOO # compound-2 +cmd1; +cmd2 +EOI +{ + { + cmd1 + cmd2 + } +} +EOO + +$* -s <>EOO # compound-3 +cmd1; +cmd2; +cmd3 +EOI +{ + { + cmd1 + cmd2 + cmd3 + } +} +EOO + +$* -s <>EOO # compound-var +cmd1; +x = abc; +cmd2 \$x +EOI +{ + { + cmd1 + cmd2 abc + } +} +EOO + +$* -s <>EOO # compound-var-first +x = abc; +cmd \$x +EOI +{ + { + cmd abc + } +} +EOO + +$* -s <>EOO # var-setup-tdown +x = abc +cmd \$x +y = 123 +EOI +{ + { + cmd abc + } +} +EOO + +$* <>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 + +$* <>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 +#$* <>EOE != 0 # expected-newline-cmd +#cmd ;\ +#EOI +#testscript:2:1: error: expected newline instead of +#EOE + +#$* <>EOE != 0 # expected-newline-var +#x =abc;\ +#EOI +#testscript:2:1: error: expected newline instead of +#EOE -- cgit v1.1