From 84ea0861673f99287de7d444a85fd527bebc62da Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Mon, 25 Apr 2022 15:59:35 -0700 Subject: [PATCH] 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. --- src/Reporter.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Reporter.cc b/src/Reporter.cc index 945041b881..0ed84562e7 100644 --- a/src/Reporter.cc +++ b/src/Reporter.cc @@ -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 )