Files
bitshift-validate/bitshift/validate/execute.cxx
T
Onyx 9361f6094c Improve failure reporting and add more assertions
Adds BV_NOTHROW, BV_THROWS, and BV_THROWS_ANY.

Improves failure reporting.
2026-06-27 05:41:58 +02:00

147 lines
2.6 KiB
C++

#include <bitshift/validate/execute.hxx>
#include <bitshift/validate/failure.hxx>
#include <bitshift/validate/filter.hxx>
#include <bitshift/validate/setup.hxx>
#include <bitshift/validate/teardown.hxx>
#include <bitshift/validate/test-case.hxx>
namespace bitshift::validate
{
/// @brief Execute setup functions.
///
static
void
execute_setup(reporter& r)
{
auto current = setup::first();
if (!current) {
return;
}
do {
r.log_setup(current->file(), current->line());
current->run();
current = current->next();
} while (current && current != setup::first());
}
/// @brief Execute teardown functions.
///
static
void
execute_teardown(reporter& r)
{
auto current = teardown::first();
if (!current) {
return;
}
do {
r.log_teardown(current->file(), current->line());
current->run();
current = current->next();
} while (current && current != teardown::first());
}
enum execute_result
{
kExecuteIgnored,
kExecutePassed,
kExecuteFailed
};
/// @brief Execute a single test case.
///
/// @param r The reporter.
/// @param tc The test case to execute.
///
static
execute_result
execute_single(reporter& r, test_case& tc)
{
execute_setup(r);
r.log_test_case(tc.name(), tc.description(), tc.file(), tc.line());
try {
tc.run();
}
catch (ignored const&) {
execute_teardown(r);
return kExecuteIgnored;
}
catch (passed const&) {
// No-op.
//
}
catch (failure const& failure) {
failure.report(r);
execute_teardown(r);
return kExecuteFailed;
}
execute_teardown(r);
return kExecutePassed;
}
bool
execute_all(reporter& r, strings const& filters)
{
auto current = test_case::first();
if (!current) {
return true;
}
uint16_t total{};
uint16_t ignored{};
uint16_t pass{};
uint16_t fail{};
do {
bool selected{filters.empty()};
for (auto const& j : filters) {
if (match_filter(j, current->name())) {
selected = true;
}
}
if (selected) {
++total;
auto result = execute_single(r, *current);
switch (result) {
case kExecuteIgnored:
++ignored;
break;
case kExecutePassed:
++pass;
break;
case kExecuteFailed:
++fail;
break;
}
}
current = current->next();
} while (current && current != test_case::first());
r.log_summary(total, ignored, pass, fail);
return fail == 0;
}
} // namespace bitshift::validate