This commit is contained in:
2026-08-09 22:47:13 +08:00
parent 1354aa54ba
commit 11407faf86
11 changed files with 85 additions and 143 deletions
+30
View File
@@ -0,0 +1,30 @@
#pragma once
#include <cstdio>
#include <cstdlib>
#include <utility>
namespace structive::test {
inline void check(bool condition, const char* expression, const char* file, int line) {
if (condition) {
return;
}
std::fprintf(stderr, "%s:%d: check failed: %s\n", file, line, expression);
std::abort();
}
template <class Exception, class Function>
bool throws_as(Function&& function) {
try {
std::forward<Function>(function)();
} catch (const Exception&) {
return true;
}
return false;
}
}
#define STRUCTIVE_CHECK(expression) ::structive::test::check(static_cast<bool>(expression), #expression, __FILE__, __LINE__)
#define STRUCTIVE_CHECK_THROWS_AS(expression, exception) \
STRUCTIVE_CHECK((::structive::test::throws_as<exception>([&] { static_cast<void>(expression); })))
#define REQUIRE(expression) STRUCTIVE_CHECK(expression)