@@ -61,34 +61,29 @@ int test(std::string_view name, std::function<void()> body) noexcept {
return 0;
}
#ifndef ETEST_WITH_SRC_LOC
void expect(bool b) noexcept {
if (!b) { ++assertion_failures; }
}
void require(bool b) {
if (!b) { throw test_failure{}; }
}
#else
void expect(bool b, std::source_location const &loc) noexcept {
void expect(bool b, etest::source_location const &loc) noexcept {
if (!b) {
++assertion_failures;
test_log << " expectation failure at "
<< loc.file_name() << "("
<< loc.line() << ":"
<< loc.column() << ")\n";
// Check if we're using the real source_location by checking for line == 0.
if (loc.line() != 0) {
test_log << " expectation failure at "
<< loc.file_name() << "("
<< loc.line() << ":"
<< loc.column() << ")\n";
}
}
}
void require(bool b, std::source_location const &loc) {
void require(bool b, etest::source_location const &loc) {
if (!b) {
test_log << " requirement failure at "
<< loc.file_name() << "("
<< loc.line() << ":"
<< loc.column() << ")\n";
if (loc.line() != 0) {
test_log << " requirement failure at "
<< loc.file_name() << "("
<< loc.line() << ":"
<< loc.column() << ")\n";
}
throw test_failure{};
}
}
#endif
} // namespace etest