From 030fb1d9a2f99b94c9c8ad8bfe541d36e7d050e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Fri, 25 Jun 2021 13:22:15 +0200 Subject: [PATCH] boostTest: Give BOOST_REQUIRE_NO_THROW a smaller block of code to make the error message clearer when a test raises an unexpected exception --- test/boostTest.cpp | 49 +++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/test/boostTest.cpp b/test/boostTest.cpp index f0a702812..8bb78a49b 100644 --- a/test/boostTest.cpp +++ b/test/boostTest.cpp @@ -60,6 +60,31 @@ void removeTestSuite(std::string const& _name) 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( boost::unit_test::test_suite& _suite, boost::filesystem::path const& _basepath, @@ -114,28 +139,8 @@ int registerTests( [config, _testCaseCreator] { BOOST_REQUIRE_NO_THROW({ - 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)); - } - }); + runTestCase(config, _testCaseCreator); + }); }, _path.stem().string(), *filenames.back(),