From 5fb9f8b808b9d235d3e30db33f8a9630edac525f Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 17 Aug 2022 14:21:55 +0300 Subject: Allow matching empty output with here-document regex without ':' modifier --- libbuild2/script/run.cxx | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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 -- cgit v1.1