aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2017-03-16 15:55:04 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2017-03-16 15:59:16 +0300
commitd2b324a72fdf16fcd68e6ba7ca0280aa95de4b71 (patch)
tree08294a644e4e944280f561058248a332ac00874a
parent5f55069b5bd01f2d5c157fa360fda400da6ba01f (diff)
Add support for >! test command redirect
-rw-r--r--build2/test/script/lexer.cxx3
-rw-r--r--build2/test/script/parser.cxx10
-rw-r--r--build2/test/script/runner.cxx34
-rw-r--r--build2/test/script/script1
-rw-r--r--build2/test/script/script.cxx6
-rw-r--r--build2/test/script/token1
-rw-r--r--build2/test/script/token.cxx1
-rw-r--r--tests/test/script/runner/redirect.test47
-rw-r--r--unit-tests/test/script/lexer/command-expansion.test18
-rw-r--r--unit-tests/test/script/lexer/command-line.test9
-rw-r--r--unit-tests/test/script/parser/redirect.test9
11 files changed, 115 insertions, 24 deletions
diff --git a/build2/test/script/lexer.cxx b/build2/test/script/lexer.cxx
index d0d59aa..e060869 100644
--- a/build2/test/script/lexer.cxx
+++ b/build2/test/script/lexer.cxx
@@ -395,7 +395,7 @@ namespace build2
type r (type::out_str);
xchar p (peek ());
- if (p == '|' || p == '-' || p == '&' ||
+ if (p == '|' || p == '-' || p == '!' || p == '&' ||
p == '=' || p == '+' || p == '>')
{
get ();
@@ -404,6 +404,7 @@ namespace build2
{
case '|': return make_token (type::out_pass);
case '-': return make_token (type::out_null);
+ case '!': return make_token (type::out_trace);
case '&': return make_token (type::out_merge);
case '=': return make_token (type::out_file_ovr);
case '+': return make_token (type::out_file_app);
diff --git a/build2/test/script/parser.cxx b/build2/test/script/parser.cxx
index 5a33007..d004223 100644
--- a/build2/test/script/parser.cxx
+++ b/build2/test/script/parser.cxx
@@ -1702,6 +1702,7 @@ namespace build2
}
case type::out_pass:
case type::out_null:
+ case type::out_trace:
case type::out_merge:
case type::out_str:
case type::out_doc:
@@ -1727,6 +1728,8 @@ namespace build2
case type::in_null:
case type::out_null: rt = redirect_type::null; break;
+ case type::out_trace: rt = redirect_type::trace; break;
+
case type::out_merge: rt = redirect_type::merge; break;
case type::in_str:
@@ -1774,6 +1777,7 @@ namespace build2
case redirect_type::none:
case redirect_type::pass:
case redirect_type::null:
+ case redirect_type::trace:
break;
case redirect_type::merge:
switch (fd)
@@ -1903,6 +1907,8 @@ namespace build2
case type::in_null:
case type::out_null:
+ case type::out_trace:
+
case type::out_merge:
case type::in_str:
@@ -2075,6 +2081,8 @@ namespace build2
case type::in_null:
case type::out_null:
+ case type::out_trace:
+
case type::out_merge:
case type::in_str:
@@ -2356,6 +2364,8 @@ namespace build2
case type::in_null:
case type::out_null:
+ case type::out_trace:
+
case type::out_merge:
case type::in_str:
diff --git a/build2/test/script/runner.cxx b/build2/test/script/runner.cxx
index c7b8dab..464c1f9 100644
--- a/build2/test/script/runner.cxx
+++ b/build2/test/script/runner.cxx
@@ -853,23 +853,6 @@ namespace build2
//
// set [-e|--exact] [(-n|--newline)|(-w|--whitespace)] [<attr>] <var>
//
- // -e|--exact
- // Unless the option is specified, a single final newline is ignored
- // in the input.
- //
- // -n|--newline
- // Split the input into a list of elements at newlines, including a
- // final blank element in case of -e. Multiple consecutive newlines
- // are not collapsed.
- //
- // -w|--whitespace
- // Split the input into a list of elements at whitespaces, including a
- // final blank element in case of -e. Multiple consecutive whitespaces
- // (including newlines) are collapsed.
- //
- // If the attr argument is specified, then it must contain a list of
- // value attributes enclosed in [].
- //
static void
set_builtin (scope& sp,
const strings& args,
@@ -1223,6 +1206,7 @@ namespace build2
break;
}
+ case redirect_type::trace:
case redirect_type::merge:
case redirect_type::here_str_regex:
case redirect_type::here_doc_regex:
@@ -1267,9 +1251,11 @@ namespace build2
// Open a file for command output redirect if requested explicitly
// (file overwrite/append redirects) or for the purpose of the output
// validation (none, here_*, file comparison redirects), register the
- // file for cleanup, return the file descriptor. Return nullfd,
- // standard stream descriptor duplicate or null-device descriptor for
- // merge, pass or null redirects respectively (not opening any file).
+ // file for cleanup, return the file descriptor. Interpret trace
+ // redirect according to the verbosity level (as null if below 2, as
+ // pass otherwise). Return nullfd, standard stream descriptor duplicate
+ // or null-device descriptor for merge, pass or null redirects
+ // respectively (not opening any file).
//
auto open = [&sp, &ll, &std_path] (const redirect& r,
int dfd,
@@ -1281,7 +1267,12 @@ namespace build2
fdopen_mode m (fdopen_mode::out | fdopen_mode::create);
auto_fd fd;
- switch (r.type)
+ redirect_type rt (r.type != redirect_type::trace
+ ? r.type
+ : verb < 2
+ ? redirect_type::null
+ : redirect_type::pass);
+ switch (rt)
{
case redirect_type::pass:
{
@@ -1351,6 +1342,7 @@ namespace build2
break;
}
+ case redirect_type::trace:
case redirect_type::here_doc_ref: assert (false); break;
}
diff --git a/build2/test/script/script b/build2/test/script/script
index c238daf..9a54c71 100644
--- a/build2/test/script/script
+++ b/build2/test/script/script
@@ -69,6 +69,7 @@ namespace build2
none,
pass,
null,
+ trace,
merge,
here_str_literal,
here_str_regex,
diff --git a/build2/test/script/script.cxx b/build2/test/script/script.cxx
index 0fa9dc6..d4945fe 100644
--- a/build2/test/script/script.cxx
+++ b/build2/test/script/script.cxx
@@ -82,6 +82,7 @@ namespace build2
case redirect_type::none: assert (false); break;
case redirect_type::pass: o << '|'; break;
case redirect_type::null: o << '-'; break;
+ case redirect_type::trace: o << '!'; break;
case redirect_type::merge: o << '&' << r.fd; break;
case redirect_type::here_str_literal:
@@ -333,6 +334,7 @@ namespace build2
case redirect_type::none:
case redirect_type::pass:
case redirect_type::null:
+ case redirect_type::trace:
case redirect_type::merge: break;
case redirect_type::here_str_literal:
@@ -363,7 +365,8 @@ namespace build2
{
case redirect_type::none:
case redirect_type::pass:
- case redirect_type::null: break;
+ case redirect_type::null:
+ case redirect_type::trace: break;
case redirect_type::merge: fd = r.fd; break;
@@ -400,6 +403,7 @@ namespace build2
case redirect_type::none:
case redirect_type::pass:
case redirect_type::null:
+ case redirect_type::trace:
case redirect_type::merge: break;
case redirect_type::here_str_literal:
diff --git a/build2/test/script/token b/build2/test/script/token
index 6dc446f..9d3e330 100644
--- a/build2/test/script/token
+++ b/build2/test/script/token
@@ -42,6 +42,7 @@ namespace build2
out_pass, // >|
out_null, // >-
+ out_trace, // >!
out_merge, // >&
out_str, // >{:~} (modifiers in value)
out_doc, // >>{:~} (modifiers in value)
diff --git a/build2/test/script/token.cxx b/build2/test/script/token.cxx
index a4d658a..3d3dc8e 100644
--- a/build2/test/script/token.cxx
+++ b/build2/test/script/token.cxx
@@ -41,6 +41,7 @@ namespace build2
case token_type::out_pass: os << q << ">|" << q; break;
case token_type::out_null: os << q << ">-" << q; break;
+ case token_type::out_trace: os << q << ">!" << q; break;
case token_type::out_merge: os << q << ">&" << q; break;
case token_type::out_str: os << q << '>' << v << q; break;
case token_type::out_doc: os << q << ">>" << v << q; break;
diff --git a/tests/test/script/runner/redirect.test b/tests/test/script/runner/redirect.test
index 0535617..7c7fada 100644
--- a/tests/test/script/runner/redirect.test
+++ b/tests/test/script/runner/redirect.test
@@ -26,6 +26,53 @@ psr = ($cxx.target.class != 'windows' ? '/' : '\\') # Path separator in regex.
$c <'$* -e foo 2>-' && $b : err
}
+: trace
+:
+{
+ : default
+ :
+ $c <'$* -o foo -e bar >! 2>!' && $b
+
+ : verbose
+ :
+ {
+ b += -v
+
+ : out
+ :
+ $c <'$* -o foo >!' && $b >foo 2>>/~%EOE%
+ %test .+ with .+ on .+%
+ mkdir test/
+ cd test/
+ mkdir test/1/
+ cd test/1/
+ %.*/driver(.exe)? -o foo%
+ rm test/1/stderr
+ rm test/1/
+ cd test/
+ rm test/
+ cd ./
+ EOE
+
+ : err
+ :
+ $c <'$* -e foo 2>!' && $b 2>>/~%EOE%
+ %test .+ with .+ on .+%
+ mkdir test/
+ cd test/
+ mkdir test/1/
+ cd test/1/
+ %.*/driver(.exe)? -e foo%
+ foo
+ rm test/1/stdout
+ rm test/1/
+ cd test/
+ rm test/
+ cd ./
+ EOE
+ }
+}
+
: str
:
{
diff --git a/unit-tests/test/script/lexer/command-expansion.test b/unit-tests/test/script/lexer/command-expansion.test
index d405de6..ffbb944 100644
--- a/unit-tests/test/script/lexer/command-expansion.test
+++ b/unit-tests/test/script/lexer/command-expansion.test
@@ -68,6 +68,24 @@ test.arguments = command-expansion
EOO
}
+: trace-redirect
+:
+{
+ : out
+ :
+ $* <:"1>!" >>EOO
+ '1'
+ >!
+ EOO
+
+ : arg-out
+ :
+ $* <:"1 >!" >>EOO
+ '1 '
+ >!
+ EOO
+}
+
: merge-redirect
:
{
diff --git a/unit-tests/test/script/lexer/command-line.test b/unit-tests/test/script/lexer/command-line.test
index 57fcfdf..adc8cd1 100644
--- a/unit-tests/test/script/lexer/command-line.test
+++ b/unit-tests/test/script/lexer/command-line.test
@@ -82,6 +82,15 @@ test.arguments = command-line
<newline>
EOO
+ : trace
+ :
+ $* <"cmd 1>!" >>EOO
+ 'cmd'
+ '1'
+ >!
+ <newline>
+ EOO
+
: merge
:
$* <"cmd 1>&2" >>EOO
diff --git a/unit-tests/test/script/parser/redirect.test b/unit-tests/test/script/parser/redirect.test
index 2e53c4d..4fc3a9d 100644
--- a/unit-tests/test/script/parser/redirect.test
+++ b/unit-tests/test/script/parser/redirect.test
@@ -2,10 +2,17 @@
# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
# license : MIT; see accompanying LICENSE file
-# @@ Add tests for redirects other than file and merge.
+# @@ Add tests for redirects other than trace, here-*, file and merge.
# @@ Does it make sense to split into separate files - one per redirect type?
#
+: trace
+:
+{
+ $* <'cmd >!' >'cmd >!' : out
+ $* <'cmd 2>!' >'cmd 2>!' : err
+}
+
: str
:
{