Added the ability to check if an operation throws the correct exception

release/4.3a0
Alex Cunningham 2010-07-16 19:53:53 +00:00
parent 7b85dc3ff4
commit 7fc184eba4
3 changed files with 12 additions and 2 deletions

View File

@ -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))); }

View File

@ -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!")));

View File

@ -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);