TEST(SomeTest, UncaughtException)
{
try {
throw std::runtime_error("testing...");
} catch (const std::exception& e) {
std::cout << "*** Exception caught in "<< __FUNCTION__ << ": '" << e.what() << "'" << std::endl;
throw(e);
}
}
--
You received this message because you are subscribed to the Google Groups "cpputest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
TEST(catch, catchmeifyoucan)
{
try
{
function_to_test();
}
catch(...)
{
FAIL("Unexpected exception");
}
}
#include "CppUTest/CommandLineTestRunner.h"
#include "CppUTest/TestHarness.h"
#include "CppUTest/TestRegistry.h"
TEST_GROUP(catch)
{
};
TEST(catch, catchHello)
{
throw "hello";
}
TEST(catch, goodTest)
{
}
TEST(catch, anotherThrower)
{
throw "world";
}
int main(int argc, char** argv)
{
TestRegistry::getCurrentRegistry()->setRunTestsInSeperateProcess();
return RUN_ALL_TESTS(argc, argv);
}
./OneTimeThrowAwayTests.exe
terminate called after throwing an instance of 'char const*'
OneTimeThrowAwayTests.cpp:18: error: Failure in TEST(catch, anotherThrower)
Failed in separate process - killed by signal 6
..terminate called after throwing an instance of 'char const*'
OneTimeThrowAwayTests.cpp:9: error: Failure in TEST(catch, catchHello)
Failed in separate process - killed by signal 6
.
Errors (2 failures, 3 tests, 0 ran, 0 checks, 0 ignored, 0 filtered out, 202 ms)
--
You received this message because you are subscribed to the Google Groups "cpputest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
@Bas, yes, it would then have to be around the entire test. Not exactly sure where in the code that would have to be. It mustn't catch exceptions due to test termination (failure).
I am really not sure that this would be a good idea, because we have no idea what exception might have occured, and it may not be safe to continue.
Also, what should happen when we are using setjmp / longjmp ? #ifdef ?