forked from arc/libarc-validate
98 lines
1.6 KiB
C++
98 lines
1.6 KiB
C++
|
#include <arc/validate/test.hxx>
|
||
|
|
||
|
#include <stdexcept>
|
||
|
|
||
|
namespace arc::validate
|
||
|
{
|
||
|
|
||
|
std::map<std::string, test_t*> test_t::tests_;
|
||
|
|
||
|
test_t::
|
||
|
test_t(std::string file, int line, std::string name, std::function<void()> f)
|
||
|
: file_{std::move(file)},
|
||
|
line_{line},
|
||
|
name_{
|
||
|
name.empty() ? throw std::invalid_argument{"invalid name"} : name
|
||
|
},
|
||
|
function_{std::move(f)}
|
||
|
{
|
||
|
if (tests_.contains(name)) {
|
||
|
throw std::invalid_argument{"test already registered: " + name};
|
||
|
}
|
||
|
|
||
|
tests_.emplace(name, this);
|
||
|
}
|
||
|
|
||
|
test_t::
|
||
|
~test_t() noexcept
|
||
|
{
|
||
|
tests_.erase(name_);
|
||
|
}
|
||
|
|
||
|
std::string const&
|
||
|
test_t::
|
||
|
file() const
|
||
|
{
|
||
|
return file_;
|
||
|
}
|
||
|
|
||
|
int
|
||
|
test_t::
|
||
|
line() const
|
||
|
{
|
||
|
return line_;
|
||
|
}
|
||
|
|
||
|
std::string const&
|
||
|
test_t::
|
||
|
name() const
|
||
|
{
|
||
|
return name_;
|
||
|
}
|
||
|
|
||
|
std::function<void()> const&
|
||
|
test_t::
|
||
|
function() const
|
||
|
{
|
||
|
return function_;
|
||
|
}
|
||
|
|
||
|
std::vector<test_t*>
|
||
|
test_t::
|
||
|
get_tests()
|
||
|
{
|
||
|
std::vector<test_t*> tests;
|
||
|
|
||
|
for (auto const& j : tests_) {
|
||
|
tests.emplace_back(j.second);
|
||
|
}
|
||
|
|
||
|
return tests;
|
||
|
}
|
||
|
|
||
|
std::vector<test_t*>
|
||
|
test_t::
|
||
|
get_tests(std::set<std::string> const& include,
|
||
|
std::set<std::string> const& exclude)
|
||
|
{
|
||
|
std::vector<test_t*> tests;
|
||
|
|
||
|
auto all_tests = get_tests();
|
||
|
|
||
|
for (auto const& j : all_tests) {
|
||
|
if (!include.empty() && !include.contains(j->name())) {
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
if (exclude.contains(j->name())) {
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
tests.emplace_back(j);
|
||
|
}
|
||
|
|
||
|
return tests;
|
||
|
}
|
||
|
|
||
|
} // namespace arc::validate
|