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