summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <bbn@mjolner.dk>2020-10-27 10:19:00 +0100
committerBent Bisballe Nyeng <bbn@mjolner.dk>2020-10-27 10:19:00 +0100
commitaee9d3674ff4c2d4e2a0e81bf7b2ea93f56b90c8 (patch)
tree2aee2207268933143a7f49cbcd451e071acdaa02
parenta0ce0a75828401be43132fdfffa89f5ae903f501 (diff)
Make sure teardown is always called, even if test or setup fails.
-rw-r--r--uunit.h15
1 files changed, 12 insertions, 3 deletions
diff --git a/uunit.h b/uunit.h
index c9cb258..cdb6097 100644
--- a/uunit.h
+++ b/uunit.h
@@ -66,13 +66,22 @@ public:
for(auto suite = uUnit::suite_list; suite; suite = suite->next_unit)
{
- for(auto test : suite->tests)
+ for(const auto& test : suite->tests)
{
++test_num;
try
{
- suite->setup();
- test.func();
+ try
+ {
+ suite->setup();
+ test.func();
+ }
+ catch(...)
+ {
+ // call teardown and ignore exceptions
+ try { suite->teardown(); } catch(...) {}
+ throw; // rethrow setup/test.func exception
+ }
suite->teardown();
}
catch(test_result& result)