119 lines
2.1 KiB
C++
119 lines
2.1 KiB
C++
#include <code/validation/exec.hxx>
|
|
|
|
#include <code/validation/except.hxx>
|
|
#include <code/validation/setup.hxx>
|
|
#include <code/validation/teardown.hxx>
|
|
#include <code/validation/test-case.hxx>
|
|
#include <code/validation/test-result.hxx>
|
|
#include <code/validation/utility.hxx>
|
|
|
|
namespace code::validation
|
|
{
|
|
|
|
static
|
|
void
|
|
exec_setup()
|
|
{
|
|
auto current = Setup::first();
|
|
|
|
if (!current) {
|
|
return;
|
|
}
|
|
|
|
do {
|
|
// fixme: report setup exceptions. fail entire unit test on exception.
|
|
//
|
|
current->run();
|
|
current = current->next();
|
|
} while (current && current != Setup::first());
|
|
}
|
|
|
|
static
|
|
void
|
|
exec_teardown()
|
|
{
|
|
auto current = Teardown::first();
|
|
|
|
if (!current) {
|
|
return;
|
|
}
|
|
|
|
do {
|
|
// fixme: report teardown exceptions. fail entire unit test on exception.
|
|
//
|
|
current->run();
|
|
current = current->next();
|
|
} while (current && current != Teardown::first());
|
|
}
|
|
|
|
static
|
|
bool
|
|
exec_test_case(Test_summary& summary, Test_case& test_case)
|
|
{
|
|
try {
|
|
Utility::Current<Test_case> current{&test_case};
|
|
|
|
exec_setup();
|
|
|
|
try {
|
|
test_case.run();
|
|
}
|
|
catch (...) {
|
|
exec_teardown();
|
|
throw;
|
|
}
|
|
|
|
exec_teardown();
|
|
|
|
summary.append({
|
|
test_case.description(),
|
|
test_case.file(),
|
|
test_case.line(),
|
|
"passed"
|
|
});
|
|
|
|
summary.inc_pass();
|
|
|
|
return true;
|
|
}
|
|
catch (Fail const& fail) {
|
|
summary.append({
|
|
test_case.description(),
|
|
test_case.file(),
|
|
test_case.line(),
|
|
"failed",
|
|
fail.extras()
|
|
});
|
|
|
|
summary.inc_fail();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool
|
|
exec(Test_summary& summary)
|
|
{
|
|
auto current = &Test_case::first();
|
|
|
|
if (!current) {
|
|
return true;
|
|
}
|
|
|
|
bool all_passed{true};
|
|
|
|
do {
|
|
bool passed = exec_test_case(summary, *current);
|
|
|
|
if (!passed) {
|
|
all_passed = false;
|
|
}
|
|
|
|
current = ¤t->next();
|
|
} while (current != &Test_case::first());
|
|
|
|
return all_passed;
|
|
}
|
|
|
|
} // namespace code::validation
|