2017-04-14 02:51:35 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <functional>
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
2017-04-14 07:01:30 +08:00
|
|
|
#include <helpers/assertions.hpp>
|
2018-07-05 16:46:32 +08:00
|
|
|
#include <helpers/path_helper.hpp>
|
|
|
|
//#include <helpers/temporary_directory.hpp>
|
|
|
|
//#include <helpers/temporary_file.hpp>
|
|
|
|
#include <helpers/timing.hpp>
|
|
|
|
#include <helpers/xml_helper.hpp>
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2017-04-14 02:51:35 +08:00
|
|
|
struct test_status
|
|
|
|
{
|
|
|
|
std::size_t tests_run = 0;
|
|
|
|
std::size_t tests_failed = 0;
|
|
|
|
std::size_t tests_passed = 0;
|
|
|
|
std::vector<std::string> failures;
|
|
|
|
};
|
|
|
|
|
2018-07-05 16:46:32 +08:00
|
|
|
inline std::string build_name(const std::string &pretty, const std::string &method)
|
2017-04-14 02:51:35 +08:00
|
|
|
{
|
|
|
|
return pretty.substr(0, pretty.find("::") + 2) + method;
|
|
|
|
}
|
|
|
|
|
2017-04-14 07:01:30 +08:00
|
|
|
#define register_test(test) register_test_internal([this]() { test(); }, build_name(__FUNCTION__, #test));
|
2017-04-14 02:51:35 +08:00
|
|
|
|
|
|
|
class test_suite
|
|
|
|
{
|
|
|
|
public:
|
2018-07-05 16:46:32 +08:00
|
|
|
static test_status go()
|
2017-04-14 02:51:35 +08:00
|
|
|
{
|
2017-04-14 07:01:30 +08:00
|
|
|
test_status status;
|
|
|
|
|
2018-07-10 09:37:34 +08:00
|
|
|
for (auto test : tests())
|
2017-04-14 07:01:30 +08:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
test.first();
|
|
|
|
std::cout << ".";
|
|
|
|
status.tests_passed++;
|
|
|
|
}
|
2018-06-18 14:43:36 +08:00
|
|
|
catch (std::exception &ex)
|
|
|
|
{
|
2018-06-18 14:56:23 +08:00
|
|
|
std::string fail_msg = test.second + " failed with:\n" + std::string(ex.what());
|
2018-06-18 14:43:36 +08:00
|
|
|
std::cout << "*\n"
|
2018-06-18 14:56:23 +08:00
|
|
|
<< fail_msg << '\n';
|
2018-06-18 14:43:36 +08:00
|
|
|
status.tests_failed++;
|
2018-06-18 14:56:23 +08:00
|
|
|
status.failures.push_back(fail_msg);
|
2018-06-18 14:43:36 +08:00
|
|
|
}
|
2017-04-14 07:01:30 +08:00
|
|
|
catch (...)
|
|
|
|
{
|
2018-06-18 14:56:23 +08:00
|
|
|
std::cout << "*\n" << test.second << " failed\n";
|
2017-04-14 07:01:30 +08:00
|
|
|
status.tests_failed++;
|
|
|
|
status.failures.push_back(test.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout.flush();
|
|
|
|
status.tests_run++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
2017-04-14 02:51:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-07-05 16:46:32 +08:00
|
|
|
static void register_test_internal(std::function<void()> t, const std::string &function)
|
2017-04-14 02:51:35 +08:00
|
|
|
{
|
2018-07-10 09:37:34 +08:00
|
|
|
tests().push_back(std::make_pair(t, function));
|
2017-04-14 02:51:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-07-10 09:37:34 +08:00
|
|
|
static std::vector<std::pair<std::function<void(void)>, std::string>> &tests();
|
2017-04-14 02:51:35 +08:00
|
|
|
};
|