Skip to content

Commit

Permalink
Fix assertions in unit tests on release build
Browse files Browse the repository at this point in the history
  • Loading branch information
foonathan committed Oct 10, 2023
1 parent e3af3c2 commit 1de9919
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
27 changes: 19 additions & 8 deletions tc/base/assert_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@
#include "fundamental.h"
#include <type_traits>
#include <cstdlib>
#include <cassert>

#define _CHECKS
#ifndef _CHECKS
#define _CHECKS
#endif

#ifndef IF_TC_CHECKS
#define IF_TC_CHECKS(...) __VA_ARGS__
#ifdef _CHECKS
#define IF_TC_CHECKS(...) __VA_ARGS__
#else
#define IF_TC_CHECKS(...)
#endif
#endif
#ifndef IF_TC_DEBUG
#ifdef _DEBUG
Expand All @@ -27,9 +33,14 @@
#define IF_TC_DEBUG(...)
#endif
#endif

#ifndef _ASSERT
#include <cassert>
#define _ASSERT(...) assert(TC_FWD(__VA_ARGS__))
#ifdef NDEBUG
#define _ASSERT(...) IF_TC_CHECKS(TC_FWD(__VA_ARGS__) ? (void)0 : std::abort())
#else
#include <cassert>
#define _ASSERT(...) IF_TC_CHECKS(assert(TC_FWD(__VA_ARGS__)))
#endif
#endif
#ifndef TRYASSERT
#define TRYASSERT _ASSERT
Expand Down Expand Up @@ -59,14 +70,14 @@
#define _ASSERTENOTIFY _ASSERTE
#endif
#ifndef _ASSERTEQUAL
#define _ASSERTEQUAL(a, b) assert((a)==(b))
#define _ASSERTEQUAL(a, b) _ASSERT((a)==(b))
#endif
#ifndef _ASSERTDEBUGEQUAL
#define _ASSERTDEBUGEQUAL(a, b) IF_TC_DEBUG(_ASSERTEQUAL(a, b))
#endif
#ifndef _ASSERTANYOF
#include <boost/preprocessor/seq/enum.hpp>
#define _ASSERTANYOF(expr, values) [](auto const& e, auto const&... val) noexcept { assert( ((e == val) || ...) ); }(expr, BOOST_PP_SEQ_ENUM(values))
#define _ASSERTANYOF(expr, values) [](auto const& e, auto const&... val) noexcept { _ASSERT( ((e == val) || ...) ); }(expr, BOOST_PP_SEQ_ENUM(values))
#endif
#ifndef _ASSERTDEBUGANYOF
#define _ASSERTDEBUGANYOF(expr, values) IF_TC_DEBUG(_ASSERTANYOF(expr, values))
Expand All @@ -75,7 +86,7 @@
#define _ASSERTINITIALIZED( expr ) tc::discard(expr)
#endif
#ifndef _ASSERTPRINT
#define _ASSERTPRINT( cond, ... ) assert( cond )
#define _ASSERTPRINT( cond, ... ) _ASSERT( cond )
#endif
#ifndef VERIFYEQUAL
#include <utility>
Expand Down
2 changes: 1 addition & 1 deletion tc/range/concat_adaptor.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ UNITTESTDEF(concat_index_test) {


tc::vector<int> vecn;
_ASSERTEQUAL(tc::break_, tc::for_each(
VERIFYEQUAL(tc::break_, tc::for_each(
tc::filter(
tc::reverse(
tc::concat(
Expand Down

0 comments on commit 1de9919

Please sign in to comment.