diff --git a/test/ThrowingBoostAssert.hpp b/test/CountingBoostAssert.hpp similarity index 69% rename from test/ThrowingBoostAssert.hpp rename to test/CountingBoostAssert.hpp index 30e86d17..a8d36d18 100644 --- a/test/ThrowingBoostAssert.hpp +++ b/test/CountingBoostAssert.hpp @@ -8,13 +8,9 @@ -#include -#include - - - #define BOOST_ENABLE_ASSERT_HANDLER +unsigned int sc_assert_failure_count(0U); namespace boost @@ -22,12 +18,9 @@ namespace boost void assertion_failed( - char const * expr, char const * func, char const * file, long ) + char const *, char const *, char const *, long ) { - throw std::logic_error( - std::string( "\nAssertion failed: \"" ) + expr + "\"\n" + - "File: \"" + file + "\"\n" + - "Function: \"" + func + "\"\n" ); + ++sc_assert_failure_count; } diff --git a/test/InvalidResultCopyTest.cpp b/test/InvalidResultCopyTest.cpp index 4b57df1c..c877cb07 100644 --- a/test/InvalidResultCopyTest.cpp +++ b/test/InvalidResultCopyTest.cpp @@ -6,7 +6,7 @@ -#include +#include "CountingBoostAssert.hpp" #include #include #include @@ -15,8 +15,6 @@ #include -#include // std::logic_error - namespace sc = boost::statechart; @@ -51,11 +49,13 @@ int test_main( int, char* [] ) { InvalidResultCopyTest machine; machine.initiate(); + BOOST_REQUIRE_EQUAL( sc_assert_failure_count, 0U ); + machine.process_event( E() ); #ifdef NDEBUG - BOOST_REQUIRE_NO_THROW( machine.process_event( E() ) ); + BOOST_REQUIRE_EQUAL( sc_assert_failure_count, 0U ); #else - BOOST_REQUIRE_THROW( machine.process_event( E() ), std::logic_error ); + BOOST_REQUIRE_EQUAL( sc_assert_failure_count, 2U ); #endif return 0; diff --git a/test/UnconsumedResultTest.cpp b/test/UnconsumedResultTest.cpp index f43312b4..4db7e6d1 100644 --- a/test/UnconsumedResultTest.cpp +++ b/test/UnconsumedResultTest.cpp @@ -6,13 +6,11 @@ -#include +#include "CountingBoostAssert.hpp" #include #include -#include // std::logic_error - namespace sc = boost::statechart; @@ -29,14 +27,13 @@ void make_unconsumed_result() sc::detail::result_utility::make_result( sc::detail::do_discard_event ); } -// TODO: The current test setup lets an exception propagate out of a -// destructor. Find a better way to test this. int test_main( int, char* [] ) { + make_unconsumed_result(); #ifdef NDEBUG - BOOST_REQUIRE_NO_THROW( make_unconsumed_result() ); + BOOST_REQUIRE_EQUAL( sc_assert_failure_count, 0U ); #else - BOOST_REQUIRE_THROW( make_unconsumed_result(), std::logic_error ); + BOOST_REQUIRE_EQUAL( sc_assert_failure_count, 1U ); #endif return 0;