diff options
-rw-r--r-- | build2/test/script/parser.cxx | 26 | ||||
-rw-r--r-- | build2/test/script/runner | 19 | ||||
-rw-r--r-- | build2/test/script/runner.cxx | 2 | ||||
-rw-r--r-- | build2/test/script/script | 23 | ||||
-rw-r--r-- | unit-tests/test/script/parser/driver.cxx | 8 |
5 files changed, 61 insertions, 17 deletions
diff --git a/build2/test/script/parser.cxx b/build2/test/script/parser.cxx index a3860c4..1448e7a 100644 --- a/build2/test/script/parser.cxx +++ b/build2/test/script/parser.cxx @@ -76,8 +76,15 @@ namespace build2 mode (lexer_mode::assign_line); next (t, tt); + if (group_->start_loc_.empty ()) + group_->start_loc_ = get_location (t); + if (tt == type::eos) + { + group_->end_loc_ = get_location (t); + replay_stop (); // Discard replay of eos. break; + } const location ll (get_location (t)); line_type lt (pre_parse_script_line (t, tt)); @@ -94,7 +101,7 @@ namespace build2 { case line_type::variable: { - ls = &group_->setup; + ls = &group_->setup_; break; } case line_type::test: @@ -105,7 +112,10 @@ namespace build2 unique_ptr<test> ( (test_ = new test (to_string (ll.line), *group_)))); - ls = &test_->tests; + test_->start_loc_ = ll; + test_->end_loc_ = get_location (t); + + ls = &test_->tests_; test_ = nullptr; } @@ -113,8 +123,6 @@ namespace build2 ls->push_back (move (l)); } - - replay_stop (); // Discard replay of eos. } void parser:: @@ -143,11 +151,13 @@ namespace build2 } }; - play (scope_->setup); + runner_->enter (*scope_, scope_->start_loc_); + + play (scope_->setup_); if (test* t = dynamic_cast<test*> (scope_)) { - play (t->tests); + play (t->tests_); } else if (group* g = dynamic_cast<group*> (scope_)) { @@ -168,7 +178,9 @@ namespace build2 else assert (false); - play (scope_->tdown); + play (scope_->tdown_); + + runner_->leave (*scope_, scope_->end_loc_); } line_type parser:: diff --git a/build2/test/script/runner b/build2/test/script/runner index e2cffcf..c4f87ee 100644 --- a/build2/test/script/runner +++ b/build2/test/script/runner @@ -21,6 +21,10 @@ namespace build2 class runner { public: + // Location is the scope start location (for diagnostics, etc). + // + virtual void + enter (scope&, const location&) = 0; // Index is the 1-base index of this command in the command list // (e.g., in a compound test). If it is 0 then it means there is only @@ -31,14 +35,25 @@ namespace build2 // It can be used in diagnostics. // virtual void - run (const scope&, const command&, size_t index, const location&) = 0; + run (scope&, const command&, size_t index, const location&) = 0; + + // Location is the scope end location (for diagnostics, etc). + // + virtual void + leave (scope&, const location&) = 0; }; class concurrent_runner: public runner { public: virtual void - run (const scope&, const command&, size_t, const location&) override; + enter (scope&, const location&) override {} + + virtual void + run (scope&, const command&, size_t, const location&) override; + + virtual void + leave (scope&, const location&) override {} }; } } diff --git a/build2/test/script/runner.cxx b/build2/test/script/runner.cxx index 7844119..a4fb31e 100644 --- a/build2/test/script/runner.cxx +++ b/build2/test/script/runner.cxx @@ -250,7 +250,7 @@ namespace build2 } void concurrent_runner:: - run (const scope&, const command& c, size_t ci, const location& cl) + run (scope&, const command& c, size_t ci, const location& cl) { if (verb >= 3) text << c; diff --git a/build2/test/script/script b/build2/test/script/script index 7fbe949..3095ccf 100644 --- a/build2/test/script/script +++ b/build2/test/script/script @@ -119,9 +119,6 @@ namespace build2 const path& id_path; // Id path ($@, relative in POSIX form). const dir_path& wd_path; // Working dir ($~, absolute and normalized). - lines setup; - lines tdown; - // Variables. // public: @@ -155,6 +152,16 @@ namespace build2 protected: scope (const string& id, scope* parent); + + // Pre-parse data. + // + private: + friend class parser; + + location start_loc_; + lines setup_; + lines tdown_; + location end_loc_; }; class group: public scope @@ -172,10 +179,14 @@ namespace build2 class test: public scope { public: - lines tests; - - public: test (const string& id, group& p): scope (id, &p) {} + + // Pre-parse data. + // + private: + friend class parser; + + lines tests_; }; class script_base // Make sure certain things are initialized early. diff --git a/unit-tests/test/script/parser/driver.cxx b/unit-tests/test/script/parser/driver.cxx index db253eb..4d71082 100644 --- a/unit-tests/test/script/parser/driver.cxx +++ b/unit-tests/test/script/parser/driver.cxx @@ -29,12 +29,18 @@ namespace build2 { public: virtual void - run (const scope&, const command& t, size_t, const location&) override + enter (scope&, const location&) override {} + + virtual void + run (scope&, const command& t, size_t, const location&) override { // Here we assume we are running serially. // cout << t << endl; } + + virtual void + leave (scope&, const location&) override {} }; // Usage: argv[0] [<testscript-name>] |