From 4230333bc5b32d30e35264b1104240bb5e2247ff Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 16 Oct 2016 13:29:57 +0200 Subject: Implement testscript $*, $NN, $~ special variables --- build2/test/script/script.cxx | 49 +++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 18 deletions(-) (limited to 'build2/test/script/script.cxx') diff --git a/build2/test/script/script.cxx b/build2/test/script/script.cxx index b206e4f..2be023d 100644 --- a/build2/test/script/script.cxx +++ b/build2/test/script/script.cxx @@ -15,32 +15,45 @@ namespace build2 namespace script { script:: - script (target& tt, target& st) - : test_target (tt), script_target (st) + script (target& tt, testscript& st) + : test_target (tt), script_target (st), + + // Enter the test* variables with the same variable types as in + // buildfiles. + // + test_var (var_pool.insert ("test")), + opts_var (var_pool.insert ("test.options")), + args_var (var_pool.insert ("test.arguments")), + + cmd_var (var_pool.insert ("*")), + cwd_var (var_pool.insert ("~")) { // 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. // + if (!find (test_var)) { - // Note: use the same variable type as in buildfile. + value& v (assign (test_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. // - const variable& var (var_pool.insert ("test")); + if (auto* p = tt.is_a ()) + v = p->path (); + else if (tt.is_a ()) + v = path (tt.dir.string ()); // Strip trailing slash. + } - if (!find (var)) - { - value& v (assign (var)); + // Also add the NULL $* value that signals it needs to be recalculated + // on first access. + // + assign (cmd_var) = nullptr; - // 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. - } - } + // Set the script CWD ($~) which is the $out_base/. + // + assign (cwd_var) = dir_path (tt.out_dir ()) /= st.name; } lookup scope:: -- cgit v1.1