Arbutils/tests/EnsureTests.cpp

32 lines
912 B
C++
Raw Normal View History

2022-02-05 12:37:47 +00:00
#include <doctest.h>
#include "../src/Ensure.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)
}