From 43378e3827fd0d17325646c40c76bab9db1da19a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 26 Oct 2016 15:01:54 +0200 Subject: Handle explicit test scopes --- unit-tests/test/script/parser/driver.cxx | 17 +++++-- unit-tests/test/script/parser/scope.test | 79 +++++++++++++++++++++++++++++++- 2 files changed, 90 insertions(+), 6 deletions(-) (limited to 'unit-tests') diff --git a/unit-tests/test/script/parser/driver.cxx b/unit-tests/test/script/parser/driver.cxx index 6e3fed5..aad94f9 100644 --- a/unit-tests/test/script/parser/driver.cxx +++ b/unit-tests/test/script/parser/driver.cxx @@ -30,13 +30,16 @@ namespace build2 class print_runner: public runner { public: - print_runner (bool scope): scope_ (scope) {} + print_runner (bool scope, bool id): scope_ (scope), id_ (id) {} virtual void - enter (scope&, const location&) override + enter (scope& s, const location&) override { if (scope_) { + if (id_ && !s.id_path.empty ()) // Skip empty root scope id. + cout << ind_ << ": " << s.id_path.string () << endl; + cout << ind_ << "{" << endl; ind_ += " "; } @@ -60,10 +63,11 @@ namespace build2 private: bool scope_; + bool id_; string ind_; }; - // Usage: argv[0] [-s] [] + // Usage: argv[0] [-s] [-i] [] // int main (int argc, char* argv[]) @@ -74,6 +78,7 @@ namespace build2 reset (strings ()); // No command line variables. bool scope (false); + bool id (false); path name; for (int i (1); i != argc; ++i) @@ -82,6 +87,8 @@ namespace build2 if (a == "-s") scope = true; + else if (a == "-i") + id = true; else { name = path (move (a)); @@ -92,6 +99,8 @@ namespace build2 if (name.empty ()) name = path ("testscript"); + assert (!id || scope); // Id can only be printed with scope. + try { cin.exceptions (istream::failbit | istream::badbit); @@ -121,7 +130,7 @@ namespace build2 // Parse and run. // script s (tt, st, dir_path (work) /= "test-driver"); - print_runner r (scope); + print_runner r (scope, id); 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 593dbb2..a903959 100644 --- a/unit-tests/test/script/parser/scope.test +++ b/unit-tests/test/script/parser/scope.test @@ -17,8 +17,16 @@ $* -s <>EOO # group-empty } EOI { - { - } +} +EOO + +$* -s <>EOO # group-empty-empty +{ + { + } +} +EOI +{ } EOO @@ -40,6 +48,73 @@ EOI } EOO +# Test scope. +# + +$* -s -i <>EOO # test-scope +{ + cmd +} +EOI +{ + : 1 + { + cmd + } +} +EOO + +$* -s -i <>EOO # test-scope-nested +{ + { + cmd + } +} +EOI +{ + : 1 + { + cmd + } +} +EOO + +$* -s -i <>EOO # test-scope-var +{ + x = abc + cmd \$x +} +EOI +{ + : 1 + { + cmd abc + } +} +EOO + +$* -s -i <>EOO # test-scope-setup +{ + x = abc + +setup + cmd \$x +} +EOI +{ + : 1 + { + setup + : 1/4 + { + cmd abc + } + } +} +EOO + + +# +# $* <:"{x" 2>>EOE != 0 # expected-newline-lcbrace testscript:1:2: error: expected newline after '{' EOE -- cgit v1.1