report a true assert when not checking for an assertion

This commit is contained in:
Gael Guennebaud 2010-07-20 12:54:53 +02:00
parent 44cb1e4802
commit 7b23fad4c9

View File

@ -67,7 +67,7 @@ namespace Eigen
// Used to avoid to raise two exceptions at a time in which // Used to avoid to raise two exceptions at a time in which
// case the exception is not properly caught. // case the exception is not properly caught.
// This may happen when a second exceptions is raise in a destructor. // This may happen when a second exceptions is triggered in a destructor.
static bool no_more_assert = false; static bool no_more_assert = false;
static bool report_on_cerr_on_assert_failure = true; static bool report_on_cerr_on_assert_failure = true;
@ -78,7 +78,7 @@ namespace Eigen
}; };
} }
// If EIGEN_DEBUG_ASSERTS is defined and if no assertion is raised while // If EIGEN_DEBUG_ASSERTS is defined and if no assertion is triggered while
// one should have been, then the list of excecuted assertions is printed out. // one should have been, then the list of excecuted assertions is printed out.
// //
// EIGEN_DEBUG_ASSERTS is not enabled by default as it // EIGEN_DEBUG_ASSERTS is not enabled by default as it
@ -109,20 +109,20 @@ namespace Eigen
#define VERIFY_RAISES_ASSERT(a) \ #define VERIFY_RAISES_ASSERT(a) \
{ \ { \
Eigen::no_more_assert = false; \ Eigen::no_more_assert = false; \
try { \
Eigen::ei_assert_list.clear(); \ Eigen::ei_assert_list.clear(); \
Eigen::ei_push_assert = true; \ Eigen::ei_push_assert = true; \
Eigen::report_on_cerr_on_assert_failure = false; \ Eigen::report_on_cerr_on_assert_failure = false; \
try { \
a; \ a; \
Eigen::report_on_cerr_on_assert_failure = true; \ std::cerr << "One of the following asserts should have been triggered:\n"; \
Eigen::ei_push_assert = false; \
std::cerr << "One of the following asserts should have been raised:\n"; \
for (uint ai=0 ; ai<ei_assert_list.size() ; ++ai) \ for (uint ai=0 ; ai<ei_assert_list.size() ; ++ai) \
std::cerr << " " << ei_assert_list[ai] << "\n"; \ std::cerr << " " << ei_assert_list[ai] << "\n"; \
VERIFY(Eigen::should_raise_an_assert && # a); \ VERIFY(Eigen::should_raise_an_assert && # a); \
} catch (Eigen::ei_assert_exception e) { \ } catch (Eigen::ei_assert_exception e) { \
Eigen::ei_push_assert = false; VERIFY(true); \ Eigen::ei_push_assert = false; VERIFY(true); \
} \ } \
Eigen::report_on_cerr_on_assert_failure = true; \
Eigen::ei_push_assert = false; \
} }
#else // EIGEN_DEBUG_ASSERTS #else // EIGEN_DEBUG_ASSERTS
@ -132,19 +132,20 @@ namespace Eigen
{ \ { \
Eigen::no_more_assert = true; \ Eigen::no_more_assert = true; \
if(report_on_cerr_on_assert_failure) \ if(report_on_cerr_on_assert_failure) \
std::cerr << #a << " " __FILE__ << "(" << __LINE__ << ")\n"; \ assert(a); \
else \
throw Eigen::ei_assert_exception(); \ throw Eigen::ei_assert_exception(); \
} }
#define VERIFY_RAISES_ASSERT(a) { \ #define VERIFY_RAISES_ASSERT(a) { \
Eigen::no_more_assert = false; \ Eigen::no_more_assert = false; \
try { \
Eigen::report_on_cerr_on_assert_failure = false; \ Eigen::report_on_cerr_on_assert_failure = false; \
try { \
a; \ a; \
Eigen::report_on_cerr_on_assert_failure = true; \
VERIFY(Eigen::should_raise_an_assert && # a); \ VERIFY(Eigen::should_raise_an_assert && # a); \
} \ } \
catch (Eigen::ei_assert_exception e) { VERIFY(true); } \ catch (Eigen::ei_assert_exception e) { VERIFY(true); } \
Eigen::report_on_cerr_on_assert_failure = true; \
} }
#endif // EIGEN_DEBUG_ASSERTS #endif // EIGEN_DEBUG_ASSERTS