aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/test/script
diff options
context:
space:
mode:
Diffstat (limited to 'libbuild2/test/script')
-rw-r--r--libbuild2/test/script/builtin.cxx6
-rw-r--r--libbuild2/test/script/parser.cxx2
-rw-r--r--libbuild2/test/script/parser.hxx4
-rw-r--r--libbuild2/test/script/parser.test.cxx30
-rw-r--r--libbuild2/test/script/runner.cxx28
-rw-r--r--libbuild2/test/script/script.cxx46
-rw-r--r--libbuild2/test/script/script.hxx19
7 files changed, 70 insertions, 65 deletions
diff --git a/libbuild2/test/script/builtin.cxx b/libbuild2/test/script/builtin.cxx
index ae979da..a725e17 100644
--- a/libbuild2/test/script/builtin.cxx
+++ b/libbuild2/test/script/builtin.cxx
@@ -956,7 +956,7 @@ namespace build2
auto mv = [ops, &wd, &sp, &error] (const path& from, const path& to)
{
- const dir_path& rwd (sp.root->wd_path);
+ const dir_path& rwd (sp.root.wd_path);
if (!from.sub (rwd) && !ops.force ())
error () << "'" << from << "' is out of working directory '"
@@ -1158,7 +1158,7 @@ namespace build2
error () << "missing file";
const dir_path& wd (sp.wd_path);
- const dir_path& rwd (sp.root->wd_path);
+ const dir_path& rwd (sp.root.wd_path);
while (scan.more ())
{
@@ -1259,7 +1259,7 @@ namespace build2
error () << "missing directory";
const dir_path& wd (sp.wd_path);
- const dir_path& rwd (sp.root->wd_path);
+ const dir_path& rwd (sp.root.wd_path);
while (scan.more ())
{
diff --git a/libbuild2/test/script/parser.cxx b/libbuild2/test/script/parser.cxx
index 260bc88..a4aeff2 100644
--- a/libbuild2/test/script/parser.cxx
+++ b/libbuild2/test/script/parser.cxx
@@ -2866,7 +2866,7 @@ namespace build2
{
try
{
- parser p;
+ parser p (scr.test_target.ctx);
p.execute (s, scr, r);
}
catch (const failed&)
diff --git a/libbuild2/test/script/parser.hxx b/libbuild2/test/script/parser.hxx
index 1beee49..e4d1f3a 100644
--- a/libbuild2/test/script/parser.hxx
+++ b/libbuild2/test/script/parser.hxx
@@ -16,6 +16,8 @@
namespace build2
{
+ class context;
+
namespace test
{
namespace script
@@ -28,6 +30,8 @@ namespace build2
// Pre-parse. Issue diagnostics and throw failed in case of an error.
//
public:
+ parser (context& c): build2::parser (c) {}
+
void
pre_parse (script&);
diff --git a/libbuild2/test/script/parser.test.cxx b/libbuild2/test/script/parser.test.cxx
index ab1f295..e45674b 100644
--- a/libbuild2/test/script/parser.test.cxx
+++ b/libbuild2/test/script/parser.test.cxx
@@ -9,7 +9,7 @@
#include <libbuild2/utility.hxx>
#include <libbuild2/target.hxx>
-#include <libbuild2/context.hxx> // reset()
+#include <libbuild2/context.hxx>
#include <libbuild2/scheduler.hxx>
#include <libbuild2/test/target.hxx>
@@ -156,7 +156,7 @@ namespace build2
init_diag (1);
init (nullptr, argv[0]);
sched.startup (1); // Serial execution.
- reset (strings ()); // No command line variables.
+ context ctx (sched);
bool scope (false);
bool id (false);
@@ -195,32 +195,32 @@ namespace build2
// really care.
//
file& tt (
- targets.insert<file> (work,
- dir_path (),
- "driver",
- string (),
- trace));
+ ctx.targets.insert<file> (work,
+ dir_path (),
+ "driver",
+ string (),
+ trace));
value& v (
tt.assign (
- var_pool.rw ().insert<target_triplet> (
+ ctx.var_pool.rw ().insert<target_triplet> (
"test.target", variable_visibility::project)));
- v = cast<target_triplet> ((*global_scope)["build.host"]);
+ v = cast<target_triplet> (ctx.global_scope["build.host"]);
testscript& st (
- targets.insert<testscript> (work,
- dir_path (),
- name.leaf ().base ().string (),
- name.leaf ().extension (),
- trace));
+ ctx.targets.insert<testscript> (work,
+ dir_path (),
+ name.leaf ().base ().string (),
+ name.leaf ().extension (),
+ trace));
tt.path (path ("driver"));
st.path (name);
// Parse and run.
//
- parser p;
+ parser p (ctx);
script s (tt, st, dir_path (work) /= "test-driver");
p.pre_parse (cin, s);
diff --git a/libbuild2/test/script/runner.cxx b/libbuild2/test/script/runner.cxx
index f0c089b..c27ad39 100644
--- a/libbuild2/test/script/runner.cxx
+++ b/libbuild2/test/script/runner.cxx
@@ -299,7 +299,7 @@ namespace build2
else
{
eop = path (op + ".orig");
- save (eop, transform (rd.str, false, rd.modifiers, *sp.root), ll);
+ save (eop, transform (rd.str, false, rd.modifiers, sp.root), ll);
sp.clean_special (eop);
}
@@ -312,7 +312,7 @@ namespace build2
// Ignore Windows newline fluff if that's what we are running on.
//
- if (test_target (*sp.root).class_ == "windows")
+ if (test_target (sp.root).class_ == "windows")
args.push_back ("--strip-trailing-cr");
args.push_back (eop.string ().c_str ());
@@ -451,14 +451,14 @@ namespace build2
if (l.regex) // Regex (possibly empty),
{
r += rl.intro;
- r += transform (l.value, true, rd.modifiers, *sp.root);
+ r += transform (l.value, true, rd.modifiers, sp.root);
r += rl.intro;
r += l.flags;
}
else if (!l.special.empty ()) // Special literal.
r += rl.intro;
else // Textual literal.
- r += transform (l.value, false, rd.modifiers, *sp.root);
+ r += transform (l.value, false, rd.modifiers, sp.root);
r += l.special;
return r;
@@ -534,7 +534,7 @@ namespace build2
{
try
{
- string s (transform (l.value, true, rd.modifiers, *sp.root));
+ string s (transform (l.value, true, rd.modifiers, sp.root));
c = line_char (
char_regex (s, gf | parse_flags (l.flags)), pool);
@@ -571,7 +571,7 @@ namespace build2
// Append literal line char.
//
rls += line_char (
- transform (l.value, false, rd.modifiers, *sp.root), pool);
+ transform (l.value, false, rd.modifiers, sp.root), pool);
}
for (char c: l.special)
@@ -693,7 +693,7 @@ namespace build2
bool default_runner::
test (scope& s) const
{
- return common_.test (s.root->test_target, s.id_path);
+ return common_.test (s.root.test_target, s.id_path);
}
void default_runner::
@@ -724,7 +724,7 @@ namespace build2
sp.parent == nullptr
? mkdir_buildignore (
sp.wd_path,
- sp.root->target_scope.root_scope ()->root_extra->buildignore_file,
+ sp.root.target_scope.root_scope ()->root_extra->buildignore_file,
2)
: mkdir (sp.wd_path, 2));
@@ -925,7 +925,7 @@ namespace build2
: (wd && sp.parent == nullptr
? rmdir_buildignore (
d,
- sp.root->target_scope.root_scope ()->root_extra->buildignore_file,
+ sp.root.target_scope.root_scope ()->root_extra->buildignore_file,
v)
: rmdir (d, v)));
@@ -1097,8 +1097,8 @@ namespace build2
// locking as the variable pool is an associative container
// (underneath) and we are only adding new variables into it.
//
- ulock ul (sp.root->var_pool_mutex);
- const variable& var (sp.root->var_pool.insert (move (vname)));
+ ulock ul (sp.root.var_pool_mutex);
+ const variable& var (sp.root.var_pool.insert (move (vname)));
ul.unlock ();
value& lhs (sp.assign (var));
@@ -1123,7 +1123,7 @@ namespace build2
dr << info (ll) << "while parsing attributes '" << *ats << "'";
});
- parser p;
+ parser p (sp.root.test_target.ctx);
p.apply_value_attributes (&var,
lhs,
value (move (ns)),
@@ -1175,7 +1175,7 @@ namespace build2
const string& ls (np.leaf ().string ());
bool wc (ls == "*" || ls == "**" || ls == "***");
const path& cp (wc ? np.directory () : np);
- const dir_path& wd (sp.root->wd_path);
+ const dir_path& wd (sp.root.wd_path);
if (!cp.sub (wd))
fail (ll) << (wc
@@ -1360,7 +1360,7 @@ namespace build2
isp = std_path ("stdin");
save (
- isp, transform (in.str, false, in.modifiers, *sp.root), ll);
+ isp, transform (in.str, false, in.modifiers, sp.root), ll);
sp.clean_special (isp);
diff --git a/libbuild2/test/script/script.cxx b/libbuild2/test/script/script.cxx
index b879eb4..af9ba82 100644
--- a/libbuild2/test/script/script.cxx
+++ b/libbuild2/test/script/script.cxx
@@ -418,12 +418,12 @@ namespace build2
// scope
//
scope::
- scope (const string& id, scope* p, script* r)
+ scope (const string& id, scope* p, script& r)
: parent (p),
root (r),
- vars (false /* global */),
- id_path (cast<path> (assign (root->id_var) = path ())),
- wd_path (cast<dir_path> (assign (root->wd_var) = dir_path ()))
+ vars (r.test_target.ctx, false /* global */),
+ id_path (cast<path> (assign (root.id_var) = path ())),
+ wd_path (cast<dir_path> (assign (root.wd_var) = dir_path ()))
{
// Construct the id_path as a string to ensure POSIX form. In fact,
@@ -455,7 +455,7 @@ namespace build2
assert (!implicit || c.type == cleanup_type::always);
const path& p (c.path);
- if (!p.sub (root->wd_path))
+ if (!p.sub (root.wd_path))
{
if (implicit)
return;
@@ -481,8 +481,11 @@ namespace build2
// script_base
//
script_base::
- script_base ()
- : // Enter the test.* variables with the same variable types as in
+ script_base (const target& tt, const testscript& st)
+ : test_target (tt),
+ target_scope (tt.base_scope ()),
+ script_target (st),
+ // Enter the test.* variables with the same variable types as in
// buildfiles except for test: while in buildfiles it can be a
// target name, in testscripts it should be resolved to a path.
//
@@ -515,10 +518,8 @@ namespace build2
script (const target& tt,
const testscript& st,
const dir_path& rwd)
- : group (st.name == "testscript" ? string () : st.name, this),
- test_target (tt),
- target_scope (tt.base_scope ()),
- script_target (st)
+ : script_base (tt, st),
+ group (st.name == "testscript" ? string () : st.name, *this)
{
// 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').
@@ -634,12 +635,11 @@ namespace build2
// in parallel). Plus, if there is no such variable, then we cannot
// possibly find any value.
//
- const variable* pvar (build2::var_pool.find (n));
+ const variable* pvar (root.test_target.ctx.var_pool.find (n));
if (pvar == nullptr)
return lookup ();
- const script& s (static_cast<const script&> (*root));
const variable& var (*pvar);
// First check the target we are testing.
@@ -649,12 +649,12 @@ namespace build2
// value. In this case, presumably the override also affects the
// script target and we will pick it up there. A bit fuzzy.
//
- auto p (s.test_target.find_original (var, target_only));
+ auto p (root.test_target.find_original (var, target_only));
if (p.first)
{
if (var.overrides != nullptr)
- p = s.target_scope.find_override (var, move (p), true);
+ p = root.target_scope.find_override (var, move (p), true);
return p.first;
}
@@ -665,7 +665,7 @@ namespace build2
// in different scopes which brings the question of which scopes we
// should search.
//
- return s.script_target[var];
+ return root.script_target[var];
}
value& scope::
@@ -696,30 +696,30 @@ namespace build2
s.insert (s.end (), v.begin (), v.end ());
};
- if (lookup l = find (root->test_var))
+ if (lookup l = find (root.test_var))
s.push_back (cast<path> (l).representation ());
- if (lookup l = find (root->options_var))
+ if (lookup l = find (root.options_var))
append (cast<strings> (l));
- if (lookup l = find (root->arguments_var))
+ if (lookup l = find (root.arguments_var))
append (cast<strings> (l));
// Keep redirects/cleanups out of $N.
//
size_t n (s.size ());
- if (lookup l = find (root->redirects_var))
+ if (lookup l = find (root.redirects_var))
append (cast<strings> (l));
- if (lookup l = find (root->cleanups_var))
+ if (lookup l = find (root.cleanups_var))
append (cast<strings> (l));
// Set the $N values if present.
//
for (size_t i (0); i <= 9; ++i)
{
- value& v (assign (*root->cmdN_var[i]));
+ value& v (assign (*root.cmdN_var[i]));
if (i < n)
{
@@ -734,7 +734,7 @@ namespace build2
// Set $*.
//
- assign (root->cmd_var) = move (s);
+ assign (root.cmd_var) = move (s);
}
}
}
diff --git a/libbuild2/test/script/script.hxx b/libbuild2/test/script/script.hxx
index e3f8251..8b34be8 100644
--- a/libbuild2/test/script/script.hxx
+++ b/libbuild2/test/script/script.hxx
@@ -343,7 +343,7 @@ namespace build2
{
public:
scope* const parent; // NULL for the root (script) scope.
- script* const root; // Self for the root (script) scope.
+ script& root; // Self for the root (script) scope.
// The chain of if-else scope alternatives. See also if_cond_ below.
//
@@ -424,7 +424,7 @@ namespace build2
~scope () = default;
protected:
- scope (const string& id, scope* parent, script* root);
+ scope (const string& id, scope* parent, script& root);
// Pre-parse data.
//
@@ -452,7 +452,7 @@ namespace build2
group (const string& id, group& p): scope (id, &p, p.root) {}
protected:
- group (const string& id, script* r): scope (id, nullptr, r) {}
+ group (const string& id, script& r): scope (id, nullptr, r) {}
// Pre-parse data.
//
@@ -505,7 +505,13 @@ namespace build2
class script_base // Make sure certain things are initialized early.
{
protected:
- script_base ();
+ script_base (const target& test_target,
+ const testscript& script_target);
+
+ public:
+ const target& test_target; // Target we are testing.
+ const build2::scope& target_scope; // Base scope of test target.
+ const testscript& script_target; // Target of the testscript file.
public:
variable_pool var_pool;
@@ -535,11 +541,6 @@ namespace build2
script& operator= (script&&) = delete;
script& operator= (const script&) = delete;
- public:
- const target& test_target; // Target we are testing.
- const build2::scope& target_scope; // Base scope of test target.
- const testscript& script_target; // Target of the testscript file.
-
// Pre-parse data.
//
private: