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
{
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();
}
}
}