Wrap call to doctest's MESSAGE() method in Reporter in try/catch block

Also check whether doctest is even enabled before trying to use it.
This commit is contained in:
Tim Wojtulewicz 2022-04-25 15:59:35 -07:00 committed by Tim Wojtulewicz
parent 6f2bedaa56
commit 84ea086167

View file

@ -678,13 +678,28 @@ void Reporter::DoLog(const char* prefix, EventHandlerPtr event, FILE* out, Conne
s += buffer;
#ifdef ENABLE_ZEEK_UNIT_TESTS
if ( doctest::is_running_in_test )
MESSAGE(s);
{
try
{
MESSAGE(s);
}
catch ( const doctest::detail::TestFailureException& e )
{
// If doctest throws an exception, just write the string out to stdout
// like normal, just so it's captured somewhere.
fprintf(out, "%s\n", s.c_str());
}
}
else
{
#endif
s += "\n";
fprintf(out, "%s", s.c_str());
#ifdef ENABLE_ZEEK_UNIT_TESTS
}
#endif
}
if ( alloced )