aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-10-21 11:52:58 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-11-04 09:26:34 +0200
commit6cf30885f0d91da534871f2e6ddeca7a8a52b415 (patch)
tree75c2b28f1506e1025c9349b4a3f99e62ab6c41c0
parent096b10b96162eca90958af42e24520e2bc728494 (diff)
Pass command index, location to test runner
-rw-r--r--build2/test/script/parser4
-rw-r--r--build2/test/script/parser.cxx22
-rw-r--r--build2/test/script/runner15
-rw-r--r--build2/test/script/runner.cxx2
-rw-r--r--unit-tests/test/script/parser/driver.cxx2
5 files changed, 30 insertions, 15 deletions
diff --git a/build2/test/script/parser b/build2/test/script/parser
index 1292738..df79cf6 100644
--- a/build2/test/script/parser
+++ b/build2/test/script/parser
@@ -58,13 +58,13 @@ namespace build2
pre_parse_script_line (token&, token_type&);
void
- parse_script_line (token&, token_type&, line_type);
+ parse_script_line (token&, token_type&, line_type, size_t);
void
parse_variable_line (token&, token_type&);
void
- parse_test_line (token&, token_type&);
+ parse_test_line (token&, token_type&, size_t);
command_exit
parse_command_exit (token&, token_type&);
diff --git a/build2/test/script/parser.cxx b/build2/test/script/parser.cxx
index 7377e88..756761f 100644
--- a/build2/test/script/parser.cxx
+++ b/build2/test/script/parser.cxx
@@ -124,8 +124,10 @@ namespace build2
token t;
type tt;
- for (line& l: ls)
+ for (size_t i (0), n (ls.size ()); i != n; ++i)
{
+ line& l (ls[i]);
+
replay_data (move (l.tokens)); // Set the tokens and start playing.
// We don't really need the assign mode since we already know the
@@ -133,7 +135,7 @@ namespace build2
//
next (t, tt);
- parse_script_line (t, tt, l.type);
+ parse_script_line (t, tt, l.type, n == 1 ? 0 : i + 1);
assert (tt == type::newline);
replay_stop (); // Stop playing.
@@ -192,17 +194,17 @@ namespace build2
}
}
- parse_test_line (t, tt);
+ parse_test_line (t, tt, 0);
return line_type::test;
}
void parser::
- parse_script_line (token& t, type& tt, line_type lt)
+ parse_script_line (token& t, type& tt, line_type lt, size_t li)
{
switch (lt)
{
- case line_type::variable: parse_variable_line (t, tt); break;
- case line_type::test: parse_test_line (t, tt); break;
+ case line_type::variable: parse_variable_line (t, tt); break;
+ case line_type::test: parse_test_line (t, tt, li); break;
}
}
@@ -286,7 +288,7 @@ namespace build2
}
void parser::
- parse_test_line (token& t, type& tt)
+ parse_test_line (token& t, type& tt, size_t li)
{
command c;
@@ -477,10 +479,12 @@ namespace build2
}
};
+ const location ll (get_location (t)); // Line location.
+
// Keep parsing chunks of the command line until we see the newline or
// the exit status comparison.
//
- location l (get_location (t));
+ location l (ll);
names ns; // Reuse to reduce allocations.
for (bool done (false); !done; l = get_location (t))
@@ -736,7 +740,7 @@ namespace build2
// Now that we have all the pieces, run the command.
//
if (!pre_parse_)
- runner_->run (c);
+ runner_->run (c, li, ll);
}
command_exit parser::
diff --git a/build2/test/script/runner b/build2/test/script/runner
index 5581039..57e506f 100644
--- a/build2/test/script/runner
+++ b/build2/test/script/runner
@@ -8,6 +8,8 @@
#include <build2/types>
#include <build2/utility>
+#include <build2/diagnostics> // location
+
#include <build2/test/script/script>
namespace build2
@@ -19,15 +21,24 @@ namespace build2
class runner
{
public:
+
+ // Index is the 1-base index of this command in the command list
+ // (e.g., in a compound test). If it is 0 then it means there is only
+ // one command (e.g., a simple test). This information can be used,
+ // for example, to derive file names.
+ //
+ // Location is the start position of this command in the testscript.
+ // It can be used in diagnostics.
+ //
virtual void
- run (const command&) = 0;
+ run (const command&, size_t index, const location&) = 0;
};
class concurrent_runner: public runner
{
public:
virtual void
- run (const command&) override;
+ run (const command&, size_t, const location&) override;
};
}
}
diff --git a/build2/test/script/runner.cxx b/build2/test/script/runner.cxx
index c547136..01c9f4f 100644
--- a/build2/test/script/runner.cxx
+++ b/build2/test/script/runner.cxx
@@ -244,7 +244,7 @@ namespace build2
}
void concurrent_runner::
- run (const command& c)
+ run (const command& c, size_t ci, const location& cl)
{
if (verb >= 3)
{
diff --git a/unit-tests/test/script/parser/driver.cxx b/unit-tests/test/script/parser/driver.cxx
index 1703f47..148a081 100644
--- a/unit-tests/test/script/parser/driver.cxx
+++ b/unit-tests/test/script/parser/driver.cxx
@@ -29,7 +29,7 @@ namespace build2
{
public:
virtual void
- run (const command& t) override
+ run (const command& t, size_t, const location&) override
{
// Here we assume we are running serially.
//