Skip to content

Commit

Permalink
Flush output on test and contract failures
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Foxhall <[email protected]>
  • Loading branch information
hallfox committed Jan 23, 2025
1 parent 4f27024 commit 291c98b
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/groups/bmq/bmqtst/bmqtst_testhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,12 @@ static inline void
_assert(bool result, const char* expression, const char* file, int line)
{
if (!result) {
printf("Error %s(%d): %s (failed)\n", file, line, expression);
bsl::fprintf(stdout,
"Error %s(%d): %s (failed)\n",
file,
line,
expression);
bsl::fflush(stdout);
if (bmqtst::TestHelperUtil::testStatus() >= 0 &&
bmqtst::TestHelperUtil::testStatus() <= 100) {
++bmqtst::TestHelperUtil::testStatus();
Expand All @@ -806,10 +811,17 @@ BSLS_ANNOTATION_NORETURN
static inline void
_assertViolationHandler(const bsls::AssertViolation& violation)
{
printf("Error %s(%d): %s (failed)\n",
violation.fileName(),
violation.lineNumber(),
violation.comment());
// Since we're handling a contract failure (as opposed to a test
// assertion), we want the program to die immediately. For this reason, we
// use stderr instead of stdout.
bsl::fprintf(stderr,
"Error %s(%d): %s (failed)\n",
violation.fileName(),
violation.lineNumber(),
violation.comment());

// Ensure the error message is printed before terminating
bsl::fflush(stderr);

bsls::AssertTest::failTestDriver(violation);
}
Expand Down

0 comments on commit 291c98b

Please sign in to comment.