aboutsummaryrefslogtreecommitdiff
path: root/libbuild2
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2022-08-17 14:21:55 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2022-08-17 16:36:56 +0300
commit5fb9f8b808b9d235d3e30db33f8a9630edac525f (patch)
tree4e0d2e29aaebe4e1432717738e49841ddcc5921c /libbuild2
parentfe94baf3fe7b7d6d4f97c9e6841c0d9b2915d810 (diff)
Allow matching empty output with here-document regex without ':' modifier
Diffstat (limited to 'libbuild2')
-rw-r--r--libbuild2/script/run.cxx25
1 files changed, 25 insertions, 0 deletions
diff --git a/libbuild2/script/run.cxx b/libbuild2/script/run.cxx
index 8b609f1..5b45afd 100644
--- a/libbuild2/script/run.cxx
+++ b/libbuild2/script/run.cxx
@@ -759,6 +759,31 @@ namespace build2
output_info (d, op);
}
+ // Note that a here-document regex without ':' modifier can never
+ // match an empty output since it always contains the trailing empty
+ // line-char. This can be confusing, as for example while testing a
+ // program which can print some line or nothing with the following
+ // test:
+ //
+ // $* >>~%EOO%
+ // %(
+ // Hello, World!
+ // %)?
+ // EOO
+ //
+ // Note that the above line-regex contains 4 line-chars and will never
+ // match empty output.
+ //
+ // Thus, let's complete an empty output with an empty line-char for
+ // such a regex, so it may potentially match.
+ //
+ if (ls.empty () &&
+ rd.type == redirect_type::here_doc_regex &&
+ rd.modifiers ().find (':') == string::npos)
+ {
+ ls += line_char (string (), regex.pool);
+ }
+
// Match the output with the regex.
//
// Note that we don't distinguish between the line_regex and