From b3e6cb1b899dcc6b3488f10d8eee437a6f87ad15 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 27 Oct 2016 18:08:12 +0300 Subject: Add support of merge redirect to testscript runner --- build2/test/script/runner.cxx | 64 ++++++++++------ tests/test/script/runner/buildfile | 2 +- tests/test/script/runner/redirect.test | 134 +++++++++++++++++++++++++++++++++ tests/test/script/runner/status.test | 9 +++ tests/test/script/runner/testscript | 117 ---------------------------- 5 files changed, 186 insertions(+), 140 deletions(-) create mode 100644 tests/test/script/runner/redirect.test create mode 100644 tests/test/script/runner/status.test delete mode 100644 tests/test/script/runner/testscript 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/redirect.test b/tests/test/script/runner/redirect.test new file mode 100644 index 0000000..a49cd3c --- /dev/null +++ b/tests/test/script/runner/redirect.test @@ -0,0 +1,134 @@ +# file : tests/test/script/runner/redirect.test +# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +$* -o foo >- # out-null +$* -e foo 2>- # err-null +$* -i 0 foo # out-str +$* -e foo 2>foo # err-str +$* -i 1 foo # inout-str +$* -i 2 foo # inerr-str +$* -i 1 -e bar foo 2>bar # inout-err-str + +$* -i 0 <>EOO # out-doc +foo +bar +EOO + +$* -e foo -e bar 2>>EOO # err-doc +foo +bar +EOO + +$* -i 1 <>EOO # inout-doc +foo +bar +EOI +foo +bar +EOO + +$* -i 2 <>EOE # inerr-doc +foo +bar +EOI +foo +bar +EOE + +$* -i 1 -e bar -e baz -s 2 <>EOO 2>>EOE == 2 # inout-err-doc-status +foo +bar +EOI +foo +bar +EOO +bar +baz +EOE + +$* -i 1 -e "" <>EOO 2>"" # empty-str-doc +EOI +EOO + +$* -i 1 <>EOO # nl-containing-doc + +EOI + +EOO + +# No-newline tests. +# +# @@ TMP Need does not compare test. +# +$* -i 1 <:"foo" >:"foo" # no-newline-str +#\ +$* -i 1 <:"foo" >!"foo" # no-newline-str-fail1 +$* -i 1 <"foo" >:!"foo" # no-newline-str-fail2 +#\ + +$* -i 1 <<:EOI >>:EOO # no-newline-doc +foo +EOI +foo +EOO + +#\ +$* -i 1 <<:EOI >>!EOO # no-newline-doc-fail1 +foo +EOI +foo +EOO + +$* -i 1 <>:!EOO # no-newline-doc-fail2 +foo +EOI +foo +EOO +#\ + +$* -i 1 <<:EOI >>:EOO 2>:"" # no-newline-empty-str-doc +EOI +EOO + +$* -i 1 <<:EOI >>:EOO # no-newline-nl-cont-doc + +EOI + +EOO + +$* -o foo >>>out; # file +$* -e bar 2>>>&out; +$* -i 1 <<>EOO +foo +bar +EOO + +$* -o foo -e bar 2>>EOE 1>&2 # merge-str +foo +bar +EOE + +$* -i 1 <>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 <<>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 diff --git a/tests/test/script/runner/testscript b/tests/test/script/runner/testscript deleted file mode 100644 index c95ed07..0000000 --- a/tests/test/script/runner/testscript +++ /dev/null @@ -1,117 +0,0 @@ -# file : tests/test/script/runner/testscript -# 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 # out-str -$* -e foo 2>foo # err-str -$* -i 1 foo # inout-str -$* -i 2 foo # inerr-str -$* -i 1 -e bar foo 2>bar # inout-err-str - -$* -i 0 <>EOO # out-doc -foo -bar -EOO - -$* -e foo -e bar 2>>EOO # err-doc -foo -bar -EOO - -$* -i 1 <>EOO # inout-doc -foo -bar -EOI -foo -bar -EOO - -$* -i 2 <>EOE # inerr-doc -foo -bar -EOI -foo -bar -EOE - -$* -i 1 -e bar -e baz -s 2 <>EOO 2>>EOE == 2 # inout-err-doc-status -foo -bar -EOI -foo -bar -EOO -bar -baz -EOE - -$* -i 1 -e "" <>EOO 2>"" # empty-str-doc -EOI -EOO - -$* -i 1 <>EOO # nl-containing-doc - -EOI - -EOO - -# No-newline tests. -# -# @@ TMP Need does not compare test. -# -$* -i 1 <:"foo" >:"foo" # no-newline-str -#\ -$* -i 1 <:"foo" >!"foo" # no-newline-str-fail1 -$* -i 1 <"foo" >:!"foo" # no-newline-str-fail2 -#\ - -$* -i 1 <<:EOI >>:EOO # no-newline-doc -foo -EOI -foo -EOO - -#\ -$* -i 1 <<:EOI >>!EOO # no-newline-doc-fail1 -foo -EOI -foo -EOO - -$* -i 1 <>:!EOO # no-newline-doc-fail2 -foo -EOI -foo -EOO -#\ - -$* -i 1 <<:EOI >>:EOO 2>:"" # no-newline-empty-str-doc -EOI -EOO - -$* -i 1 <<:EOI >>:EOO # no-newline-nl-cont-doc - -EOI - -EOO - -$* -o foo >>>out; # file-redirect -$* -e bar 2>>>&out; -$* -i 1 <<>EOO -foo -bar -EOO -- cgit v1.1