Rename Assert macro to Ensure, clean up exception to be in line with THROW.
continuous-integration/drone/push Build is passing

This commit is contained in:
Deukhoofd committed 2020-12-13 11:41:41 +01:00
1 parent 4466aeeee6
commit 4e854516c1
9 files changed
+67 -68

No files matched your search

-31
View File
@@ -1,31 +0,0 @@
#include "../extern/doctest.hpp"
#include "../src/Assert.hpp"
void TestWrapper(bool wrapperExpression) { Assert(wrapperExpression) }
void TestWrapperNotNull(void* value) { AssertNotNull(value) }
TEST_CASE("Assert succeeds if true") { REQUIRE_NOTHROW(TestWrapper(true)); }
TEST_CASE("Assert throws if false") { REQUIRE_THROWS(TestWrapper(false)); }
TEST_CASE("Assert throws if false with message") {
try {
TestWrapper(false);
} catch (const ArbUt::Exception& e) {
REQUIRE(strcmp(e.what(), "ASSERTION FAILED: [AssertTests.cpp (3)] \"wrapperExpression\"") == 0);
return;
}
throw ArbUt::Exception("Didn't throw.");
}
TEST_CASE("Multiple asserts") {
Assert(true)
Assert(true)
Assert(true)
}
TEST_CASE("AssertNotNull throws if nullptr") { REQUIRE_THROWS(TestWrapperNotNull(nullptr)); }
TEST_CASE("Assert for each") {
auto i = {10, 500, 2300, 454};
AssertForEach(i, item > 0)
}
+28
View File
@@ -0,0 +1,28 @@
#include "../extern/doctest.hpp"
#include "../src/Assert.hpp"
void TestWrapper(bool wrapperExpression) { Ensure(wrapperExpression) }
void TestWrapperNotNull(void* value) {EnsureNotNull(value) }
TEST_CASE("Ensure succeeds if true") { REQUIRE_NOTHROW(TestWrapper(true)); }
TEST_CASE("Ensure throws if false") { REQUIRE_THROWS(TestWrapper(false)); }
TEST_CASE("Ensure throws if false with message") {
try {
TestWrapper(false);
} catch (const ArbUt::Exception& e) {
REQUIRE(std::string(e.what()) == "[EnsureTests.cpp:3] ENSURE FAILED: \"wrapperExpression\"");
return;
}
throw ArbUt::Exception("Didn't throw.");
}
TEST_CASE("Multiple asserts") {Ensure(true) Ensure(true) Ensure(true)
}
TEST_CASE("EnsureNotNull throws if nullptr") { REQUIRE_THROWS(TestWrapperNotNull(nullptr)); }
TEST_CASE("Ensure for each") {
auto i = {10, 500, 2300, 454};
EnsureForEach(i, item > 0)
}