From d1ab8f029560057dd17d853f2ffa4dd92780e23a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 2 May 2017 14:19:30 +0200 Subject: Cleanup testscript runner diagnostics --- build2/test/rule.cxx | 7 ++++-- build2/test/script/runner.cxx | 41 ++++++++++++++++------------------ build2/test/script/script.cxx | 4 ++-- build2/test/script/script.hxx | 2 +- tests/test/script/builtin/sed.test | 32 +++++++++++++------------- tests/test/script/runner/expr.test | 2 +- tests/test/script/runner/pipe.test | 4 ++-- tests/test/script/runner/redirect.test | 36 +++++++++++++---------------- tests/test/script/runner/regex.test | 10 ++++----- tests/test/script/runner/set.test | 8 +++---- tests/test/script/runner/status.test | 6 ++--- 11 files changed, 73 insertions(+), 79 deletions(-) diff --git a/build2/test/rule.cxx b/build2/test/rule.cxx index db4083e..c9a1fb9 100644 --- a/build2/test/rule.cxx +++ b/build2/test/rule.cxx @@ -377,8 +377,11 @@ namespace build2 { if (verb) { - const auto& tt (cast (t["test.target"])); - text << "test " << t << " with " << ts << " on " << tt; + diag_record dr (text); + dr << "test " << ts; + + if (!t.is_a ()) + dr << ' ' << t; } build2::test::script::script s (t, ts, wd); diff --git a/build2/test/script/runner.cxx b/build2/test/script/runner.cxx index ce32150..11873ca 100644 --- a/build2/test/script/runner.cxx +++ b/build2/test/script/runner.cxx @@ -362,7 +362,7 @@ namespace build2 if (diag) { diag_record d (error (ll)); - d << pr << " " << what << " doesn't match the expected output"; + d << pr << " " << what << " doesn't match expected"; output_info (d, op); output_info (d, eop, "expected "); @@ -484,10 +484,10 @@ namespace build2 // name suffix. For example if icase and idot flags are specified // the name will look like: // - // test/1/stdout.regex~di + // test/1/stdout.regex-di // if (rd.type == redirect_type::here_doc_regex && !rl.flags.empty ()) - rp += "~" + rl.flags; + rp += '-' + rl.flags; // Note that if would be more efficient to directly write chunks // to file rather than to compose a string first. Hower we don't @@ -663,7 +663,7 @@ namespace build2 if (diag) { diag_record d (error (ll)); - d << pr << " " << what << " doesn't match the regex"; + d << pr << " " << what << " doesn't match regex"; output_info (d, op); output_info (d, rp, "", " regex"); @@ -747,7 +747,7 @@ namespace build2 // Cast to uint16_t to avoid ambiguity with libbutl::rmdir_r(). // rmdir_status r ( - rmdir_r (p.directory (), true, static_cast (2))); + rmdir_r (p.directory (), true, static_cast (3))); if (r == rmdir_status::success || (r == rmdir_status::not_exist && t == cleanup_type::maybe)) @@ -789,7 +789,7 @@ namespace build2 // We can get not_exist here due to racing conditions, but // that's ok if somebody did our job. // - rmdir_status r (rmdir (sd, 2)); + rmdir_status r (rmdir (sd, 3)); if (r != rmdir_status::not_empty) return true; @@ -812,7 +812,7 @@ namespace build2 auto rm = [&d] (path&& p, const string&, bool interm) -> bool { if (!interm) - rmfile (d / p, 2); // That's ok if not exists. + rmfile (d / p, 3); // That's ok if not exists. return true; }; @@ -837,7 +837,7 @@ namespace build2 // a file cleanup when try to rmfile() directory instead of // file. // - rmdir_status r (rmdir (d, 2)); + rmdir_status r (rmdir (d, 3)); if (r == rmdir_status::success || (r == rmdir_status::not_exist && t == cleanup_type::maybe)) @@ -856,7 +856,7 @@ namespace build2 // Remove the file if exists. Fail otherwise. Removal of // non-existing file is not an error for 'maybe' cleanup type. // - if (rmfile (p, 2) == rmfile_status::not_exist && + if (rmfile (p, 3) == rmfile_status::not_exist && t == cleanup_type::always) fail (ll) << "registered for cleanup file " << p << " does not exist"; @@ -1251,17 +1251,16 @@ namespace build2 if (c.program.string () == "set") { if (!last) - fail (ll) << "set builtin must be the last command in a pipe"; + fail (ll) << "set builtin must be the last pipe command"; if (out.type != redirect_type::none) - fail (ll) << "set builtin stdout must not be redirected"; + fail (ll) << "set builtin stdout cannot be redirected"; if (err.type != redirect_type::none) - fail (ll) << "set builtin stderr must not be redirected"; + fail (ll) << "set builtin stderr cannot be redirected"; - if ((c.exit.comparison == exit_comparison::eq) != - (c.exit.status == 0)) - fail (ll) << "set builtin exit status must not be other than zero"; + if ((c.exit.comparison == exit_comparison::eq) != (c.exit.code == 0)) + fail (ll) << "set builtin exit code cannot be non-zero"; set_builtin (sp, c.arguments, move (ifd), ll); return true; @@ -1543,7 +1542,7 @@ namespace build2 #endif bool eq (c.exit.comparison == exit_comparison::eq); - success = valid && eq == (exit->code () == c.exit.status); + success = valid && eq == (exit->code () == c.exit.code); if (!valid || (!success && diag)) { @@ -1554,8 +1553,7 @@ namespace build2 if (!exit->normal ()) { - d << pr << " terminated abnormally" << - info << exit->description (); + d << pr << " terminated abnormally: " << exit->description (); if (exit->core ()) d << " (core dumped)"; @@ -1565,13 +1563,12 @@ namespace build2 uint16_t ec (exit->code ()); // Make sure is printed as integer. if (!valid) - d << pr << " exit status " << ec << " is invalid" << - info << "must be an unsigned integer < 256"; + d << pr << " exit code " << ec << " out of 0-255 range"; else if (!success) { if (diag) - d << pr << " exit status " << ec << (eq ? " != " : " == ") - << static_cast (c.exit.status); + d << pr << " exit code " << ec << (eq ? " != " : " == ") + << static_cast (c.exit.code); } else assert (false); diff --git a/build2/test/script/script.cxx b/build2/test/script/script.cxx index 25f72af..cb114a6 100644 --- a/build2/test/script/script.cxx +++ b/build2/test/script/script.cxx @@ -228,7 +228,7 @@ namespace build2 print_path (p.path); } - if (c.exit.comparison != exit_comparison::eq || c.exit.status != 0) + if (c.exit.comparison != exit_comparison::eq || c.exit.code != 0) { switch (c.exit.comparison) { @@ -236,7 +236,7 @@ namespace build2 case exit_comparison::ne: o << " != "; break; } - o << static_cast (c.exit.status); + o << static_cast (c.exit.code); } } diff --git a/build2/test/script/script.hxx b/build2/test/script/script.hxx index 4f6fdab..9aadf06 100644 --- a/build2/test/script/script.hxx +++ b/build2/test/script/script.hxx @@ -254,7 +254,7 @@ namespace build2 // Codes With Special Meanings" in the Advanced Bash-Scripting Guide). // exit_comparison comparison; - uint8_t status; + uint8_t code; }; // command diff --git a/tests/test/script/builtin/sed.test b/tests/test/script/builtin/sed.test index dbd70c4..5f3a31e 100644 --- a/tests/test/script/builtin/sed.test +++ b/tests/test/script/builtin/sed.test @@ -20,7 +20,7 @@ : missed : $c <'sed' && $b 2>>/EOE != 0 - testscript:1:1: error: sed exit status 1 != 0 + testscript:1:1: error: sed exit code 1 != 0 info: stderr: test/1/stderr sed: missing script EOE @@ -28,7 +28,7 @@ : missed-val : $c <'sed -e' && $b 2>>/EOE != 0 - testscript:1:1: error: sed exit status 1 != 0 + testscript:1:1: error: sed exit code 1 != 0 info: stderr: test/1/stderr sed: missing script EOE @@ -36,7 +36,7 @@ : empty : $c <"sed -e ''" && $b 2>>/EOE != 0 - testscript:1:1: error: sed exit status 1 != 0 + testscript:1:1: error: sed exit code 1 != 0 info: stderr: test/1/stderr sed: empty script EOE @@ -44,7 +44,7 @@ : multiple : $c <"sed -e 's/a//' -e 's/a//'" && $b 2>>/EOE != 0 - testscript:1:1: error: sed exit status 1 != 0 + testscript:1:1: error: sed exit code 1 != 0 info: stderr: test/1/stderr sed: multiple scripts EOE @@ -52,7 +52,7 @@ : invalid : $c <"sed -e 'z'" && $b 2>>/EOE != 0 - testscript:1:1: error: sed exit status 1 != 0 + testscript:1:1: error: sed exit code 1 != 0 info: stderr: test/1/stderr sed: only 's' command supported EOE @@ -83,7 +83,7 @@ : not-exist : $c <"sed -e 's/foo/bar/' f" && $b 2>>/~%EOE% != 0 - testscript:1:1: error: sed exit status 1 != 0 + testscript:1:1: error: sed exit code 1 != 0 info: stderr: test/1/stderr %sed: unable to edit '.+/1/f': .+% EOE @@ -91,7 +91,7 @@ : empty : $c <"sed -e 's/foo/bar/' ''" && $b 2>>/EOE != 0 - testscript:1:1: error: sed exit status 1 != 0 + testscript:1:1: error: sed exit code 1 != 0 info: stderr: test/1/stderr sed: invalid path '' EOE @@ -100,7 +100,7 @@ : unexpected : $c <"sed -e 's/a//' a b" && $b 2>>/EOE != 0 - testscript:1:1: error: sed exit status 1 != 0 + testscript:1:1: error: sed exit code 1 != 0 info: stderr: test/1/stderr sed: unexpected argument EOE @@ -121,7 +121,7 @@ : none : $c <"sed -e 's'" && $b 2>>/EOE != 0 - testscript:1:1: error: sed exit status 1 != 0 + testscript:1:1: error: sed exit code 1 != 0 info: stderr: test/1/stderr sed: no delimiter for 's' command EOE @@ -129,7 +129,7 @@ : invalid : $c <"sed -e 's\\'" && $b 2>>/EOE != 0 - testscript:1:1: error: sed exit status 1 != 0 + testscript:1:1: error: sed exit code 1 != 0 info: stderr: test/1/stderr sed: invalid delimiter for 's' command EOE @@ -141,7 +141,7 @@ : unterminated : $c <"sed -e 's/foo'" && $b 2>>/EOE != 0 - testscript:1:1: error: sed exit status 1 != 0 + testscript:1:1: error: sed exit code 1 != 0 info: stderr: test/1/stderr sed: unterminated 's' command regex EOE @@ -149,7 +149,7 @@ : empty : $c <"sed -e 's///'" && $b 2>>/EOE != 0 - testscript:1:1: error: sed exit status 1 != 0 + testscript:1:1: error: sed exit code 1 != 0 info: stderr: test/1/stderr sed: empty regex in 's' command EOE @@ -160,7 +160,7 @@ : regex errors. For example '*' is parsed successfully. : $c <"sed -e 's/foo[/bar/'" && $b 2>>/~%EOE% != 0 - testscript:1:1: error: sed exit status 1 != 0 + testscript:1:1: error: sed exit code 1 != 0 info: stderr: test/1/stderr %sed: invalid regex.*% EOE @@ -169,7 +169,7 @@ : unterminated-replacement : $c <"sed -e 's/foo/bar'" && $b 2>>/EOE != 0 - testscript:1:1: error: sed exit status 1 != 0 + testscript:1:1: error: sed exit code 1 != 0 info: stderr: test/1/stderr sed: unterminated 's' command replacement EOE @@ -177,7 +177,7 @@ : invalid-flags : $c <"sed -e 's/foo/bar/a'" && $b 2>>/EOE != 0 - testscript:1:1: error: sed exit status 1 != 0 + testscript:1:1: error: sed exit code 1 != 0 info: stderr: test/1/stderr sed: invalid 's' command flag 'a' EOE @@ -304,7 +304,7 @@ : no-file : $c <"sed -i -e 's/a/b/'" && $b 2>>/EOE != 0 - testscript:1:1: error: sed exit status 1 != 0 + testscript:1:1: error: sed exit code 1 != 0 info: stderr: test/1/stderr sed: -i option specified while reading from stdin EOE diff --git a/tests/test/script/runner/expr.test b/tests/test/script/runner/expr.test index 454da1e..2ccbaa9 100644 --- a/tests/test/script/runner/expr.test +++ b/tests/test/script/runner/expr.test @@ -21,7 +21,7 @@ true = '$* >| -o' false = '$* -s 1 >| -o' - bf = $b 2>/~'%.+/driver(\.exe)? exit status 1 != 0%' + bf = $b 2>/~'%.+/driver(\.exe)? exit code 1 != 0%' : true : diff --git a/tests/test/script/runner/pipe.test b/tests/test/script/runner/pipe.test index bfbe8cb..5e1ada8 100644 --- a/tests/test/script/runner/pipe.test +++ b/tests/test/script/runner/pipe.test @@ -17,14 +17,14 @@ $c <'$* -o foo | cat >foo' && $b : process-to-builtin : exit-code : $c <'$* -o foo -s 1 | $* -i 1 >foo -s 2' && $b 2>>/~%EOE% != 0 - %testscript:1:1: error: .+ exit status 2 != 0% + %testscript:1:1: error: .+ exit code 2 != 0% info: stdout: test/1/stdout-2 EOE : stderr : $c <'$* -o foo -e foo 2>bar | $* -i 2 2>baz' && $b 2>>/~%EOE% != 0 - %testscript:1:1: error: .+ stderr doesn't match the expected output% + %testscript:1:1: error: .+ stderr doesn't match expected% info: stderr: test/1/stderr-2 info: expected stderr: test/1/stderr-2.orig info: stderr diff: test/1/stderr-2.diff diff --git a/tests/test/script/runner/redirect.test b/tests/test/script/runner/redirect.test index 7c7fada..cc3989c 100644 --- a/tests/test/script/runner/redirect.test +++ b/tests/test/script/runner/redirect.test @@ -41,33 +41,27 @@ psr = ($cxx.target.class != 'windows' ? '/' : '\\') # Path separator in regex. : out : $c <'$* -o foo >!' && $b >foo 2>>/~%EOE% - %test .+ with .+ on .+% + %test .+% mkdir test/ cd test/ mkdir test/1/ cd test/1/ %.*/driver(.exe)? -o foo% - rm test/1/stderr - rm test/1/ cd test/ - rm test/ cd ./ EOE : err : $c <'$* -e foo 2>!' && $b 2>>/~%EOE% - %test .+ with .+ on .+% + %test .+% mkdir test/ cd test/ mkdir test/1/ cd test/1/ %.*/driver(.exe)? -e foo% foo - rm test/1/stdout - rm test/1/ cd test/ - rm test/ cd ./ EOE } @@ -87,7 +81,7 @@ psr = ($cxx.target.class != 'windows' ? '/' : '\\') # Path separator in regex. : inout-fail : $c <'$* -i 1 bar' && $b 2>>/~%EOE%d != 0 - %testscript:1: error: ../../../../../driver(.exe)? stdout doesn't match the expected output% + %testscript:1: error: ../../../../../driver(.exe)? stdout doesn't match expected% info: stdout: test/1/stdout info: expected stdout: test/1/stdout.orig info: stdout diff: test/1/stdout.diff @@ -108,7 +102,7 @@ psr = ($cxx.target.class != 'windows' ? '/' : '\\') # Path separator in regex. : no-newline-fail1 : $c <'$* -i 1 <:"foo" >"foo"' && $b 2>>~/EOE/ != 0 - /testscript:1: error: .+driver(\.exe)? stdout doesn't match the expected output/ + /testscript:1: error: .+driver(\.exe)? stdout doesn't match expected/ /.{7} -foo +foo @@ -118,7 +112,7 @@ psr = ($cxx.target.class != 'windows' ? '/' : '\\') # Path separator in regex. : no-newline-fail2 : $c <'$* -i 1 <"foo" >:"foo"' && $b 2>>~/EOE/ != 0 - /testscript:1: error: .+driver(\.exe)? stdout doesn't match the expected output/ + /testscript:1: error: .+driver(\.exe)? stdout doesn't match expected/ /.{7} -foo \ No newline at end of file @@ -156,7 +150,7 @@ psr = ($cxx.target.class != 'windows' ? '/' : '\\') # Path separator in regex. : mismatch : $c <'$* -o fooo >~/Foo?/i' && $b 2>>/~%EOE%d != 0 - %testscript:1: error: ../../../../../driver(.exe)? stdout doesn't match the regex% + %testscript:1: error: ../../../../../driver(.exe)? stdout doesn't match regex% info: stdout: test/1/stdout info: stdout regex: test/1/stdout.regex fooo @@ -171,7 +165,7 @@ psr = ($cxx.target.class != 'windows' ? '/' : '\\') # Path separator in regex. : newline : $c <"\$* -i 1 <'foo' >/~%bar/%" && $b 2>>/~%EOE%d != 0; - %testscript:1: error: ../../../../../../driver(.exe)? stdout doesn't match the regex% + %testscript:1: error: ../../../../../../driver(.exe)? stdout doesn't match regex% info: stdout: test/1/stdout info: stdout regex: test/1/stdout.regex info: stdin: test/1/stdin @@ -182,7 +176,7 @@ psr = ($cxx.target.class != 'windows' ? '/' : '\\') # Path separator in regex. : no-newline : $c <"\$* -i 1 <'foo' >:/~%bar/%" && $b 2>>/~%EOE%d != 0; - %testscript:1: error: ../../../../../../driver(.exe)? stdout doesn't match the regex% + %testscript:1: error: ../../../../../../driver(.exe)? stdout doesn't match regex% info: stdout: test/1/stdout info: stdout regex: test/1/stdout.regex info: stdin: test/1/stdin @@ -296,7 +290,7 @@ psr = ($cxx.target.class != 'windows' ? '/' : '\\') # Path separator in regex. foo EOO EOI - /testscript:1: error: .+driver(\.exe)? stdout doesn't match the expected output/ + /testscript:1: error: .+driver(\.exe)? stdout doesn't match expected/ /.{7} -foo +foo @@ -312,7 +306,7 @@ psr = ($cxx.target.class != 'windows' ? '/' : '\\') # Path separator in regex. foo EOO EOI - /testscript:1: error: .+driver(\.exe)? stdout doesn't match the expected output/ + /testscript:1: error: .+driver(\.exe)? stdout doesn't match expected/ /.{7} -foo \ No newline at end of file @@ -364,7 +358,7 @@ psr = ($cxx.target.class != 'windows' ? '/' : '\\') # Path separator in regex. x$s EOO EOI - %testscript:3: error: ../../../../../driver(.exe)? stdout doesn't match the expected output% + %testscript:3: error: ../../../../../driver(.exe)? stdout doesn't match expected% info: stdout: test/1/stdout info: expected stdout: test/1/stdout.orig info: stdout diff: test/1/stdout.diff @@ -439,7 +433,7 @@ psr = ($cxx.target.class != 'windows' ? '/' : '\\') # Path separator in regex. bar EOO EOI - %testscript:1: error: ../../../../../driver(.exe)? stdout doesn't match the regex% + %testscript:1: error: ../../../../../driver(.exe)? stdout doesn't match regex% info: stdout: test/1/stdout info: stdout regex: test/1/stdout.regex foo @@ -452,9 +446,9 @@ psr = ($cxx.target.class != 'windows' ? '/' : '\\') # Path separator in regex. bar EOO EOI - %testscript:1: error: ../../../../../driver(.exe)? stdout doesn't match the regex% + %testscript:1: error: ../../../../../driver(.exe)? stdout doesn't match regex% info: stdout: test/1/stdout - info: stdout regex: test/1/stdout.regex~i + info: stdout regex: test/1/stdout.regex-i foo EOE } @@ -490,7 +484,7 @@ psr = ($cxx.target.class != 'windows' ? '/' : '\\') # Path separator in regex. $* -o foo >=out; $* -o bar >>>out EOI - %testscript:2: error: ../../../../../driver(.exe)? stdout doesn't match the expected output% + %testscript:2: error: ../../../../../driver(.exe)? stdout doesn't match expected% info: stdout: test/1/stdout-2 info: expected stdout: test/1/out info: stdout diff: test/1/stdout-2.diff diff --git a/tests/test/script/runner/regex.test b/tests/test/script/runner/regex.test index e0ef1c9..964b961 100644 --- a/tests/test/script/runner/regex.test +++ b/tests/test/script/runner/regex.test @@ -40,7 +40,7 @@ : no-match : $c <'cat ~/bar/' && $b 2>>/EOE != 0 - testscript:1:1: error: cat stdout doesn't match the regex + testscript:1:1: error: cat stdout doesn't match regex info: stdout: test/1/stdout info: stdout regex: test/1/stdout.regex info: stdin: test/1/stdin @@ -165,7 +165,7 @@ foo EOO EOI - testscript:1:1: error: cat stdout doesn't match the regex + testscript:1:1: error: cat stdout doesn't match regex info: stdout: test/1/stdout info: stdout regex: test/1/stdout.regex info: stdin: test/1/stdin @@ -200,7 +200,7 @@ : Syntax dot becomes escaped dot and matches only '.' and so we fail. : $c <'cat ~/f.o/d' && $b 2>>~/EOE/ != 0 - testscript:1:1: error: cat stdout doesn't match the regex + testscript:1:1: error: cat stdout doesn't match regex /.+ EOE } @@ -237,7 +237,7 @@ /f.o/d EOO EOI - testscript:1:1: error: cat stdout doesn't match the regex + testscript:1:1: error: cat stdout doesn't match regex /.+ EOE } @@ -271,7 +271,7 @@ /f.o/ EOO EOI - testscript:1:1: error: cat stdout doesn't match the regex + testscript:1:1: error: cat stdout doesn't match regex /.+ EOE } diff --git a/tests/test/script/runner/set.test b/tests/test/script/runner/set.test index 7c24669..aebe9cb 100644 --- a/tests/test/script/runner/set.test +++ b/tests/test/script/runner/set.test @@ -10,7 +10,7 @@ : pipelining : $c <'set foo | cat >bar' && $b 2>>EOE != 0 - testscript:1:1: error: set builtin must be the last command in a pipe + testscript:1:1: error: set builtin must be the last pipe command EOE : redirecting @@ -19,20 +19,20 @@ : stdout : $c <'set foo >bar' && $b 2>>EOE != 0 - testscript:1:1: error: set builtin stdout must not be redirected + testscript:1:1: error: set builtin stdout cannot be redirected EOE : stderr : $c <'set foo 2>bar' && $b 2>>EOE != 0 - testscript:1:1: error: set builtin stderr must not be redirected + testscript:1:1: error: set builtin stderr cannot be redirected EOE } : status : $c <'set foo == 1' && $b 2>>EOE != 0 - testscript:1:1: error: set builtin exit status must not be other than zero + testscript:1:1: error: set builtin exit code cannot be non-zero EOE } diff --git a/tests/test/script/runner/status.test b/tests/test/script/runner/status.test index 67ce3ae..87c80e1 100644 --- a/tests/test/script/runner/status.test +++ b/tests/test/script/runner/status.test @@ -16,7 +16,7 @@ b += --no-column : false : $c <'$* -s 1 == 0' && $b 2>>/~%EOE%d != 0 - %testscript:1: error: ../../../../driver(.exe)? exit status 1 != 0% + %testscript:1: error: ../../../../driver(.exe)? exit code 1 != 0% EOE } @@ -30,14 +30,14 @@ b += --no-column : false : $c <'$* -s 1 != 1' && $b 2>>/~%EOE% != 0 - %testscript:1: error: ../../../../driver(.exe)? exit status 1 == 1% + %testscript:1: error: ../../../../driver(.exe)? exit code 1 == 1% EOE } : error : $c <'$* -s 1 -e "Error"' && $b 2>>/~%EOE% != 0 -%testscript:1: error: ../../../driver(.exe)? exit status 1 != 0% +%testscript:1: error: ../../../driver(.exe)? exit code 1 != 0% info: stderr: test/1/stderr Error EOE -- cgit v1.1