Guard test code with __try __except

This commit is contained in:
Dr. Chat 2015-05-04 20:12:02 -05:00
parent 78921c1a7e
commit bb398f32ca
1 changed files with 34 additions and 10 deletions

View File

@ -367,6 +367,39 @@ bool DiscoverTests(std::wstring& test_path,
return true;
}
#ifdef _MSC_VER
int filter(unsigned int code) {
if (code == EXCEPTION_ILLEGAL_INSTRUCTION)
return EXCEPTION_EXECUTE_HANDLER;
return EXCEPTION_CONTINUE_SEARCH;
}
#endif
void ProtectedRunTest(TestSuite &test_suite, TestRunner &runner, TestCase &test_case, int &failed_count, int &passed_count) {
#ifdef _MSC_VER
__try {
#endif
if (!runner.Setup(test_suite)) {
XELOGE(" TEST FAILED SETUP");
++failed_count;
}
if (runner.Run(test_case)) {
++passed_count;
} else {
XELOGE(" TEST FAILED");
++failed_count;
}
#ifdef _MSC_VER
} __except (filter(GetExceptionCode())) {
XELOGE(" TEST FAILED (UNSUPPORTED INSTRUCTION)");
++failed_count;
}
#endif
}
bool RunTests(const std::wstring& test_name) {
int result_code = 1;
int failed_count = 0;
@ -409,16 +442,7 @@ bool RunTests(const std::wstring& test_name) {
for (auto& test_case : test_suite.test_cases) {
XELOGI(" - %s", test_case.name.c_str());
TestRunner runner;
if (!runner.Setup(test_suite)) {
XELOGE(" TEST FAILED SETUP");
++failed_count;
}
if (runner.Run(test_case)) {
++passed_count;
} else {
XELOGE(" TEST FAILED");
++failed_count;
}
ProtectedRunTest(test_suite, runner, test_case, failed_count, passed_count);
}
XELOGI("");