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,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();
}

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
} // 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&)",
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<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&)",
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<ConsoleLogger>();
@@ -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<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();
}

File diff suppressed because it is too large Load Diff

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,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<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",
(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();
}

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,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)