Files
Adminive/backend/test_support/adminive_test.hpp
T
2026-08-09 22:47:14 +08:00

26 lines
828 B
C++

#pragma once
#include <cstdlib>
#include <iostream>
#include <utility>
namespace adminive::test {
inline void check(bool condition, const char* expression, const char* file, int line) {
if(condition) {
return;
}
std::cerr << file << ':' << line << ": check failed: " << expression << '\n';
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 ADMINIVE_CHECK(expression) ::adminive::test::check(static_cast<bool>(expression), #expression, __FILE__, __LINE__)
#define ADMINIVE_CHECK_THROWS_AS(expression, exception) \
ADMINIVE_CHECK((::adminive::test::throws_as<exception>([&] { static_cast<void>(expression); })))