aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbuild2/test/script/runner.cxx12
-rw-r--r--libbuild2/test/script/script.cxx29
-rw-r--r--libbuild2/test/script/script.hxx18
-rw-r--r--tests/test/script/runner/test-runner.testscript32
4 files changed, 58 insertions, 33 deletions
diff --git a/libbuild2/test/script/runner.cxx b/libbuild2/test/script/runner.cxx
index eb30e02..af5f30a 100644
--- a/libbuild2/test/script/runner.cxx
+++ b/libbuild2/test/script/runner.cxx
@@ -41,6 +41,18 @@ namespace build2
dr << info << "test id: " << sp.id_path.posix_string ();
});
+ // Note that we could probably keep the test programs sets fully
+ // independent across the scopes and check if the program is a test by
+ // traversing the scopes upwards recursively. Note though, that the
+ // parent scope's set cannot change during the nested scope execution
+ // and normally contains just a single entry. Thus, it seems more
+ // efficient to get rid of the recursion by copying the set from the
+ // parent now and potentially changing it later on the test variable
+ // assignment, etc.
+ //
+ if (sp.parent != nullptr)
+ sp.test_programs = sp.parent->test_programs;
+
// Scope working directory shall be empty (the script working
// directory is cleaned up by the test rule prior the script
// execution).
diff --git a/libbuild2/test/script/script.cxx b/libbuild2/test/script/script.cxx
index 32bd989..165b9b7 100644
--- a/libbuild2/test/script/script.cxx
+++ b/libbuild2/test/script/script.cxx
@@ -94,37 +94,24 @@ namespace build2
const_cast<path&> (id_path) = path (move (s));
}
- // Calculate the working directory path and the test programs set
- // unless this is the root scope (handled in an ad hoc way).
+ // Calculate the working directory path unless this is the root scope
+ // (handled in an ad hoc way).
//
if (p != nullptr)
- {
const_cast<dir_path&> (*work_dir.path) =
dir_path (*p->work_dir.path) /= id;
-
- // Note that we could probably keep the test programs sets fully
- // independent across the scopes and check if the program is a test
- // by traversing the scopes upwards recursively. Note though, that
- // the parent scope's set cannot change during the nested scope
- // lifetime and normally contains just a single entry. Thus, it
- // seems more efficient to get rid of the recursion by copying the
- // set from the parent now and potentially changing it later on the
- // test variable assignment, etc.
- //
- test_programs_ = p->test_programs_;
- }
}
bool scope::
test_program (const path& p)
{
- assert (!test_programs_.empty ());
+ assert (!test_programs.empty ());
- return find_if (test_programs_.begin (), test_programs_.end (),
+ return find_if (test_programs.begin (), test_programs.end (),
[&p] (const path* tp)
{
return tp != nullptr ? *tp == p : false;
- }) != test_programs_.end ();
+ }) != test_programs.end ();
}
void scope::
@@ -319,7 +306,7 @@ namespace build2
// variable. Note that the value will be assigned by the below
// reset_special() call.
//
- test_programs_.push_back (nullptr);
+ test_programs.push_back (nullptr);
// Set the special $*, $N variables.
//
@@ -430,7 +417,7 @@ namespace build2
const path& p (cast<path> (l));
s.push_back (p.representation ());
- test_programs_[0] = &p;
+ test_programs[0] = &p;
if (auto l = lookup (root.options_var))
append (cast<strings> (l));
@@ -439,7 +426,7 @@ namespace build2
append (cast<strings> (l));
}
else
- test_programs_[0] = nullptr;
+ test_programs[0] = nullptr;
// Keep redirects/cleanups out of $N.
//
diff --git a/libbuild2/test/script/script.hxx b/libbuild2/test/script/script.hxx
index 53e4329..ea1f579 100644
--- a/libbuild2/test/script/script.hxx
+++ b/libbuild2/test/script/script.hxx
@@ -95,6 +95,15 @@ namespace build2
scope_state state = scope_state::unknown;
+ // Test program paths.
+ //
+ // Currently always contains a single element (see test_program() for
+ // details). While in the future there can be more of them, the zero
+ // index will always refer to the test variable value and can
+ // potentially be NULL (see reset_special() for details).
+ //
+ small_vector<const path*, 1> test_programs;
+
void
set_variable (string&& name,
names&&,
@@ -174,15 +183,6 @@ namespace build2
location end_loc_;
optional<line> if_cond_;
-
- // Test program paths.
- //
- // Currently always contains a single element (see test_program() for
- // details). While in the future there can be more of them, the zero
- // index will always refer to the test variable value and can
- // potentially be NULL (see reset_special() for details).
- //
- small_vector<const path*, 1> test_programs_;
};
// group
diff --git a/tests/test/script/runner/test-runner.testscript b/tests/test/script/runner/test-runner.testscript
index 772fa1b..372330b 100644
--- a/tests/test/script/runner/test-runner.testscript
+++ b/tests/test/script/runner/test-runner.testscript
@@ -22,10 +22,36 @@ run=$~/run
: basic
:
-$c <<"EOI" && $b "config.test.runner=$run --trace"
- cat <'text' >'text'; # Non-test program.
- \$* -o 'text' >>~%EOO% # Test program.
+$c <<EOI && $b "config.test.runner=$run --trace"
+ +cat <'text' >'text' # Non-test program.
+
+ +$* -o 'text' >>~%EOO% # Test program.
%.+/driver -o text%
text
EOO
+
+ {
+ prog = $0
+ test=cat
+
+ +cat <'text' >>EOO # Test program.
+ cat
+ text
+ EOO
+
+ +$prog -o 'text' >>~%EOO% # Non-test program.
+ text
+ EOO
+
+ test=$prog
+
+ {
+ cat <'text' >'text'; # Non-test program.
+
+ $* -o 'text' >>~%EOO% # Test program.
+ %.+/driver -o text%
+ text
+ EOO
+ }
+ }
EOI