diff --git a/src/Assert.hpp b/src/Assert.hpp index 983ad03..848a452 100644 --- a/src/Assert.hpp +++ b/src/Assert.hpp @@ -9,7 +9,7 @@ #ifndef NO_ASSERT #define Assert(expr) \ { \ - if (!expr) { \ + if (!(expr)) { \ std::stringstream ss; \ ss << "ASSERTION FAILED: [" << __FILENAME__ << " (" << __LINE__ << ")] \""; \ ss << #expr << "\""; \ diff --git a/tests/AssertTests.cpp b/tests/AssertTests.cpp index bbac7f8..99c9f7d 100644 --- a/tests/AssertTests.cpp +++ b/tests/AssertTests.cpp @@ -1,6 +1,7 @@ #include "../extern/catch.hpp" #include "../src/Assert.hpp" void TestWrapper(bool wrapperExpression){Assert(wrapperExpression)} +void TestWrapperNotNull(void* value){AssertNotNull(value)} TEST_CASE("Assert succeeds if true", "[Utilities]") { REQUIRE_NOTHROW(TestWrapper(true)); @@ -12,3 +13,5 @@ TEST_CASE("Assert throws if false with message", "[Utilities]") { REQUIRE_THROWS_WITH(TestWrapper(false), Catch::Matchers::Equals("ASSERTION FAILED: [AssertTests.cpp (3)] \"wrapperExpression\"")); } + +TEST_CASE("AssertNotNull throws if nullptr", "[Utilities]") { REQUIRE_THROWS(TestWrapperNotNull(nullptr)); }