2020-09-25 09:50:53 +00:00
|
|
|
#include "../extern/doctest.hpp"
|
2020-03-22 10:14:47 +00:00
|
|
|
#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-09-25 09:50:53 +00:00
|
|
|
TEST_CASE("Assert succeeds if true") { REQUIRE_NOTHROW(TestWrapper(true)); }
|
2020-03-22 10:14:47 +00:00
|
|
|
|
2020-09-25 09:50:53 +00:00
|
|
|
TEST_CASE("Assert throws if false") { REQUIRE_THROWS(TestWrapper(false)); }
|
2020-03-22 10:14:47 +00:00
|
|
|
|
2020-09-25 09:50:53 +00:00
|
|
|
TEST_CASE("Assert throws if false with message") {
|
2020-08-15 12:50:17 +00:00
|
|
|
try {
|
|
|
|
TestWrapper(false);
|
2020-08-15 12:54:19 +00:00
|
|
|
} catch (const ArbUt::Exception& e) {
|
2020-08-15 12:50:17 +00:00
|
|
|
REQUIRE(strcmp(e.what(), "ASSERTION FAILED: [AssertTests.cpp (3)] \"wrapperExpression\"") == 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
throw ArbUt::Exception("Didn't throw.");
|
2020-03-22 10:14:47 +00:00
|
|
|
}
|
2020-03-22 10:41:55 +00:00
|
|
|
|
2020-09-25 09:50:53 +00:00
|
|
|
TEST_CASE("Multiple asserts") {
|
2020-03-22 11:20:39 +00:00
|
|
|
Assert(true)
|
|
|
|
Assert(true)
|
|
|
|
Assert(true)
|
2020-03-22 11:02:02 +00:00
|
|
|
}
|
|
|
|
|
2020-09-25 09:50:53 +00:00
|
|
|
TEST_CASE("AssertNotNull throws if nullptr") { REQUIRE_THROWS(TestWrapperNotNull(nullptr)); }
|
2020-04-22 10:44:50 +00:00
|
|
|
|
2020-09-25 09:50:53 +00:00
|
|
|
TEST_CASE("Assert for each") {
|
2020-04-22 10:44:50 +00:00
|
|
|
auto i = {10, 500, 2300, 454};
|
|
|
|
AssertForEach(i, item > 0)
|
|
|
|
}
|