From 4219d7f14e5c63e251f83fd0fff32b707e412cd6 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 9 Feb 2017 23:16:28 +0300 Subject: Fix save_regex() --- build2/test/script/runner.cxx | 10 +++--- tests/test/script/runner/redirect.test | 21 ++++-------- tests/test/script/runner/regex.test | 58 ++++++++++++++++++++++++---------- 3 files changed, 54 insertions(+), 35 deletions(-) diff --git a/build2/test/script/runner.cxx b/build2/test/script/runner.cxx index 4047b5a..ffb95e8 100644 --- a/build2/test/script/runner.cxx +++ b/build2/test/script/runner.cxx @@ -431,8 +431,7 @@ namespace build2 // // test/1/stdout.regex~di // - if (rd.type == redirect_type::here_doc_regex && - !rl.flags.empty ()) + if (rd.type == redirect_type::here_doc_regex && !rl.flags.empty ()) rp += "~" + rl.flags; // Note that if would be more efficient to directly write chunks @@ -441,10 +440,11 @@ namespace build2 // already failed. // string s; - for (const auto& l: rl.lines) + for (auto b (rl.lines.cbegin ()), i (b), e (rl.lines.cend ()); + i != e; ++i) { - if (!s.empty ()) s += '\n'; - s += line (l); + if (i != b) s += '\n'; + s += line (*i); } save (rp, s, ll); diff --git a/tests/test/script/runner/redirect.test b/tests/test/script/runner/redirect.test index 3cd6c69..b316011 100644 --- a/tests/test/script/runner/redirect.test +++ b/tests/test/script/runner/redirect.test @@ -39,8 +39,7 @@ psr = ($cxx.target.class != 'windows' ? '/' : '\\') # Path separator in regex. : inout-fail : - $c <'$* -i 1 bar'; - $b 2>>/~%EOE%d != 0 + $c <'$* -i 1 bar' && $b 2>>/~%EOE%d != 0 %testscript:1: error: ../../../../../driver(.exe)? stdout doesn't match the expected output% info: stdout: test/1/stdout info: expected stdout: test/1/stdout.orig @@ -61,8 +60,7 @@ psr = ($cxx.target.class != 'windows' ? '/' : '\\') # Path separator in regex. : no-newline-fail1 : - $c <'$* -i 1 <:"foo" >"foo"'; - $b 2>>~/EOE/ != 0 + $c <'$* -i 1 <:"foo" >"foo"' && $b 2>>~/EOE/ != 0 /testscript:1: error: .+driver(\.exe)? stdout doesn't match the expected output/ /.{7} -foo @@ -72,8 +70,7 @@ psr = ($cxx.target.class != 'windows' ? '/' : '\\') # Path separator in regex. : no-newline-fail2 : - $c <'$* -i 1 <"foo" >:"foo"'; - $b 2>>~/EOE/ != 0 + $c <'$* -i 1 <"foo" >:"foo"' && $b 2>>~/EOE/ != 0 /testscript:1: error: .+driver(\.exe)? stdout doesn't match the expected output/ /.{7} -foo @@ -107,13 +104,11 @@ psr = ($cxx.target.class != 'windows' ? '/' : '\\') # Path separator in regex. { : match : - $c <'$* -o foo >~/Foo?/i'; - $b + $c <'$* -o foo >~/Foo?/i' && $b : mismatch : - $c <'$* -o fooo >~/Foo?/i'; - $b 2>>/~%EOE%d != 0 + $c <'$* -o fooo >~/Foo?/i' && $b 2>>/~%EOE%d != 0 %testscript:1: error: ../../../../../driver(.exe)? stdout doesn't match the regex% info: stdout: test/1/stdout info: stdout regex: test/1/stdout.regex @@ -127,8 +122,7 @@ psr = ($cxx.target.class != 'windows' ? '/' : '\\') # Path separator in regex. { : newline : - $c <"\$* -i 1 <'foo' >/~%bar/%"; - $b 2>>/~%EOE%d != 0; + $c <"\$* -i 1 <'foo' >/~%bar/%" && $b 2>>/~%EOE%d != 0; %testscript:1: error: ../../../../../../driver(.exe)? stdout doesn't match the regex% info: stdout: test/1/stdout info: stdout regex: test/1/stdout.regex @@ -138,8 +132,7 @@ psr = ($cxx.target.class != 'windows' ? '/' : '\\') # Path separator in regex. : no-newline : - $c <"\$* -i 1 <'foo' >:/~%bar/%"; - $b 2>>/~%EOE%d != 0; + $c <"\$* -i 1 <'foo' >:/~%bar/%" && $b 2>>/~%EOE%d != 0; %testscript:1: error: ../../../../../../driver(.exe)? stdout doesn't match the regex% info: stdout: test/1/stdout info: stdout regex: test/1/stdout.regex diff --git a/tests/test/script/runner/regex.test b/tests/test/script/runner/regex.test index 413069c..c45c3a5 100644 --- a/tests/test/script/runner/regex.test +++ b/tests/test/script/runner/regex.test @@ -32,11 +32,19 @@ : Note that old versions of libc++ (for example 1.1) do not detect some : regex errors. For example '*' is parsed successfully. : - $c <'$* -o foo >~/foo[/'; - $b 2>>~/EOE/ != 0 - /testscript:1:13: error: invalid stdout regex redirect.*/ + $c <'cat ~/foo[/' && $b 2>>~/EOE/ != 0 + /testscript:1:12: error: invalid stdout regex redirect.*/ info: regex: '/foo[/' EOE + + : no-match + : + $c <'cat ~/bar/' && $b 2>>/EOE != 0 + testscript:1:1: error: cat stdout doesn't match the regex + info: stdout: test/1/stdout + info: stdout regex: test/1/stdout.regex + info: stdin: test/1/stdin + EOE } : doc @@ -114,36 +122,54 @@ : invalid-syntax-char : $c <>EOE != 0 - $* -o foo >>~/EOO/ - /x - EOO + cat >~/EOO/ + /x + EOO EOI - testscript:2:3: error: invalid syntax character 'x' in stdout regex redirect + testscript:2:1: error: invalid syntax character 'x' in stdout regex redirect info: regex line: '/x' EOE : invalid-char-regex : $c <>~/EOE/ != 0 - $* -o foo >>~/EOO/ - /foo[/ - EOO + cat >~/EOO/ + /foo[/ + EOO EOI - /testscript:2:3: error: invalid char-regex in stdout regex redirect.*/ + /testscript:2:1: error: invalid char-regex in stdout regex redirect.*/ info: regex line: '/foo[/' EOE : invalid-line-regex : $c <>/~%EOE% != 0 - $* -o foo >>~/EOO/ - a - /{ - EOO + cat >~/EOO/ + a + /{ + EOO EOI - %testscript:4:3: error: invalid stdout regex redirect.*% + %testscript:4:1: error: invalid stdout regex redirect.*% info: stdout regex: test/1/stdout.regex EOE + + : no-match + : + { + : leading-blank + : + $c <>/EOE != 0 + cat >~/EOO/ + + foo + EOO + EOI + testscript:1:1: error: cat stdout doesn't match the regex + info: stdout: test/1/stdout + info: stdout regex: test/1/stdout.regex + info: stdin: test/1/stdin + EOE + } } } -- cgit v1.1