aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2016-10-27 18:08:12 +0300
committerBoris Kolpackov <boris@codesynthesis.com>2016-11-04 09:26:36 +0200
commitb3e6cb1b899dcc6b3488f10d8eee437a6f87ad15 (patch)
treeecc0a77c4fe0c823b4a4960c626ba4835c46e20d
parent94f807424dbf1ed7c33ba7826f1b19b49c413b63 (diff)
Add support of merge redirect to testscript runner
-rw-r--r--build2/test/script/runner.cxx64
-rw-r--r--tests/test/script/runner/buildfile2
-rw-r--r--tests/test/script/runner/redirect.test (renamed from tests/test/script/runner/testscript)33
-rw-r--r--tests/test/script/runner/status.test9
4 files changed, 77 insertions, 31 deletions
diff --git a/build2/test/script/runner.cxx b/build2/test/script/runner.cxx
index eb6531d..79cbfc4 100644
--- a/build2/test/script/runner.cxx
+++ b/build2/test/script/runner.cxx
@@ -43,7 +43,8 @@ namespace build2
}
// Check if the test command output matches the expected result (redirect
- // value).
+ // value). Noop for redirect types other than none, here_string,
+ // here_document.
//
static void
check_output (const process_path& pr,
@@ -55,6 +56,8 @@ namespace build2
{
if (rd.type == redirect_type::none)
{
+ assert (!op.empty ());
+
// Check that there is no output produced.
//
if (non_empty (op, cl))
@@ -64,6 +67,8 @@ namespace build2
else if (rd.type == redirect_type::here_string ||
rd.type == redirect_type::here_document)
{
+ assert (!op.empty ());
+
path orp (op + ".orig");
try
@@ -291,6 +296,8 @@ namespace build2
in = si.fd ();
break;
}
+
+ case redirect_type::merge: assert (false); break;
}
// Dealing with stdout and stderr redirect types other than 'null'
@@ -311,37 +318,50 @@ namespace build2
// Open a file for command output redirect if requested explicitly
// (file redirect) or for the purpose of the output validation (none,
// here_string, here_document), register the file for cleanup, return
- // the file descriptor. Return the default and -2 file descriptors
- // for pass and null redirects respectively not opening a file.
+ // the file descriptor. Return the specified, default and -2 file
+ // descriptors for merge, pass and null redirects respectively not
+ // opening a file.
//
auto open = [&sp, &ci, &cl, &normalize] (const redirect& r,
- int fd,
+ int dfd,
path& p,
ofdstream& os) -> int
{
- assert (fd == 1 || fd == 2);
-
- if (r.type == redirect_type::pass || r.type == redirect_type::null)
- return r.type == redirect_type::pass ? fd : -2;
+ assert (dfd == 1 || dfd == 2);
ofdstream::openmode m (ofdstream::out);
- if (r.type == redirect_type::file)
- {
- p = normalize (r.file.path);
- if (r.file.append)
- m |= ofdstream::app;
- }
- else
+
+ switch (r.type)
{
- path op (fd == 1 ? "stdout" : "stderr");
+ case redirect_type::pass: return dfd;
+ case redirect_type::null: return -2;
+ case redirect_type::merge: return r.fd;
- // 0 if a single-command test, otherwise is the command number
- // (start from one) in the test.
- //
- if (ci > 0)
- op += "-" + to_string (ci);
+ case redirect_type::file:
+ {
+ p = normalize (r.file.path);
+
+ if (r.file.append)
+ m |= ofdstream::app;
+
+ break;
+ }
- p = normalize (move (op));
+ case redirect_type::none:
+ case redirect_type::here_string:
+ case redirect_type::here_document:
+ {
+ path op (dfd == 1 ? "stdout" : "stderr");
+
+ // 0 if belongs to a single-command test scope, otherwise is
+ // the command number (start from one) in the test scope.
+ //
+ if (ci > 0)
+ op += "-" + to_string (ci);
+
+ p = normalize (move (op));
+ break;
+ }
}
try
diff --git a/tests/test/script/runner/buildfile b/tests/test/script/runner/buildfile
index c91f940..ddab8a5 100644
--- a/tests/test/script/runner/buildfile
+++ b/tests/test/script/runner/buildfile
@@ -2,6 +2,6 @@
# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
# license : MIT; see accompanying LICENSE file
-exe{driver}: cxx{driver} test{testscript}
+exe{driver}: cxx{driver} test{redirect status}
include ../../../../../build2/
diff --git a/tests/test/script/runner/testscript b/tests/test/script/runner/redirect.test
index c95ed07..a49cd3c 100644
--- a/tests/test/script/runner/testscript
+++ b/tests/test/script/runner/redirect.test
@@ -1,13 +1,7 @@
-# file : tests/test/script/runner/testscript
+# file : tests/test/script/runner/redirect.test
# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
# license : MIT; see accompanying LICENSE file
-$* # status-def
-$* == 0 # status-eq-0
-$* -s 1 != 0 # status-ne-0
-$* -s 1 == 1 # status-eq-1
-$* != 1 # status-ne-1
-
$* -o foo >- # out-null
$* -e foo 2>- # err-null
$* -i 0 <foo # in-str
@@ -109,9 +103,32 @@ EOI
EOO
-$* -o foo >>>out; # file-redirect
+$* -o foo >>>out; # file
$* -e bar 2>>>&out;
$* -i 1 <<<out >>EOO
foo
bar
EOO
+
+$* -o foo -e bar 2>>EOE 1>&2 # merge-str
+foo
+bar
+EOE
+
+$* -i 1 <<EOI -e baz >>EOO 2>&1 # merge-doc
+foo
+bar
+EOI
+foo
+bar
+baz
+EOO
+
+$* -o foo -e bar 2>&1 >>>out; # merge-file
+$* -e baz -o biz 1>&2 2>>>&out;
+$* -i 1 <<<out >>EOO
+foo
+bar
+baz
+biz
+EOO
diff --git a/tests/test/script/runner/status.test b/tests/test/script/runner/status.test
new file mode 100644
index 0000000..5d4d116
--- /dev/null
+++ b/tests/test/script/runner/status.test
@@ -0,0 +1,9 @@
+# file : tests/test/script/runner/status.tests
+# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+$* # status-def
+$* == 0 # status-eq-0
+$* -s 1 != 0 # status-ne-0
+$* -s 1 == 1 # status-eq-1
+$* != 1 # status-ne-1