Implements easier assertions for iterators
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-04-22 12:44:50 +02:00
parent 43e612122c
commit 195043d4c5
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 8 additions and 3 deletions

View File

@ -12,12 +12,12 @@
ss << #expr << "\""; \ ss << #expr << "\""; \
throw std::logic_error(ss.str()); \ throw std::logic_error(ss.str()); \
} }
#define AssertForEach(iterator, assertion) { for (auto item: iterator) Assert(assertion)}
#else #else
// Assert is empty if NO_ASSERT is defined. // Assert is empty if NO_ASSERT is defined.
#define Assert(expr) ; #define Assert(expr) ;
#define AssertForEach(iterator, assertion) ;
#endif #endif
#define AssertNotNull(value) Assert(value != nullptr) #define AssertNotNull(value) Assert(value != nullptr)
#define UnpackWeakPtr(weakPtr, sharedPtr) \ #define AssertAllNotNull(iterator) AssertForEach(iterator, item != nullptr)
Assert(!weakPtr.expired()); \
auto sharedPtr = weakPtr.lock();

View File

@ -19,3 +19,8 @@ TEST_CASE("Multiple asserts", "[Utilities]") {
} }
TEST_CASE("AssertNotNull throws if nullptr", "[Utilities]") { REQUIRE_THROWS(TestWrapperNotNull(nullptr)); } TEST_CASE("AssertNotNull throws if nullptr", "[Utilities]") { REQUIRE_THROWS(TestWrapperNotNull(nullptr)); }
TEST_CASE("Assert for each", "[Utilities]") {
auto i = {10, 500, 2300, 454};
AssertForEach(i, item > 0)
}