Implemented methods up to execute.

This commit is contained in:
2023-04-03 00:55:03 -07:00
parent 5a9eea1ccb
commit 347f311c2e
2 changed files with 167 additions and 43 deletions

View File

@@ -4,6 +4,12 @@ namespace JTest {
using std::wostream;
// TODO: Consider making testresults_t a class so we can hide the vectors behind accessor methods void add(...), T get(), vector<T> get(uint32_t index)
struct testbundle_t;
struct test_t;
typedef std::function<test_t()> make_test_fn;
typedef std::function<testbundle_t()> make_testbundle_fn;
typedef std::function<void()> configure_fn;
struct testresults_t {
uint32_t total;
uint32_t skipped;
@@ -14,6 +20,35 @@ namespace JTest {
// vector<testmethod_t> skipped;
};
struct test_t {};
struct testbundle_t {
std::wstring _label;
std::vector<test_t> _tests;
std::vector<testbundle_t> _children;
std::optional<configure_fn> _beforeEach;
std::optional<configure_fn> _afterEach;
std::optional<configure_fn> _beforeAll;
std::optional<configure_fn> _afterAll;
};
struct describeoptions_t {
// TODO: Should these configure_fn params be const and/or &?
describeoptions_t& beforeEach(configure_fn);
describeoptions_t& afterEach(configure_fn);
describeoptions_t& beforeAll(configure_fn);
describeoptions_t& afterAll(configure_fn);
std::optional<configure_fn> getBeforeEach() const;
std::optional<configure_fn> getAfterEach() const;
std::optional<configure_fn> getBeforeAll() const;
std::optional<configure_fn> getAfterAll() const;
private:
std::optional<configure_fn> _beforeEach;
std::optional<configure_fn> _afterEach;
std::optional<configure_fn> _beforeAll;
std::optional<configure_fn> _afterAll;
};
struct testoptions_t {};
testresults_t operator+(const testresults_t& left, const testresults_t& right);
testresults_t& operator+=(testresults_t& left, const testresults_t& right);
@@ -23,41 +58,15 @@ namespace JTest {
testresults_t add(const testresults_t&, const testresults_t&);
void print_test_results(const testresults_t&, wostream&);
struct testbundle_t {};
// Executes the tests in tests. Possibly in parallel. Will block until all async tests have completed.
testresults_t execute(testbundle_t tests);
typedef std::function<testbundle_t()> make_testbundle_fn;
typedef std::function<void()> configure_fn;
struct describeoptions_t {
// TODO: Should these configure_fn params be const and/or &?
describeoptions_t& beforeEach(configure_fn);
describeoptions_t& afterEach(configure_fn);
describeoptions_t& beforeAll(configure_fn);
describeoptions_t& afterAll(configure_fn);
private:
configure_fn _beforeEach;
configure_fn _afterEach;
configure_fn _beforeAll;
configure_fn _afterAll;
};
//
testbundle_t describe(const std::wstring& label, const make_testbundle_fn& make_tests, std::optional<describeoptions_t> options = std::nullopt);
struct testoptions_t {};
struct test_t {};
testbundle_t make_testbundle(const std::vector<testbundle_t>& tests, const describeoptions_t& options);
// testbundle_t make_testbundle( initializer_list tests, const testoptions_t& options);
typedef std::function<test_t()> make_test_fn;
// TODO: Make this return a test_t instead.
// TOOD: Bake make_test_fn not need to return testresults_t. Method calls should be surrounded with try/catch.
// The label should be extracted from the test_t it returns.
@@ -66,9 +75,6 @@ namespace JTest {
describeoptions_t make_describeoptions();
testbundle_t make_testbundle(const std::wstring& label, const std::vector<test_t>& tests);
}