aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2019-09-13 20:47:58 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2019-09-27 18:04:30 +0300
commit28d1791e2dc66cc610468deb29ea030e28d0793c (patch)
treece740bad52aa15506dfeed5075771d137c3234dd
parentdbed808c7d534069f76e63a1a68a85f30d2be81c (diff)
Add support for testscript builtin escaping
-rw-r--r--doc/testscript.cli7
-rw-r--r--libbuild2/test/script/runner.cxx27
-rw-r--r--tests/test/script/runner/expr.testscript20
3 files changed, 50 insertions, 4 deletions
diff --git a/doc/testscript.cli b/doc/testscript.cli
index 8b9509d..f51bf14 100644
--- a/doc/testscript.cli
+++ b/doc/testscript.cli
@@ -2232,6 +2232,13 @@ in option handling) and extensions, as described in this chapter. Note also
that the builtins are implemented in-process with some of the simple ones
such as \c{true/false}, \c{mkdir}, etc., being just function calls.
+To run a system utility instead of a builtin prefix its name with \c{^}, for
+example:
+
+\
+^cat --squeeze-blank <file>
+\
+
\h#builtins-cat|\c{cat}|
diff --git a/libbuild2/test/script/runner.cxx b/libbuild2/test/script/runner.cxx
index 630d4c2..554edd0 100644
--- a/libbuild2/test/script/runner.cxx
+++ b/libbuild2/test/script/runner.cxx
@@ -1865,7 +1865,9 @@ namespace build2
// Resolve the relative not simple program path against the scope's
// working directory. The simple one will be left for the process
- // path search machinery.
+ // path search machinery. Also strip the potential leading `^`,
+ // indicating that this is an external program rather than a
+ // builtin.
//
path p;
@@ -1873,10 +1875,25 @@ namespace build2
{
p = path (args[0]);
- if (p.relative () && !p.simple ())
+ if (p.relative ())
{
- p = sp.wd_path / p;
- args[0] = p.string ().c_str ();
+ auto program = [&p, &args] (path pp)
+ {
+ p = move (pp);
+ args[0] = p.string ().c_str ();
+ };
+
+ if (p.simple ())
+ {
+ const string& s (p.string ());
+
+ // Don't end up with an empty path.
+ //
+ if (s.size () > 1 && s[0] == '^')
+ program (path (s, 1, s.size () - 1));
+ }
+ else
+ program (sp.wd_path / p);
}
}
catch (const invalid_path& e)
@@ -1888,6 +1905,8 @@ namespace build2
{
process_path pp (process::path_search (args[0]));
+ // Note: the builtin-escaping character '^' is not printed.
+ //
if (verb >= 2)
print_process (args);
diff --git a/tests/test/script/runner/expr.testscript b/tests/test/script/runner/expr.testscript
index fd9c643..56747a4 100644
--- a/tests/test/script/runner/expr.testscript
+++ b/tests/test/script/runner/expr.testscript
@@ -522,3 +522,23 @@
info: test id: 1
EOE
}
+
+: escape-builtin
+:
+if ($cxx.target.class == 'linux')
+{
+ $c <<EOI && $b
+ cat <<EOF >=f;
+ x
+
+
+ y
+ EOF
+
+ ^cat --squeeze-blank f >>EOO
+ x
+
+ y
+ EOO
+ EOI
+}