diff --git a/test/fixture.cpp b/test/fixture.cpp index 90f293c041f..7eaf460cf20 100644 --- a/test/fixture.cpp +++ b/test/fixture.cpp @@ -19,11 +19,13 @@ #include "fixture.h" #include "color.h" +#include "errortypes.h" #include "options.h" #include "redirect.h" #include #include +#include #include #include #include @@ -311,12 +313,27 @@ void TestFixture::printHelp() void TestFixture::run(const std::string &str) { testToRun = str; - if (quiet_tests) { - std::cout << '\n' << classname << ':'; - REDIRECT; - run(); - } else - run(); + try { + if (quiet_tests) { + std::cout << '\n' << classname << ':'; + REDIRECT; + run(); + } + else + run(); + } + catch (const InternalError& e) { + ++fails_counter; + errmsg << "InternalError: " << e.errorMessage << std::endl; + } + catch (const std::exception& error) { + ++fails_counter; + errmsg << "exception: " << error.what() << std::endl; + } + catch (...) { + ++fails_counter; + errmsg << "Unknown exception" << std::endl; + } } void TestFixture::processOptions(const options& args) diff --git a/test/main.cpp b/test/main.cpp index 25873d28b5e..5ae9b52abc6 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -22,14 +22,6 @@ #include -#ifdef NDEBUG -#include "errortypes.h" // for InternalError - -#include -#include -#include -#endif - int main(int argc, char *argv[]) { // MS Visual C++ memory leak debug tracing @@ -37,9 +29,6 @@ int main(int argc, char *argv[]) _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF); #endif -#ifdef NDEBUG - try { -#endif Preprocessor::macroChar = '$'; // While macroChar is char(1) per default outside test suite, we require it to be a human-readable character here. options args(argc, argv); @@ -50,15 +39,4 @@ int main(int argc, char *argv[]) } const std::size_t failedTestsCount = TestFixture::runTests(args); return (failedTestsCount == 0) ? EXIT_SUCCESS : EXIT_FAILURE; -#ifdef NDEBUG -} -catch (const InternalError& e) { - std::cout << e.errorMessage << std::endl; -} catch (const std::exception& error) { - std::cout << error.what() << std::endl; -} catch (...) { - std::cout << "Unknown exception" << std::endl; -} -return EXIT_FAILURE; -#endif }