From 2560265fcb9bd717dd35e65d5240219c1b666a79 Mon Sep 17 00:00:00 2001 From: Tom Hicks Date: Fri, 7 Apr 2023 12:04:12 -0700 Subject: [PATCH] Changes from wstring to string expecting UTF-8. --- examples/JTest.cpp | 26 ++++++++++++---------- examples/JTest.h | 32 +++++++++++++++------------ examples/example.cpp | 51 +++++++++++++++++++++----------------------- 3 files changed, 57 insertions(+), 52 deletions(-) diff --git a/examples/JTest.cpp b/examples/JTest.cpp index fbde060..23c53a3 100644 --- a/examples/JTest.cpp +++ b/examples/JTest.cpp @@ -2,10 +2,10 @@ #include namespace JTest { - using std::wostream; + using std::ostream; using std::endl; using std::vector; - using std::wstring; + using std::string; using std::runtime_error; using std::string; using std::optional; @@ -34,9 +34,9 @@ namespace JTest { return {l.total + r.total, l.skipped + r.skipped, l.passed + r.passed, l.failed + r.failed}; } - void print_test_results(const testresults_t& results, wostream& out) { - out << L"Tests: " << results.total << endl; - out << L"Failed: " << results.failed << ", Passed: " << results.passed << ", Skipped: " << results.skipped << endl; + void print_test_results(const testresults_t& results, ostream& out) { + out << "Tests: " << results.total << endl; + out << "Failed: " << results.failed << ", Passed: " << results.passed << ", Skipped: " << results.skipped << endl; } testresults_t operator+(const testresults_t& left, const testresults_t& right) { @@ -87,10 +87,14 @@ namespace JTest { return {}; } - testbundle_t it(const wstring& label, const make_test_fn& test_method, optional options) { + // TODO test_method is the actual test method. We should save it to the test instead of executing it. + testbundle_t it(const string& label, const test_fn& test_method, optional options) { // TODO: Stop ignoring options. - test_t test = test_method(); - return make_testbundle(label, {test}); + test_t test; + test._disabled = false; + test._label = label; + test._test_method = test_method; + return make_testbundle("", {test}); } testresults_t execute(testbundle_t bundle) { @@ -173,7 +177,7 @@ namespace JTest { return bundle; } - testbundle_t make_testbundle(const wstring& label, const vector& tests) { + testbundle_t make_testbundle(const string& label, const vector& tests) { testbundle_t bundle; bundle._label = label; bundle._tests.clear(); @@ -201,9 +205,9 @@ namespace JTest { // TODO: Use these to make the unimplemented_* errors simpler to call. // For this function - // testbundle_t describe(const std::wstring& label, const make_testbundle_fn& make_tests, std::optional options) + // testbundle_t describe(const std::string& label, const make_testbundle_fn& make_tests, std::optional options) // __PRETTY_FUNCTION__ - // Unimplemented function: JTest::testbundle_t JTest::describe(const std::wstring &, const JTest::make_testbundle_fn &, std::optional) + // Unimplemented function: JTest::testbundle_t JTest::describe(const std::string &, const JTest::make_testbundle_fn &, std::optional) // __FUNCSIG__ is not defined on clang++ // __func__ // describe diff --git a/examples/JTest.h b/examples/JTest.h index 0d3a34e..a8c5ffc 100644 --- a/examples/JTest.h +++ b/examples/JTest.h @@ -1,12 +1,12 @@ #include // TODO: Maybe just ostream. namespace JTest { - using std::wostream; + using std::ostream; // TODO: Consider making testresults_t a class so we can hide the vectors behind accessor methods void add(...), T get(), vector get(uint32_t index) struct testbundle_t; struct test_t; - typedef std::function make_test_fn; + typedef std::function test_fn; typedef std::function make_testbundle_fn; typedef std::function configure_fn; @@ -20,15 +20,20 @@ namespace JTest { // vector skipped; }; - struct test_t {}; + std::string _label; + test_fn _test_method; + bool _disabled; + }; + struct testbundle_t { - std::wstring _label; + std::string _label; std::vector _tests; std::vector _children; std::optional _beforeEach; std::optional _afterEach; std::optional _beforeAll; - std::optional _afterAll; + std::optional _afterAll; + bool _disabled; }; struct describeoptions_t { @@ -56,25 +61,24 @@ namespace JTest { testresults_t make_testresults(); testresults_t make_testresults(uint32_t total, uint32_t skipped, uint32_t passed, uint32_t failed); testresults_t add(const testresults_t&, const testresults_t&); - void print_test_results(const testresults_t&, wostream&); + void print_test_results(const testresults_t&, ostream&); // Executes the tests in tests. Possibly in parallel. Will block until all async tests have completed. testresults_t execute(testbundle_t tests); + testresults_t execute(test_t test); // - testbundle_t describe(const std::wstring& label, const make_testbundle_fn& make_tests, std::optional options = std::nullopt); + testbundle_t describe(const std::string& label, const make_testbundle_fn& make_tests, std::optional options = std::nullopt); + testbundle_t xdescribe(const std::string& label, const make_testbundle_fn& make_tests, std::optional options = std::nullopt); testbundle_t make_testbundle(const std::vector& tests, const describeoptions_t& options); - // testbundle_t make_testbundle( initializer_list tests, const testoptions_t& options); - + // 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. - // The testresults_t should be constructed based on the try/catch block and whether this was called as it/xit. - testbundle_t it(const std::wstring& label, const make_test_fn& test_method, std::optional options = std::nullopt); + testbundle_t it(const std::string& label, const test_fn& test_method, std::optional options = std::nullopt); + testbundle_t xit(const std::string& label, const test_fn& test_method, std::optional options = std::nullopt); describeoptions_t make_describeoptions(); - testbundle_t make_testbundle(const std::wstring& label, const std::vector& tests); + testbundle_t make_testbundle(const std::string& label, const std::vector& tests); } diff --git a/examples/example.cpp b/examples/example.cpp index 848853c..5f322bf 100644 --- a/examples/example.cpp +++ b/examples/example.cpp @@ -9,19 +9,19 @@ using namespace JTest; using namespace MyNS; -using std::wstring; +using std::string; using std::vector; -using std::wcout; +using std::cout; using std::exception; using std::endl; -// const vector& might stop being a reference -testresults_t test_ClassToTest_main(int argc, const vector& argv) { +// const vector& might stop being a reference +testresults_t test_ClassToTest_main(const vector& argv) { return execute( - describe(L"ClassToTest", [](){ + describe("ClassToTest", [](){ return make_testbundle( { - it(L"should do the thing", [](){ + it("should do the thing", [](){ // Throw exception if somethings goes wrong @@ -29,16 +29,13 @@ testresults_t test_ClassToTest_main(int argc, const vector& argv) { return (test_t){}; }), - it(L"should do the other thing", [](){ - return (test_t){}; + it("should do the other thing", [](){ }), - it(L"should not do the bad thing", [](){ - return (test_t){}; + it("should not do the bad thing", [](){ }), - it(L"should throw an exception if we do the other bad thing", [](){ - return (test_t){}; + it("should throw an exception if we do the other bad thing", [](){ }), }, make_describeoptions() @@ -50,16 +47,16 @@ testresults_t test_ClassToTest_main(int argc, const vector& argv) { ); } -testresults_t test_temp(int argc, const vector& argv) { +testresults_t test_temp(const vector& argv) { return execute( - describe(L"ClassToTest", [](){ + describe("ClassToTest", [](){ return make_testbundle({ - describe(L"FeatureToTest", [](){ + describe("FeatureToTest", [](){ return make_testbundle({ - // it(L"should do the thing", [](){ + // it("should do the thing", [](){ // }), - // it(L"should not do the other thing", [](){ + // it("should not do the other thing", [](){ // }), }, make_describeoptions()); @@ -70,11 +67,11 @@ testresults_t test_temp(int argc, const vector& argv) { } // Exmple of nested describes. -testresults_t test_something(int argc, const vector& argv) { +testresults_t test_something(const vector& argv) { return execute( - describe(L"", [](){ + describe("", [](){ return make_testbundle({ - describe(L"", [](){ + describe("", [](){ return make_testbundle({ }, make_describeoptions()); @@ -84,9 +81,9 @@ testresults_t test_something(int argc, const vector& argv) { ); } -testresults_t test_ClassToTest_2(int argc, const vector& argv) { +testresults_t test_ClassToTest_2(const vector& argv) { return execute( - describe(L"ClassToTest", [](){ + describe("ClassToTest", [](){ return make_testbundle({ }, make_describeoptions() @@ -101,15 +98,15 @@ testresults_t test_ClassToTest_2(int argc, const vector& argv) { // Dummy test harness int main(int argc, char* argv[]) { try { - testresults_t results = make_testresults(); + vector args; + testresults_t results; - results = add(results, test_ClassToTest_main(0, vector())); + results = add(results, test_ClassToTest_main(args)); - print_test_results(results, wcout); + print_test_results(results, cout); } catch (std::runtime_error ex) { - std::cout << ex.what() << endl; - // wcout << L"Unhandled exception: " << ex.what() << endl; + std::cout << "Unhandled exception: " << ex.what() << endl; } return 0;