aboutsummaryrefslogtreecommitdiff
path: root/build2/test/script
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-01-11 10:14:23 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-01-12 10:58:19 +0200
commit9bf93c1ab73ee3cd2b763285fc5fc5456e972854 (patch)
tree0357c36e12fe2137ef6c9bd228e9d69bb2489a02 /build2/test/script
parent33ed305eac57bff406fa3f672ba8acc4941e8f13 (diff)
Implement support for narrowing down tests (config.test)
Diffstat (limited to 'build2/test/script')
-rw-r--r--build2/test/script/parser8
-rw-r--r--build2/test/script/parser.cxx12
-rw-r--r--build2/test/script/runner16
-rw-r--r--build2/test/script/runner.cxx32
-rw-r--r--build2/test/script/script.cxx22
5 files changed, 58 insertions, 32 deletions
diff --git a/build2/test/script/parser b/build2/test/script/parser
index 8f30a8c..9ad5fe9 100644
--- a/build2/test/script/parser
+++ b/build2/test/script/parser
@@ -136,7 +136,11 @@ namespace build2
//
public:
void
- execute (script& s, runner& r) {if (!s.empty ()) execute (s, s, r);}
+ execute (script& s, runner& r)
+ {
+ if (!s.empty ())
+ execute (s, s, r);
+ }
void
execute (scope&, script&, runner&);
@@ -195,7 +199,7 @@ namespace build2
lexer* lexer_;
string id_prefix_; // Auto-derived id prefix.
- // Parse state.
+ // Execute state.
//
runner* runner_;
scope* scope_;
diff --git a/build2/test/script/parser.cxx b/build2/test/script/parser.cxx
index da072dc..f250d27 100644
--- a/build2/test/script/parser.cxx
+++ b/build2/test/script/parser.cxx
@@ -2,11 +2,11 @@
// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
+#include <build2/test/script/parser>
+
#include <sstream>
#include <cstring> // strstr()
-#include <build2/test/script/parser>
-
#include <build2/scheduler>
#include <build2/test/script/lexer>
@@ -2743,6 +2743,14 @@ namespace build2
for (unique_ptr<scope>& chain: g->scopes)
{
+ // Check if this scope is ignored (e.g., via config.test).
+ //
+ if (!runner_->test (*chain))
+ {
+ chain.reset ();
+ continue;
+ }
+
// Pick a scope from the if-else chain.
//
// In fact, we are going to drop all but the selected (if any)
diff --git a/build2/test/script/runner b/build2/test/script/runner
index 5e05255..7b932b9 100644
--- a/build2/test/script/runner
+++ b/build2/test/script/runner
@@ -16,11 +16,18 @@ namespace build2
{
namespace test
{
+ class common;
+
namespace script
{
class runner
{
public:
+ // Return false if this test/group should be skipped.
+ //
+ virtual bool
+ test (scope&) const = 0;
+
// Location is the scope start location (for diagnostics, etc).
//
virtual void
@@ -49,6 +56,12 @@ namespace build2
class default_runner: public runner
{
public:
+ explicit
+ default_runner (const common& c): common_ (c) {}
+
+ virtual bool
+ test (scope& s) const override;
+
virtual void
enter (scope&, const location&) override;
@@ -60,6 +73,9 @@ namespace build2
virtual void
leave (scope&, const location&) override;
+
+ private:
+ const common& common_;
};
}
}
diff --git a/build2/test/script/runner.cxx b/build2/test/script/runner.cxx
index 64c6e87..522dedd 100644
--- a/build2/test/script/runner.cxx
+++ b/build2/test/script/runner.cxx
@@ -10,6 +10,9 @@
#include <butl/fdstream> // fdopen_mode, fdnull(), fddup()
#include <build2/filesystem>
+
+#include <build2/test/common>
+
#include <build2/test/script/builtin>
using namespace std;
@@ -310,21 +313,26 @@ namespace build2
}
}
+ bool default_runner::
+ test (scope& s) const
+ {
+ return common_.test (s.root->test_target, s.id_path);
+ }
+
void default_runner::
enter (scope& sp, const location&)
{
- if (!exists (sp.wd_path))
- // @@ Shouldn't we add an optional location parameter to mkdir() and
- // alike utility functions so the failure message can contain
- // location info?
- //
- mkdir (sp.wd_path, 2);
- else
- // Scope working directory shall be empty (the script working
- // directory is cleaned up by the test rule prior the script
- // execution).
- //
- assert (empty (sp.wd_path));
+ // Scope working directory shall be empty (the script working
+ // directory is cleaned up by the test rule prior the script
+ // execution).
+ //
+ // @@ Shouldn't we add an optional location parameter to mkdir() and
+ // alike utility functions so the failure message can contain
+ // location info?
+ //
+ if (mkdir (sp.wd_path, 2) == mkdir_status::already_exists)
+ fail << "working directory " << sp.wd_path << " already exists" <<
+ info << "are tests stomping on each other's feet?";
// We don't change the current directory here but indicate that the
// scope test commands will be executed in that directory.
diff --git a/build2/test/script/script.cxx b/build2/test/script/script.cxx
index 661ec7f..2a34f66 100644
--- a/build2/test/script/script.cxx
+++ b/build2/test/script/script.cxx
@@ -424,24 +424,11 @@ namespace build2
// script
//
- static inline string
- script_id (const path& p)
- {
- string r (p.leaf ().string ());
-
- if (r == "testscript")
- return string ();
-
- size_t n (path::traits::find_extension (r));
- assert (n != string::npos);
- r.resize (n);
- return r;
- }
-
script::
script (target& tt, testscript& st, const dir_path& rwd)
- : group (script_id (st.path ())),
- test_target (tt), script_target (st)
+ : group (st.name == "testscript" ? string () : st.name),
+ test_target (tt),
+ script_target (st)
{
// Set the script working dir ($~) to $out_base/test/<id> (id_path
// for root is just the id which is empty if st is 'testscript').
@@ -458,7 +445,10 @@ namespace build2
//
lookup l (find_in_buildfile ("test", false));
+ // Note that we have similar code for simple tests.
+ //
target* t (nullptr);
+
if (l.defined ())
{
const name* n (cast_null<name> (l));