testrunner: moved exception handling to `TestFixture::run()` and made it unconditional (#4810)

This commit is contained in:
Oliver Stöneberg 2023-02-24 21:46:07 +01:00 committed by GitHub
parent 92b42255da
commit 634881db61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 28 deletions

View File

@ -19,11 +19,13 @@
#include "fixture.h"
#include "color.h"
#include "errortypes.h"
#include "options.h"
#include "redirect.h"
#include <cstdio>
#include <cctype>
#include <exception>
#include <iostream>
#include <sstream>
#include <string>
@ -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)

View File

@ -22,14 +22,6 @@
#include <cstdlib>
#ifdef NDEBUG
#include "errortypes.h" // for InternalError
#include <exception>
#include <iostream>
#include <string>
#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
}