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.
This commit is contained in:
Daniel James
2016-10-24 09:46:13 +01:00
parent 5b5b46ea1c
commit 14ccdbc7b6

View File

@ -179,12 +179,13 @@ namespace test {
class test_runner class test_runner
{ {
Test const& test_; Test const& test_;
bool exception_in_check_;
test_runner(test_runner const&); test_runner(test_runner const&);
test_runner& operator=(test_runner const&); test_runner& operator=(test_runner const&);
public: public:
test_runner(Test const& t) : test_(t) {} test_runner(Test const& t) : test_(t), exception_in_check_(false) {}
void operator()() const { void run() {
DISABLE_EXCEPTIONS; DISABLE_EXCEPTIONS;
test::scope = ""; test::scope = "";
BOOST_DEDUCED_TYPENAME Test::data_type x(test_.init()); BOOST_DEDUCED_TYPENAME Test::data_type x(test_.init());
@ -199,14 +200,24 @@ namespace test {
>(&Test::run, test_, x, strong); >(&Test::run, test_, x, strong);
} }
catch(...) { catch(...) {
call_ignore_extra_parameters< try {
Test, DISABLE_EXCEPTIONS;
BOOST_DEDUCED_TYPENAME Test::data_type const, call_ignore_extra_parameters<
BOOST_DEDUCED_TYPENAME Test::strong_type const Test,
>(&Test::check, test_, constant(x), constant(strong)); 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; throw;
} }
} }
void end() {
if (exception_in_check_) {
BOOST_ERROR("Unexcpected exception in test_runner check call.");
}
}
}; };
// Quick exception testing based on lightweight test // Quick exception testing based on lightweight test
@ -236,26 +247,30 @@ namespace test {
iteration = 0; iteration = 0;
bool success = false; bool success = false;
char const* error_msg = 0;
do { do {
++iteration; ++iteration;
count = 0; count = 0;
try { try {
runner(); runner.run();
success = true; success = true;
} }
catch(test_failure) { catch(test_failure) {
BOOST_ERROR("test_failure caught."); error_msg = "test_failure caught.";
break; break;
} }
catch(test_exception) { catch(test_exception) {
continue; continue;
} }
catch(...) { catch(...) {
BOOST_ERROR("Unexpected exception."); error_msg = "Unexpected exception.";
break; break;
} }
} while(!success); } while(!success);
if (error_msg) { BOOST_ERROR(error_msg); }
runner.end();
} }
} }
} }