Updates tests to work with the latest TinyTest.

Adds StringTraits::Literal variants that work with strings.
Names the workspace CPPUtils to match the import name in TinyTest.
This resolves the dependency issue.
This commit is contained in:
2023-05-10 18:27:40 -07:00
parent 52de4b8bc2
commit 3dd951eee9
8 changed files with 887 additions and 852 deletions

3
BUILD
View File

@@ -7,6 +7,8 @@
# #
# Licensed under the MIT license. See below for details. #
# #
########################################################################################################################
# #
# MIT License #
# #
# Copyright (c) 2023 Tom Hicks <headhunter3@gmail.com> #
@@ -36,6 +38,7 @@ cc_library(
srcs = ["ansi_escapes.cpp"],
hdrs = ["ansi_escapes.h"],
includes = ["ansi_escapes.h"],
deps = [":pretty_print"],
)
cc_test(

View File

@@ -8,6 +8,8 @@
# #
# Licensed under the MIT license. See below for details. #
# #
########################################################################################################################
# #
# MIT License #
# #
# Copyright (c) 2023 Tom Hicks <headhunter3@gmail.com> #
@@ -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"],
)

View File

@@ -43,44 +43,44 @@ 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
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)",
return ExecuteSuite(
MakeTestSuite("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)),
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)",
return ExecuteSuite(
MakeTestSuite("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)),
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)",
return ExecuteSuite(
MakeTestSuite("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)),
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)),
}));
}
@@ -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,13 +138,13 @@ TestResults test_ForegroundColor8Bit() {
CPPUtils::ForegroundColor8Bit(os, color);
return os.str();
};
return execute_suite(
make_test_suite("CPPUtils::ForegroundColor8Bit(uint8_t)",
return ExecuteSuite(
MakeTestSuite("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)),
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)),
}));
}
@@ -154,13 +154,13 @@ TestResults test_BackgroundColor8Bit() {
CPPUtils::BackgroundColor8Bit(os, color);
return os.str();
};
return execute_suite(
make_test_suite("CPPUtils::BackgroundColor8Bit(uint8_t)",
return ExecuteSuite(
MakeTestSuite("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)),
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)),
}));
}
@@ -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,12 +198,12 @@ 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)",
return ExecuteSuite(MakeTestSuite("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)),
MakeTest("should write \"\\033[38;2;21;69;136m\"",
(string) "\033[38;2;21;69;136m",
make_tuple(0x15, 0x45, 0x88)),
}));
}
@@ -213,12 +213,12 @@ 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)",
return ExecuteSuite(MakeTestSuite("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)),
MakeTest("should write \"\\033[48;2;21;69;136m\"",
(string) "\033[48;2;21;69;136m",
make_tuple(0x15, 0x45, 0x88)),
}));
}
@@ -228,14 +228,14 @@ TestResults test_Reset() {
CPPUtils::Reset(os);
return os.str();
};
return execute_suite(make_test_suite("CPPUtils::Reset",
return ExecuteSuite(MakeTestSuite("CPPUtils::Reset",
function_to_test,
{
make_test("should write \"\\033[m\"", (string) "\033[m", make_tuple()),
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();
}

View File

@@ -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
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<ConsoleLogger>();
@@ -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&)",
return ExecuteSuite(MakeTestSuite("CPPUtils::ConsoleLogger::LogMessage(cosnt std::string&)",
log_message,
{make_test("should print \"[Debug] this is a 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")),
make_test("should print \"[Error] this is an error\"",
MakeTest("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\"",
MakeTest("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\"",
MakeTest("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\"",
MakeTest("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\"",
MakeTest("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\"",
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<ConsoleLogger>();
@@ -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&)",
return ExecuteSuite(
MakeTestSuite("CPPUtils::ConsoleLogger::LogError(const std::exception&)",
log_error,
{make_test("should print \"[Debug] caught exception: this is an exception\"",
{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"))),
make_test("should print \"[Error] caught exception: this is an error\"",
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"))),
make_test("should print \"[Wtf] caught exception: what a terrible failure\"",
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"))),
make_test("should print \"[Info] caught exception: this is some information\"",
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"))),
make_test("should print \"[Warning] caught exception: this is a warning\"",
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"))),
make_test("should print \"[Verbose] caught exception: this is verbose\"",
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"))),
make_test("should print \"[Unclassified] caught exception: unclassified message\"",
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<ConsoleLogger>();
@@ -131,37 +131,37 @@ 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\"",
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"))),
make_test(
"should print \"[Info] this is some information with caught exception this is an exception\"",
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"))),
make_test("should print \"[Warning] this is a warning with caught exception this is an exception\"",
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"))),
make_test(
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\"",
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"))),
@@ -169,7 +169,7 @@ TestResults test_ConsoleLogger_LogErrorWithoutMessage() {
}
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<ConsoleLogger>();
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();
}

View File

@@ -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<Logger::MessageType, optional<string>, optional<string>> 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<LogEntry> log;
};
template <typename T>
ostream& PrintOptional(ostream& os, optional<T> op) {
template <typename T> ostream &PrintOptional(ostream &os, optional<T> op) {
if (op.has_value()) {
os << op.value();
} else {
@@ -98,14 +97,14 @@ ostream& PrintOptional(ostream& os, optional<T> 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<string> expected, const LogEntry& log_entry) {
void ExpectMessageText(ostream &error_message, optional<string> expected, const LogEntry &log_entry) {
optional<string> actual = get<1>(log_entry);
if (actual != expected) {
error_message << "Unexpected message text. Expected: ";
@@ -114,7 +113,7 @@ void ExpectMessageText(ostream& error_message, optional<string> expected, const
}
}
void ExpectMessageException(ostream& error_message, optional<string> expected, const LogEntry& log_entry) {
void ExpectMessageException(ostream &error_message, optional<string> expected, const LogEntry &log_entry) {
optional<string> actual = get<2>(log_entry);
if (actual != expected) {
error_message << "Unexpected message exception. Expected: ";
@@ -123,14 +122,14 @@ void ExpectMessageException(ostream& error_message, optional<string> expected, c
}
}
void ExpectLogSize(ostream& error_message, size_t expected, shared_ptr<SpyLoggerDestination> destination) {
void ExpectLogSize(ostream &error_message, size_t expected, shared_ptr<SpyLoggerDestination> 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;
@@ -141,7 +140,7 @@ string GetError(ostringstream& error_message) {
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<SpyLoggerDestination>();
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",
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<SpyLoggerDestination>();
if (type == Logger::MessageType::Unknown) {
spy->SetMaxType(Logger::MessageType::Debug);
@@ -179,21 +178,21 @@ 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",
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))),
}));
@@ -206,10 +205,10 @@ TestResults test_Logger_GetShared() {
auto second = Logger::GetShared();
return first == second;
};
return execute_suite(make_test_suite("CPPUtils::Logger::GetShared()",
return ExecuteSuite(MakeTestSuite("CPPUtils::Logger::GetShared()",
function_to_test,
{
make_test("should get the same instance twice", true, make_tuple()),
MakeTest("should get the same instance twice", true, make_tuple()),
}));
}
@@ -228,17 +227,17 @@ TestResults test_Logger_GetUnique() {
TestResults results;
results += execute_suite(make_test_suite("CPPUtils::Logger::GetUnique()",
results += ExecuteSuite(MakeTestSuite("CPPUtils::Logger::GetUnique()",
get_unique_is_different,
{
make_test("should get two different instances", true, make_tuple()),
MakeTest("should get two different instances", true, make_tuple()),
}));
results += execute_suite(
make_test_suite("CPPUtils::Logger::GetUnique()",
results += ExecuteSuite(
MakeTestSuite("CPPUtils::Logger::GetUnique()",
get_unique_is_not_get_shared,
{
make_test("should get and instance that is not the shared instance", true, make_tuple()),
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,10 +299,10 @@ TestResults test_Logger_LogUnhandledError() {
}
return GetError(error_message);
};
return execute_suite(make_test_suite("CPPUtils::Logger::LogUnhandledError(const std::exception&)",
return ExecuteSuite(MakeTestSuite("CPPUtils::Logger::LogUnhandledError(const std::exception&)",
log_unhandled_error,
{
make_test("should log an error", no_errors, make_tuple()),
MakeTest("should log an error", no_errors, make_tuple()),
}));
}
@@ -324,17 +323,17 @@ TestResults test_Logger_LogUnimplementedFeature() {
}
return GetError(error_message);
};
return execute_suite(make_test_suite("CPPUtils::Logger::LogUnimplementedFeature()",
return ExecuteSuite(MakeTestSuite("CPPUtils::Logger::LogUnimplementedFeature()",
log_unimplemented_feature,
{
make_test("should log an unimplemented feature", no_errors, make_tuple()),
MakeTest("should log an unimplemented feature", no_errors, make_tuple()),
}));
}
TestResults test_Logger_Log_Level() {
auto log = [](const Logger::MessageType& type,
const optional<string>& message_text,
const optional<std::exception>& ex) -> string {
auto log = [](const Logger::MessageType &type,
const optional<string> &message_text,
const optional<std::exception> &ex) -> string {
ostringstream error_message;
auto logger = Logger::GetUnique();
auto spy = make_shared<SpyLoggerDestination>();
@@ -430,108 +429,108 @@ TestResults test_Logger_Log_Level() {
}
return GetError(error_message);
};
return execute_suite(
make_test_suite("CPPUtils::Logger::Log*(...)",
return ExecuteSuite(
MakeTestSuite("CPPUtils::Logger::Log*(...)",
log,
{
make_test("should log what a terrible failure with a message",
MakeTest("should log what a terrible failure with a message",
no_errors,
make_tuple(Logger::MessageType::Wtf,
(const optional<string>&)"this should never happen",
(const optional<std::exception>&)nullopt)),
make_test("should log what a terrible failure with a message and an exception",
(const optional<string> &)"this should never happen",
(const optional<std::exception> &)nullopt)),
MakeTest("should log what a terrible failure with a message and an exception",
no_errors,
make_tuple(Logger::MessageType::Wtf,
(const optional<string>&)"this should never happen",
(const optional<std::exception>&)runtime_error("bad thing happen"))),
make_test("should log what a terrible failure with a message",
(const optional<string> &)"this should never happen",
(const optional<std::exception> &)runtime_error("bad thing happen"))),
MakeTest("should log what a terrible failure with a message",
no_errors,
make_tuple(Logger::MessageType::Wtf,
(const optional<string>&)nullopt,
(const optional<std::exception>&)runtime_error("bad thing happen"))),
make_test("should log an error with a message",
(const optional<string> &)nullopt,
(const optional<std::exception> &)runtime_error("bad thing happen"))),
MakeTest("should log an error with a message",
no_errors,
make_tuple(Logger::MessageType::Error,
(const optional<string>&)"this should never happen",
(const optional<std::exception>&)nullopt)),
make_test("should log an error with a message and an exception",
(const optional<string> &)"this should never happen",
(const optional<std::exception> &)nullopt)),
MakeTest("should log an error with a message and an exception",
no_errors,
make_tuple(Logger::MessageType::Error,
(const optional<string>&)"this should never happen",
(const optional<std::exception>&)runtime_error("bad thing happen"))),
make_test("should log an error with a message",
(const optional<string> &)"this should never happen",
(const optional<std::exception> &)runtime_error("bad thing happen"))),
MakeTest("should log an error with a message",
no_errors,
make_tuple(Logger::MessageType::Error,
(const optional<string>&)nullopt,
(const optional<std::exception>&)runtime_error("bad thing happen"))),
make_test("should log a warning with a message",
(const optional<string> &)nullopt,
(const optional<std::exception> &)runtime_error("bad thing happen"))),
MakeTest("should log a warning with a message",
no_errors,
make_tuple(Logger::MessageType::Warning,
(const optional<string>&)"this should never happen",
(const optional<std::exception>&)nullopt)),
make_test("should log a warning with a message and an exception",
(const optional<string> &)"this should never happen",
(const optional<std::exception> &)nullopt)),
MakeTest("should log a warning with a message and an exception",
no_errors,
make_tuple(Logger::MessageType::Warning,
(const optional<string>&)"this should never happen",
(const optional<std::exception>&)runtime_error("bad thing happen"))),
make_test("should log a warning with a message",
(const optional<string> &)"this should never happen",
(const optional<std::exception> &)runtime_error("bad thing happen"))),
MakeTest("should log a warning with a message",
no_errors,
make_tuple(Logger::MessageType::Warning,
(const optional<string>&)nullopt,
(const optional<std::exception>&)runtime_error("bad thing happen"))),
make_test("should log an info with a message",
(const optional<string> &)nullopt,
(const optional<std::exception> &)runtime_error("bad thing happen"))),
MakeTest("should log an info with a message",
no_errors,
make_tuple(Logger::MessageType::Info,
(const optional<string>&)"this should never happen",
(const optional<std::exception>&)nullopt)),
make_test("should log an info with a message and an exception",
(const optional<string> &)"this should never happen",
(const optional<std::exception> &)nullopt)),
MakeTest("should log an info with a message and an exception",
no_errors,
make_tuple(Logger::MessageType::Info,
(const optional<string>&)"this should never happen",
(const optional<std::exception>&)runtime_error("bad thing happen"))),
make_test("should log an info with a message",
(const optional<string> &)"this should never happen",
(const optional<std::exception> &)runtime_error("bad thing happen"))),
MakeTest("should log an info with a message",
no_errors,
make_tuple(Logger::MessageType::Info,
(const optional<string>&)nullopt,
(const optional<std::exception>&)runtime_error("bad thing happen"))),
make_test("should log a debug with a message",
(const optional<string> &)nullopt,
(const optional<std::exception> &)runtime_error("bad thing happen"))),
MakeTest("should log a debug with a message",
no_errors,
make_tuple(Logger::MessageType::Debug,
(const optional<string>&)"this should never happen",
(const optional<std::exception>&)nullopt)),
make_test("should log a debug with a message and an exception",
(const optional<string> &)"this should never happen",
(const optional<std::exception> &)nullopt)),
MakeTest("should log a debug with a message and an exception",
no_errors,
make_tuple(Logger::MessageType::Debug,
(const optional<string>&)"this should never happen",
(const optional<std::exception>&)runtime_error("bad thing happen"))),
make_test("should log a debug with a message",
(const optional<string> &)"this should never happen",
(const optional<std::exception> &)runtime_error("bad thing happen"))),
MakeTest("should log a debug with a message",
no_errors,
make_tuple(Logger::MessageType::Debug,
(const optional<string>&)nullopt,
(const optional<std::exception>&)runtime_error("bad thing happen"))),
make_test("should log a verbose with a message",
(const optional<string> &)nullopt,
(const optional<std::exception> &)runtime_error("bad thing happen"))),
MakeTest("should log a verbose with a message",
no_errors,
make_tuple(Logger::MessageType::Verbose,
(const optional<string>&)"this should never happen",
(const optional<std::exception>&)nullopt)),
make_test("should log a verbose with a message and an exception",
(const optional<string> &)"this should never happen",
(const optional<std::exception> &)nullopt)),
MakeTest("should log a verbose with a message and an exception",
no_errors,
make_tuple(Logger::MessageType::Verbose,
(const optional<string>&)"this should never happen",
(const optional<std::exception>&)runtime_error("bad thing happen"))),
make_test("should log a verbose with a message",
(const optional<string> &)"this should never happen",
(const optional<std::exception> &)runtime_error("bad thing happen"))),
MakeTest("should log a verbose with a message",
no_errors,
make_tuple(Logger::MessageType::Verbose,
(const optional<string>&)nullopt,
(const optional<std::exception>&)runtime_error("bad thing happen"))),
(const optional<string> &)nullopt,
(const optional<std::exception> &)runtime_error("bad thing happen"))),
}));
}
TestResults test_Logger_Log() {
auto log = [](const Logger::MessageType& type,
const optional<string>& message_text,
const optional<std::exception>& ex) -> string {
auto log = [](const Logger::MessageType &type,
const optional<string> &message_text,
const optional<std::exception> &ex) -> string {
ostringstream error_message;
auto logger = Logger::GetUnique();
auto spy = make_shared<SpyLoggerDestination>();
@@ -627,106 +626,106 @@ TestResults test_Logger_Log() {
}
return GetError(error_message);
};
return execute_suite(
make_test_suite("CPPUtils::Logger::Log(const MessageType&, ...)",
return ExecuteSuite(
MakeTestSuite("CPPUtils::Logger::Log(const MessageType&, ...)",
log,
{
make_test("should log what a terrible failure with a message",
MakeTest("should log what a terrible failure with a message",
no_errors,
make_tuple(Logger::MessageType::Wtf,
(const optional<string>&)"this should never happen",
(const optional<std::exception>&)nullopt)),
make_test("should log what a terrible failure with a message and an exception",
(const optional<string> &)"this should never happen",
(const optional<std::exception> &)nullopt)),
MakeTest("should log what a terrible failure with a message and an exception",
no_errors,
make_tuple(Logger::MessageType::Wtf,
(const optional<string>&)"this should never happen",
(const optional<std::exception>&)runtime_error("bad thing happen"))),
make_test("should log what a terrible failure with a message",
(const optional<string> &)"this should never happen",
(const optional<std::exception> &)runtime_error("bad thing happen"))),
MakeTest("should log what a terrible failure with a message",
no_errors,
make_tuple(Logger::MessageType::Wtf,
(const optional<string>&)nullopt,
(const optional<std::exception>&)runtime_error("bad thing happen"))),
make_test("should log an error with a message",
(const optional<string> &)nullopt,
(const optional<std::exception> &)runtime_error("bad thing happen"))),
MakeTest("should log an error with a message",
no_errors,
make_tuple(Logger::MessageType::Error,
(const optional<string>&)"this should never happen",
(const optional<std::exception>&)nullopt)),
make_test("should log an error with a message and an exception",
(const optional<string> &)"this should never happen",
(const optional<std::exception> &)nullopt)),
MakeTest("should log an error with a message and an exception",
no_errors,
make_tuple(Logger::MessageType::Error,
(const optional<string>&)"this should never happen",
(const optional<std::exception>&)runtime_error("bad thing happen"))),
make_test("should log an error with a message",
(const optional<string> &)"this should never happen",
(const optional<std::exception> &)runtime_error("bad thing happen"))),
MakeTest("should log an error with a message",
no_errors,
make_tuple(Logger::MessageType::Error,
(const optional<string>&)nullopt,
(const optional<std::exception>&)runtime_error("bad thing happen"))),
make_test("should log a warning with a message",
(const optional<string> &)nullopt,
(const optional<std::exception> &)runtime_error("bad thing happen"))),
MakeTest("should log a warning with a message",
no_errors,
make_tuple(Logger::MessageType::Warning,
(const optional<string>&)"this should never happen",
(const optional<std::exception>&)nullopt)),
make_test("should log a warning with a message and an exception",
(const optional<string> &)"this should never happen",
(const optional<std::exception> &)nullopt)),
MakeTest("should log a warning with a message and an exception",
no_errors,
make_tuple(Logger::MessageType::Warning,
(const optional<string>&)"this should never happen",
(const optional<std::exception>&)runtime_error("bad thing happen"))),
make_test("should log a warning with a message",
(const optional<string> &)"this should never happen",
(const optional<std::exception> &)runtime_error("bad thing happen"))),
MakeTest("should log a warning with a message",
no_errors,
make_tuple(Logger::MessageType::Warning,
(const optional<string>&)nullopt,
(const optional<std::exception>&)runtime_error("bad thing happen"))),
make_test("should log an info with a message",
(const optional<string> &)nullopt,
(const optional<std::exception> &)runtime_error("bad thing happen"))),
MakeTest("should log an info with a message",
no_errors,
make_tuple(Logger::MessageType::Info,
(const optional<string>&)"this should never happen",
(const optional<std::exception>&)nullopt)),
make_test("should log an info with a message and an exception",
(const optional<string> &)"this should never happen",
(const optional<std::exception> &)nullopt)),
MakeTest("should log an info with a message and an exception",
no_errors,
make_tuple(Logger::MessageType::Info,
(const optional<string>&)"this should never happen",
(const optional<std::exception>&)runtime_error("bad thing happen"))),
make_test("should log an info with a message",
(const optional<string> &)"this should never happen",
(const optional<std::exception> &)runtime_error("bad thing happen"))),
MakeTest("should log an info with a message",
no_errors,
make_tuple(Logger::MessageType::Info,
(const optional<string>&)nullopt,
(const optional<std::exception>&)runtime_error("bad thing happen"))),
make_test("should log a debug with a message",
(const optional<string> &)nullopt,
(const optional<std::exception> &)runtime_error("bad thing happen"))),
MakeTest("should log a debug with a message",
no_errors,
make_tuple(Logger::MessageType::Debug,
(const optional<string>&)"this should never happen",
(const optional<std::exception>&)nullopt)),
make_test("should log a debug with a message and an exception",
(const optional<string> &)"this should never happen",
(const optional<std::exception> &)nullopt)),
MakeTest("should log a debug with a message and an exception",
no_errors,
make_tuple(Logger::MessageType::Debug,
(const optional<string>&)"this should never happen",
(const optional<std::exception>&)runtime_error("bad thing happen"))),
make_test("should log a debug with a message",
(const optional<string> &)"this should never happen",
(const optional<std::exception> &)runtime_error("bad thing happen"))),
MakeTest("should log a debug with a message",
no_errors,
make_tuple(Logger::MessageType::Debug,
(const optional<string>&)nullopt,
(const optional<std::exception>&)runtime_error("bad thing happen"))),
make_test("should log a verbose with a message",
(const optional<string> &)nullopt,
(const optional<std::exception> &)runtime_error("bad thing happen"))),
MakeTest("should log a verbose with a message",
no_errors,
make_tuple(Logger::MessageType::Verbose,
(const optional<string>&)"this should never happen",
(const optional<std::exception>&)nullopt)),
make_test("should log a verbose with a message and an exception",
(const optional<string> &)"this should never happen",
(const optional<std::exception> &)nullopt)),
MakeTest("should log a verbose with a message and an exception",
no_errors,
make_tuple(Logger::MessageType::Verbose,
(const optional<string>&)"this should never happen",
(const optional<std::exception>&)runtime_error("bad thing happen"))),
make_test("should log a verbose with a message",
(const optional<string> &)"this should never happen",
(const optional<std::exception> &)runtime_error("bad thing happen"))),
MakeTest("should log a verbose with a message",
no_errors,
make_tuple(Logger::MessageType::Verbose,
(const optional<string>&)nullopt,
(const optional<std::exception>&)runtime_error("bad thing happen"))),
(const optional<string> &)nullopt,
(const optional<std::exception> &)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<SpyLoggerDestination>();
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\"",
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")),
make_test("should log a TODO for \"refactor this\"", no_errors, make_tuple("refactor this")),
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("",
return ExecuteSuite(MakeTestSuite("",
add_destination,
{
make_test("should add and clear destinations", no_errors, make_tuple()),
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();
}

View File

@@ -56,21 +56,50 @@ template <typename TChar> struct StringTraits;
/// @brief This SFINAE struct is use to select a narrow string.
template <> struct StringTraits<char> {
/// @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<wchar_t> {
/// @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 <typename T> struct is_container {
/// @brief Returns true because the type has begin and end methods.
/// @tparam U The type to check.
/// @param <anonymous> A pointer that is not used.
/// @return True because the type is a container.
template <typename U> static constexpr bool test(decltype(std::begin(std::declval<U>())) *) { return true; }
/// @brief Returns false because the type is not a container.
/// @tparam U The type to check.
/// @param <anonymous> A pointer that is not used.
/// @return False because the type is not a container.
template <typename U> static constexpr bool test(...) { return false; }
/// @brief Tests whether type T is a container.
static constexpr bool value = test<T>(nullptr);
};

View File

@@ -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,16 +55,16 @@ 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*)",
results += ExecuteSuite(
MakeTestSuite("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",
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.")),
make_test("should escape the escape character by itself", (string) "\\033", make_tuple("\033")),
make_test("should escape the escape character within a 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.")),
}));
@@ -74,16 +74,16 @@ TestResults test_EscapeForPrintingWithAConstCharPointer() {
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",
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.")),
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",
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.")),
}));
@@ -92,16 +92,16 @@ TestResults test_EscapeForPrintingWithAString() {
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",
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.")),
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",
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,12 +113,12 @@ TestResults test_PrettyPrintWithAConstCharPointer() {
PrettyPrint(os, value);
return os.str();
};
return execute_suite(make_test_suite(
"CPPUtils::PrettyPrint(std::ostream&, const char*)",
return ExecuteSuite(
MakeTestSuite("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")),
MakeTest("should print \"\" for an empty string", (string) "\"\"", make_tuple("")),
MakeTest("should print \"hello world\"", (string) "\"hello world\"", make_tuple("hello world")),
}));
}
@@ -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",
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)),
make_test("should print an initializer_list of doubles", (string) "[ 1.1, 2.2, 3.3 ]", make_tuple(5)),
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,10 +270,10 @@ TestResults test_PrettyPrintWithSimpleTypes() {
PrettyPrint(os, value);
return os.str();
};
results += execute_suite(make_test_suite("CPPUtils::PrettyPrint(std::ostream&, const TItem&)",
results += ExecuteSuite(MakeTestSuite("CPPUtils::PrettyPrint(std::ostream&, const TItem&)",
pretty_print_int,
{
make_test("should print 42 for an int", (string) "42", make_tuple(42)),
MakeTest("should print 42 for an int", (string) "42", make_tuple(42)),
}));
auto pretty_print_float = [](float value) -> string {
@@ -283,10 +282,10 @@ TestResults test_PrettyPrintWithSimpleTypes() {
return os.str();
};
results +=
execute_suite(make_test_suite("CPPUtils::PrettyPrint(std::ostream&, const TItem&)",
ExecuteSuite(MakeTestSuite("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)),
MakeTest("should print 3.14 for a float", (string) "3.14", make_tuple(3.14f)),
}));
auto pretty_print_string = [](const string &value) -> string {
@@ -294,10 +293,10 @@ TestResults test_PrettyPrintWithSimpleTypes() {
PrettyPrint(os, value);
return os.str();
};
results += execute_suite(make_test_suite("CPPUtils::PrettyPrint(std::ostream&, const TItem&)",
results += ExecuteSuite(MakeTestSuite("CPPUtils::PrettyPrint(std::ostream&, const TItem&)",
pretty_print_string,
{
make_test("should print \"hello world\" for a string",
MakeTest("should print \"hello world\" for a string",
(string) "\"hello world\"",
make_tuple((string) "hello world")),
}));
@@ -320,13 +319,13 @@ TestResults test_PrettyPrintWithAPair() {
}
return os.str();
};
return execute_suite(make_test_suite(
return ExecuteSuite(MakeTestSuite(
"CPPUtils::PrettyPrint(std::ostream&, const std::pair<T1, T2>&)",
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",
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,15 +347,15 @@ TestResults test_PrettyPrintWithSeparatorWithAConstCharPointer() {
}
return os.str();
};
return execute_suite(
make_test_suite("CPPUtils::PrettyPrintWithSeparator(std::ostream&, const TChar*, Args&&...)",
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(", ", 1)),
make_test("should print 3.14; 42; \"hello world\" for a list of float, int and string",
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)),
make_test("should print \"hello\" \"world\" for a list of strings",
MakeTest("should print \"hello\" \"world\" for a list of strings",
(string) "\"hello\" \"world\"",
make_tuple(" ", 3)),
}));
@@ -378,15 +377,15 @@ 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",
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)),
make_test("should print \"hello\" - \"world\" for a list of strings",
MakeTest("should print \"hello\" - \"world\" for a list of strings",
(string) "\"hello\" - \"world\"",
make_tuple((string) " - ", 3)),
}));
@@ -408,16 +407,16 @@ 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",
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)),
make_test("should print \"hello\" - \"world\" for a list of strings",
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();
}

View File

@@ -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<string, string, UINT> MessageBoxEvent;
@@ -302,51 +302,51 @@ 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\"",
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)),
make_test(
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?\"",
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)),
make_test("should log \"this is some information\" with title \"Information\"",
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)),
make_test("should log \"this is a warning\" with title \"Warning\"",
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)),
make_test("should log \"this is verbose\" with title \"Verbose\"",
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)),
make_test("should log \"unclassified message\" with title \"Unclassified\"",
MakeTest("should log \"unclassified message\" with title \"Unclassified\"",
no_errors,
make_tuple((Logger::MessageType)1000,
"unclassified message",
@@ -374,53 +374,53 @@ 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\"",
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)),
make_test("should log \"Exception: this is an error\" with title \"ERROR\"",
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)),
make_test("should log \"Exception: what a terrible failure\" with title \"How did you let this happen?\"",
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)),
make_test("should log \"Exception: this is some information\" with title \"Information\"",
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)),
make_test("should log \"Exception: this is a warning\" with title \"Warning\"",
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)),
make_test("should log \"Exception: this is verbose\" with title \"Verbose\"",
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)),
make_test("should log \"Exception: unclassified message\" with title \"Unclassified\"",
MakeTest("should log \"Exception: unclassified message\" with title \"Unclassified\"",
no_errors,
make_tuple((Logger::MessageType)1000,
std::runtime_error("unclassified message"),
@@ -449,11 +449,11 @@ 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\"",
MakeTest("should log \"Exception: this is an exception\" with title \"Debug\"",
no_errors,
make_tuple(Logger::MessageType::Debug,
"this is a message",
@@ -461,7 +461,7 @@ TestResults test_WindowsLogger_LogErrorWithoutMessage() {
"Exception: this is an exception",
"Debug",
MB_OK | MB_ICONEXCLAMATION)),
make_test("should log \"Exception: this is an exception\" with title \"ERROR\"",
MakeTest("should log \"Exception: this is an exception\" with title \"ERROR\"",
no_errors,
make_tuple(Logger::MessageType::Error,
"this is an error",
@@ -469,7 +469,7 @@ TestResults test_WindowsLogger_LogErrorWithoutMessage() {
"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?\"",
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",
@@ -477,7 +477,7 @@ TestResults test_WindowsLogger_LogErrorWithoutMessage() {
"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\"",
MakeTest("should log \"Exception this is an exception\" with title \"Information\"",
no_errors,
make_tuple(Logger::MessageType::Info,
"this is some information",
@@ -485,7 +485,7 @@ TestResults test_WindowsLogger_LogErrorWithoutMessage() {
"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 "
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,
@@ -494,7 +494,7 @@ TestResults test_WindowsLogger_LogErrorWithoutMessage() {
"Exception: this is an exception",
"Warning",
MB_OK | MB_ICONEXCLAMATION)),
make_test("should log \"Exception: this is an exception\" with title \"Verbose\"",
MakeTest("should log \"Exception: this is an exception\" with title \"Verbose\"",
no_errors,
make_tuple(Logger::MessageType::Verbose,
"this is verbose",
@@ -502,7 +502,7 @@ TestResults test_WindowsLogger_LogErrorWithoutMessage() {
"Exception: this is an exception",
"Verbose",
MB_OK | MB_ICONASTERISK)),
make_test("should log \"Exception: this is an exception\" with title \"Unclassified\"",
MakeTest("should log \"Exception: this is an exception\" with title \"Unclassified\"",
no_errors,
make_tuple((Logger::MessageType)1000,
"unclassified message",
@@ -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)