Arbutils/tests/AssertTests.cpp

27 lines
932 B
C++
Raw Normal View History

2020-03-22 10:14:47 +00:00
#include "../extern/catch.hpp"
#include "../src/Assert.hpp"
2020-03-22 11:05:16 +00:00
void TestWrapper(bool wrapperExpression) { Assert(wrapperExpression) }
2020-03-22 11:20:39 +00:00
void TestWrapperNotNull(void* value) { AssertNotNull(value) }
2020-03-22 10:14:47 +00:00
2020-03-22 11:20:39 +00:00
TEST_CASE("Assert succeeds if true", "[Utilities]") { REQUIRE_NOTHROW(TestWrapper(true)); }
2020-03-22 10:14:47 +00:00
TEST_CASE("Assert throws if false", "[Utilities]") { REQUIRE_THROWS(TestWrapper(false)); }
TEST_CASE("Assert throws if false with message", "[Utilities]") {
REQUIRE_THROWS_WITH(TestWrapper(false),
Catch::Matchers::Equals("ASSERTION FAILED: [AssertTests.cpp (3)] \"wrapperExpression\""));
}
2020-03-22 10:41:55 +00:00
2020-03-22 11:02:02 +00:00
TEST_CASE("Multiple asserts", "[Utilities]") {
2020-03-22 11:20:39 +00:00
Assert(true)
Assert(true)
Assert(true)
2020-03-22 11:02:02 +00:00
}
2020-03-22 10:41:55 +00:00
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)
}