mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
Add exception message and test name to std::cout when a test fails
-- '*' doesn't help much when debugging
This commit is contained in:
parent
92ae444791
commit
cfef764ab9
|
@ -3,26 +3,55 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
|
||||||
#define xlnt_assert(expression) do\
|
#define XLNT_STRINGIFYX(x) #x
|
||||||
{\
|
#define XLNT_STRINGIFY(x) XLNT_STRINGIFYX(x)
|
||||||
try { if (expression) break; }\
|
|
||||||
catch (...) {}\
|
#define xlnt_assert(expression) \
|
||||||
throw xlnt::exception("test failed");\
|
do \
|
||||||
|
{ \
|
||||||
|
try \
|
||||||
|
{ \
|
||||||
|
if (expression) break; \
|
||||||
|
} \
|
||||||
|
catch (std::exception & ex) \
|
||||||
|
{ \
|
||||||
|
throw ex; \
|
||||||
|
} \
|
||||||
|
catch (...) \
|
||||||
|
{ \
|
||||||
|
} \
|
||||||
|
throw xlnt::exception("test failed -> " XLNT_STRINGIFY(expression)); \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
|
||||||
#define xlnt_assert_throws_nothing(expression) do\
|
#define xlnt_assert_throws_nothing(expression) \
|
||||||
{\
|
do \
|
||||||
try { expression; break; }\
|
{ \
|
||||||
catch (...) {}\
|
try \
|
||||||
throw xlnt::exception("test failed");\
|
{ \
|
||||||
|
expression; \
|
||||||
|
break; \
|
||||||
|
} \
|
||||||
|
catch (...) \
|
||||||
|
{ \
|
||||||
|
} \
|
||||||
|
throw xlnt::exception("test failed -> " XLNT_STRINGIFY(expression)); \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
|
||||||
#define xlnt_assert_throws(expression, exception_type) do\
|
#define xlnt_assert_throws(expression, exception_type) \
|
||||||
{\
|
do \
|
||||||
try { expression; }\
|
{ \
|
||||||
catch (exception_type) { break; }\
|
try \
|
||||||
catch (...) {}\
|
{ \
|
||||||
throw xlnt::exception("test failed");\
|
expression; \
|
||||||
|
} \
|
||||||
|
catch (exception_type) \
|
||||||
|
{ \
|
||||||
|
break; \
|
||||||
|
} \
|
||||||
|
catch (...) \
|
||||||
|
{ \
|
||||||
|
} \
|
||||||
|
throw xlnt::exception("test failed -> " XLNT_STRINGIFY(expression)); \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
|
||||||
#define xlnt_assert_equals(left, right) xlnt_assert(left == right)
|
#define xlnt_assert_equals(left, right) xlnt_assert(left == right)
|
||||||
|
|
|
@ -39,9 +39,18 @@ public:
|
||||||
std::cout << ".";
|
std::cout << ".";
|
||||||
status.tests_passed++;
|
status.tests_passed++;
|
||||||
}
|
}
|
||||||
|
catch (std::exception &ex)
|
||||||
|
{
|
||||||
|
std::cout << "*\n"
|
||||||
|
<< test.second << " failed with:\n"
|
||||||
|
<< ex.what() << '\n';
|
||||||
|
status.tests_failed++;
|
||||||
|
status.failures.push_back(test.second);
|
||||||
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
std::cout << "*";
|
std::cout << "*\n"
|
||||||
|
<< test.second << " failed" << '\n';
|
||||||
status.tests_failed++;
|
status.tests_failed++;
|
||||||
status.failures.push_back(test.second);
|
status.failures.push_back(test.second);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user