diff --git a/BUILD b/BUILD index 0465f9d..8259647 100644 --- a/BUILD +++ b/BUILD @@ -7,6 +7,8 @@ # # # Licensed under the MIT license. See below for details. # # # +######################################################################################################################## +# # # MIT License # # # # Copyright (c) 2023 Tom Hicks # @@ -36,6 +38,7 @@ cc_library( srcs = ["ansi_escapes.cpp"], hdrs = ["ansi_escapes.h"], includes = ["ansi_escapes.h"], + deps = [":pretty_print"], ) cc_test( diff --git a/WORKSPACE b/WORKSPACE index 9b19011..1f8d97f 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -8,6 +8,8 @@ # # # Licensed under the MIT license. See below for details. # # # +######################################################################################################################## +# # # MIT License # # # # Copyright (c) 2023 Tom Hicks # @@ -26,6 +28,8 @@ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # # # ######################################################################################################################## +workspace(name = "CPPUtils") + load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") # Hedron's Compile Commands Extractor for Bazel @@ -45,7 +49,8 @@ hedron_compile_commands_setup() http_archive( name = "tinytest", - sha256 = "71f366e680606e18268e6b9673a65c44c9e672f7356a61ffbcd3502c6a8eea0b", - strip_prefix = "TinyTest-460c9492d927689b9db7f28d8742705dc0bbee62", - urls = ["https://github.com/headhunter45/TinyTest/archive/460c9492d927689b9db7f28d8742705dc0bbee62.zip"], + # sha256 = "71f366e680606e18268e6b9673a65c44c9e672f7356a61ffbcd3502c6a8eea0b", + sha256 = "49a229ff3b2470e72743f2cc239cb2bc381f2976047a34b6832115097be7d887", + strip_prefix = "TinyTest-011953cd2ccecdc5fe0b8fe83b8d0dde10fa81ab", + urls = ["https://github.com/headhunter45/TinyTest/archive/011953cd2ccecdc5fe0b8fe83b8d0dde10fa81ab.zip"], ) diff --git a/ansi_escapes_test.cpp b/ansi_escapes_test.cpp index 13a70a2..0386f9f 100644 --- a/ansi_escapes_test.cpp +++ b/ansi_escapes_test.cpp @@ -43,45 +43,45 @@ using std::ostream; using std::ostringstream; using std::string; using std::string_view; -using TinyTest::execute_suite; -using TinyTest::make_test; -using TinyTest::make_test_suite; +using TinyTest::ExecuteSuite; +using TinyTest::MakeTest; +using TinyTest::MakeTestSuite; using TinyTest::TestResults; -} // End namespace +} // End namespace -string filter(const string& text) { +string filter(const string &text) { std::regex pattern("\033"); return std::regex_replace(text, pattern, "\\033"); } TestResults test_GetRedComponent() { - return execute_suite(make_test_suite( - "CPPUtils::GetRedComponent(uint32_t)", - CPPUtils::GetRedComponent, - { - make_test("should get the red component 0x34 from 0x12345678", 0x34U, make_tuple(0x12345678U)), - make_test("should get the red component 0x56 from 0x34567890", 0x56U, make_tuple(0x34567890U)), - })); + return ExecuteSuite( + MakeTestSuite("CPPUtils::GetRedComponent(uint32_t)", + CPPUtils::GetRedComponent, + { + MakeTest("should get the red component 0x34 from 0x12345678", 0x34U, make_tuple(0x12345678U)), + MakeTest("should get the red component 0x56 from 0x34567890", 0x56U, make_tuple(0x34567890U)), + })); } TestResults test_GetGreenComponent() { - return execute_suite(make_test_suite( - "CPPUtils::GetGreenComponent(uint32_t)", - CPPUtils::GetGreenComponent, - { - make_test("should get the green component 0x56 from 0x12345678", 0x56U, make_tuple(0x12345678U)), - make_test("should get the green component 0x78 from 0x34567890", 0x78U, make_tuple(0x34567890U)), - })); + return ExecuteSuite( + MakeTestSuite("CPPUtils::GetGreenComponent(uint32_t)", + CPPUtils::GetGreenComponent, + { + MakeTest("should get the green component 0x56 from 0x12345678", 0x56U, make_tuple(0x12345678U)), + MakeTest("should get the green component 0x78 from 0x34567890", 0x78U, make_tuple(0x34567890U)), + })); } TestResults test_GetBlueComponent() { - return execute_suite( - make_test_suite("CPPUtils::GetBlueComponent(uint32_t)", - CPPUtils::GetBlueComponent, - { - make_test("should get the blue component 0x78 from 0x12345678", 0x78, make_tuple(0x12345678)), - make_test("should get the blue component 0x90 from 0x34567890", 0x90, make_tuple(0x34567890)), - })); + return ExecuteSuite( + MakeTestSuite("CPPUtils::GetBlueComponent(uint32_t)", + CPPUtils::GetBlueComponent, + { + MakeTest("should get the blue component 0x78 from 0x12345678", 0x78, make_tuple(0x12345678)), + MakeTest("should get the blue component 0x90 from 0x34567890", 0x90, make_tuple(0x34567890)), + })); } TestResults test_EscapeWithBasicString() { @@ -90,13 +90,13 @@ TestResults test_EscapeWithBasicString() { CPPUtils::Escape(os, text); return os.str(); }; - return execute_suite(make_test_suite( + return ExecuteSuite(MakeTestSuite( "CPPUtils::Escape(string)", function_to_test, { - make_test("should escape \"asdf\" to \"\\033[asdfm\"", (string) "\033[asdfm", make_tuple("asdf")), - make_test("should escape \"fdsa\" to \"\\033[fdsam\"", (string) "\033[fdsam", make_tuple("fdsa")), - make_test("should escape \"1;2;3\" to \"\\033[1;2;3m\"", (string) "\033[1;2;3m", make_tuple("1;2;3")), + MakeTest("should escape \"asdf\" to \"\\033[asdfm\"", (string) "\033[asdfm", make_tuple("asdf")), + MakeTest("should escape \"fdsa\" to \"\\033[fdsam\"", (string) "\033[fdsam", make_tuple("fdsa")), + MakeTest("should escape \"1;2;3\" to \"\\033[1;2;3m\"", (string) "\033[1;2;3m", make_tuple("1;2;3")), })); } @@ -106,29 +106,29 @@ TestResults test_EscapeWithBasicStringView() { CPPUtils::Escape(os, text); return os.str(); }; - return execute_suite(make_test_suite( + return ExecuteSuite(MakeTestSuite( "CPPUtils::Escape(string_view)", function_to_test, { - make_test("should escape \"asdf\" to \"\\033[asdfm\"", (string) "\033[asdfm", make_tuple("asdf")), - make_test("should escape \"fdsa\" to \"\\033[fdsam\"", (string) "\033[fdsam", make_tuple("fdsa")), - make_test("should escape \"1;2;3\" to \"\\033[1;2;3m\"", (string) "\033[1;2;3m", make_tuple("1;2;3")), + MakeTest("should escape \"asdf\" to \"\\033[asdfm\"", (string) "\033[asdfm", make_tuple("asdf")), + MakeTest("should escape \"fdsa\" to \"\\033[fdsam\"", (string) "\033[fdsam", make_tuple("fdsa")), + MakeTest("should escape \"1;2;3\" to \"\\033[1;2;3m\"", (string) "\033[1;2;3m", make_tuple("1;2;3")), })); } TestResults test_EscapeWithConstCharStar() { - auto function_to_test = [](const char* text) { + auto function_to_test = [](const char *text) { ostringstream os; CPPUtils::Escape(os, text); return os.str(); }; - return execute_suite(make_test_suite( + return ExecuteSuite(MakeTestSuite( "CPPUtils::Escape(const char*)", function_to_test, { - make_test("should escape \"asdf\" to \"\\033[asdfm\"", (string) "\033[asdfm", make_tuple("asdf")), - make_test("should escape \"fdsa\" to \"\\033[fdsam\"", (string) "\033[fdsam", make_tuple("fdsa")), - make_test("should escape \"1;2;3\" to \"\\033[1;2;3m\"", (string) "\033[1;2;3m", make_tuple("1;2;3")), + MakeTest("should escape \"asdf\" to \"\\033[asdfm\"", (string) "\033[asdfm", make_tuple("asdf")), + MakeTest("should escape \"fdsa\" to \"\\033[fdsam\"", (string) "\033[fdsam", make_tuple("fdsa")), + MakeTest("should escape \"1;2;3\" to \"\\033[1;2;3m\"", (string) "\033[1;2;3m", make_tuple("1;2;3")), })); } @@ -138,14 +138,14 @@ TestResults test_ForegroundColor8Bit() { CPPUtils::ForegroundColor8Bit(os, color); return os.str(); }; - return execute_suite( - make_test_suite("CPPUtils::ForegroundColor8Bit(uint8_t)", - function_to_test, - { - make_test("should write \"\\033[38;5;7m\"", (string) "\033[38;5;7m", make_tuple(0x07U)), - make_test("should write \"\\033[38;5;1m\"", (string) "\033[38;5;1m", make_tuple(0x01U)), - make_test("should write \"\\033[38;5;11m\"", (string) "\033[38;5;11m", make_tuple(0x0BU)), - })); + return ExecuteSuite( + MakeTestSuite("CPPUtils::ForegroundColor8Bit(uint8_t)", + function_to_test, + { + MakeTest("should write \"\\033[38;5;7m\"", (string) "\033[38;5;7m", make_tuple(0x07U)), + MakeTest("should write \"\\033[38;5;1m\"", (string) "\033[38;5;1m", make_tuple(0x01U)), + MakeTest("should write \"\\033[38;5;11m\"", (string) "\033[38;5;11m", make_tuple(0x0BU)), + })); } TestResults test_BackgroundColor8Bit() { @@ -154,14 +154,14 @@ TestResults test_BackgroundColor8Bit() { CPPUtils::BackgroundColor8Bit(os, color); return os.str(); }; - return execute_suite( - make_test_suite("CPPUtils::BackgroundColor8Bit(uint8_t)", - function_to_test, - { - make_test("should write \"\\033[48;5;7m\"", (string) "\033[48;5;7m", make_tuple(0x07U)), - make_test("should write \"\\033[48;5;1m\"", (string) "\033[48;5;1m", make_tuple(0x01U)), - make_test("should write \"\\033[48;5;11m\"", (string) "\033[48;5;11m", make_tuple(0x0BU)), - })); + return ExecuteSuite( + MakeTestSuite("CPPUtils::BackgroundColor8Bit(uint8_t)", + function_to_test, + { + MakeTest("should write \"\\033[48;5;7m\"", (string) "\033[48;5;7m", make_tuple(0x07U)), + MakeTest("should write \"\\033[48;5;1m\"", (string) "\033[48;5;1m", make_tuple(0x01U)), + MakeTest("should write \"\\033[48;5;11m\"", (string) "\033[48;5;11m", make_tuple(0x0BU)), + })); } TestResults test_ForegroundTrueColorWithUInt32() { @@ -170,11 +170,11 @@ TestResults test_ForegroundTrueColorWithUInt32() { CPPUtils::ForegroundTrueColor(os, color); return os.str(); }; - return execute_suite(make_test_suite( + return ExecuteSuite(MakeTestSuite( "CPPUtils::ForegroundTrueColor(uint32_t)", function_to_test, { - make_test("should write \"\\033[38;2;21;69;136m\"", (string) "\033[38;2;21;69;136m", make_tuple(0x00154588)), + MakeTest("should write \"\\033[38;2;21;69;136m\"", (string) "\033[38;2;21;69;136m", make_tuple(0x00154588)), })); } @@ -184,11 +184,11 @@ TestResults test_BackgroundTrueColorWithUInt32() { CPPUtils::BackgroundTrueColor(os, color); return os.str(); }; - return execute_suite(make_test_suite( + return ExecuteSuite(MakeTestSuite( "CPPUtils::BackgroundTrueColor(uint32_t)", function_to_test, { - make_test("should write \"\\033[48;2;21;69;136m\"", (string) "\033[48;2;21;69;136m", make_tuple(0x00154588)), + MakeTest("should write \"\\033[48;2;21;69;136m\"", (string) "\033[48;2;21;69;136m", make_tuple(0x00154588)), })); } @@ -198,13 +198,13 @@ TestResults test_ForegroundTrueColorWith3UInt8() { CPPUtils::ForegroundTrueColor(os, red, green, blue); return os.str(); }; - return execute_suite(make_test_suite( - "CPPUtils::ForegroundTrueColor(uint8_t, uint8_t, uint8_t)", - function_to_test, - { - make_test( - "should write \"\\033[38;2;21;69;136m\"", (string) "\033[38;2;21;69;136m", make_tuple(0x15, 0x45, 0x88)), - })); + return ExecuteSuite(MakeTestSuite("CPPUtils::ForegroundTrueColor(uint8_t, uint8_t, uint8_t)", + function_to_test, + { + MakeTest("should write \"\\033[38;2;21;69;136m\"", + (string) "\033[38;2;21;69;136m", + make_tuple(0x15, 0x45, 0x88)), + })); } TestResults test_BackgroundTrueColorWith3UInt8() { @@ -213,13 +213,13 @@ TestResults test_BackgroundTrueColorWith3UInt8() { CPPUtils::BackgroundTrueColor(os, red, green, blue); return os.str(); }; - return execute_suite(make_test_suite( - "CPPUtils::BackgroundTrueColor(uint8_t, uint8_t, uint8_t)", - function_to_test, - { - make_test( - "should write \"\\033[48;2;21;69;136m\"", (string) "\033[48;2;21;69;136m", make_tuple(0x15, 0x45, 0x88)), - })); + return ExecuteSuite(MakeTestSuite("CPPUtils::BackgroundTrueColor(uint8_t, uint8_t, uint8_t)", + function_to_test, + { + MakeTest("should write \"\\033[48;2;21;69;136m\"", + (string) "\033[48;2;21;69;136m", + make_tuple(0x15, 0x45, 0x88)), + })); } TestResults test_Reset() { @@ -228,14 +228,14 @@ TestResults test_Reset() { CPPUtils::Reset(os); return os.str(); }; - return execute_suite(make_test_suite("CPPUtils::Reset", - function_to_test, - { - make_test("should write \"\\033[m\"", (string) "\033[m", make_tuple()), - })); + return ExecuteSuite(MakeTestSuite("CPPUtils::Reset", + function_to_test, + { + MakeTest("should write \"\\033[m\"", (string) "\033[m", make_tuple()), + })); } -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { TestResults results; results += test_GetRedComponent(); @@ -252,5 +252,5 @@ int main(int argc, char* argv[]) { results += test_BackgroundTrueColorWith3UInt8(); results += test_Reset(); - return results.failed() + results.errors(); + return results.Failed() + results.Errors(); } diff --git a/console_logger_test.cpp b/console_logger_test.cpp index 0848e01..a5c91ad 100644 --- a/console_logger_test.cpp +++ b/console_logger_test.cpp @@ -45,16 +45,16 @@ using std::make_tuple; using std::ostream; using std::ostringstream; using std::string; -using TinyTest::execute_suite; -using TinyTest::make_test; -using TinyTest::make_test_suite; +using TinyTest::ExecuteSuite; +using TinyTest::MakeTest; +using TinyTest::MakeTestSuite; using TinyTest::TestResults; string no_errors = "no errors"; -} // namespace +} // namespace TestResults test_ConsoleLogger_LogMessage() { - auto log_message = [](const Logger::MessageType& type, const string& message) -> string { + auto log_message = [](const Logger::MessageType &type, const string &message) -> string { ostringstream errors; ostringstream output; auto destination = make_shared(); @@ -62,33 +62,33 @@ TestResults test_ConsoleLogger_LogMessage() { destination->LogMessage(type, message); return output.str(); }; - return execute_suite(make_test_suite("CPPUtils::ConsoleLogger::LogMessage(cosnt std::string&)", - log_message, - {make_test("should print \"[Debug] this is a message\"", - (string) "[Debug] this is a message\n", - make_tuple(Logger::MessageType::Debug, "this is a message")), - make_test("should print \"[Error] this is an error\"", - (string) "[Error] this is an error\n", - make_tuple(Logger::MessageType::Error, "this is an error")), - make_test("should print \"[Wtf] what a terrible failure\"", - (string) "[Wtf] what a terrible failure\n", - make_tuple(Logger::MessageType::Wtf, "what a terrible failure")), - make_test("should print \"[Info] this is some information\"", - (string) "[Info] this is some information\n", - make_tuple(Logger::MessageType::Info, "this is some information")), - make_test("should print \"[Warning] this is a warning\"", - (string) "[Warning] this is a warning\n", - make_tuple(Logger::MessageType::Warning, "this is a warning")), - make_test("should print \"[Verbose] this is verbose\"", - (string) "[Verbose] this is verbose\n", - make_tuple(Logger::MessageType::Verbose, "this is verbose")), - make_test("should print \"[Unclassified] unclassified message\"", - (string) "[Unclassified] unclassified message\n", - make_tuple((Logger::MessageType)1000, "unclassified message"))})); + return ExecuteSuite(MakeTestSuite("CPPUtils::ConsoleLogger::LogMessage(cosnt std::string&)", + log_message, + {MakeTest("should print \"[Debug] this is a message\"", + (string) "[Debug] this is a message\n", + make_tuple(Logger::MessageType::Debug, "this is a message")), + MakeTest("should print \"[Error] this is an error\"", + (string) "[Error] this is an error\n", + make_tuple(Logger::MessageType::Error, "this is an error")), + MakeTest("should print \"[Wtf] what a terrible failure\"", + (string) "[Wtf] what a terrible failure\n", + make_tuple(Logger::MessageType::Wtf, "what a terrible failure")), + MakeTest("should print \"[Info] this is some information\"", + (string) "[Info] this is some information\n", + make_tuple(Logger::MessageType::Info, "this is some information")), + MakeTest("should print \"[Warning] this is a warning\"", + (string) "[Warning] this is a warning\n", + make_tuple(Logger::MessageType::Warning, "this is a warning")), + MakeTest("should print \"[Verbose] this is verbose\"", + (string) "[Verbose] this is verbose\n", + make_tuple(Logger::MessageType::Verbose, "this is verbose")), + MakeTest("should print \"[Unclassified] unclassified message\"", + (string) "[Unclassified] unclassified message\n", + make_tuple((Logger::MessageType)1000, "unclassified message"))})); } TestResults test_ConsoleLogger_LogErrorWithMessage() { - auto log_error = [](const Logger::MessageType& type, const std::exception& ex) -> string { + auto log_error = [](const Logger::MessageType &type, const std::exception &ex) -> string { ostringstream errors; ostringstream output; auto destination = make_shared(); @@ -96,34 +96,34 @@ TestResults test_ConsoleLogger_LogErrorWithMessage() { destination->LogError(type, ex); return output.str(); }; - return execute_suite( - make_test_suite("CPPUtils::ConsoleLogger::LogError(const std::exception&)", - log_error, - {make_test("should print \"[Debug] caught exception: this is an exception\"", - (string) "[Debug] caught exception: this is an exception\n", - make_tuple(Logger::MessageType::Debug, std::runtime_error("this is an exception"))), - make_test("should print \"[Error] caught exception: this is an error\"", - (string) "[Error] caught exception: this is an error\n", - make_tuple(Logger::MessageType::Error, std::runtime_error("this is an error"))), - make_test("should print \"[Wtf] caught exception: what a terrible failure\"", - (string) "[Wtf] caught exception: what a terrible failure\n", - make_tuple(Logger::MessageType::Wtf, std::runtime_error("what a terrible failure"))), - make_test("should print \"[Info] caught exception: this is some information\"", - (string) "[Info] caught exception: this is some information\n", - make_tuple(Logger::MessageType::Info, std::runtime_error("this is some information"))), - make_test("should print \"[Warning] caught exception: this is a warning\"", - (string) "[Warning] caught exception: this is a warning\n", - make_tuple(Logger::MessageType::Warning, std::runtime_error("this is a warning"))), - make_test("should print \"[Verbose] caught exception: this is verbose\"", - (string) "[Verbose] caught exception: this is verbose\n", - make_tuple(Logger::MessageType::Verbose, std::runtime_error("this is verbose"))), - make_test("should print \"[Unclassified] caught exception: unclassified message\"", - (string) "[Unclassified] caught exception: unclassified message\n", - make_tuple((Logger::MessageType)1000, std::runtime_error("unclassified message")))})); + return ExecuteSuite( + MakeTestSuite("CPPUtils::ConsoleLogger::LogError(const std::exception&)", + log_error, + {MakeTest("should print \"[Debug] caught exception: this is an exception\"", + (string) "[Debug] caught exception: this is an exception\n", + make_tuple(Logger::MessageType::Debug, std::runtime_error("this is an exception"))), + MakeTest("should print \"[Error] caught exception: this is an error\"", + (string) "[Error] caught exception: this is an error\n", + make_tuple(Logger::MessageType::Error, std::runtime_error("this is an error"))), + MakeTest("should print \"[Wtf] caught exception: what a terrible failure\"", + (string) "[Wtf] caught exception: what a terrible failure\n", + make_tuple(Logger::MessageType::Wtf, std::runtime_error("what a terrible failure"))), + MakeTest("should print \"[Info] caught exception: this is some information\"", + (string) "[Info] caught exception: this is some information\n", + make_tuple(Logger::MessageType::Info, std::runtime_error("this is some information"))), + MakeTest("should print \"[Warning] caught exception: this is a warning\"", + (string) "[Warning] caught exception: this is a warning\n", + make_tuple(Logger::MessageType::Warning, std::runtime_error("this is a warning"))), + MakeTest("should print \"[Verbose] caught exception: this is verbose\"", + (string) "[Verbose] caught exception: this is verbose\n", + make_tuple(Logger::MessageType::Verbose, std::runtime_error("this is verbose"))), + MakeTest("should print \"[Unclassified] caught exception: unclassified message\"", + (string) "[Unclassified] caught exception: unclassified message\n", + make_tuple((Logger::MessageType)1000, std::runtime_error("unclassified message")))})); } TestResults test_ConsoleLogger_LogErrorWithoutMessage() { - auto log_error = [](const Logger::MessageType& type, const std::string& message, const std::exception& ex) -> string { + auto log_error = [](const Logger::MessageType &type, const std::string &message, const std::exception &ex) -> string { ostringstream errors; ostringstream output; auto destination = make_shared(); @@ -131,45 +131,45 @@ TestResults test_ConsoleLogger_LogErrorWithoutMessage() { destination->LogError(type, message, ex); return output.str(); }; - return execute_suite(make_test_suite( + return ExecuteSuite(MakeTestSuite( "CPPUtils::ConsoleLogger::LogError(const std::string&, const std::exception&)", log_error, { - make_test( + MakeTest( "should print \"[Debug] this is a message with caught exception this is an exception\"", (string) "[Debug] this is a message with caught exception this is an exception\n", make_tuple(Logger::MessageType::Debug, "this is a message", std::runtime_error("this is an exception"))), - make_test( + MakeTest( "should print \"[Error] this is an error with caught exception this is an exception\"", (string) "[Error] this is an error with caught exception this is an exception\n", make_tuple(Logger::MessageType::Error, "this is an error", std::runtime_error("this is an exception"))), - make_test( - "should print \"[Wtf] what a terrible failure with caught exception this is an exception\"", - (string) "[Wtf] what a terrible failure with caught exception this is an exception\n", - make_tuple( - Logger::MessageType::Wtf, "what a terrible failure", std::runtime_error("this is an exception"))), - make_test( - "should print \"[Info] this is some information with caught exception this is an exception\"", - (string) "[Info] this is some information with caught exception this is an exception\n", - make_tuple( - Logger::MessageType::Info, "this is some information", std::runtime_error("this is an exception"))), - make_test("should print \"[Warning] this is a warning with caught exception this is an exception\"", - (string) "[Warning] this is a warning with caught exception this is an exception\n", - make_tuple( - Logger::MessageType::Warning, "this is a warning", std::runtime_error("this is an exception"))), - make_test( + MakeTest("should print \"[Wtf] what a terrible failure with caught exception this is an exception\"", + (string) "[Wtf] what a terrible failure with caught exception this is an exception\n", + make_tuple(Logger::MessageType::Wtf, + "what a terrible failure", + std::runtime_error("this is an exception"))), + MakeTest("should print \"[Info] this is some information with caught exception this is an exception\"", + (string) "[Info] this is some information with caught exception this is an exception\n", + make_tuple(Logger::MessageType::Info, + "this is some information", + std::runtime_error("this is an exception"))), + MakeTest("should print \"[Warning] this is a warning with caught exception this is an exception\"", + (string) "[Warning] this is a warning with caught exception this is an exception\n", + make_tuple( + Logger::MessageType::Warning, "this is a warning", std::runtime_error("this is an exception"))), + MakeTest( "should print \"[Verbose] this is verbose with caught exception this is an exception\"", (string) "[Verbose] this is verbose with caught exception this is an exception\n", make_tuple(Logger::MessageType::Verbose, "this is verbose", std::runtime_error("this is an exception"))), - make_test("should print \"[Unclassified] unclassified message with caught exception this is an exception\"", - (string) "[Unclassified] unclassified message with caught exception this is an exception\n", - make_tuple( - (Logger::MessageType)1000, "unclassified message", std::runtime_error("this is an exception"))), + MakeTest("should print \"[Unclassified] unclassified message with caught exception this is an exception\"", + (string) "[Unclassified] unclassified message with caught exception this is an exception\n", + make_tuple( + (Logger::MessageType)1000, "unclassified message", std::runtime_error("this is an exception"))), })); } TestResults test_ConsoleLogger_SetOutputStream() { - auto set_get_output_stream = [](std::ostream& os, bool only_get) -> bool { + auto set_get_output_stream = [](std::ostream &os, bool only_get) -> bool { auto destination = make_shared(); if (!only_get) { destination->SetOutputStream(os); @@ -177,17 +177,17 @@ TestResults test_ConsoleLogger_SetOutputStream() { return &destination->GetOutputStream() == &os; }; std::ostringstream os1; - return execute_suite(make_test_suite( + return ExecuteSuite(MakeTestSuite( "CPPUtils::ConsoleLogger::Set/GetOutputStream(std::ostream&)", set_get_output_stream, { - make_test("should get cout by default", true, make_tuple(std::ref(std::cout), true)), - make_test("should set and get the same output stream", true, make_tuple(std::ref(std::cout), false)), - make_test("should set and get the same output stream", true, make_tuple(std::ref((std::ostream&)os1), false)), + MakeTest("should get cout by default", true, make_tuple(std::ref(std::cout), true)), + MakeTest("should set and get the same output stream", true, make_tuple(std::ref(std::cout), false)), + MakeTest("should set and get the same output stream", true, make_tuple(std::ref((std::ostream &)os1), false)), })); } -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { TestResults results; results += test_ConsoleLogger_LogMessage(); @@ -197,5 +197,5 @@ int main(int argc, char* argv[]) { PrintResults(cout, results); - return results.failed() + results.errors(); + return results.Failed() + results.Errors(); } diff --git a/logger_test.cpp b/logger_test.cpp index f4a9d1d..ca6b31b 100644 --- a/logger_test.cpp +++ b/logger_test.cpp @@ -56,16 +56,16 @@ using std::shared_ptr; using std::string; using std::tuple; using std::vector; -using TinyTest::execute_suite; -using TinyTest::make_test; -using TinyTest::make_test_suite; +using TinyTest::ExecuteSuite; +using TinyTest::MakeTest; +using TinyTest::MakeTestSuite; using TinyTest::TestResults; string no_errors = "no errors"; typedef tuple, optional> LogEntry; class SpyLoggerDestination : public Logger::Destination { - public: +public: SpyLoggerDestination() { min_type_ = Logger::MessageType::Unknown; max_type_ = Logger::MessageType::Wtf; @@ -73,23 +73,22 @@ class SpyLoggerDestination : public Logger::Destination { virtual ~SpyLoggerDestination() {} - virtual void LogMessage(const Logger::MessageType& type, const std::string& message) const { + virtual void LogMessage(const Logger::MessageType &type, const std::string &message) const { log.push_back(make_tuple(type, message, nullopt)); } - virtual void LogError(const Logger::MessageType& type, const std::exception& ex) const { + virtual void LogError(const Logger::MessageType &type, const std::exception &ex) const { log.push_back(make_tuple(type, nullopt, ex.what())); } - virtual void LogError(const Logger::MessageType& type, const std::string& message, const std::exception& ex) const { + virtual void LogError(const Logger::MessageType &type, const std::string &message, const std::exception &ex) const { log.push_back(make_tuple(type, message, ex.what())); } mutable vector log; }; -template -ostream& PrintOptional(ostream& os, optional op) { +template ostream &PrintOptional(ostream &os, optional op) { if (op.has_value()) { os << op.value(); } else { @@ -98,14 +97,14 @@ ostream& PrintOptional(ostream& os, optional op) { return os; } -void ExpectMessageType(ostream& error_message, const Logger::MessageType& expected, const LogEntry& log_entry) { +void ExpectMessageType(ostream &error_message, const Logger::MessageType &expected, const LogEntry &log_entry) { Logger::MessageType actual = get<0>(log_entry); if (actual != expected) { error_message << "Unexpected MessageType expected: " << expected << ", actual: " << actual << endl; } } -void ExpectMessageText(ostream& error_message, optional expected, const LogEntry& log_entry) { +void ExpectMessageText(ostream &error_message, optional expected, const LogEntry &log_entry) { optional actual = get<1>(log_entry); if (actual != expected) { error_message << "Unexpected message text. Expected: "; @@ -114,7 +113,7 @@ void ExpectMessageText(ostream& error_message, optional expected, const } } -void ExpectMessageException(ostream& error_message, optional expected, const LogEntry& log_entry) { +void ExpectMessageException(ostream &error_message, optional expected, const LogEntry &log_entry) { optional actual = get<2>(log_entry); if (actual != expected) { error_message << "Unexpected message exception. Expected: "; @@ -123,25 +122,25 @@ void ExpectMessageException(ostream& error_message, optional expected, c } } -void ExpectLogSize(ostream& error_message, size_t expected, shared_ptr destination) { +void ExpectLogSize(ostream &error_message, size_t expected, shared_ptr destination) { size_t actual = destination->log.size(); if (actual != expected) { error_message << "Unexpected number of events logged. Expected: " << expected << ", Actual: " << actual << endl; } } -string GetError(ostringstream& error_message) { +string GetError(ostringstream &error_message) { string error = error_message.str(); if (error.size() > 0) { return error; } return no_errors; } -} // End namespace +} // End namespace TestResults test_Destination_TypeRangeGettersAndSetters() { TestResults results; - auto set_min_type = [](const Logger::MessageType& type) { + auto set_min_type = [](const Logger::MessageType &type) { auto spy = make_shared(); if (type == Logger::MessageType::Unknown) { spy->SetMinType(Logger::MessageType::Debug); @@ -151,25 +150,25 @@ TestResults test_Destination_TypeRangeGettersAndSetters() { spy->SetMinType(type); return spy->GetMinType(); }; - results += execute_suite(make_test_suite( + results += ExecuteSuite(MakeTestSuite( "CPPUtils::Logger::SetMinType(const MessageType&)", set_min_type, { - make_test( + MakeTest( "should set min type to Unknown", Logger::MessageType::Unknown, make_tuple(Logger::MessageType::Unknown)), - make_test("should set min type to Debug", Logger::MessageType::Debug, make_tuple(Logger::MessageType::Debug)), - make_test( + MakeTest("should set min type to Debug", Logger::MessageType::Debug, make_tuple(Logger::MessageType::Debug)), + MakeTest( "should set min type to Verbose", Logger::MessageType::Verbose, make_tuple(Logger::MessageType::Verbose)), - make_test("should set min type to Info", Logger::MessageType::Info, make_tuple(Logger::MessageType::Info)), - make_test( + MakeTest("should set min type to Info", Logger::MessageType::Info, make_tuple(Logger::MessageType::Info)), + MakeTest( "should set min type to Warning", Logger::MessageType::Warning, make_tuple(Logger::MessageType::Warning)), - make_test("should set min type to Error", Logger::MessageType::Error, make_tuple(Logger::MessageType::Error)), - make_test("should set min type to Wtf", Logger::MessageType::Wtf, make_tuple(Logger::MessageType::Wtf)), - make_test("should set min type to Unknown for an invalid MessageType", - Logger::MessageType::Unknown, - (make_tuple((Logger::MessageType)-1))), + MakeTest("should set min type to Error", Logger::MessageType::Error, make_tuple(Logger::MessageType::Error)), + MakeTest("should set min type to Wtf", Logger::MessageType::Wtf, make_tuple(Logger::MessageType::Wtf)), + MakeTest("should set min type to Unknown for an invalid MessageType", + Logger::MessageType::Unknown, + (make_tuple((Logger::MessageType)-1))), })); - auto set_max_type = [](const Logger::MessageType& type) { + auto set_max_type = [](const Logger::MessageType &type) { auto spy = make_shared(); if (type == Logger::MessageType::Unknown) { spy->SetMaxType(Logger::MessageType::Debug); @@ -179,23 +178,23 @@ TestResults test_Destination_TypeRangeGettersAndSetters() { spy->SetMaxType(type); return spy->GetMaxType(); }; - results += execute_suite(make_test_suite( + results += ExecuteSuite(MakeTestSuite( "CPPUtils::Logger::SetMaxType(const MessageType&)", set_max_type, { - make_test( + MakeTest( "should set max type to Unknown", Logger::MessageType::Unknown, make_tuple(Logger::MessageType::Unknown)), - make_test("should set max type to Debug", Logger::MessageType::Debug, make_tuple(Logger::MessageType::Debug)), - make_test( + MakeTest("should set max type to Debug", Logger::MessageType::Debug, make_tuple(Logger::MessageType::Debug)), + MakeTest( "should set max type to Verbose", Logger::MessageType::Verbose, make_tuple(Logger::MessageType::Verbose)), - make_test("should set max type to Info", Logger::MessageType::Info, make_tuple(Logger::MessageType::Info)), - make_test( + MakeTest("should set max type to Info", Logger::MessageType::Info, make_tuple(Logger::MessageType::Info)), + MakeTest( "should set max type to Warning", Logger::MessageType::Warning, make_tuple(Logger::MessageType::Warning)), - make_test("should set max type to Error", Logger::MessageType::Error, make_tuple(Logger::MessageType::Error)), - make_test("should set max type to Wtf", Logger::MessageType::Wtf, make_tuple(Logger::MessageType::Wtf)), - make_test("should set max type to Unknown for an invalid MessageType", - Logger::MessageType::Unknown, - (make_tuple((Logger::MessageType)-1))), + MakeTest("should set max type to Error", Logger::MessageType::Error, make_tuple(Logger::MessageType::Error)), + MakeTest("should set max type to Wtf", Logger::MessageType::Wtf, make_tuple(Logger::MessageType::Wtf)), + MakeTest("should set max type to Unknown for an invalid MessageType", + Logger::MessageType::Unknown, + (make_tuple((Logger::MessageType)-1))), })); return results; } @@ -206,11 +205,11 @@ TestResults test_Logger_GetShared() { auto second = Logger::GetShared(); return first == second; }; - return execute_suite(make_test_suite("CPPUtils::Logger::GetShared()", - function_to_test, - { - make_test("should get the same instance twice", true, make_tuple()), - })); + return ExecuteSuite(MakeTestSuite("CPPUtils::Logger::GetShared()", + function_to_test, + { + MakeTest("should get the same instance twice", true, make_tuple()), + })); } TestResults test_Logger_GetUnique() { @@ -228,18 +227,18 @@ TestResults test_Logger_GetUnique() { TestResults results; - results += execute_suite(make_test_suite("CPPUtils::Logger::GetUnique()", - get_unique_is_different, - { - make_test("should get two different instances", true, make_tuple()), - })); + results += ExecuteSuite(MakeTestSuite("CPPUtils::Logger::GetUnique()", + get_unique_is_different, + { + MakeTest("should get two different instances", true, make_tuple()), + })); - results += execute_suite( - make_test_suite("CPPUtils::Logger::GetUnique()", - get_unique_is_not_get_shared, - { - make_test("should get and instance that is not the shared instance", true, make_tuple()), - })); + results += ExecuteSuite( + MakeTestSuite("CPPUtils::Logger::GetUnique()", + get_unique_is_not_get_shared, + { + MakeTest("should get and instance that is not the shared instance", true, make_tuple()), + })); return results; } @@ -274,11 +273,11 @@ TestResults test_LogUnimplementedMethod() { } return GetError(error_message); }; - return execute_suite(make_test_suite( + return ExecuteSuite(MakeTestSuite( "CPPUtils::Logger::LogUnimplementedMethod", function_to_test, { - make_test("should log a debug message", no_errors, make_tuple("int main(int argc, char* argv[])")), + MakeTest("should log a debug message", no_errors, make_tuple("int main(int argc, char* argv[])")), })); #endif } @@ -300,11 +299,11 @@ TestResults test_Logger_LogUnhandledError() { } return GetError(error_message); }; - return execute_suite(make_test_suite("CPPUtils::Logger::LogUnhandledError(const std::exception&)", - log_unhandled_error, - { - make_test("should log an error", no_errors, make_tuple()), - })); + return ExecuteSuite(MakeTestSuite("CPPUtils::Logger::LogUnhandledError(const std::exception&)", + log_unhandled_error, + { + MakeTest("should log an error", no_errors, make_tuple()), + })); } TestResults test_Logger_LogUnimplementedFeature() { @@ -324,102 +323,102 @@ TestResults test_Logger_LogUnimplementedFeature() { } return GetError(error_message); }; - return execute_suite(make_test_suite("CPPUtils::Logger::LogUnimplementedFeature()", - log_unimplemented_feature, - { - make_test("should log an unimplemented feature", no_errors, make_tuple()), - })); + return ExecuteSuite(MakeTestSuite("CPPUtils::Logger::LogUnimplementedFeature()", + log_unimplemented_feature, + { + MakeTest("should log an unimplemented feature", no_errors, make_tuple()), + })); } TestResults test_Logger_Log_Level() { - auto log = [](const Logger::MessageType& type, - const optional& message_text, - const optional& ex) -> string { + auto log = [](const Logger::MessageType &type, + const optional &message_text, + const optional &ex) -> string { ostringstream error_message; auto logger = Logger::GetUnique(); auto spy = make_shared(); logger->AddDestination(spy); switch (type) { - case Logger::MessageType::Debug: - if (message_text.has_value()) { - if (ex.has_value()) { - logger->LogDebug(message_text.value(), ex.value()); - } else { - logger->LogDebug(message_text.value()); - } + case Logger::MessageType::Debug: + if (message_text.has_value()) { + if (ex.has_value()) { + logger->LogDebug(message_text.value(), ex.value()); } else { - if (ex.has_value()) { - logger->LogDebug(ex.value()); - } + logger->LogDebug(message_text.value()); } - break; - case Logger::MessageType::Verbose: - if (message_text.has_value()) { - if (ex.has_value()) { - logger->LogVerbose(message_text.value(), ex.value()); - } else { - logger->LogVerbose(message_text.value()); - } + } else { + if (ex.has_value()) { + logger->LogDebug(ex.value()); + } + } + break; + case Logger::MessageType::Verbose: + if (message_text.has_value()) { + if (ex.has_value()) { + logger->LogVerbose(message_text.value(), ex.value()); } else { - if (ex.has_value()) { - logger->LogVerbose(ex.value()); - } + logger->LogVerbose(message_text.value()); } - break; - case Logger::MessageType::Info: - if (message_text.has_value()) { - if (ex.has_value()) { - logger->LogInfo(message_text.value(), ex.value()); - } else { - logger->LogInfo(message_text.value()); - } + } else { + if (ex.has_value()) { + logger->LogVerbose(ex.value()); + } + } + break; + case Logger::MessageType::Info: + if (message_text.has_value()) { + if (ex.has_value()) { + logger->LogInfo(message_text.value(), ex.value()); } else { - if (ex.has_value()) { - logger->LogInfo(ex.value()); - } + logger->LogInfo(message_text.value()); } - break; - case Logger::MessageType::Warning: - if (message_text.has_value()) { - if (ex.has_value()) { - logger->LogWarning(message_text.value(), ex.value()); - } else { - logger->LogWarning(message_text.value()); - } + } else { + if (ex.has_value()) { + logger->LogInfo(ex.value()); + } + } + break; + case Logger::MessageType::Warning: + if (message_text.has_value()) { + if (ex.has_value()) { + logger->LogWarning(message_text.value(), ex.value()); } else { - if (ex.has_value()) { - logger->LogWarning(ex.value()); - } + logger->LogWarning(message_text.value()); } - break; - case Logger::MessageType::Error: - if (message_text.has_value()) { - if (ex.has_value()) { - logger->LogError(message_text.value(), ex.value()); - } else { - logger->LogError(message_text.value()); - } + } else { + if (ex.has_value()) { + logger->LogWarning(ex.value()); + } + } + break; + case Logger::MessageType::Error: + if (message_text.has_value()) { + if (ex.has_value()) { + logger->LogError(message_text.value(), ex.value()); } else { - if (ex.has_value()) { - logger->LogError(ex.value()); - } + logger->LogError(message_text.value()); } - break; - case Logger::MessageType::Wtf: - if (message_text.has_value()) { - if (ex.has_value()) { - logger->LogWtf(message_text.value(), ex.value()); - } else { - logger->LogWtf(message_text.value()); - } + } else { + if (ex.has_value()) { + logger->LogError(ex.value()); + } + } + break; + case Logger::MessageType::Wtf: + if (message_text.has_value()) { + if (ex.has_value()) { + logger->LogWtf(message_text.value(), ex.value()); } else { - if (ex.has_value()) { - logger->LogWtf(ex.value()); - } + logger->LogWtf(message_text.value()); } - break; - default: - break; + } else { + if (ex.has_value()) { + logger->LogWtf(ex.value()); + } + } + break; + default: + break; } ExpectLogSize(error_message, 1, spy); if (spy->log.size() > 0) { @@ -430,193 +429,193 @@ TestResults test_Logger_Log_Level() { } return GetError(error_message); }; - return execute_suite( - make_test_suite("CPPUtils::Logger::Log*(...)", - log, - { - make_test("should log what a terrible failure with a message", - no_errors, - make_tuple(Logger::MessageType::Wtf, - (const optional&)"this should never happen", - (const optional&)nullopt)), - make_test("should log what a terrible failure with a message and an exception", - no_errors, - make_tuple(Logger::MessageType::Wtf, - (const optional&)"this should never happen", - (const optional&)runtime_error("bad thing happen"))), - make_test("should log what a terrible failure with a message", - no_errors, - make_tuple(Logger::MessageType::Wtf, - (const optional&)nullopt, - (const optional&)runtime_error("bad thing happen"))), - make_test("should log an error with a message", - no_errors, - make_tuple(Logger::MessageType::Error, - (const optional&)"this should never happen", - (const optional&)nullopt)), - make_test("should log an error with a message and an exception", - no_errors, - make_tuple(Logger::MessageType::Error, - (const optional&)"this should never happen", - (const optional&)runtime_error("bad thing happen"))), - make_test("should log an error with a message", - no_errors, - make_tuple(Logger::MessageType::Error, - (const optional&)nullopt, - (const optional&)runtime_error("bad thing happen"))), - make_test("should log a warning with a message", - no_errors, - make_tuple(Logger::MessageType::Warning, - (const optional&)"this should never happen", - (const optional&)nullopt)), - make_test("should log a warning with a message and an exception", - no_errors, - make_tuple(Logger::MessageType::Warning, - (const optional&)"this should never happen", - (const optional&)runtime_error("bad thing happen"))), - make_test("should log a warning with a message", - no_errors, - make_tuple(Logger::MessageType::Warning, - (const optional&)nullopt, - (const optional&)runtime_error("bad thing happen"))), - make_test("should log an info with a message", - no_errors, - make_tuple(Logger::MessageType::Info, - (const optional&)"this should never happen", - (const optional&)nullopt)), - make_test("should log an info with a message and an exception", - no_errors, - make_tuple(Logger::MessageType::Info, - (const optional&)"this should never happen", - (const optional&)runtime_error("bad thing happen"))), - make_test("should log an info with a message", - no_errors, - make_tuple(Logger::MessageType::Info, - (const optional&)nullopt, - (const optional&)runtime_error("bad thing happen"))), - make_test("should log a debug with a message", - no_errors, - make_tuple(Logger::MessageType::Debug, - (const optional&)"this should never happen", - (const optional&)nullopt)), - make_test("should log a debug with a message and an exception", - no_errors, - make_tuple(Logger::MessageType::Debug, - (const optional&)"this should never happen", - (const optional&)runtime_error("bad thing happen"))), - make_test("should log a debug with a message", - no_errors, - make_tuple(Logger::MessageType::Debug, - (const optional&)nullopt, - (const optional&)runtime_error("bad thing happen"))), - make_test("should log a verbose with a message", - no_errors, - make_tuple(Logger::MessageType::Verbose, - (const optional&)"this should never happen", - (const optional&)nullopt)), - make_test("should log a verbose with a message and an exception", - no_errors, - make_tuple(Logger::MessageType::Verbose, - (const optional&)"this should never happen", - (const optional&)runtime_error("bad thing happen"))), - make_test("should log a verbose with a message", - no_errors, - make_tuple(Logger::MessageType::Verbose, - (const optional&)nullopt, - (const optional&)runtime_error("bad thing happen"))), + return ExecuteSuite( + MakeTestSuite("CPPUtils::Logger::Log*(...)", + log, + { + MakeTest("should log what a terrible failure with a message", + no_errors, + make_tuple(Logger::MessageType::Wtf, + (const optional &)"this should never happen", + (const optional &)nullopt)), + MakeTest("should log what a terrible failure with a message and an exception", + no_errors, + make_tuple(Logger::MessageType::Wtf, + (const optional &)"this should never happen", + (const optional &)runtime_error("bad thing happen"))), + MakeTest("should log what a terrible failure with a message", + no_errors, + make_tuple(Logger::MessageType::Wtf, + (const optional &)nullopt, + (const optional &)runtime_error("bad thing happen"))), + MakeTest("should log an error with a message", + no_errors, + make_tuple(Logger::MessageType::Error, + (const optional &)"this should never happen", + (const optional &)nullopt)), + MakeTest("should log an error with a message and an exception", + no_errors, + make_tuple(Logger::MessageType::Error, + (const optional &)"this should never happen", + (const optional &)runtime_error("bad thing happen"))), + MakeTest("should log an error with a message", + no_errors, + make_tuple(Logger::MessageType::Error, + (const optional &)nullopt, + (const optional &)runtime_error("bad thing happen"))), + MakeTest("should log a warning with a message", + no_errors, + make_tuple(Logger::MessageType::Warning, + (const optional &)"this should never happen", + (const optional &)nullopt)), + MakeTest("should log a warning with a message and an exception", + no_errors, + make_tuple(Logger::MessageType::Warning, + (const optional &)"this should never happen", + (const optional &)runtime_error("bad thing happen"))), + MakeTest("should log a warning with a message", + no_errors, + make_tuple(Logger::MessageType::Warning, + (const optional &)nullopt, + (const optional &)runtime_error("bad thing happen"))), + MakeTest("should log an info with a message", + no_errors, + make_tuple(Logger::MessageType::Info, + (const optional &)"this should never happen", + (const optional &)nullopt)), + MakeTest("should log an info with a message and an exception", + no_errors, + make_tuple(Logger::MessageType::Info, + (const optional &)"this should never happen", + (const optional &)runtime_error("bad thing happen"))), + MakeTest("should log an info with a message", + no_errors, + make_tuple(Logger::MessageType::Info, + (const optional &)nullopt, + (const optional &)runtime_error("bad thing happen"))), + MakeTest("should log a debug with a message", + no_errors, + make_tuple(Logger::MessageType::Debug, + (const optional &)"this should never happen", + (const optional &)nullopt)), + MakeTest("should log a debug with a message and an exception", + no_errors, + make_tuple(Logger::MessageType::Debug, + (const optional &)"this should never happen", + (const optional &)runtime_error("bad thing happen"))), + MakeTest("should log a debug with a message", + no_errors, + make_tuple(Logger::MessageType::Debug, + (const optional &)nullopt, + (const optional &)runtime_error("bad thing happen"))), + MakeTest("should log a verbose with a message", + no_errors, + make_tuple(Logger::MessageType::Verbose, + (const optional &)"this should never happen", + (const optional &)nullopt)), + MakeTest("should log a verbose with a message and an exception", + no_errors, + make_tuple(Logger::MessageType::Verbose, + (const optional &)"this should never happen", + (const optional &)runtime_error("bad thing happen"))), + MakeTest("should log a verbose with a message", + no_errors, + make_tuple(Logger::MessageType::Verbose, + (const optional &)nullopt, + (const optional &)runtime_error("bad thing happen"))), - })); + })); } TestResults test_Logger_Log() { - auto log = [](const Logger::MessageType& type, - const optional& message_text, - const optional& ex) -> string { + auto log = [](const Logger::MessageType &type, + const optional &message_text, + const optional &ex) -> string { ostringstream error_message; auto logger = Logger::GetUnique(); auto spy = make_shared(); logger->AddDestination(spy); switch (type) { - case Logger::MessageType::Debug: - if (message_text.has_value()) { - if (ex.has_value()) { - logger->Log(Logger::MessageType::Debug, message_text.value(), ex.value()); - } else { - logger->Log(Logger::MessageType::Debug, message_text.value()); - } + case Logger::MessageType::Debug: + if (message_text.has_value()) { + if (ex.has_value()) { + logger->Log(Logger::MessageType::Debug, message_text.value(), ex.value()); } else { - if (ex.has_value()) { - logger->Log(Logger::MessageType::Debug, ex.value()); - } + logger->Log(Logger::MessageType::Debug, message_text.value()); } - break; - case Logger::MessageType::Verbose: - if (message_text.has_value()) { - if (ex.has_value()) { - logger->Log(Logger::MessageType::Verbose, message_text.value(), ex.value()); - } else { - logger->Log(Logger::MessageType::Verbose, message_text.value()); - } + } else { + if (ex.has_value()) { + logger->Log(Logger::MessageType::Debug, ex.value()); + } + } + break; + case Logger::MessageType::Verbose: + if (message_text.has_value()) { + if (ex.has_value()) { + logger->Log(Logger::MessageType::Verbose, message_text.value(), ex.value()); } else { - if (ex.has_value()) { - logger->Log(Logger::MessageType::Verbose, ex.value()); - } + logger->Log(Logger::MessageType::Verbose, message_text.value()); } - break; - case Logger::MessageType::Info: - if (message_text.has_value()) { - if (ex.has_value()) { - logger->Log(Logger::MessageType::Info, message_text.value(), ex.value()); - } else { - logger->Log(Logger::MessageType::Info, message_text.value()); - } + } else { + if (ex.has_value()) { + logger->Log(Logger::MessageType::Verbose, ex.value()); + } + } + break; + case Logger::MessageType::Info: + if (message_text.has_value()) { + if (ex.has_value()) { + logger->Log(Logger::MessageType::Info, message_text.value(), ex.value()); } else { - if (ex.has_value()) { - logger->Log(Logger::MessageType::Info, ex.value()); - } + logger->Log(Logger::MessageType::Info, message_text.value()); } - break; - case Logger::MessageType::Warning: - if (message_text.has_value()) { - if (ex.has_value()) { - logger->Log(Logger::MessageType::Warning, message_text.value(), ex.value()); - } else { - logger->Log(Logger::MessageType::Warning, message_text.value()); - } + } else { + if (ex.has_value()) { + logger->Log(Logger::MessageType::Info, ex.value()); + } + } + break; + case Logger::MessageType::Warning: + if (message_text.has_value()) { + if (ex.has_value()) { + logger->Log(Logger::MessageType::Warning, message_text.value(), ex.value()); } else { - if (ex.has_value()) { - logger->Log(Logger::MessageType::Warning, ex.value()); - } + logger->Log(Logger::MessageType::Warning, message_text.value()); } - break; - case Logger::MessageType::Error: - if (message_text.has_value()) { - if (ex.has_value()) { - logger->Log(Logger::MessageType::Error, message_text.value(), ex.value()); - } else { - logger->Log(Logger::MessageType::Error, message_text.value()); - } + } else { + if (ex.has_value()) { + logger->Log(Logger::MessageType::Warning, ex.value()); + } + } + break; + case Logger::MessageType::Error: + if (message_text.has_value()) { + if (ex.has_value()) { + logger->Log(Logger::MessageType::Error, message_text.value(), ex.value()); } else { - if (ex.has_value()) { - logger->Log(Logger::MessageType::Error, ex.value()); - } + logger->Log(Logger::MessageType::Error, message_text.value()); } - break; - case Logger::MessageType::Wtf: - if (message_text.has_value()) { - if (ex.has_value()) { - logger->Log(Logger::MessageType::Wtf, message_text.value(), ex.value()); - } else { - logger->Log(Logger::MessageType::Wtf, message_text.value()); - } + } else { + if (ex.has_value()) { + logger->Log(Logger::MessageType::Error, ex.value()); + } + } + break; + case Logger::MessageType::Wtf: + if (message_text.has_value()) { + if (ex.has_value()) { + logger->Log(Logger::MessageType::Wtf, message_text.value(), ex.value()); } else { - if (ex.has_value()) { - logger->Log(Logger::MessageType::Wtf, ex.value()); - } + logger->Log(Logger::MessageType::Wtf, message_text.value()); } - break; - default: - break; + } else { + if (ex.has_value()) { + logger->Log(Logger::MessageType::Wtf, ex.value()); + } + } + break; + default: + break; } ExpectLogSize(error_message, 1, spy); if (spy->log.size() > 0) { @@ -627,106 +626,106 @@ TestResults test_Logger_Log() { } return GetError(error_message); }; - return execute_suite( - make_test_suite("CPPUtils::Logger::Log(const MessageType&, ...)", - log, - { - make_test("should log what a terrible failure with a message", - no_errors, - make_tuple(Logger::MessageType::Wtf, - (const optional&)"this should never happen", - (const optional&)nullopt)), - make_test("should log what a terrible failure with a message and an exception", - no_errors, - make_tuple(Logger::MessageType::Wtf, - (const optional&)"this should never happen", - (const optional&)runtime_error("bad thing happen"))), - make_test("should log what a terrible failure with a message", - no_errors, - make_tuple(Logger::MessageType::Wtf, - (const optional&)nullopt, - (const optional&)runtime_error("bad thing happen"))), - make_test("should log an error with a message", - no_errors, - make_tuple(Logger::MessageType::Error, - (const optional&)"this should never happen", - (const optional&)nullopt)), - make_test("should log an error with a message and an exception", - no_errors, - make_tuple(Logger::MessageType::Error, - (const optional&)"this should never happen", - (const optional&)runtime_error("bad thing happen"))), - make_test("should log an error with a message", - no_errors, - make_tuple(Logger::MessageType::Error, - (const optional&)nullopt, - (const optional&)runtime_error("bad thing happen"))), - make_test("should log a warning with a message", - no_errors, - make_tuple(Logger::MessageType::Warning, - (const optional&)"this should never happen", - (const optional&)nullopt)), - make_test("should log a warning with a message and an exception", - no_errors, - make_tuple(Logger::MessageType::Warning, - (const optional&)"this should never happen", - (const optional&)runtime_error("bad thing happen"))), - make_test("should log a warning with a message", - no_errors, - make_tuple(Logger::MessageType::Warning, - (const optional&)nullopt, - (const optional&)runtime_error("bad thing happen"))), - make_test("should log an info with a message", - no_errors, - make_tuple(Logger::MessageType::Info, - (const optional&)"this should never happen", - (const optional&)nullopt)), - make_test("should log an info with a message and an exception", - no_errors, - make_tuple(Logger::MessageType::Info, - (const optional&)"this should never happen", - (const optional&)runtime_error("bad thing happen"))), - make_test("should log an info with a message", - no_errors, - make_tuple(Logger::MessageType::Info, - (const optional&)nullopt, - (const optional&)runtime_error("bad thing happen"))), - make_test("should log a debug with a message", - no_errors, - make_tuple(Logger::MessageType::Debug, - (const optional&)"this should never happen", - (const optional&)nullopt)), - make_test("should log a debug with a message and an exception", - no_errors, - make_tuple(Logger::MessageType::Debug, - (const optional&)"this should never happen", - (const optional&)runtime_error("bad thing happen"))), - make_test("should log a debug with a message", - no_errors, - make_tuple(Logger::MessageType::Debug, - (const optional&)nullopt, - (const optional&)runtime_error("bad thing happen"))), - make_test("should log a verbose with a message", - no_errors, - make_tuple(Logger::MessageType::Verbose, - (const optional&)"this should never happen", - (const optional&)nullopt)), - make_test("should log a verbose with a message and an exception", - no_errors, - make_tuple(Logger::MessageType::Verbose, - (const optional&)"this should never happen", - (const optional&)runtime_error("bad thing happen"))), - make_test("should log a verbose with a message", - no_errors, - make_tuple(Logger::MessageType::Verbose, - (const optional&)nullopt, - (const optional&)runtime_error("bad thing happen"))), + return ExecuteSuite( + MakeTestSuite("CPPUtils::Logger::Log(const MessageType&, ...)", + log, + { + MakeTest("should log what a terrible failure with a message", + no_errors, + make_tuple(Logger::MessageType::Wtf, + (const optional &)"this should never happen", + (const optional &)nullopt)), + MakeTest("should log what a terrible failure with a message and an exception", + no_errors, + make_tuple(Logger::MessageType::Wtf, + (const optional &)"this should never happen", + (const optional &)runtime_error("bad thing happen"))), + MakeTest("should log what a terrible failure with a message", + no_errors, + make_tuple(Logger::MessageType::Wtf, + (const optional &)nullopt, + (const optional &)runtime_error("bad thing happen"))), + MakeTest("should log an error with a message", + no_errors, + make_tuple(Logger::MessageType::Error, + (const optional &)"this should never happen", + (const optional &)nullopt)), + MakeTest("should log an error with a message and an exception", + no_errors, + make_tuple(Logger::MessageType::Error, + (const optional &)"this should never happen", + (const optional &)runtime_error("bad thing happen"))), + MakeTest("should log an error with a message", + no_errors, + make_tuple(Logger::MessageType::Error, + (const optional &)nullopt, + (const optional &)runtime_error("bad thing happen"))), + MakeTest("should log a warning with a message", + no_errors, + make_tuple(Logger::MessageType::Warning, + (const optional &)"this should never happen", + (const optional &)nullopt)), + MakeTest("should log a warning with a message and an exception", + no_errors, + make_tuple(Logger::MessageType::Warning, + (const optional &)"this should never happen", + (const optional &)runtime_error("bad thing happen"))), + MakeTest("should log a warning with a message", + no_errors, + make_tuple(Logger::MessageType::Warning, + (const optional &)nullopt, + (const optional &)runtime_error("bad thing happen"))), + MakeTest("should log an info with a message", + no_errors, + make_tuple(Logger::MessageType::Info, + (const optional &)"this should never happen", + (const optional &)nullopt)), + MakeTest("should log an info with a message and an exception", + no_errors, + make_tuple(Logger::MessageType::Info, + (const optional &)"this should never happen", + (const optional &)runtime_error("bad thing happen"))), + MakeTest("should log an info with a message", + no_errors, + make_tuple(Logger::MessageType::Info, + (const optional &)nullopt, + (const optional &)runtime_error("bad thing happen"))), + MakeTest("should log a debug with a message", + no_errors, + make_tuple(Logger::MessageType::Debug, + (const optional &)"this should never happen", + (const optional &)nullopt)), + MakeTest("should log a debug with a message and an exception", + no_errors, + make_tuple(Logger::MessageType::Debug, + (const optional &)"this should never happen", + (const optional &)runtime_error("bad thing happen"))), + MakeTest("should log a debug with a message", + no_errors, + make_tuple(Logger::MessageType::Debug, + (const optional &)nullopt, + (const optional &)runtime_error("bad thing happen"))), + MakeTest("should log a verbose with a message", + no_errors, + make_tuple(Logger::MessageType::Verbose, + (const optional &)"this should never happen", + (const optional &)nullopt)), + MakeTest("should log a verbose with a message and an exception", + no_errors, + make_tuple(Logger::MessageType::Verbose, + (const optional &)"this should never happen", + (const optional &)runtime_error("bad thing happen"))), + MakeTest("should log a verbose with a message", + no_errors, + make_tuple(Logger::MessageType::Verbose, + (const optional &)nullopt, + (const optional &)runtime_error("bad thing happen"))), - })); + })); } TestResults test_Logger_LogToDo() { - auto log_to_do = [](const string& todo_message) { + auto log_to_do = [](const string &todo_message) { auto logger = Logger::GetUnique(); auto spy = make_shared(); logger->AddDestination(spy); @@ -741,15 +740,15 @@ TestResults test_Logger_LogToDo() { } return GetError(error_message); }; - return execute_suite(make_test_suite( + return ExecuteSuite(MakeTestSuite( "CPPUtils::Logger::LogToDo(const std:;string&)", log_to_do, { - make_test("should log a TODO for \"fill in this function\"", no_errors, make_tuple("fill in this function")), - make_test("should log a TODO for \"delete this after fixing bug:2048\"", - no_errors, - make_tuple("delete this after fixing bug:2048")), - make_test("should log a TODO for \"refactor this\"", no_errors, make_tuple("refactor this")), + MakeTest("should log a TODO for \"fill in this function\"", no_errors, make_tuple("fill in this function")), + MakeTest("should log a TODO for \"delete this after fixing bug:2048\"", + no_errors, + make_tuple("delete this after fixing bug:2048")), + MakeTest("should log a TODO for \"refactor this\"", no_errors, make_tuple("refactor this")), })); } @@ -777,17 +776,17 @@ TestResults test_Logger_AddDestination_and_ClearDestinations() { } return GetError(error_message); }; - return execute_suite(make_test_suite("", - add_destination, - { - make_test("should add and clear destinations", no_errors, make_tuple()), - })); + return ExecuteSuite(MakeTestSuite("", + add_destination, + { + MakeTest("should add and clear destinations", no_errors, make_tuple()), + })); } // AddDestination // ClearDestinations -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { TestResults results; results += test_Destination_TypeRangeGettersAndSetters(); @@ -803,5 +802,5 @@ int main(int argc, char* argv[]) { PrintResults(cout, results); - return results.failed() + results.errors(); + return results.Failed() + results.Errors(); } diff --git a/pretty_print.h b/pretty_print.h index 5bb965a..d754bad 100644 --- a/pretty_print.h +++ b/pretty_print.h @@ -56,21 +56,50 @@ template struct StringTraits; /// @brief This SFINAE struct is use to select a narrow string. template <> struct StringTraits { + /// @brief Gets the narrow string. + /// @param narrow The narrow string. This is always returned by this specialization. + /// @param wide The wide string. This is ignored for this specialization. + /// @return The narrow string. static constexpr const char *Literal(const char *narrow, const wchar_t *wide) { return narrow; } + + /// @brief Gets the narrow string. + /// @param narrow The narrow string. This is always returned by this specialization. + /// @param wide The wide string. This is ignored for this specialization. + /// @return The narrow string. + static const std::string Literal(const std::string &narrow, const std::wstring &wide) { return narrow; } }; /// @brief This SFINAE struct is used to select a wide string. template <> struct StringTraits { + /// @brief Gets the wide string. + /// @param narrow The narrow string. This ignored for this specialization. + /// @param wide The wide string. This is is always returned by this specialization. + /// @return The wide string. static constexpr const wchar_t *Literal(const char *narrow, const wchar_t *wide) { return wide; } + + /// @brief Gets the wide string. + /// @param narrow The narrow string. This ignored for this specialization. + /// @param wide The wide string. This is is always returned by this specialization. + /// @return The wide string. + static const std::wstring Literal(const std::string &narrow, const std::wstring &wide) { return wide; } }; /// @brief This SFINAE struct is used to help select container like types. /// @tparam T The potential container type. template struct is_container { + /// @brief Returns true because the type has begin and end methods. + /// @tparam U The type to check. + /// @param A pointer that is not used. + /// @return True because the type is a container. template static constexpr bool test(decltype(std::begin(std::declval())) *) { return true; } + /// @brief Returns false because the type is not a container. + /// @tparam U The type to check. + /// @param A pointer that is not used. + /// @return False because the type is not a container. template static constexpr bool test(...) { return false; } + /// @brief Tests whether type T is a container. static constexpr bool value = test(nullptr); }; diff --git a/pretty_print_test.cpp b/pretty_print_test.cpp index f209fea..55437fd 100644 --- a/pretty_print_test.cpp +++ b/pretty_print_test.cpp @@ -44,9 +44,9 @@ using std::make_tuple; using std::ostringstream; using std::string; using std::string_view; -using TinyTest::execute_suite; -using TinyTest::make_test; -using TinyTest::make_test_suite; +using TinyTest::ExecuteSuite; +using TinyTest::MakeTest; +using TinyTest::MakeTestSuite; using TinyTest::TestResults; using namespace CPPUtils; using std::wstring; @@ -55,55 +55,55 @@ using std::wstring; TestResults test_EscapeForPrintingWithAConstCharPointer() { TestResults results; auto escape_const_char_pointer = [](const char *value) -> string { return EscapeForPrinting(value); }; - results += execute_suite(make_test_suite( - "CPPUtils::EscapeForPrinting(const char*)", - escape_const_char_pointer, - { - make_test("should escape an empty string", (string) "", make_tuple("")), - make_test("should esacpe a string with no special characters", - (string) "This is a normal string.", - make_tuple("This is a normal string.")), - make_test("should escape the escape character by itself", (string) "\\033", make_tuple("\033")), - make_test("should escape the escape character within a string", - (string) "This string has an \\033 in it.", - make_tuple("This string has an \033 in it.")), - })); + results += ExecuteSuite( + MakeTestSuite("CPPUtils::EscapeForPrinting(const char*)", + escape_const_char_pointer, + { + MakeTest("should escape an empty string", (string) "", make_tuple("")), + MakeTest("should esacpe a string with no special characters", + (string) "This is a normal string.", + make_tuple("This is a normal string.")), + MakeTest("should escape the escape character by itself", (string) "\\033", make_tuple("\033")), + MakeTest("should escape the escape character within a string", + (string) "This string has an \\033 in it.", + make_tuple("This string has an \033 in it.")), + })); return results; } TestResults test_EscapeForPrintingWithAString() { TestResults results; auto escape_string = [](const string &value) -> string { return EscapeForPrinting(value); }; - results += execute_suite(make_test_suite( + results += ExecuteSuite(MakeTestSuite( "CPPUtils::EscapeForPrinting(const std::string&)", escape_string, { - make_test("should escape an empty string", (string) "", make_tuple((string) "")), - make_test("should escape a string with no special characters", - (string) "This is a normal string.", - make_tuple((string) "This is a normal string.")), - make_test("should escape the escape character by itself", (string) "\\033", make_tuple((string) "\033")), - make_test("should escape the escape character within a string", - (string) "This string has an \\033 in it.", - make_tuple((string) "This string has an \033 in it.")), + MakeTest("should escape an empty string", (string) "", make_tuple((string) "")), + MakeTest("should escape a string with no special characters", + (string) "This is a normal string.", + make_tuple((string) "This is a normal string.")), + MakeTest("should escape the escape character by itself", (string) "\\033", make_tuple((string) "\033")), + MakeTest("should escape the escape character within a string", + (string) "This string has an \\033 in it.", + make_tuple((string) "This string has an \033 in it.")), })); return results; } TestResults test_EscapeForPrintingWithAStringView() { auto escape_string_view = [](const string_view &value) -> string { return EscapeForPrinting(value); }; - return execute_suite(make_test_suite( + return ExecuteSuite(MakeTestSuite( "CPPUtils::EscapeForPrinting(const std::string_view&)", escape_string_view, { - make_test("should escape an empty string", (string) "", make_tuple((string_view) "")), - make_test("should escape a string with no special characters", - (string) "This is a normal string.", - make_tuple((string_view) "This is a normal string.")), - make_test("should escape the escape character by itself", (string) "\\033", make_tuple((string_view) "\033")), - make_test("should escape the escape character within a string", - (string) "This string has an \\033 in it.", - make_tuple((string_view) "This string has an \033 in it.")), + MakeTest("should escape an empty string", (string) "", make_tuple((string_view) "")), + MakeTest("should escape a string with no special characters", + (string) "This is a normal string.", + make_tuple((string_view) "This is a normal string.")), + MakeTest("should escape the escape character by itself", (string) "\\033", make_tuple((string_view) "\033")), + MakeTest("should escape the escape character within a string", + (string) "This string has an \\033 in it.", + make_tuple((string_view) "This string has an \033 in it.")), })); } @@ -113,13 +113,13 @@ TestResults test_PrettyPrintWithAConstCharPointer() { PrettyPrint(os, value); return os.str(); }; - return execute_suite(make_test_suite( - "CPPUtils::PrettyPrint(std::ostream&, const char*)", - pretty_print, - { - make_test("should print \"\" for an empty string", (string) "\"\"", make_tuple("")), - make_test("should print \"hello world\"", (string) "\"hello world\"", make_tuple("hello world")), - })); + return ExecuteSuite( + MakeTestSuite("CPPUtils::PrettyPrint(std::ostream&, const char*)", + pretty_print, + { + MakeTest("should print \"\" for an empty string", (string) "\"\"", make_tuple("")), + MakeTest("should print \"hello world\"", (string) "\"hello world\"", make_tuple("hello world")), + })); } TestResults test_PrettyPrintWithAString() { @@ -128,12 +128,12 @@ TestResults test_PrettyPrintWithAString() { PrettyPrint(os, value); return os.str(); }; - return execute_suite(make_test_suite( + return ExecuteSuite(MakeTestSuite( "CPPUtils::PrettyPrint(std::ostream&, const std::string&)", pretty_print, { - make_test("should print \"\" for an empty string", (string) "\"\"", make_tuple((string) "")), - make_test("should print \"hello world\"", (string) "\"hello world\"", make_tuple((string) "hello world")), + MakeTest("should print \"\" for an empty string", (string) "\"\"", make_tuple((string) "")), + MakeTest("should print \"hello world\"", (string) "\"hello world\"", make_tuple((string) "hello world")), })); } @@ -143,13 +143,12 @@ TestResults test_PrettyPrintWithAStringView() { PrettyPrint(os, value); return os.str(); }; - return execute_suite(make_test_suite( + return ExecuteSuite(MakeTestSuite( "CPPUtils::PrettyPrint(std::ostream&, const std::string_view&)", pretty_print, { - make_test("should print \"\" for an empty string", (string) "\"\"", make_tuple((string_view) "")), - make_test( - "should print \"hello world\"", (string) "\"hello world\"", make_tuple((string_view) "hello world")), + MakeTest("should print \"\" for an empty string", (string) "\"\"", make_tuple((string_view) "")), + MakeTest("should print \"hello world\"", (string) "\"hello world\"", make_tuple((string_view) "hello world")), })); } @@ -169,13 +168,13 @@ TestResults test_PrettyPrintWithATuple() { } return os.str(); }; - return execute_suite(make_test_suite( + return ExecuteSuite(MakeTestSuite( "CPPUtils::PrettyPrint(std::ostream&, std::tuple)", pretty_print, { - make_test("should print a tuple of mixed types", (string) "[ 1, \"hello\", 9 ]", make_tuple(1)), - make_test("should print an empty tuple", (string) "[]", make_tuple(2)), - make_test("should print a tuple of strings", (string) "[ \"one\", \"two\", \"three\" ]", make_tuple(3)), + MakeTest("should print a tuple of mixed types", (string) "[ 1, \"hello\", 9 ]", make_tuple(1)), + MakeTest("should print an empty tuple", (string) "[]", make_tuple(2)), + MakeTest("should print a tuple of strings", (string) "[ \"one\", \"two\", \"three\" ]", make_tuple(3)), })); } @@ -203,18 +202,18 @@ TestResults test_PrettyPrintWithAnInitializerList() { return os.str(); }; - return execute_suite(make_test_suite( + return ExecuteSuite(MakeTestSuite( "CPPUtils::PrettyPrint(std::ostream&, std::initializer_list)", pretty_print, { - make_test( + MakeTest( "should print an initializer_list of strings", (string) "[ \"one\", \"two\", \"three\" ]", make_tuple(1)), - make_test("should print an empty initializer_list", (string) "[]", make_tuple(2)), - make_test("should print an initializer_list of integers", (string) "[ 1, 2, 3 ]", make_tuple(3)), - make_test("should print an initializer_list of strings with four elements", - (string) "[ \"one\", \"two\", \"three\", \"four\" ]", - make_tuple(4)), - make_test("should print an initializer_list of doubles", (string) "[ 1.1, 2.2, 3.3 ]", make_tuple(5)), + MakeTest("should print an empty initializer_list", (string) "[]", make_tuple(2)), + MakeTest("should print an initializer_list of integers", (string) "[ 1, 2, 3 ]", make_tuple(3)), + MakeTest("should print an initializer_list of strings with four elements", + (string) "[ \"one\", \"two\", \"three\", \"four\" ]", + make_tuple(4)), + MakeTest("should print an initializer_list of doubles", (string) "[ 1.1, 2.2, 3.3 ]", make_tuple(5)), })); } @@ -252,14 +251,14 @@ TestResults test_PrettyPrintWithDifferentContainerTypes() { return os.str(); }; - return execute_suite(make_test_suite( + return ExecuteSuite(MakeTestSuite( "CPPUtils::PrettyPrint(std::ostream&, TContainer)", pretty_print, { - make_test("should print a vector of integers", (string) "[ 1, 2, 3 ]", make_tuple(1)), - make_test("should print a queue of integers", (string) "[ 1, 2, 3 ]", make_tuple(2)), - make_test("should print a vector of strings", (string) "[ \"one\", \"two\", \"three\" ]", make_tuple(3)), - make_test("should print a queue of strings", (string) "[ \"one\", \"two\", \"three\" ]", make_tuple(4)), + MakeTest("should print a vector of integers", (string) "[ 1, 2, 3 ]", make_tuple(1)), + MakeTest("should print a queue of integers", (string) "[ 1, 2, 3 ]", make_tuple(2)), + MakeTest("should print a vector of strings", (string) "[ \"one\", \"two\", \"three\" ]", make_tuple(3)), + MakeTest("should print a queue of strings", (string) "[ \"one\", \"two\", \"three\" ]", make_tuple(4)), })); } @@ -271,11 +270,11 @@ TestResults test_PrettyPrintWithSimpleTypes() { PrettyPrint(os, value); return os.str(); }; - results += execute_suite(make_test_suite("CPPUtils::PrettyPrint(std::ostream&, const TItem&)", - pretty_print_int, - { - make_test("should print 42 for an int", (string) "42", make_tuple(42)), - })); + results += ExecuteSuite(MakeTestSuite("CPPUtils::PrettyPrint(std::ostream&, const TItem&)", + pretty_print_int, + { + MakeTest("should print 42 for an int", (string) "42", make_tuple(42)), + })); auto pretty_print_float = [](float value) -> string { ostringstream os; @@ -283,24 +282,24 @@ TestResults test_PrettyPrintWithSimpleTypes() { return os.str(); }; results += - execute_suite(make_test_suite("CPPUtils::PrettyPrint(std::ostream&, const TItem&)", - pretty_print_float, - { - make_test("should print 3.14 for a float", (string) "3.14", make_tuple(3.14f)), - })); + ExecuteSuite(MakeTestSuite("CPPUtils::PrettyPrint(std::ostream&, const TItem&)", + pretty_print_float, + { + MakeTest("should print 3.14 for a float", (string) "3.14", make_tuple(3.14f)), + })); auto pretty_print_string = [](const string &value) -> string { ostringstream os; PrettyPrint(os, value); return os.str(); }; - results += execute_suite(make_test_suite("CPPUtils::PrettyPrint(std::ostream&, const TItem&)", - pretty_print_string, - { - make_test("should print \"hello world\" for a string", - (string) "\"hello world\"", - make_tuple((string) "hello world")), - })); + results += ExecuteSuite(MakeTestSuite("CPPUtils::PrettyPrint(std::ostream&, const TItem&)", + pretty_print_string, + { + MakeTest("should print \"hello world\" for a string", + (string) "\"hello world\"", + make_tuple((string) "hello world")), + })); return results; } @@ -320,15 +319,15 @@ TestResults test_PrettyPrintWithAPair() { } return os.str(); }; - return execute_suite(make_test_suite( + return ExecuteSuite(MakeTestSuite( "CPPUtils::PrettyPrint(std::ostream&, const std::pair&)", pretty_print, { - make_test("should print (1, 2) for a pair of ints", (string) "(1, 2)", make_tuple(1)), - make_test("should print (3.14, 42) for a pair of float and int", (string) "(3.14, 42)", make_tuple(2)), - make_test("should print (\"hello\", \"world\") for a pair of strings", - (string) "(\"hello\", \"world\")", - make_tuple(3)), + MakeTest("should print (1, 2) for a pair of ints", (string) "(1, 2)", make_tuple(1)), + MakeTest("should print (3.14, 42) for a pair of float and int", (string) "(3.14, 42)", make_tuple(2)), + MakeTest("should print (\"hello\", \"world\") for a pair of strings", + (string) "(\"hello\", \"world\")", + make_tuple(3)), })); } @@ -348,18 +347,18 @@ TestResults test_PrettyPrintWithSeparatorWithAConstCharPointer() { } return os.str(); }; - return execute_suite( - make_test_suite("CPPUtils::PrettyPrintWithSeparator(std::ostream&, const TChar*, Args&&...)", - pretty_print, - { - make_test("should print 1, 2, 3 for a list of ints", (string) "1, 2, 3", make_tuple(", ", 1)), - make_test("should print 3.14; 42; \"hello world\" for a list of float, int and string", - (string) "3.14; 42; \"hello world\"", - make_tuple("; ", 2)), - make_test("should print \"hello\" \"world\" for a list of strings", - (string) "\"hello\" \"world\"", - make_tuple(" ", 3)), - })); + return ExecuteSuite( + MakeTestSuite("CPPUtils::PrettyPrintWithSeparator(std::ostream&, const TChar*, Args&&...)", + pretty_print, + { + MakeTest("should print 1, 2, 3 for a list of ints", (string) "1, 2, 3", make_tuple(", ", 1)), + MakeTest("should print 3.14; 42; \"hello world\" for a list of float, int and string", + (string) "3.14; 42; \"hello world\"", + make_tuple("; ", 2)), + MakeTest("should print \"hello\" \"world\" for a list of strings", + (string) "\"hello\" \"world\"", + make_tuple(" ", 3)), + })); } TestResults test_PrettyPrintWithSeparatorWithAString() { @@ -378,17 +377,17 @@ TestResults test_PrettyPrintWithSeparatorWithAString() { } return os.str(); }; - return execute_suite(make_test_suite( + return ExecuteSuite(MakeTestSuite( "CPPUtils::PrettyPrintWithSeparator(std::ostream&, const TChar*, Args&&...)", pretty_print, { - make_test("should print 1 | 2 | 3 for a list of ints", (string) "1 | 2 | 3", make_tuple((string) " | ", 1)), - make_test("should print 3.14 / 42 / \"hello world\" for a list of float, int and string", - (string) "3.14 / 42 / \"hello world\"", - make_tuple((string) " / ", 2)), - make_test("should print \"hello\" - \"world\" for a list of strings", - (string) "\"hello\" - \"world\"", - make_tuple((string) " - ", 3)), + MakeTest("should print 1 | 2 | 3 for a list of ints", (string) "1 | 2 | 3", make_tuple((string) " | ", 1)), + MakeTest("should print 3.14 / 42 / \"hello world\" for a list of float, int and string", + (string) "3.14 / 42 / \"hello world\"", + make_tuple((string) " / ", 2)), + MakeTest("should print \"hello\" - \"world\" for a list of strings", + (string) "\"hello\" - \"world\"", + make_tuple((string) " - ", 3)), })); } @@ -408,18 +407,18 @@ TestResults test_PrettyPrintWithSeparatorWithAStringView() { } return os.str(); }; - return execute_suite(make_test_suite( + return ExecuteSuite(MakeTestSuite( "CPPUtils::PrettyPrintWithSeparator(std::ostream&, const TChar*, Args&&...)", pretty_print, { - make_test( + MakeTest( "should print 1 | 2 | 3 for a list of ints", (string) "1 | 2 | 3", make_tuple((string_view) " | ", 1)), - make_test("should print 3.14 / 42 / \"hello world\" for a list of float, int and string", - (string) "3.14 / 42 / \"hello world\"", - make_tuple((string_view) " / ", 2)), - make_test("should print \"hello\" - \"world\" for a list of strings", - (string) "\"hello\" - \"world\"", - make_tuple((string_view) " - ", 3)), + MakeTest("should print 3.14 / 42 / \"hello world\" for a list of float, int and string", + (string) "3.14 / 42 / \"hello world\"", + make_tuple((string_view) " / ", 2)), + MakeTest("should print \"hello\" - \"world\" for a list of strings", + (string) "\"hello\" - \"world\"", + make_tuple((string_view) " - ", 3)), })); } @@ -444,5 +443,5 @@ int main(int argc, char *argv[]) { results += test_PrettyPrintWithSeparatorWithAString(); results += test_PrettyPrintWithSeparatorWithAStringView(); - return results.failed() + results.errors(); + return results.Failed() + results.Errors(); } diff --git a/windows_logger_test.cpp b/windows_logger_test.cpp index de91d49..249e70a 100644 --- a/windows_logger_test.cpp +++ b/windows_logger_test.cpp @@ -53,9 +53,9 @@ using std::shared_ptr; using std::string; using std::tuple; using std::vector; -using TinyTest::execute_suite; -using TinyTest::make_test; -using TinyTest::make_test_suite; +using TinyTest::ExecuteSuite; +using TinyTest::MakeTest; +using TinyTest::MakeTestSuite; using TinyTest::TestResults; string no_errors = "no errors"; typedef tuple MessageBoxEvent; @@ -302,57 +302,57 @@ TestResults test_WindowsLogger_LogMessage() { } return GetErrors(errors); }; - return execute_suite(make_test_suite( + return ExecuteSuite(MakeTestSuite( "CPPUtils::WindowsLogger::LogMessage(cosnt std::string&)", log_message, { - make_test("should log \"this is a message\" with title \"Debug\"", - no_errors, - make_tuple(Logger::MessageType::Debug, - "this is a message", - "this is a message", - "Debug", - MB_OK | MB_ICONEXCLAMATION)), - make_test( + MakeTest("should log \"this is a message\" with title \"Debug\"", + no_errors, + make_tuple(Logger::MessageType::Debug, + "this is a message", + "this is a message", + "Debug", + MB_OK | MB_ICONEXCLAMATION)), + MakeTest( "should log \"this is an error\" with title \"ERROR\"", no_errors, make_tuple( Logger::MessageType::Error, "this is an error", "this is an error", "ERROR", MB_OK | MB_ICONHAND)), - make_test("should log \"what a terrible failure\" with title \"How did you let this happen?\"", - no_errors, - make_tuple(Logger::MessageType::Wtf, - "what a terrible failure", - "what a terrible failure", - "How did you let this happen?", - MB_OK | MB_ICONHAND)), - make_test("should log \"this is some information\" with title \"Information\"", - no_errors, - make_tuple(Logger::MessageType::Info, - "this is some information", - "this is some information", - "Information", - MB_OK | MB_ICONASTERISK)), - make_test("should log \"this is a warning\" with title \"Warning\"", - no_errors, - make_tuple(Logger::MessageType::Warning, - "this is a warning", - "this is a warning", - "Warning", - MB_OK | MB_ICONEXCLAMATION)), - make_test("should log \"this is verbose\" with title \"Verbose\"", - no_errors, - make_tuple(Logger::MessageType::Verbose, - "this is verbose", - "this is verbose", - "Verbose", - MB_OK | MB_ICONASTERISK)), - make_test("should log \"unclassified message\" with title \"Unclassified\"", - no_errors, - make_tuple((Logger::MessageType)1000, - "unclassified message", - "unclassified message", - "Unclassified", - MB_OK | MB_ICONASTERISK)), + MakeTest("should log \"what a terrible failure\" with title \"How did you let this happen?\"", + no_errors, + make_tuple(Logger::MessageType::Wtf, + "what a terrible failure", + "what a terrible failure", + "How did you let this happen?", + MB_OK | MB_ICONHAND)), + MakeTest("should log \"this is some information\" with title \"Information\"", + no_errors, + make_tuple(Logger::MessageType::Info, + "this is some information", + "this is some information", + "Information", + MB_OK | MB_ICONASTERISK)), + MakeTest("should log \"this is a warning\" with title \"Warning\"", + no_errors, + make_tuple(Logger::MessageType::Warning, + "this is a warning", + "this is a warning", + "Warning", + MB_OK | MB_ICONEXCLAMATION)), + MakeTest("should log \"this is verbose\" with title \"Verbose\"", + no_errors, + make_tuple(Logger::MessageType::Verbose, + "this is verbose", + "this is verbose", + "Verbose", + MB_OK | MB_ICONASTERISK)), + MakeTest("should log \"unclassified message\" with title \"Unclassified\"", + no_errors, + make_tuple((Logger::MessageType)1000, + "unclassified message", + "unclassified message", + "Unclassified", + MB_OK | MB_ICONASTERISK)), })); } @@ -374,59 +374,59 @@ TestResults test_WindowsLogger_LogErrorWithMessage() { } return GetErrors(errors); }; - return execute_suite(make_test_suite( + return ExecuteSuite(MakeTestSuite( "CPPUtils::WindowsLogger::LogError(const std::exception&)", log_error, { - make_test("should log \"Exception: this is an exception\" with title \"Debug\"", - no_errors, - make_tuple(Logger::MessageType::Debug, - std::runtime_error("this is an exception"), - "Exception: this is an exception", - "Debug", - MB_OK | MB_ICONEXCLAMATION)), - make_test("should log \"Exception: this is an error\" with title \"ERROR\"", - no_errors, - make_tuple(Logger::MessageType::Error, - std::runtime_error("this is an error"), - "Exception: this is an error", - "ERROR", - MB_OK | MB_ICONHAND)), - make_test("should log \"Exception: what a terrible failure\" with title \"How did you let this happen?\"", - no_errors, - make_tuple(Logger::MessageType::Wtf, - std::runtime_error("what a terrible failure"), - "Exception: what a terrible failure", - "How did you let this happen?", - MB_OK | MB_ICONHAND)), - make_test("should log \"Exception: this is some information\" with title \"Information\"", - no_errors, - make_tuple(Logger::MessageType::Info, - std::runtime_error("this is some information"), - "Exception: this is some information", - "Information", - MB_OK | MB_ICONASTERISK)), - make_test("should log \"Exception: this is a warning\" with title \"Warning\"", - no_errors, - make_tuple(Logger::MessageType::Warning, - std::runtime_error("this is a warning"), - "Exception: this is a warning", - "Warning", - MB_OK | MB_ICONEXCLAMATION)), - make_test("should log \"Exception: this is verbose\" with title \"Verbose\"", - no_errors, - make_tuple(Logger::MessageType::Verbose, - std::runtime_error("this is verbose"), - "Exception: this is verbose", - "Verbose", - MB_OK | MB_ICONASTERISK)), - make_test("should log \"Exception: unclassified message\" with title \"Unclassified\"", - no_errors, - make_tuple((Logger::MessageType)1000, - std::runtime_error("unclassified message"), - "Exception: unclassified message", - "Unclassified", - MB_OK | MB_ICONASTERISK)), + MakeTest("should log \"Exception: this is an exception\" with title \"Debug\"", + no_errors, + make_tuple(Logger::MessageType::Debug, + std::runtime_error("this is an exception"), + "Exception: this is an exception", + "Debug", + MB_OK | MB_ICONEXCLAMATION)), + MakeTest("should log \"Exception: this is an error\" with title \"ERROR\"", + no_errors, + make_tuple(Logger::MessageType::Error, + std::runtime_error("this is an error"), + "Exception: this is an error", + "ERROR", + MB_OK | MB_ICONHAND)), + MakeTest("should log \"Exception: what a terrible failure\" with title \"How did you let this happen?\"", + no_errors, + make_tuple(Logger::MessageType::Wtf, + std::runtime_error("what a terrible failure"), + "Exception: what a terrible failure", + "How did you let this happen?", + MB_OK | MB_ICONHAND)), + MakeTest("should log \"Exception: this is some information\" with title \"Information\"", + no_errors, + make_tuple(Logger::MessageType::Info, + std::runtime_error("this is some information"), + "Exception: this is some information", + "Information", + MB_OK | MB_ICONASTERISK)), + MakeTest("should log \"Exception: this is a warning\" with title \"Warning\"", + no_errors, + make_tuple(Logger::MessageType::Warning, + std::runtime_error("this is a warning"), + "Exception: this is a warning", + "Warning", + MB_OK | MB_ICONEXCLAMATION)), + MakeTest("should log \"Exception: this is verbose\" with title \"Verbose\"", + no_errors, + make_tuple(Logger::MessageType::Verbose, + std::runtime_error("this is verbose"), + "Exception: this is verbose", + "Verbose", + MB_OK | MB_ICONASTERISK)), + MakeTest("should log \"Exception: unclassified message\" with title \"Unclassified\"", + no_errors, + make_tuple((Logger::MessageType)1000, + std::runtime_error("unclassified message"), + "Exception: unclassified message", + "Unclassified", + MB_OK | MB_ICONASTERISK)), })); } @@ -449,67 +449,67 @@ TestResults test_WindowsLogger_LogErrorWithoutMessage() { } return GetErrors(errors); }; - return execute_suite(make_test_suite( + return ExecuteSuite(MakeTestSuite( "CPPUtils::WindowsLogger::LogError(const std::string&, const std::exception&)", log_error, { - make_test("should log \"Exception: this is an exception\" with title \"Debug\"", - no_errors, - make_tuple(Logger::MessageType::Debug, - "this is a message", - std::runtime_error("this is an exception"), - "Exception: this is an exception", - "Debug", - MB_OK | MB_ICONEXCLAMATION)), - make_test("should log \"Exception: this is an exception\" with title \"ERROR\"", - no_errors, - make_tuple(Logger::MessageType::Error, - "this is an error", - std::runtime_error("this is an exception"), - "Exception: this is an exception", - "ERROR", - MB_OK | MB_ICONHAND)), - make_test("should log \"Exception: this is an exception\" with title \"How did you let this happen?\"", - no_errors, - make_tuple(Logger::MessageType::Wtf, - "what a terrible failure", - std::runtime_error("this is an exception"), - "Exception: this is an exception", - "How did you let this happen?", - MB_OK | MB_ICONHAND)), - make_test("should log \"Exception this is an exception\" with title \"Information\"", - no_errors, - make_tuple(Logger::MessageType::Info, - "this is some information", - std::runtime_error("this is an exception"), - "Exception: this is an exception", - "Information", - MB_OK | MB_ICONASTERISK)), - make_test("should log \"Exception: this is a warning with caught exception this is an exception\" with title " - "\"Warning\"", - no_errors, - make_tuple(Logger::MessageType::Warning, - "this is a warning", - std::runtime_error("this is an exception"), - "Exception: this is an exception", - "Warning", - MB_OK | MB_ICONEXCLAMATION)), - make_test("should log \"Exception: this is an exception\" with title \"Verbose\"", - no_errors, - make_tuple(Logger::MessageType::Verbose, - "this is verbose", - std::runtime_error("this is an exception"), - "Exception: this is an exception", - "Verbose", - MB_OK | MB_ICONASTERISK)), - make_test("should log \"Exception: this is an exception\" with title \"Unclassified\"", - no_errors, - make_tuple((Logger::MessageType)1000, - "unclassified message", - std::runtime_error("this is an exception"), - "Exception: this is an exception", - "Unclassified", - MB_OK | MB_ICONASTERISK)), + MakeTest("should log \"Exception: this is an exception\" with title \"Debug\"", + no_errors, + make_tuple(Logger::MessageType::Debug, + "this is a message", + std::runtime_error("this is an exception"), + "Exception: this is an exception", + "Debug", + MB_OK | MB_ICONEXCLAMATION)), + MakeTest("should log \"Exception: this is an exception\" with title \"ERROR\"", + no_errors, + make_tuple(Logger::MessageType::Error, + "this is an error", + std::runtime_error("this is an exception"), + "Exception: this is an exception", + "ERROR", + MB_OK | MB_ICONHAND)), + MakeTest("should log \"Exception: this is an exception\" with title \"How did you let this happen?\"", + no_errors, + make_tuple(Logger::MessageType::Wtf, + "what a terrible failure", + std::runtime_error("this is an exception"), + "Exception: this is an exception", + "How did you let this happen?", + MB_OK | MB_ICONHAND)), + MakeTest("should log \"Exception this is an exception\" with title \"Information\"", + no_errors, + make_tuple(Logger::MessageType::Info, + "this is some information", + std::runtime_error("this is an exception"), + "Exception: this is an exception", + "Information", + MB_OK | MB_ICONASTERISK)), + MakeTest("should log \"Exception: this is a warning with caught exception this is an exception\" with title " + "\"Warning\"", + no_errors, + make_tuple(Logger::MessageType::Warning, + "this is a warning", + std::runtime_error("this is an exception"), + "Exception: this is an exception", + "Warning", + MB_OK | MB_ICONEXCLAMATION)), + MakeTest("should log \"Exception: this is an exception\" with title \"Verbose\"", + no_errors, + make_tuple(Logger::MessageType::Verbose, + "this is verbose", + std::runtime_error("this is an exception"), + "Exception: this is an exception", + "Verbose", + MB_OK | MB_ICONASTERISK)), + MakeTest("should log \"Exception: this is an exception\" with title \"Unclassified\"", + no_errors, + make_tuple((Logger::MessageType)1000, + "unclassified message", + std::runtime_error("this is an exception"), + "Exception: this is an exception", + "Unclassified", + MB_OK | MB_ICONASTERISK)), })); } @@ -522,6 +522,6 @@ int main(int argc, char *argv[]) { PrintResults(cout, results); - return results.failed() + results.errors(); + return results.Failed() + results.Errors(); } #endif // End defined(_WIN32)