修复
This commit is contained in:
@@ -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)
|
||||
Reference in New Issue
Block a user