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/lexer/assign-line.test | 8 ++ unit-tests/test/script/lexer/buildfile | 3 +- unit-tests/test/script/lexer/driver.cxx | 7 +- unit-tests/test/script/lexer/script-line.test | 18 ++++ unit-tests/test/script/lexer/variable-line.test | 18 ++++ unit-tests/test/script/parser/driver.cxx | 54 ++++++++++-- unit-tests/test/script/parser/scope.test | 107 ++++++++++++++++++++++-- 7 files changed, 195 insertions(+), 20 deletions(-) create mode 100644 unit-tests/test/script/lexer/assign-line.test create mode 100644 unit-tests/test/script/lexer/script-line.test create mode 100644 unit-tests/test/script/lexer/variable-line.test (limited to 'unit-tests/test/script') diff --git a/unit-tests/test/script/lexer/assign-line.test b/unit-tests/test/script/lexer/assign-line.test new file mode 100644 index 0000000..ce3e8a1 --- /dev/null +++ b/unit-tests/test/script/lexer/assign-line.test @@ -0,0 +1,8 @@ +# Note: this mode auto-expires after each token. +# +test.arguments += assign-line + +$* <";" >>EOO # semi-only +; + +EOO diff --git a/unit-tests/test/script/lexer/buildfile b/unit-tests/test/script/lexer/buildfile index a9f6be9..70be793 100644 --- a/unit-tests/test/script/lexer/buildfile +++ b/unit-tests/test/script/lexer/buildfile @@ -7,6 +7,7 @@ import libs = libbutl%lib{butl} src = token lexer diagnostics utility variable name test/script/{token lexer} -exe{driver}: cxx{driver} ../../../../build2/cxx{$src} $libs test{variable.test} +exe{driver}: cxx{driver} ../../../../build2/cxx{$src} $libs \ +test{script-line assign-line variable-line variable} include ../../../../build2/ diff --git a/unit-tests/test/script/lexer/driver.cxx b/unit-tests/test/script/lexer/driver.cxx index cd7110f..e37e29d 100644 --- a/unit-tests/test/script/lexer/driver.cxx +++ b/unit-tests/test/script/lexer/driver.cxx @@ -42,9 +42,12 @@ namespace build2 { cin.exceptions (istream::failbit | istream::badbit); - // The variable mode auto-expires so we need something underneath. + // Some modes auto-expire so we need something underneath. // - bool u (m == lexer_mode::variable); + bool u (m == lexer_mode::assign_line || + m == lexer_mode::variable_line || + m == lexer_mode::variable); + lexer l (cin, path ("stdin"), u ? lexer_mode::script_line : m); if (u) l.mode (m); diff --git a/unit-tests/test/script/lexer/script-line.test b/unit-tests/test/script/lexer/script-line.test new file mode 100644 index 0000000..b4fe3ef --- /dev/null +++ b/unit-tests/test/script/lexer/script-line.test @@ -0,0 +1,18 @@ +test.arguments += script-line + +$* <"cmd;" >>EOO # semi +'cmd' +; + +EOO + +$* <"cmd ;" >>EOO # semi-separated +'cmd' +; + +EOO + +$* <";" >>EOO # semi-only +; + +EOO diff --git a/unit-tests/test/script/lexer/variable-line.test b/unit-tests/test/script/lexer/variable-line.test new file mode 100644 index 0000000..543c6f9 --- /dev/null +++ b/unit-tests/test/script/lexer/variable-line.test @@ -0,0 +1,18 @@ +test.arguments += variable-line + +$* <"cmd;" >>EOO # semi +'cmd' +; + +EOO + +$* <"cmd ;" >>EOO # semi-separated +'cmd' +; + +EOO + +$* <";" >>EOO # semi-only +; + +EOO 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