aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2022-10-14 13:43:32 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2022-10-14 17:30:12 +0300
commit74eea8fe332c05774f108c5094eb335e58f44cfa (patch)
tree84a89e57729fbe5eb358270e40dcc7643ab4a577
parent0ce23b6a1e2e0d7c50fbab83f3aef26a1aeb2271 (diff)
Fix printing test id multiple times on test failure
-rw-r--r--libbuild2/test/script/runner.cxx40
-rw-r--r--libbuild2/test/script/script.hxx18
-rw-r--r--tests/test/script/runner/for.testscript26
3 files changed, 70 insertions, 14 deletions
diff --git a/libbuild2/test/script/runner.cxx b/libbuild2/test/script/runner.cxx
index 340ada4..98d6868 100644
--- a/libbuild2/test/script/runner.cxx
+++ b/libbuild2/test/script/runner.cxx
@@ -166,18 +166,24 @@ namespace build2
text << ": " << c << expr;
}
- // Print test id once per test expression.
+ // Print test id once per test expression and only for the topmost
+ // one.
//
auto df = make_diag_frame (
- [&sp](const diag_record& dr)
+ [&sp, print = (sp.exec_level == 0)](const diag_record& dr)
{
- // Let's not depend on how the path representation can be improved
- // for readability on printing.
- //
- dr << info << "test id: " << sp.id_path.posix_string ();
+ if (print)
+ {
+ // Let's not depend on how the path representation can be
+ // improved for readability on printing.
+ //
+ dr << info << "test id: " << sp.id_path.posix_string ();
+ }
});
+ ++sp.exec_level;
build2::script::run (sp, expr, ii, li, ll, cf);
+ --sp.exec_level;
}
bool default_runner::
@@ -189,18 +195,26 @@ namespace build2
if (verb >= 3)
text << ": ?" << expr;
- // Print test id once per test expression.
+ // Print test id once per test expression and only for the topmost
+ // one.
//
auto df = make_diag_frame (
- [&sp](const diag_record& dr)
+ [&sp, print = (sp.exec_level == 0)](const diag_record& dr)
{
- // Let's not depend on how the path representation can be improved
- // for readability on printing.
- //
- dr << info << "test id: " << sp.id_path.posix_string ();
+ if (print)
+ {
+ // Let's not depend on how the path representation can be
+ // improved for readability on printing.
+ //
+ dr << info << "test id: " << sp.id_path.posix_string ();
+ }
});
- return build2::script::run_cond (sp, expr, ii, li, ll);
+ ++sp.exec_level;
+ bool r (build2::script::run_cond (sp, expr, ii, li, ll));
+ --sp.exec_level;
+
+ return r;
}
}
}
diff --git a/libbuild2/test/script/script.hxx b/libbuild2/test/script/script.hxx
index 319a9e2..3c2cbc4 100644
--- a/libbuild2/test/script/script.hxx
+++ b/libbuild2/test/script/script.hxx
@@ -96,6 +96,22 @@ namespace build2
scope_state state = scope_state::unknown;
+ // The command expression execution nesting level. Can be maintained
+ // by the runner to, for example, only perform some housekeeping on
+ // the topmost level (add the test id to the diagnostics, etc).
+ //
+ // Note that the command expression execution can be nested, so that
+ // the outer expression execution is not completed before all the
+ // inner expressions are executed. As for example in:
+ //
+ // echo 'a b' | for x
+ // echo 'c d' | for y
+ // test $x $y
+ // end
+ // end
+ //
+ size_t exec_level = 0;
+
// Test program paths.
//
// Currently always contains a single element (see test_program() for
@@ -105,7 +121,7 @@ namespace build2
//
small_vector<const path*, 1> test_programs;
- void
+ virtual void
set_variable (string name,
names&&,
const string& attrs,
diff --git a/tests/test/script/runner/for.testscript b/tests/test/script/runner/for.testscript
index 5c1133d..1ac7666 100644
--- a/tests/test/script/runner/for.testscript
+++ b/tests/test/script/runner/for.testscript
@@ -148,6 +148,19 @@
%.+
EOE
+ : nested-diag-test-id
+ :
+ $c <<EOI && $b 2>>EOE != 0
+ echo "a b" | for -w x
+ echo "x y" | for -w y
+ test -f $x$y
+ end
+ end
+ EOI
+ testscript:3:5: error: test exited with code 1
+ info: test id: 1
+ EOE
+
: var-value
:
$c <<EOI && $b >>EOO
@@ -346,6 +359,19 @@
%.+
EOE
+ : nested-diag-test-id
+ :
+ $c <<EOI && $b 2>>EOE != 0
+ for -w x <"a b"
+ for -w y <"x y"
+ test -f $x$y
+ end
+ end
+ EOI
+ testscript:3:5: error: test exited with code 1
+ info: test id: 1
+ EOE
+
: var-value
:
$c <<EOI && $b >>EOO