From e6932f85e8b20876f66968b31f84488eee31153d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 15 Oct 2016 19:30:14 +0200 Subject: Set test variable for testscript, improve test rule --- build2/test/script/script | 3 +-- build2/test/script/script.cxx | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) (limited to 'build2/test/script') diff --git a/build2/test/script/script b/build2/test/script/script index cda4feb..f5e5ef0 100644 --- a/build2/test/script/script +++ b/build2/test/script/script @@ -60,8 +60,7 @@ namespace build2 class script { public: - script (target& tt, target& st) - : test_target (tt), script_target (st) {} + script (target& test_target, target& script_target); public: target& test_target; // Target we are testing. diff --git a/build2/test/script/script.cxx b/build2/test/script/script.cxx index 706c87d..1b47846 100644 --- a/build2/test/script/script.cxx +++ b/build2/test/script/script.cxx @@ -14,6 +14,35 @@ namespace build2 { namespace script { + script:: + script (target& tt, target& st) + : test_target (tt), script_target (st) + { + // Unless we have the test variable set on the test or script target, + // set it at the script level to the test target's path. + // + { + // Note: use the same variable type as in buildfile. + // + const variable& var (var_pool.insert ("test")); + + if (!find (var)) + { + value& v (assign (var)); + + // If this is a path-based target, then we use the path. If this + // is a directory (alias) target, then we use the directory path. + // Otherwise, we leave it NULL expecting the testscript to set it + // to something appropriate, if used. + // + if (auto* p = tt.is_a ()) + v = p->path (); + else if (tt.is_a ()) + v = path (tt.dir.string ()); // Strip trailing slash. + } + } + } + lookup script:: find (const variable& var) const { -- cgit v1.1