From 28d1791e2dc66cc610468deb29ea030e28d0793c Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 13 Sep 2019 20:47:58 +0300 Subject: Add support for testscript builtin escaping --- doc/testscript.cli | 7 +++++++ libbuild2/test/script/runner.cxx | 27 +++++++++++++++++++++++---- tests/test/script/runner/expr.testscript | 20 ++++++++++++++++++++ 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 +\ + \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 <=f; + x + + + y + EOF + + ^cat --squeeze-blank f >>EOO + x + + y + EOO + EOI +} -- cgit v1.1