Added the ability to check if an operation throws the correct exception
parent
7b85dc3ff4
commit
7fc184eba4
|
@ -60,7 +60,11 @@ protected:
|
|||
{ if (!(condition)) \
|
||||
{ result_.addFailure (Failure (name_, __FILE__,__LINE__, #condition)); return; } }
|
||||
|
||||
|
||||
#define THROWS_EXCEPTION(condition)\
|
||||
{ try { condition; \
|
||||
result_.addFailure (Failure (name_, __FILE__,__LINE__, SimpleString("Didn't throw: ") + StringFrom(#condition))); \
|
||||
return; } \
|
||||
catch (...) {} }
|
||||
|
||||
#define CHECK_EQUAL(expected,actual)\
|
||||
{ if ((expected) == (actual)) return; result_.addFailure(Failure(name_, __FILE__, __LINE__, StringFrom(expected), StringFrom(actual))); }
|
||||
|
|
|
@ -45,14 +45,15 @@ int TestRegistry::run (TestResult& result)
|
|||
result.testsStarted ();
|
||||
|
||||
for (Test *test = tests; test != 0; test = test->getNext ()) {
|
||||
// TODO: add a try/catch wrapper here
|
||||
try {
|
||||
test->run (result);
|
||||
} catch (std::exception& e) {
|
||||
// catch standard exceptions and derivatives
|
||||
result.addFailure(
|
||||
Failure(test->getName(), test->getFilename(), test->getLineNumber(),
|
||||
SimpleString("Exception: ") + SimpleString(e.what())));
|
||||
} catch (...) {
|
||||
// catch all other exceptions
|
||||
result.addFailure(
|
||||
Failure(test->getName(), test->getFilename(), test->getLineNumber(),
|
||||
SimpleString("ExceptionThrown!")));
|
||||
|
|
|
@ -26,6 +26,11 @@ TEST( wrap, ArgumentList ) {
|
|||
CHECK(args.names()=="x,x,x");
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
TEST( wrap, check_exception ) {
|
||||
THROWS_EXCEPTION(Module(".", "geometry",verbose));
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
TEST( wrap, parse ) {
|
||||
Module module(".", "geometry",verbose);
|
||||
|
|
Loading…
Reference in New Issue