More fixes for Assert.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-03-22 12:02:02 +01:00
parent 2d4cc2cd80
commit aa1b90554f
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 13 additions and 8 deletions

View File

@ -6,14 +6,12 @@
#ifndef NO_ASSERT #ifndef NO_ASSERT
#define Assert(expr) \ #define Assert(expr) \
{ \ if (!(expr)) { \
if (!(expr)) { \ std::stringstream ss; \
std::stringstream ss; \ ss << "ASSERTION FAILED: [" << __FILENAME__ << " (" << __LINE__ << ")] \""; \
ss << "ASSERTION FAILED: [" << __FILENAME__ << " (" << __LINE__ << ")] \""; \ ss << #expr << "\""; \
ss << #expr << "\""; \ throw std::logic_error(ss.str()); \
throw std::logic_error(ss.str()); \ }
} \
};
#else #else
// Assert is empty if NO_ASSERT is defined. // Assert is empty if NO_ASSERT is defined.
#define Assert(expr) #define Assert(expr)

View File

@ -14,4 +14,11 @@ TEST_CASE("Assert throws if false with message", "[Utilities]") {
Catch::Matchers::Equals("ASSERTION FAILED: [AssertTests.cpp (3)] \"wrapperExpression\"")); Catch::Matchers::Equals("ASSERTION FAILED: [AssertTests.cpp (3)] \"wrapperExpression\""));
} }
TEST_CASE("Multiple asserts", "[Utilities]") {
Assert(true);
Assert(true);
Assert(true);
}
TEST_CASE("AssertNotNull throws if nullptr", "[Utilities]") { REQUIRE_THROWS(TestWrapperNotNull(nullptr)); } TEST_CASE("AssertNotNull throws if nullptr", "[Utilities]") { REQUIRE_THROWS(TestWrapperNotNull(nullptr)); }