testrunner: moved exception handling to `TestFixture::run()` and made it unconditional (#4810)
This commit is contained in:
parent
92b42255da
commit
634881db61
|
@ -19,11 +19,13 @@
|
||||||
#include "fixture.h"
|
#include "fixture.h"
|
||||||
|
|
||||||
#include "color.h"
|
#include "color.h"
|
||||||
|
#include "errortypes.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "redirect.h"
|
#include "redirect.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
#include <exception>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -311,13 +313,28 @@ void TestFixture::printHelp()
|
||||||
void TestFixture::run(const std::string &str)
|
void TestFixture::run(const std::string &str)
|
||||||
{
|
{
|
||||||
testToRun = str;
|
testToRun = str;
|
||||||
|
try {
|
||||||
if (quiet_tests) {
|
if (quiet_tests) {
|
||||||
std::cout << '\n' << classname << ':';
|
std::cout << '\n' << classname << ':';
|
||||||
REDIRECT;
|
REDIRECT;
|
||||||
run();
|
run();
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
run();
|
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)
|
void TestFixture::processOptions(const options& args)
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,14 +22,6 @@
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
#ifdef NDEBUG
|
|
||||||
#include "errortypes.h" // for InternalError
|
|
||||||
|
|
||||||
#include <exception>
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
// MS Visual C++ memory leak debug tracing
|
// 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);
|
_CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
|
||||||
#endif
|
#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.
|
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);
|
options args(argc, argv);
|
||||||
|
@ -50,15 +39,4 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
const std::size_t failedTestsCount = TestFixture::runTests(args);
|
const std::size_t failedTestsCount = TestFixture::runTests(args);
|
||||||
return (failedTestsCount == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
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
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue