Override BX_ASSERT/BX_ASSERT_LOC in test.h to throw directly.

This commit is contained in:
Бранимир Караџић
2026-05-03 16:26:21 -07:00
committed by Branimir Karadžić
parent 84fd8d86e9
commit 5a43e56c3b
2 changed files with 31 additions and 0 deletions

View File

@@ -6,6 +6,29 @@
#ifndef BX_TEST_H_HEADER_GUARD
#define BX_TEST_H_HEADER_GUARD
#include <exception>
// Override bx asserts in test builds: failing asserts throw std::exception so that Catch2's
// REQUIRE_ASSERTS (REQUIRE_THROWS) can catch them.
#if BX_CONFIG_DEBUG
# define BX_ASSERT(_condition, ...) \
do { \
if (!(_condition) ) \
{ \
throw ::std::exception(); \
} \
} while (false)
# define BX_ASSERT_LOC(_location, _condition, ...) \
do { \
(void)(_location); \
if (!(_condition) ) \
{ \
throw ::std::exception(); \
} \
} while (false)
#endif // BX_CONFIG_DEBUG
#include <bx/bx.h>
BX_PRAGMA_DIAGNOSTIC_PUSH();

View File

@@ -247,7 +247,11 @@ TEST_CASE("type-traits isVolatile", "")
TEST_CASE("type-traits isSigned", "")
{
STATIC_REQUIRE(!bx::isSigned<bool >() );
#if CHAR_MIN < 0
STATIC_REQUIRE( bx::isSigned<char >() );
#else
STATIC_REQUIRE(!bx::isSigned<char >() );
#endif // CHAR_MIN < 0
STATIC_REQUIRE( bx::isSigned<signed char >() );
STATIC_REQUIRE(!bx::isSigned<unsigned char >() );
STATIC_REQUIRE( bx::isSigned<short >() );
@@ -283,7 +287,11 @@ TEST_CASE("type-traits isSigned", "")
TEST_CASE("type-traits isUnsigned", "")
{
STATIC_REQUIRE( bx::isUnsigned<bool >() );
#if CHAR_MIN < 0
STATIC_REQUIRE(!bx::isUnsigned<char >() );
#else
STATIC_REQUIRE( bx::isUnsigned<char >() );
#endif // CHAR_MIN < 0
STATIC_REQUIRE(!bx::isUnsigned<signed char >() );
STATIC_REQUIRE( bx::isUnsigned<unsigned char >() );
STATIC_REQUIRE(!bx::isUnsigned<short >() );