diff options
author | Bent Bisballe Nyeng <bbn@mjolner.dk> | 2020-10-27 10:19:00 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <bbn@mjolner.dk> | 2020-10-27 10:19:00 +0100 |
commit | aee9d3674ff4c2d4e2a0e81bf7b2ea93f56b90c8 (patch) | |
tree | 2aee2207268933143a7f49cbcd451e071acdaa02 | |
parent | a0ce0a75828401be43132fdfffa89f5ae903f501 (diff) |
Make sure teardown is always called, even if test or setup fails.
-rw-r--r-- | uunit.h | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -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) |