Hello BitShift Validate
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
#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 (ignore const&) {
|
||||
execute_teardown(r);
|
||||
return kExecuteIgnored;
|
||||
}
|
||||
catch (assertion_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
|
||||
Reference in New Issue
Block a user