mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
Modifications to test suite to support test auto-registration
Issue #299
This commit is contained in:
parent
e0d62b0835
commit
a7b167032b
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <cmath>
|
||||
#include <exception>
|
||||
#include <xlnt/utils/exceptions.hpp>
|
||||
|
||||
#define XLNT_STRINGIFYX(x) #x
|
||||
#define XLNT_STRINGIFY(x) XLNT_STRINGIFYX(x)
|
||||
|
|
|
@ -8,6 +8,11 @@
|
|||
#include <vector>
|
||||
|
||||
#include <helpers/assertions.hpp>
|
||||
#include <helpers/path_helper.hpp>
|
||||
//#include <helpers/temporary_directory.hpp>
|
||||
//#include <helpers/temporary_file.hpp>
|
||||
#include <helpers/timing.hpp>
|
||||
#include <helpers/xml_helper.hpp>
|
||||
|
||||
struct test_status
|
||||
{
|
||||
|
@ -17,7 +22,7 @@ struct test_status
|
|||
std::vector<std::string> failures;
|
||||
};
|
||||
|
||||
std::string build_name(const std::string &pretty, const std::string &method)
|
||||
inline std::string build_name(const std::string &pretty, const std::string &method)
|
||||
{
|
||||
return pretty.substr(0, pretty.find("::") + 2) + method;
|
||||
}
|
||||
|
@ -27,7 +32,7 @@ std::string build_name(const std::string &pretty, const std::string &method)
|
|||
class test_suite
|
||||
{
|
||||
public:
|
||||
test_status go()
|
||||
static test_status go()
|
||||
{
|
||||
test_status status;
|
||||
|
||||
|
@ -62,11 +67,11 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
void register_test_internal(std::function<void()> t, const std::string &function)
|
||||
static void register_test_internal(std::function<void()> t, const std::string &function)
|
||||
{
|
||||
tests.push_back(std::make_pair(t, function));
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::pair<std::function<void(void)>, std::string>> tests;
|
||||
static std::vector<std::pair<std::function<void(void)>, std::string>> tests;
|
||||
};
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
namespace xlnt {
|
||||
namespace benchmarks {
|
||||
|
||||
std::size_t current_time()
|
||||
inline std::size_t current_time()
|
||||
{
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto time_since_epoch = now.time_since_epoch();
|
||||
|
|
|
@ -22,50 +22,18 @@
|
|||
// @author: see AUTHORS file
|
||||
|
||||
#include <iostream>
|
||||
#include <helpers/test_suite.hpp>
|
||||
|
||||
#include <cell/cell_test_suite.hpp>
|
||||
#include <cell/index_types_test_suite.hpp>
|
||||
#include <cell/rich_text_test_suite.hpp>
|
||||
std::vector<std::pair<std::function<void(void)>, std::string>> test_suite::tests;
|
||||
|
||||
#include <styles/alignment_test_suite.hpp>
|
||||
#include <styles/color_test_suite.hpp>
|
||||
#include <styles/fill_test_suite.hpp>
|
||||
#include <styles/number_format_test_suite.hpp>
|
||||
|
||||
#include <utils/datetime_test_suite.hpp>
|
||||
#include <utils/path_test_suite.hpp>
|
||||
#include <utils/helper_test_suite.hpp>
|
||||
#include <utils/timedelta_test_suite.hpp>
|
||||
|
||||
#include <workbook/named_range_test_suite.hpp>
|
||||
#include <workbook/serialization_test_suite.hpp>
|
||||
#include <workbook/workbook_test_suite.hpp>
|
||||
|
||||
#include <worksheet/page_setup_test_suite.hpp>
|
||||
#include <worksheet/range_test_suite.hpp>
|
||||
#include <worksheet/worksheet_test_suite.hpp>
|
||||
|
||||
#include <detail/cryptography/compound_document.hpp>
|
||||
|
||||
test_status overall_status;
|
||||
|
||||
template<typename T>
|
||||
void run_tests()
|
||||
{
|
||||
auto status = T{}.go();
|
||||
|
||||
overall_status.tests_run += status.tests_run;
|
||||
overall_status.tests_passed += status.tests_passed;
|
||||
overall_status.tests_failed += status.tests_failed;
|
||||
|
||||
std::copy(status.failures.begin(), status.failures.end(), std::back_inserter(overall_status.failures));
|
||||
}
|
||||
|
||||
void print_summary()
|
||||
void print_summary(const test_status& results)
|
||||
{
|
||||
std::cout << "\n\n";
|
||||
|
||||
for (auto failure : overall_status.failures)
|
||||
std::cout << "Passed: " << results.tests_passed << '\n';
|
||||
std::cout << "Failed: " << results.tests_failed << '\n';
|
||||
|
||||
for (auto failure : results.failures)
|
||||
{
|
||||
std::cout << failure << "\n\n";
|
||||
}
|
||||
|
@ -73,34 +41,9 @@ void print_summary()
|
|||
|
||||
int main()
|
||||
{
|
||||
// cell
|
||||
run_tests<cell_test_suite>();
|
||||
run_tests<index_types_test_suite>();
|
||||
run_tests<rich_text_test_suite>();
|
||||
test_status overall_status = test_suite::go();
|
||||
|
||||
// styles
|
||||
run_tests<alignment_test_suite>();
|
||||
run_tests<color_test_suite>();
|
||||
run_tests<fill_test_suite>();
|
||||
run_tests<number_format_test_suite>();
|
||||
|
||||
// utils
|
||||
run_tests<datetime_test_suite>();
|
||||
run_tests<path_test_suite>();
|
||||
run_tests<helper_test_suite>();
|
||||
run_tests<timedelta_test_suite>();
|
||||
|
||||
// workbook
|
||||
run_tests<named_range_test_suite>();
|
||||
run_tests<serialization_test_suite>();
|
||||
run_tests<workbook_test_suite>();
|
||||
|
||||
// worksheet
|
||||
run_tests<page_setup_test_suite>();
|
||||
run_tests<range_test_suite>();
|
||||
run_tests<worksheet_test_suite>();
|
||||
|
||||
print_summary();
|
||||
print_summary(overall_status);
|
||||
|
||||
return static_cast<int>(overall_status.tests_failed);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user