diff options
author | Lefteris Karapetsas <lefteris@refu.co> | 2015-03-09 19:23:37 +0800 |
---|---|---|
committer | Lefteris Karapetsas <lefteris@refu.co> | 2015-03-09 19:27:30 +0800 |
commit | 3efbe46a49496ee71c23a9e49b4c374f6157a357 (patch) | |
tree | df40be499f9d649e074b3e7e62b2b7e925ed2c1c /TestHelper.h | |
parent | 52e9a85d6286ab4bfe439908400e82d191dd87b1 (diff) | |
download | dexon-solidity-3efbe46a49496ee71c23a9e49b4c374f6157a357.tar dexon-solidity-3efbe46a49496ee71c23a9e49b4c374f6157a357.tar.gz dexon-solidity-3efbe46a49496ee71c23a9e49b4c374f6157a357.tar.bz2 dexon-solidity-3efbe46a49496ee71c23a9e49b4c374f6157a357.tar.lz dexon-solidity-3efbe46a49496ee71c23a9e49b4c374f6157a357.tar.xz dexon-solidity-3efbe46a49496ee71c23a9e49b4c374f6157a357.tar.zst dexon-solidity-3efbe46a49496ee71c23a9e49b4c374f6157a357.zip |
Improving ETH_TEST() exceptions
- Properly printing fail check/require message same way as BOOST
implementation does
- Also add a Test Pass Checkpoint call to be sure the last checkpoint is
reported properly
- Catch any sort of exception in the no throw
Diffstat (limited to 'TestHelper.h')
-rw-r--r-- | TestHelper.h | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/TestHelper.h b/TestHelper.h index 91ec977d..bd416257 100644 --- a/TestHelper.h +++ b/TestHelper.h @@ -46,39 +46,55 @@ namespace test /// Make sure that no Exception is thrown during testing. If one is thrown show its info and fail the test. /// Our version of BOOST_REQUIRE_NO_THROW() -/// @param _expression The expression for which to make sure no exceptions are thrown +/// @param _statenent The statement for which to make sure no exceptions are thrown /// @param _message A message to act as a prefix to the expression's error information -#define ETH_TEST_REQUIRE_NO_THROW(_expression, _message) \ +#define ETH_TEST_REQUIRE_NO_THROW(_statement, _message) \ do \ { \ try \ { \ - _expression; \ + BOOST_TEST_PASSPOINT(); \ + _statement; \ } \ catch (boost::exception const& _e) \ { \ - auto msg = std::string(_message"\n") + boost::diagnostic_information(_e); \ - BOOST_FAIL(msg); \ + auto msg = std::string(_message" due to an exception thrown by " \ + BOOST_STRINGIZE(_statement)"\n") + boost::diagnostic_information(_e); \ + BOOST_CHECK_IMPL(false, msg, REQUIRE, CHECK_MSG); \ } \ - } while (0) + catch (...) \ + { \ + BOOST_CHECK_IMPL( false, "Unknown exception thrown by " \ + BOOST_STRINGIZE(_statement), REQUIRE, CHECK_MSG); \ + } \ + } \ + while (0) /// Check if an Exception is thrown during testing. If one is thrown show its info and continue the test /// Our version of BOOST_CHECK_NO_THROW() -/// @param _expression The expression for which to make sure no exceptions are thrown +/// @param _statement The statement for which to make sure no exceptions are thrown /// @param _message A message to act as a prefix to the expression's error information -#define ETH_TEST_CHECK_NO_THROW(_expression, _message) \ +#define ETH_TEST_CHECK_NO_THROW(_statement, _message) \ do \ { \ try \ { \ - _expression; \ + BOOST_TEST_PASSPOINT(); \ + _statement; \ } \ catch (boost::exception const& _e) \ { \ - auto msg = std::string(_message"\n") + boost::diagnostic_information(_e); \ - BOOST_MESSAGE(msg); \ + auto msg = std::string(_message" due to an exception thrown by " \ + BOOST_STRINGIZE(_statement)"\n") + boost::diagnostic_information(_e); \ + BOOST_CHECK_IMPL(false, msg, CHECK, CHECK_MSG); \ + } \ + catch (...) \ + { \ + BOOST_CHECK_IMPL( false, "Unknown exception thrown by " \ + BOOST_STRINGIZE(_statement), CHECK, CHECK_MSG ); \ } \ - } while (0) + } \ + while (0) class ImportTest |