boostTest: Give BOOST_REQUIRE_NO_THROW a smaller block of code to make the error message clearer when a test raises an unexpected exception

This commit is contained in:
Kamil Śliwak 2021-06-25 13:22:15 +02:00
parent cbf1c3ae69
commit 030fb1d9a2

View File

@ -60,6 +60,31 @@ void removeTestSuite(std::string const& _name)
master.remove(id); master.remove(id);
} }
void runTestCase(TestCase::Config const& _config, TestCase::TestCaseCreator const& _testCaseCreator)
{
try
{
stringstream errorStream;
auto testCase = _testCaseCreator(_config);
if (testCase->shouldRun())
switch (testCase->run(errorStream))
{
case TestCase::TestResult::Success:
break;
case TestCase::TestResult::Failure:
BOOST_ERROR("Test expectation mismatch.\n" + errorStream.str());
break;
case TestCase::TestResult::FatalError:
BOOST_ERROR("Fatal error during test.\n" + errorStream.str());
break;
}
}
catch (boost::exception const& _e)
{
BOOST_ERROR("Exception during extracted test: " << boost::diagnostic_information(_e));
}
}
int registerTests( int registerTests(
boost::unit_test::test_suite& _suite, boost::unit_test::test_suite& _suite,
boost::filesystem::path const& _basepath, boost::filesystem::path const& _basepath,
@ -114,27 +139,7 @@ int registerTests(
[config, _testCaseCreator] [config, _testCaseCreator]
{ {
BOOST_REQUIRE_NO_THROW({ BOOST_REQUIRE_NO_THROW({
try runTestCase(config, _testCaseCreator);
{
stringstream errorStream;
auto testCase = _testCaseCreator(config);
if (testCase->shouldRun())
switch (testCase->run(errorStream))
{
case TestCase::TestResult::Success:
break;
case TestCase::TestResult::Failure:
BOOST_ERROR("Test expectation mismatch.\n" + errorStream.str());
break;
case TestCase::TestResult::FatalError:
BOOST_ERROR("Fatal error during test.\n" + errorStream.str());
break;
}
}
catch (boost::exception const& _e)
{
BOOST_ERROR("Exception during extracted test: " << boost::diagnostic_information(_e));
}
}); });
}, },
_path.stem().string(), _path.stem().string(),