aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2016-10-24 21:43:23 +0300
committerBoris Kolpackov <boris@codesynthesis.com>2016-11-04 09:26:35 +0200
commit56ce654f7e4608599369b303ed39eaddb0f77eee (patch)
tree85deb385c4353c198d6f2147348c0edbacdac0b7
parent79a83d6dd0f312a5e390f5627f68cc96c4427d33 (diff)
Fix printing no-newline here-doc and here-str
-rw-r--r--build2/test/script/parser.cxx2
-rw-r--r--build2/test/script/script.cxx32
-rw-r--r--tests/test/script/runner/driver.cxx3
-rw-r--r--tests/test/script/runner/testscript70
4 files changed, 74 insertions, 33 deletions
diff --git a/build2/test/script/parser.cxx b/build2/test/script/parser.cxx
index f8b414f..1231759 100644
--- a/build2/test/script/parser.cxx
+++ b/build2/test/script/parser.cxx
@@ -654,7 +654,7 @@ namespace build2
if (pre_parse_)
{
// The only thing we need to handle here are the here-document
- // end markers since we need to know how many of the to pre-
+ // end markers since we need to know how many of them to pre-
// parse after the command.
//
nn = false;
diff --git a/build2/test/script/script.cxx b/build2/test/script/script.cxx
index da9c83a..6f303d5 100644
--- a/build2/test/script/script.cxx
+++ b/build2/test/script/script.cxx
@@ -37,23 +37,29 @@ namespace build2
size_t n (string::traits_type::length (prefix));
assert (n > 0);
- //@@ TODO: we don't handle 'exact' (<: <<: etc). Could check for
- // lack of newline at the end of value. In fact, won't we write
- // here-end on the same line if <<:. Also will write newline at
- // the end of here-string in case of <.
- //
+ const string& v (r.value);
+ bool nl (!v.empty () && v.back () == '\n');
+
switch (r.type)
{
- case redirect_type::none: assert (false); break;
- case redirect_type::pass: o << '+'; break;
- case redirect_type::null: o << '-'; break;
- case redirect_type::here_string: to_stream_q (o, r.value); break;
+ case redirect_type::none: assert (false); break;
+ case redirect_type::pass: o << '+'; break;
+ case redirect_type::null: o << '-'; break;
+
+ case redirect_type::here_string:
+ {
+ if (!nl)
+ o << ':';
+
+ to_stream_q (o, nl ? string (v, 0, v.size () - 1) : v);
+ break;
+ }
case redirect_type::here_document:
{
// Add another '>' or '<'. Note that here end marker never
// needs to be quoted.
//
- o << prefix[n - 1] << r.here_end;
+ o << prefix[n - 1] << (nl ? "" : ":") << r.here_end;
break;
}
}
@@ -61,9 +67,9 @@ namespace build2
auto print_doc = [&o] (const redirect& r)
{
- // Here-document value always ends with a newline.
- //
- o << endl << r.value << r.here_end;
+ const string& v (r.value);
+ bool nl (!v.empty () && v.back () == '\n');
+ o << endl << v << (nl ? "" : "\n") << r.here_end;
};
if ((m & command_to_stream::header) == command_to_stream::header)
diff --git a/tests/test/script/runner/driver.cxx b/tests/test/script/runner/driver.cxx
index 940a68c..9eb36a0 100644
--- a/tests/test/script/runner/driver.cxx
+++ b/tests/test/script/runner/driver.cxx
@@ -6,6 +6,7 @@
#include <string>
#include <cassert>
#include <ostream> // endl, *bit
+#include <istream> // istream::traits_type::eof()
#include <iostream>
#include <exception>
@@ -50,7 +51,7 @@ main (int argc, char* argv[])
if (ifd == 0)
cin.ignore (numeric_limits<streamsize>::max ());
- else
+ else if (cin.peek () != istream::traits_type::eof ())
(ifd == 1 ? cout : cerr) << cin.rdbuf ();
}
else if (o == "-o")
diff --git a/tests/test/script/runner/testscript b/tests/test/script/runner/testscript
index 4d5d3b3..89ef6a3 100644
--- a/tests/test/script/runner/testscript
+++ b/tests/test/script/runner/testscript
@@ -1,31 +1,42 @@
-$*
-$* -i 0 <foo
-$* -o foo >foo
-$* -o foo >-
-$* -e foo 2>-
+$* # status-def
+$* == 0 # status-eq-0
+$* -s 1 != 0 # status-ne-0
+$* -s 1 == 1 # status-eq-1
+$* != 1 # status-ne-1
-$* -o foo -o bar >>EOO
+$* -o foo >- # out-null
+$* -e foo 2>- # err-null
+$* -i 0 <foo # in-str
+$* -o foo >foo # out-str
+$* -e foo 2>foo # err-str
+$* -i 1 <foo >foo # inout-str
+$* -i 2 <foo 2>foo # inerr-str
+$* -i 1 -e bar <foo 1>foo 2>bar # inout-err-str
+
+$* -i 0 <<EOO # in-doc
foo
bar
EOO
-$* -i 1 <<EOI >>EOO
+$* -o foo -o bar >>EOO # out-doc
foo
bar
-EOI
+EOO
+
+$* -e foo -e bar 2>>EOO # err-doc
foo
bar
EOO
-$* -i 2 <<EOI 2>>EOE
+$* -i 1 <<EOI >>EOO # inout-doc
foo
bar
EOI
foo
bar
-EOE
+EOO
-$* -i 2 -s 1 <<EOI 2>>EOE != 0
+$* -i 2 <<EOI 2>>EOE # inerr-doc
foo
bar
EOI
@@ -33,40 +44,63 @@ foo
bar
EOE
-$* -i 2 -o baz -s 10 <<EOI 1>baz 2>>EOE == 10
+$* -i 1 -e bar -e baz -s 2 <<EOI 1>>EOO 2>>EOE == 2 # inout-err-doc-status
foo
bar
EOI
foo
bar
+EOO
+bar
+baz
EOE
+$* -i 1 -e "" <<EOI >>EOO 2>"" # empty-str-doc
+EOI
+EOO
+
+$* -i 1 <<EOI >>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
#\
-$* -i 1 <:"foo" >!"foo" # no-newline-str-fail1
-$* -i 1 <"foo" >:!"foo" # no-newline-str-fail2
+$* -i 1 <:"foo" >!"foo" # no-newline-str-fail1
+$* -i 1 <"foo" >:!"foo" # no-newline-str-fail2
#\
-$* -i 1 <<:EOI >>:EOO # no-newline-doc
+$* -i 1 <<:EOI >>:EOO # no-newline-doc
foo
EOI
foo
EOO
#\
-$* -i 1 <<:EOI >>!EOO # no-newline-doc-fail1
+$* -i 1 <<:EOI >>!EOO # no-newline-doc-fail1
foo
EOI
foo
EOO
-$* -i 1 <<EOI >>:!EOO # no-newline-doc-fail2
+$* -i 1 <<EOI >>:!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