From e07e07253dfeaef66123cff0060458eb9f78033a Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 22 Mar 2020 12:20:39 +0100 Subject: [PATCH] Tweaks and fixes for Assert --- .clang-format | 2 ++ src/Assert.hpp | 14 +++++++------- tests/AssertTests.cpp | 12 +++++------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.clang-format b/.clang-format index 2c6fbf1..965124f 100644 --- a/.clang-format +++ b/.clang-format @@ -116,6 +116,8 @@ Standard: Cpp11 StatementMacros: - Q_UNUSED - QT_REQUIRE_VERSION + - Assert + - AssertNotNull TabWidth: 8 UseTab: Never ... diff --git a/src/Assert.hpp b/src/Assert.hpp index 25db294..2d8a3fe 100644 --- a/src/Assert.hpp +++ b/src/Assert.hpp @@ -6,15 +6,15 @@ #ifndef NO_ASSERT #define Assert(expr) \ - if (!(expr)) { \ - std::stringstream ss; \ - ss << "ASSERTION FAILED: [" << __FILENAME__ << " (" << __LINE__ << ")] \""; \ - ss << #expr << "\""; \ - throw std::logic_error(ss.str()); \ + if (!(expr)) { \ + std::stringstream ss; \ + ss << "ASSERTION FAILED: [" << __FILENAME__ << " (" << __LINE__ << ")] \""; \ + ss << #expr << "\""; \ + throw std::logic_error(ss.str()); \ } #else // Assert is empty if NO_ASSERT is defined. -#define Assert(expr) +#define Assert(expr) ; #endif -#define AssertNotNull(value) Assert(value != nullptr); \ No newline at end of file +#define AssertNotNull(value) Assert(value != nullptr) \ No newline at end of file diff --git a/tests/AssertTests.cpp b/tests/AssertTests.cpp index dc0e9a8..dc79505 100644 --- a/tests/AssertTests.cpp +++ b/tests/AssertTests.cpp @@ -1,11 +1,9 @@ #include "../extern/catch.hpp" #include "../src/Assert.hpp" void TestWrapper(bool wrapperExpression) { Assert(wrapperExpression) } -void TestWrapperNotNull(void* value){AssertNotNull(value)} +void TestWrapperNotNull(void* value) { AssertNotNull(value) } -TEST_CASE("Assert succeeds if true", "[Utilities]") { - REQUIRE_NOTHROW(TestWrapper(true)); -} +TEST_CASE("Assert succeeds if true", "[Utilities]") { REQUIRE_NOTHROW(TestWrapper(true)); } TEST_CASE("Assert throws if false", "[Utilities]") { REQUIRE_THROWS(TestWrapper(false)); } @@ -15,9 +13,9 @@ TEST_CASE("Assert throws if false with message", "[Utilities]") { } TEST_CASE("Multiple asserts", "[Utilities]") { - Assert(true); - Assert(true); - Assert(true); + Assert(true) + Assert(true) + Assert(true) } TEST_CASE("AssertNotNull throws if nullptr", "[Utilities]") { REQUIRE_THROWS(TestWrapperNotNull(nullptr)); }