From 14ccdbc7b6ef6a488aa55f2b5c587e8d1f02d3b1 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Mon, 24 Oct 2016 09:46:13 +0100 Subject: [PATCH] Add guards against exceptions that shouldn't happen I'm getting a couple of "terminate called after throwing an instance of 'test::lightweight::test_exception'" errors on the sun platform. Not sure where they're happening, so I've made the code a tad more resilient against exceptions that should not really be thrown. --- test/helpers/exception_test.hpp | 35 +++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/test/helpers/exception_test.hpp b/test/helpers/exception_test.hpp index c3aad5d5..d1bc1317 100644 --- a/test/helpers/exception_test.hpp +++ b/test/helpers/exception_test.hpp @@ -179,12 +179,13 @@ namespace test { class test_runner { Test const& test_; + bool exception_in_check_; test_runner(test_runner const&); test_runner& operator=(test_runner const&); public: - test_runner(Test const& t) : test_(t) {} - void operator()() const { + test_runner(Test const& t) : test_(t), exception_in_check_(false) {} + void run() { DISABLE_EXCEPTIONS; test::scope = ""; BOOST_DEDUCED_TYPENAME Test::data_type x(test_.init()); @@ -199,14 +200,24 @@ namespace test { >(&Test::run, test_, x, strong); } catch(...) { - call_ignore_extra_parameters< - Test, - BOOST_DEDUCED_TYPENAME Test::data_type const, - BOOST_DEDUCED_TYPENAME Test::strong_type const - >(&Test::check, test_, constant(x), constant(strong)); + try { + DISABLE_EXCEPTIONS; + call_ignore_extra_parameters< + Test, + BOOST_DEDUCED_TYPENAME Test::data_type const, + BOOST_DEDUCED_TYPENAME Test::strong_type const + >(&Test::check, test_, constant(x), constant(strong)); + } catch(...) { + exception_in_check_ = true; + } throw; } } + void end() { + if (exception_in_check_) { + BOOST_ERROR("Unexcpected exception in test_runner check call."); + } + } }; // Quick exception testing based on lightweight test @@ -236,26 +247,30 @@ namespace test { iteration = 0; bool success = false; + char const* error_msg = 0; do { ++iteration; count = 0; try { - runner(); + runner.run(); success = true; } catch(test_failure) { - BOOST_ERROR("test_failure caught."); + error_msg = "test_failure caught."; break; } catch(test_exception) { continue; } catch(...) { - BOOST_ERROR("Unexpected exception."); + error_msg = "Unexpected exception."; break; } } while(!success); + + if (error_msg) { BOOST_ERROR(error_msg); } + runner.end(); } } }