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:
3
BUILD
3
BUILD
@@ -7,6 +7,8 @@
|
|||||||
# #
|
# #
|
||||||
# Licensed under the MIT license. See below for details. #
|
# Licensed under the MIT license. See below for details. #
|
||||||
# #
|
# #
|
||||||
|
########################################################################################################################
|
||||||
|
# #
|
||||||
# MIT License #
|
# MIT License #
|
||||||
# #
|
# #
|
||||||
# Copyright (c) 2023 Tom Hicks <headhunter3@gmail.com> #
|
# Copyright (c) 2023 Tom Hicks <headhunter3@gmail.com> #
|
||||||
@@ -36,6 +38,7 @@ cc_library(
|
|||||||
srcs = ["ansi_escapes.cpp"],
|
srcs = ["ansi_escapes.cpp"],
|
||||||
hdrs = ["ansi_escapes.h"],
|
hdrs = ["ansi_escapes.h"],
|
||||||
includes = ["ansi_escapes.h"],
|
includes = ["ansi_escapes.h"],
|
||||||
|
deps = [":pretty_print"],
|
||||||
)
|
)
|
||||||
|
|
||||||
cc_test(
|
cc_test(
|
||||||
|
|||||||
11
WORKSPACE
11
WORKSPACE
@@ -8,6 +8,8 @@
|
|||||||
# #
|
# #
|
||||||
# Licensed under the MIT license. See below for details. #
|
# Licensed under the MIT license. See below for details. #
|
||||||
# #
|
# #
|
||||||
|
########################################################################################################################
|
||||||
|
# #
|
||||||
# MIT License #
|
# MIT License #
|
||||||
# #
|
# #
|
||||||
# Copyright (c) 2023 Tom Hicks <headhunter3@gmail.com> #
|
# 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. #
|
# 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")
|
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||||
|
|
||||||
# Hedron's Compile Commands Extractor for Bazel
|
# Hedron's Compile Commands Extractor for Bazel
|
||||||
@@ -45,7 +49,8 @@ hedron_compile_commands_setup()
|
|||||||
|
|
||||||
http_archive(
|
http_archive(
|
||||||
name = "tinytest",
|
name = "tinytest",
|
||||||
sha256 = "71f366e680606e18268e6b9673a65c44c9e672f7356a61ffbcd3502c6a8eea0b",
|
# sha256 = "71f366e680606e18268e6b9673a65c44c9e672f7356a61ffbcd3502c6a8eea0b",
|
||||||
strip_prefix = "TinyTest-460c9492d927689b9db7f28d8742705dc0bbee62",
|
sha256 = "49a229ff3b2470e72743f2cc239cb2bc381f2976047a34b6832115097be7d887",
|
||||||
urls = ["https://github.com/headhunter45/TinyTest/archive/460c9492d927689b9db7f28d8742705dc0bbee62.zip"],
|
strip_prefix = "TinyTest-011953cd2ccecdc5fe0b8fe83b8d0dde10fa81ab",
|
||||||
|
urls = ["https://github.com/headhunter45/TinyTest/archive/011953cd2ccecdc5fe0b8fe83b8d0dde10fa81ab.zip"],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -43,9 +43,9 @@ using std::ostream;
|
|||||||
using std::ostringstream;
|
using std::ostringstream;
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::string_view;
|
using std::string_view;
|
||||||
using TinyTest::execute_suite;
|
using TinyTest::ExecuteSuite;
|
||||||
using TinyTest::make_test;
|
using TinyTest::MakeTest;
|
||||||
using TinyTest::make_test_suite;
|
using TinyTest::MakeTestSuite;
|
||||||
using TinyTest::TestResults;
|
using TinyTest::TestResults;
|
||||||
} // End namespace
|
} // End namespace
|
||||||
|
|
||||||
@@ -55,32 +55,32 @@ string filter(const string& text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TestResults test_GetRedComponent() {
|
TestResults test_GetRedComponent() {
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(
|
||||||
"CPPUtils::GetRedComponent(uint32_t)",
|
MakeTestSuite("CPPUtils::GetRedComponent(uint32_t)",
|
||||||
CPPUtils::GetRedComponent,
|
CPPUtils::GetRedComponent,
|
||||||
{
|
{
|
||||||
make_test("should get the red component 0x34 from 0x12345678", 0x34U, make_tuple(0x12345678U)),
|
MakeTest("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 0x56 from 0x34567890", 0x56U, make_tuple(0x34567890U)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResults test_GetGreenComponent() {
|
TestResults test_GetGreenComponent() {
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(
|
||||||
"CPPUtils::GetGreenComponent(uint32_t)",
|
MakeTestSuite("CPPUtils::GetGreenComponent(uint32_t)",
|
||||||
CPPUtils::GetGreenComponent,
|
CPPUtils::GetGreenComponent,
|
||||||
{
|
{
|
||||||
make_test("should get the green component 0x56 from 0x12345678", 0x56U, make_tuple(0x12345678U)),
|
MakeTest("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 0x78 from 0x34567890", 0x78U, make_tuple(0x34567890U)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResults test_GetBlueComponent() {
|
TestResults test_GetBlueComponent() {
|
||||||
return execute_suite(
|
return ExecuteSuite(
|
||||||
make_test_suite("CPPUtils::GetBlueComponent(uint32_t)",
|
MakeTestSuite("CPPUtils::GetBlueComponent(uint32_t)",
|
||||||
CPPUtils::GetBlueComponent,
|
CPPUtils::GetBlueComponent,
|
||||||
{
|
{
|
||||||
make_test("should get the blue component 0x78 from 0x12345678", 0x78, make_tuple(0x12345678)),
|
MakeTest("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 0x90 from 0x34567890", 0x90, make_tuple(0x34567890)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,13 +90,13 @@ TestResults test_EscapeWithBasicString() {
|
|||||||
CPPUtils::Escape(os, text);
|
CPPUtils::Escape(os, text);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::Escape(string)",
|
"CPPUtils::Escape(string)",
|
||||||
function_to_test,
|
function_to_test,
|
||||||
{
|
{
|
||||||
make_test("should escape \"asdf\" to \"\\033[asdfm\"", (string) "\033[asdfm", make_tuple("asdf")),
|
MakeTest("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")),
|
MakeTest("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 \"1;2;3\" to \"\\033[1;2;3m\"", (string) "\033[1;2;3m", make_tuple("1;2;3")),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,13 +106,13 @@ TestResults test_EscapeWithBasicStringView() {
|
|||||||
CPPUtils::Escape(os, text);
|
CPPUtils::Escape(os, text);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::Escape(string_view)",
|
"CPPUtils::Escape(string_view)",
|
||||||
function_to_test,
|
function_to_test,
|
||||||
{
|
{
|
||||||
make_test("should escape \"asdf\" to \"\\033[asdfm\"", (string) "\033[asdfm", make_tuple("asdf")),
|
MakeTest("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")),
|
MakeTest("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 \"1;2;3\" to \"\\033[1;2;3m\"", (string) "\033[1;2;3m", make_tuple("1;2;3")),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,13 +122,13 @@ TestResults test_EscapeWithConstCharStar() {
|
|||||||
CPPUtils::Escape(os, text);
|
CPPUtils::Escape(os, text);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::Escape(const char*)",
|
"CPPUtils::Escape(const char*)",
|
||||||
function_to_test,
|
function_to_test,
|
||||||
{
|
{
|
||||||
make_test("should escape \"asdf\" to \"\\033[asdfm\"", (string) "\033[asdfm", make_tuple("asdf")),
|
MakeTest("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")),
|
MakeTest("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 \"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);
|
CPPUtils::ForegroundColor8Bit(os, color);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(
|
return ExecuteSuite(
|
||||||
make_test_suite("CPPUtils::ForegroundColor8Bit(uint8_t)",
|
MakeTestSuite("CPPUtils::ForegroundColor8Bit(uint8_t)",
|
||||||
function_to_test,
|
function_to_test,
|
||||||
{
|
{
|
||||||
make_test("should write \"\\033[38;5;7m\"", (string) "\033[38;5;7m", make_tuple(0x07U)),
|
MakeTest("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)),
|
MakeTest("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;11m\"", (string) "\033[38;5;11m", make_tuple(0x0BU)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,13 +154,13 @@ TestResults test_BackgroundColor8Bit() {
|
|||||||
CPPUtils::BackgroundColor8Bit(os, color);
|
CPPUtils::BackgroundColor8Bit(os, color);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(
|
return ExecuteSuite(
|
||||||
make_test_suite("CPPUtils::BackgroundColor8Bit(uint8_t)",
|
MakeTestSuite("CPPUtils::BackgroundColor8Bit(uint8_t)",
|
||||||
function_to_test,
|
function_to_test,
|
||||||
{
|
{
|
||||||
make_test("should write \"\\033[48;5;7m\"", (string) "\033[48;5;7m", make_tuple(0x07U)),
|
MakeTest("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)),
|
MakeTest("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;11m\"", (string) "\033[48;5;11m", make_tuple(0x0BU)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,11 +170,11 @@ TestResults test_ForegroundTrueColorWithUInt32() {
|
|||||||
CPPUtils::ForegroundTrueColor(os, color);
|
CPPUtils::ForegroundTrueColor(os, color);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::ForegroundTrueColor(uint32_t)",
|
"CPPUtils::ForegroundTrueColor(uint32_t)",
|
||||||
function_to_test,
|
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);
|
CPPUtils::BackgroundTrueColor(os, color);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::BackgroundTrueColor(uint32_t)",
|
"CPPUtils::BackgroundTrueColor(uint32_t)",
|
||||||
function_to_test,
|
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);
|
CPPUtils::ForegroundTrueColor(os, red, green, blue);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite("CPPUtils::ForegroundTrueColor(uint8_t, uint8_t, uint8_t)",
|
||||||
"CPPUtils::ForegroundTrueColor(uint8_t, uint8_t, uint8_t)",
|
|
||||||
function_to_test,
|
function_to_test,
|
||||||
{
|
{
|
||||||
make_test(
|
MakeTest("should write \"\\033[38;2;21;69;136m\"",
|
||||||
"should write \"\\033[38;2;21;69;136m\"", (string) "\033[38;2;21;69;136m", make_tuple(0x15, 0x45, 0x88)),
|
(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);
|
CPPUtils::BackgroundTrueColor(os, red, green, blue);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite("CPPUtils::BackgroundTrueColor(uint8_t, uint8_t, uint8_t)",
|
||||||
"CPPUtils::BackgroundTrueColor(uint8_t, uint8_t, uint8_t)",
|
|
||||||
function_to_test,
|
function_to_test,
|
||||||
{
|
{
|
||||||
make_test(
|
MakeTest("should write \"\\033[48;2;21;69;136m\"",
|
||||||
"should write \"\\033[48;2;21;69;136m\"", (string) "\033[48;2;21;69;136m", make_tuple(0x15, 0x45, 0x88)),
|
(string) "\033[48;2;21;69;136m",
|
||||||
|
make_tuple(0x15, 0x45, 0x88)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,10 +228,10 @@ TestResults test_Reset() {
|
|||||||
CPPUtils::Reset(os);
|
CPPUtils::Reset(os);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite("CPPUtils::Reset",
|
return ExecuteSuite(MakeTestSuite("CPPUtils::Reset",
|
||||||
function_to_test,
|
function_to_test,
|
||||||
{
|
{
|
||||||
make_test("should write \"\\033[m\"", (string) "\033[m", make_tuple()),
|
MakeTest("should write \"\\033[m\"", (string) "\033[m", make_tuple()),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,5 +252,5 @@ int main(int argc, char* argv[]) {
|
|||||||
results += test_BackgroundTrueColorWith3UInt8();
|
results += test_BackgroundTrueColorWith3UInt8();
|
||||||
results += test_Reset();
|
results += test_Reset();
|
||||||
|
|
||||||
return results.failed() + results.errors();
|
return results.Failed() + results.Errors();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,9 +45,9 @@ using std::make_tuple;
|
|||||||
using std::ostream;
|
using std::ostream;
|
||||||
using std::ostringstream;
|
using std::ostringstream;
|
||||||
using std::string;
|
using std::string;
|
||||||
using TinyTest::execute_suite;
|
using TinyTest::ExecuteSuite;
|
||||||
using TinyTest::make_test;
|
using TinyTest::MakeTest;
|
||||||
using TinyTest::make_test_suite;
|
using TinyTest::MakeTestSuite;
|
||||||
using TinyTest::TestResults;
|
using TinyTest::TestResults;
|
||||||
string no_errors = "no errors";
|
string no_errors = "no errors";
|
||||||
|
|
||||||
@@ -62,27 +62,27 @@ TestResults test_ConsoleLogger_LogMessage() {
|
|||||||
destination->LogMessage(type, message);
|
destination->LogMessage(type, message);
|
||||||
return output.str();
|
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,
|
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",
|
(string) "[Debug] this is a message\n",
|
||||||
make_tuple(Logger::MessageType::Debug, "this is a message")),
|
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",
|
(string) "[Error] this is an error\n",
|
||||||
make_tuple(Logger::MessageType::Error, "this is an error")),
|
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",
|
(string) "[Wtf] what a terrible failure\n",
|
||||||
make_tuple(Logger::MessageType::Wtf, "what a terrible failure")),
|
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",
|
(string) "[Info] this is some information\n",
|
||||||
make_tuple(Logger::MessageType::Info, "this is some information")),
|
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",
|
(string) "[Warning] this is a warning\n",
|
||||||
make_tuple(Logger::MessageType::Warning, "this is a warning")),
|
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",
|
(string) "[Verbose] this is verbose\n",
|
||||||
make_tuple(Logger::MessageType::Verbose, "this is verbose")),
|
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",
|
(string) "[Unclassified] unclassified message\n",
|
||||||
make_tuple((Logger::MessageType)1000, "unclassified message"))}));
|
make_tuple((Logger::MessageType)1000, "unclassified message"))}));
|
||||||
}
|
}
|
||||||
@@ -96,28 +96,28 @@ TestResults test_ConsoleLogger_LogErrorWithMessage() {
|
|||||||
destination->LogError(type, ex);
|
destination->LogError(type, ex);
|
||||||
return output.str();
|
return output.str();
|
||||||
};
|
};
|
||||||
return execute_suite(
|
return ExecuteSuite(
|
||||||
make_test_suite("CPPUtils::ConsoleLogger::LogError(const std::exception&)",
|
MakeTestSuite("CPPUtils::ConsoleLogger::LogError(const std::exception&)",
|
||||||
log_error,
|
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",
|
(string) "[Debug] caught exception: this is an exception\n",
|
||||||
make_tuple(Logger::MessageType::Debug, std::runtime_error("this is an exception"))),
|
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",
|
(string) "[Error] caught exception: this is an error\n",
|
||||||
make_tuple(Logger::MessageType::Error, std::runtime_error("this is an error"))),
|
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",
|
(string) "[Wtf] caught exception: what a terrible failure\n",
|
||||||
make_tuple(Logger::MessageType::Wtf, std::runtime_error("what a terrible failure"))),
|
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",
|
(string) "[Info] caught exception: this is some information\n",
|
||||||
make_tuple(Logger::MessageType::Info, std::runtime_error("this is some information"))),
|
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",
|
(string) "[Warning] caught exception: this is a warning\n",
|
||||||
make_tuple(Logger::MessageType::Warning, std::runtime_error("this is a warning"))),
|
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",
|
(string) "[Verbose] caught exception: this is verbose\n",
|
||||||
make_tuple(Logger::MessageType::Verbose, std::runtime_error("this is verbose"))),
|
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",
|
(string) "[Unclassified] caught exception: unclassified message\n",
|
||||||
make_tuple((Logger::MessageType)1000, std::runtime_error("unclassified message")))}));
|
make_tuple((Logger::MessageType)1000, std::runtime_error("unclassified message")))}));
|
||||||
}
|
}
|
||||||
@@ -131,37 +131,37 @@ TestResults test_ConsoleLogger_LogErrorWithoutMessage() {
|
|||||||
destination->LogError(type, message, ex);
|
destination->LogError(type, message, ex);
|
||||||
return output.str();
|
return output.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::ConsoleLogger::LogError(const std::string&, const std::exception&)",
|
"CPPUtils::ConsoleLogger::LogError(const std::string&, const std::exception&)",
|
||||||
log_error,
|
log_error,
|
||||||
{
|
{
|
||||||
make_test(
|
MakeTest(
|
||||||
"should print \"[Debug] this is a message with caught exception this is an exception\"",
|
"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",
|
(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_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\"",
|
"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",
|
(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_tuple(Logger::MessageType::Error, "this is an error", std::runtime_error("this is an exception"))),
|
||||||
make_test(
|
MakeTest("should print \"[Wtf] what a terrible failure with caught exception this is an exception\"",
|
||||||
"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",
|
(string) "[Wtf] what a terrible failure with caught exception this is an exception\n",
|
||||||
make_tuple(
|
make_tuple(Logger::MessageType::Wtf,
|
||||||
Logger::MessageType::Wtf, "what a terrible failure", std::runtime_error("this is an exception"))),
|
"what a terrible failure",
|
||||||
make_test(
|
std::runtime_error("this is an exception"))),
|
||||||
"should print \"[Info] this is some information with caught exception 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",
|
(string) "[Info] this is some information with caught exception this is an exception\n",
|
||||||
make_tuple(
|
make_tuple(Logger::MessageType::Info,
|
||||||
Logger::MessageType::Info, "this is some information", std::runtime_error("this is an exception"))),
|
"this is some information",
|
||||||
make_test("should print \"[Warning] this is a warning with caught exception this is an exception\"",
|
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",
|
(string) "[Warning] this is a warning with caught exception this is an exception\n",
|
||||||
make_tuple(
|
make_tuple(
|
||||||
Logger::MessageType::Warning, "this is a warning", std::runtime_error("this is an exception"))),
|
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\"",
|
"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",
|
(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_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",
|
(string) "[Unclassified] unclassified message with caught exception this is an exception\n",
|
||||||
make_tuple(
|
make_tuple(
|
||||||
(Logger::MessageType)1000, "unclassified message", std::runtime_error("this is an exception"))),
|
(Logger::MessageType)1000, "unclassified message", std::runtime_error("this is an exception"))),
|
||||||
@@ -177,13 +177,13 @@ TestResults test_ConsoleLogger_SetOutputStream() {
|
|||||||
return &destination->GetOutputStream() == &os;
|
return &destination->GetOutputStream() == &os;
|
||||||
};
|
};
|
||||||
std::ostringstream os1;
|
std::ostringstream os1;
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::ConsoleLogger::Set/GetOutputStream(std::ostream&)",
|
"CPPUtils::ConsoleLogger::Set/GetOutputStream(std::ostream&)",
|
||||||
set_get_output_stream,
|
set_get_output_stream,
|
||||||
{
|
{
|
||||||
make_test("should get cout by default", true, make_tuple(std::ref(std::cout), true)),
|
MakeTest("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)),
|
MakeTest("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 set and get the same output stream", true, make_tuple(std::ref((std::ostream &)os1), false)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,5 +197,5 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
PrintResults(cout, results);
|
PrintResults(cout, results);
|
||||||
|
|
||||||
return results.failed() + results.errors();
|
return results.Failed() + results.Errors();
|
||||||
}
|
}
|
||||||
|
|||||||
165
logger_test.cpp
165
logger_test.cpp
@@ -56,9 +56,9 @@ using std::shared_ptr;
|
|||||||
using std::string;
|
using std::string;
|
||||||
using std::tuple;
|
using std::tuple;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
using TinyTest::execute_suite;
|
using TinyTest::ExecuteSuite;
|
||||||
using TinyTest::make_test;
|
using TinyTest::MakeTest;
|
||||||
using TinyTest::make_test_suite;
|
using TinyTest::MakeTestSuite;
|
||||||
using TinyTest::TestResults;
|
using TinyTest::TestResults;
|
||||||
|
|
||||||
string no_errors = "no errors";
|
string no_errors = "no errors";
|
||||||
@@ -88,8 +88,7 @@ class SpyLoggerDestination : public Logger::Destination {
|
|||||||
mutable vector<LogEntry> log;
|
mutable vector<LogEntry> log;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T> ostream &PrintOptional(ostream &os, optional<T> op) {
|
||||||
ostream& PrintOptional(ostream& os, optional<T> op) {
|
|
||||||
if (op.has_value()) {
|
if (op.has_value()) {
|
||||||
os << op.value();
|
os << op.value();
|
||||||
} else {
|
} else {
|
||||||
@@ -151,21 +150,21 @@ TestResults test_Destination_TypeRangeGettersAndSetters() {
|
|||||||
spy->SetMinType(type);
|
spy->SetMinType(type);
|
||||||
return spy->GetMinType();
|
return spy->GetMinType();
|
||||||
};
|
};
|
||||||
results += execute_suite(make_test_suite(
|
results += ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::Logger::SetMinType(const MessageType&)",
|
"CPPUtils::Logger::SetMinType(const MessageType&)",
|
||||||
set_min_type,
|
set_min_type,
|
||||||
{
|
{
|
||||||
make_test(
|
MakeTest(
|
||||||
"should set min type to Unknown", Logger::MessageType::Unknown, make_tuple(Logger::MessageType::Unknown)),
|
"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)),
|
MakeTest("should set min type to Debug", Logger::MessageType::Debug, make_tuple(Logger::MessageType::Debug)),
|
||||||
make_test(
|
MakeTest(
|
||||||
"should set min type to Verbose", Logger::MessageType::Verbose, make_tuple(Logger::MessageType::Verbose)),
|
"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)),
|
MakeTest("should set min type to Info", Logger::MessageType::Info, make_tuple(Logger::MessageType::Info)),
|
||||||
make_test(
|
MakeTest(
|
||||||
"should set min type to Warning", Logger::MessageType::Warning, make_tuple(Logger::MessageType::Warning)),
|
"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)),
|
MakeTest("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)),
|
MakeTest("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 Unknown for an invalid MessageType",
|
||||||
Logger::MessageType::Unknown,
|
Logger::MessageType::Unknown,
|
||||||
(make_tuple((Logger::MessageType)-1))),
|
(make_tuple((Logger::MessageType)-1))),
|
||||||
}));
|
}));
|
||||||
@@ -179,21 +178,21 @@ TestResults test_Destination_TypeRangeGettersAndSetters() {
|
|||||||
spy->SetMaxType(type);
|
spy->SetMaxType(type);
|
||||||
return spy->GetMaxType();
|
return spy->GetMaxType();
|
||||||
};
|
};
|
||||||
results += execute_suite(make_test_suite(
|
results += ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::Logger::SetMaxType(const MessageType&)",
|
"CPPUtils::Logger::SetMaxType(const MessageType&)",
|
||||||
set_max_type,
|
set_max_type,
|
||||||
{
|
{
|
||||||
make_test(
|
MakeTest(
|
||||||
"should set max type to Unknown", Logger::MessageType::Unknown, make_tuple(Logger::MessageType::Unknown)),
|
"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)),
|
MakeTest("should set max type to Debug", Logger::MessageType::Debug, make_tuple(Logger::MessageType::Debug)),
|
||||||
make_test(
|
MakeTest(
|
||||||
"should set max type to Verbose", Logger::MessageType::Verbose, make_tuple(Logger::MessageType::Verbose)),
|
"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)),
|
MakeTest("should set max type to Info", Logger::MessageType::Info, make_tuple(Logger::MessageType::Info)),
|
||||||
make_test(
|
MakeTest(
|
||||||
"should set max type to Warning", Logger::MessageType::Warning, make_tuple(Logger::MessageType::Warning)),
|
"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)),
|
MakeTest("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)),
|
MakeTest("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 Unknown for an invalid MessageType",
|
||||||
Logger::MessageType::Unknown,
|
Logger::MessageType::Unknown,
|
||||||
(make_tuple((Logger::MessageType)-1))),
|
(make_tuple((Logger::MessageType)-1))),
|
||||||
}));
|
}));
|
||||||
@@ -206,10 +205,10 @@ TestResults test_Logger_GetShared() {
|
|||||||
auto second = Logger::GetShared();
|
auto second = Logger::GetShared();
|
||||||
return first == second;
|
return first == second;
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite("CPPUtils::Logger::GetShared()",
|
return ExecuteSuite(MakeTestSuite("CPPUtils::Logger::GetShared()",
|
||||||
function_to_test,
|
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;
|
TestResults results;
|
||||||
|
|
||||||
results += execute_suite(make_test_suite("CPPUtils::Logger::GetUnique()",
|
results += ExecuteSuite(MakeTestSuite("CPPUtils::Logger::GetUnique()",
|
||||||
get_unique_is_different,
|
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(
|
results += ExecuteSuite(
|
||||||
make_test_suite("CPPUtils::Logger::GetUnique()",
|
MakeTestSuite("CPPUtils::Logger::GetUnique()",
|
||||||
get_unique_is_not_get_shared,
|
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;
|
return results;
|
||||||
@@ -274,11 +273,11 @@ TestResults test_LogUnimplementedMethod() {
|
|||||||
}
|
}
|
||||||
return GetError(error_message);
|
return GetError(error_message);
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::Logger::LogUnimplementedMethod",
|
"CPPUtils::Logger::LogUnimplementedMethod",
|
||||||
function_to_test,
|
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
|
#endif
|
||||||
}
|
}
|
||||||
@@ -300,10 +299,10 @@ TestResults test_Logger_LogUnhandledError() {
|
|||||||
}
|
}
|
||||||
return GetError(error_message);
|
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,
|
log_unhandled_error,
|
||||||
{
|
{
|
||||||
make_test("should log an error", no_errors, make_tuple()),
|
MakeTest("should log an error", no_errors, make_tuple()),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,10 +323,10 @@ TestResults test_Logger_LogUnimplementedFeature() {
|
|||||||
}
|
}
|
||||||
return GetError(error_message);
|
return GetError(error_message);
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite("CPPUtils::Logger::LogUnimplementedFeature()",
|
return ExecuteSuite(MakeTestSuite("CPPUtils::Logger::LogUnimplementedFeature()",
|
||||||
log_unimplemented_feature,
|
log_unimplemented_feature,
|
||||||
{
|
{
|
||||||
make_test("should log an unimplemented feature", no_errors, make_tuple()),
|
MakeTest("should log an unimplemented feature", no_errors, make_tuple()),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -430,96 +429,96 @@ TestResults test_Logger_Log_Level() {
|
|||||||
}
|
}
|
||||||
return GetError(error_message);
|
return GetError(error_message);
|
||||||
};
|
};
|
||||||
return execute_suite(
|
return ExecuteSuite(
|
||||||
make_test_suite("CPPUtils::Logger::Log*(...)",
|
MakeTestSuite("CPPUtils::Logger::Log*(...)",
|
||||||
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,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Wtf,
|
make_tuple(Logger::MessageType::Wtf,
|
||||||
(const optional<string> &)"this should never happen",
|
(const optional<string> &)"this should never happen",
|
||||||
(const optional<std::exception> &)nullopt)),
|
(const optional<std::exception> &)nullopt)),
|
||||||
make_test("should log what a terrible failure with a message and an exception",
|
MakeTest("should log what a terrible failure with a message and an exception",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Wtf,
|
make_tuple(Logger::MessageType::Wtf,
|
||||||
(const optional<string> &)"this should never happen",
|
(const optional<string> &)"this should never happen",
|
||||||
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
||||||
make_test("should log what a terrible failure with a message",
|
MakeTest("should log what a terrible failure with a message",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Wtf,
|
make_tuple(Logger::MessageType::Wtf,
|
||||||
(const optional<string> &)nullopt,
|
(const optional<string> &)nullopt,
|
||||||
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
||||||
make_test("should log an error with a message",
|
MakeTest("should log an error with a message",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Error,
|
make_tuple(Logger::MessageType::Error,
|
||||||
(const optional<string> &)"this should never happen",
|
(const optional<string> &)"this should never happen",
|
||||||
(const optional<std::exception> &)nullopt)),
|
(const optional<std::exception> &)nullopt)),
|
||||||
make_test("should log an error with a message and an exception",
|
MakeTest("should log an error with a message and an exception",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Error,
|
make_tuple(Logger::MessageType::Error,
|
||||||
(const optional<string> &)"this should never happen",
|
(const optional<string> &)"this should never happen",
|
||||||
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
||||||
make_test("should log an error with a message",
|
MakeTest("should log an error with a message",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Error,
|
make_tuple(Logger::MessageType::Error,
|
||||||
(const optional<string> &)nullopt,
|
(const optional<string> &)nullopt,
|
||||||
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
||||||
make_test("should log a warning with a message",
|
MakeTest("should log a warning with a message",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Warning,
|
make_tuple(Logger::MessageType::Warning,
|
||||||
(const optional<string> &)"this should never happen",
|
(const optional<string> &)"this should never happen",
|
||||||
(const optional<std::exception> &)nullopt)),
|
(const optional<std::exception> &)nullopt)),
|
||||||
make_test("should log a warning with a message and an exception",
|
MakeTest("should log a warning with a message and an exception",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Warning,
|
make_tuple(Logger::MessageType::Warning,
|
||||||
(const optional<string> &)"this should never happen",
|
(const optional<string> &)"this should never happen",
|
||||||
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
||||||
make_test("should log a warning with a message",
|
MakeTest("should log a warning with a message",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Warning,
|
make_tuple(Logger::MessageType::Warning,
|
||||||
(const optional<string> &)nullopt,
|
(const optional<string> &)nullopt,
|
||||||
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
||||||
make_test("should log an info with a message",
|
MakeTest("should log an info with a message",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Info,
|
make_tuple(Logger::MessageType::Info,
|
||||||
(const optional<string> &)"this should never happen",
|
(const optional<string> &)"this should never happen",
|
||||||
(const optional<std::exception> &)nullopt)),
|
(const optional<std::exception> &)nullopt)),
|
||||||
make_test("should log an info with a message and an exception",
|
MakeTest("should log an info with a message and an exception",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Info,
|
make_tuple(Logger::MessageType::Info,
|
||||||
(const optional<string> &)"this should never happen",
|
(const optional<string> &)"this should never happen",
|
||||||
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
||||||
make_test("should log an info with a message",
|
MakeTest("should log an info with a message",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Info,
|
make_tuple(Logger::MessageType::Info,
|
||||||
(const optional<string> &)nullopt,
|
(const optional<string> &)nullopt,
|
||||||
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
||||||
make_test("should log a debug with a message",
|
MakeTest("should log a debug with a message",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Debug,
|
make_tuple(Logger::MessageType::Debug,
|
||||||
(const optional<string> &)"this should never happen",
|
(const optional<string> &)"this should never happen",
|
||||||
(const optional<std::exception> &)nullopt)),
|
(const optional<std::exception> &)nullopt)),
|
||||||
make_test("should log a debug with a message and an exception",
|
MakeTest("should log a debug with a message and an exception",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Debug,
|
make_tuple(Logger::MessageType::Debug,
|
||||||
(const optional<string> &)"this should never happen",
|
(const optional<string> &)"this should never happen",
|
||||||
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
||||||
make_test("should log a debug with a message",
|
MakeTest("should log a debug with a message",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Debug,
|
make_tuple(Logger::MessageType::Debug,
|
||||||
(const optional<string> &)nullopt,
|
(const optional<string> &)nullopt,
|
||||||
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
||||||
make_test("should log a verbose with a message",
|
MakeTest("should log a verbose with a message",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Verbose,
|
make_tuple(Logger::MessageType::Verbose,
|
||||||
(const optional<string> &)"this should never happen",
|
(const optional<string> &)"this should never happen",
|
||||||
(const optional<std::exception> &)nullopt)),
|
(const optional<std::exception> &)nullopt)),
|
||||||
make_test("should log a verbose with a message and an exception",
|
MakeTest("should log a verbose with a message and an exception",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Verbose,
|
make_tuple(Logger::MessageType::Verbose,
|
||||||
(const optional<string> &)"this should never happen",
|
(const optional<string> &)"this should never happen",
|
||||||
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
||||||
make_test("should log a verbose with a message",
|
MakeTest("should log a verbose with a message",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Verbose,
|
make_tuple(Logger::MessageType::Verbose,
|
||||||
(const optional<string> &)nullopt,
|
(const optional<string> &)nullopt,
|
||||||
@@ -627,96 +626,96 @@ TestResults test_Logger_Log() {
|
|||||||
}
|
}
|
||||||
return GetError(error_message);
|
return GetError(error_message);
|
||||||
};
|
};
|
||||||
return execute_suite(
|
return ExecuteSuite(
|
||||||
make_test_suite("CPPUtils::Logger::Log(const MessageType&, ...)",
|
MakeTestSuite("CPPUtils::Logger::Log(const MessageType&, ...)",
|
||||||
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,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Wtf,
|
make_tuple(Logger::MessageType::Wtf,
|
||||||
(const optional<string> &)"this should never happen",
|
(const optional<string> &)"this should never happen",
|
||||||
(const optional<std::exception> &)nullopt)),
|
(const optional<std::exception> &)nullopt)),
|
||||||
make_test("should log what a terrible failure with a message and an exception",
|
MakeTest("should log what a terrible failure with a message and an exception",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Wtf,
|
make_tuple(Logger::MessageType::Wtf,
|
||||||
(const optional<string> &)"this should never happen",
|
(const optional<string> &)"this should never happen",
|
||||||
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
||||||
make_test("should log what a terrible failure with a message",
|
MakeTest("should log what a terrible failure with a message",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Wtf,
|
make_tuple(Logger::MessageType::Wtf,
|
||||||
(const optional<string> &)nullopt,
|
(const optional<string> &)nullopt,
|
||||||
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
||||||
make_test("should log an error with a message",
|
MakeTest("should log an error with a message",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Error,
|
make_tuple(Logger::MessageType::Error,
|
||||||
(const optional<string> &)"this should never happen",
|
(const optional<string> &)"this should never happen",
|
||||||
(const optional<std::exception> &)nullopt)),
|
(const optional<std::exception> &)nullopt)),
|
||||||
make_test("should log an error with a message and an exception",
|
MakeTest("should log an error with a message and an exception",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Error,
|
make_tuple(Logger::MessageType::Error,
|
||||||
(const optional<string> &)"this should never happen",
|
(const optional<string> &)"this should never happen",
|
||||||
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
||||||
make_test("should log an error with a message",
|
MakeTest("should log an error with a message",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Error,
|
make_tuple(Logger::MessageType::Error,
|
||||||
(const optional<string> &)nullopt,
|
(const optional<string> &)nullopt,
|
||||||
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
||||||
make_test("should log a warning with a message",
|
MakeTest("should log a warning with a message",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Warning,
|
make_tuple(Logger::MessageType::Warning,
|
||||||
(const optional<string> &)"this should never happen",
|
(const optional<string> &)"this should never happen",
|
||||||
(const optional<std::exception> &)nullopt)),
|
(const optional<std::exception> &)nullopt)),
|
||||||
make_test("should log a warning with a message and an exception",
|
MakeTest("should log a warning with a message and an exception",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Warning,
|
make_tuple(Logger::MessageType::Warning,
|
||||||
(const optional<string> &)"this should never happen",
|
(const optional<string> &)"this should never happen",
|
||||||
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
||||||
make_test("should log a warning with a message",
|
MakeTest("should log a warning with a message",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Warning,
|
make_tuple(Logger::MessageType::Warning,
|
||||||
(const optional<string> &)nullopt,
|
(const optional<string> &)nullopt,
|
||||||
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
||||||
make_test("should log an info with a message",
|
MakeTest("should log an info with a message",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Info,
|
make_tuple(Logger::MessageType::Info,
|
||||||
(const optional<string> &)"this should never happen",
|
(const optional<string> &)"this should never happen",
|
||||||
(const optional<std::exception> &)nullopt)),
|
(const optional<std::exception> &)nullopt)),
|
||||||
make_test("should log an info with a message and an exception",
|
MakeTest("should log an info with a message and an exception",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Info,
|
make_tuple(Logger::MessageType::Info,
|
||||||
(const optional<string> &)"this should never happen",
|
(const optional<string> &)"this should never happen",
|
||||||
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
||||||
make_test("should log an info with a message",
|
MakeTest("should log an info with a message",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Info,
|
make_tuple(Logger::MessageType::Info,
|
||||||
(const optional<string> &)nullopt,
|
(const optional<string> &)nullopt,
|
||||||
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
||||||
make_test("should log a debug with a message",
|
MakeTest("should log a debug with a message",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Debug,
|
make_tuple(Logger::MessageType::Debug,
|
||||||
(const optional<string> &)"this should never happen",
|
(const optional<string> &)"this should never happen",
|
||||||
(const optional<std::exception> &)nullopt)),
|
(const optional<std::exception> &)nullopt)),
|
||||||
make_test("should log a debug with a message and an exception",
|
MakeTest("should log a debug with a message and an exception",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Debug,
|
make_tuple(Logger::MessageType::Debug,
|
||||||
(const optional<string> &)"this should never happen",
|
(const optional<string> &)"this should never happen",
|
||||||
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
||||||
make_test("should log a debug with a message",
|
MakeTest("should log a debug with a message",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Debug,
|
make_tuple(Logger::MessageType::Debug,
|
||||||
(const optional<string> &)nullopt,
|
(const optional<string> &)nullopt,
|
||||||
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
||||||
make_test("should log a verbose with a message",
|
MakeTest("should log a verbose with a message",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Verbose,
|
make_tuple(Logger::MessageType::Verbose,
|
||||||
(const optional<string> &)"this should never happen",
|
(const optional<string> &)"this should never happen",
|
||||||
(const optional<std::exception> &)nullopt)),
|
(const optional<std::exception> &)nullopt)),
|
||||||
make_test("should log a verbose with a message and an exception",
|
MakeTest("should log a verbose with a message and an exception",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Verbose,
|
make_tuple(Logger::MessageType::Verbose,
|
||||||
(const optional<string> &)"this should never happen",
|
(const optional<string> &)"this should never happen",
|
||||||
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
(const optional<std::exception> &)runtime_error("bad thing happen"))),
|
||||||
make_test("should log a verbose with a message",
|
MakeTest("should log a verbose with a message",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Verbose,
|
make_tuple(Logger::MessageType::Verbose,
|
||||||
(const optional<string> &)nullopt,
|
(const optional<string> &)nullopt,
|
||||||
@@ -741,15 +740,15 @@ TestResults test_Logger_LogToDo() {
|
|||||||
}
|
}
|
||||||
return GetError(error_message);
|
return GetError(error_message);
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::Logger::LogToDo(const std:;string&)",
|
"CPPUtils::Logger::LogToDo(const std:;string&)",
|
||||||
log_to_do,
|
log_to_do,
|
||||||
{
|
{
|
||||||
make_test("should log a TODO for \"fill in this function\"", no_errors, make_tuple("fill in this function")),
|
MakeTest("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 \"delete this after fixing bug:2048\"",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple("delete this after fixing bug:2048")),
|
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,10 +776,10 @@ TestResults test_Logger_AddDestination_and_ClearDestinations() {
|
|||||||
}
|
}
|
||||||
return GetError(error_message);
|
return GetError(error_message);
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite("",
|
return ExecuteSuite(MakeTestSuite("",
|
||||||
add_destination,
|
add_destination,
|
||||||
{
|
{
|
||||||
make_test("should add and clear destinations", no_errors, make_tuple()),
|
MakeTest("should add and clear destinations", no_errors, make_tuple()),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -803,5 +802,5 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
PrintResults(cout, results);
|
PrintResults(cout, results);
|
||||||
|
|
||||||
return results.failed() + results.errors();
|
return results.Failed() + results.Errors();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,21 +56,50 @@ template <typename TChar> struct StringTraits;
|
|||||||
|
|
||||||
/// @brief This SFINAE struct is use to select a narrow string.
|
/// @brief This SFINAE struct is use to select a narrow string.
|
||||||
template <> struct StringTraits<char> {
|
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; }
|
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.
|
/// @brief This SFINAE struct is used to select a wide string.
|
||||||
template <> struct StringTraits<wchar_t> {
|
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; }
|
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.
|
/// @brief This SFINAE struct is used to help select container like types.
|
||||||
/// @tparam T The potential container type.
|
/// @tparam T The potential container type.
|
||||||
template <typename T> struct is_container {
|
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; }
|
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; }
|
template <typename U> static constexpr bool test(...) { return false; }
|
||||||
|
|
||||||
|
/// @brief Tests whether type T is a container.
|
||||||
static constexpr bool value = test<T>(nullptr);
|
static constexpr bool value = test<T>(nullptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -44,9 +44,9 @@ using std::make_tuple;
|
|||||||
using std::ostringstream;
|
using std::ostringstream;
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::string_view;
|
using std::string_view;
|
||||||
using TinyTest::execute_suite;
|
using TinyTest::ExecuteSuite;
|
||||||
using TinyTest::make_test;
|
using TinyTest::MakeTest;
|
||||||
using TinyTest::make_test_suite;
|
using TinyTest::MakeTestSuite;
|
||||||
using TinyTest::TestResults;
|
using TinyTest::TestResults;
|
||||||
using namespace CPPUtils;
|
using namespace CPPUtils;
|
||||||
using std::wstring;
|
using std::wstring;
|
||||||
@@ -55,16 +55,16 @@ using std::wstring;
|
|||||||
TestResults test_EscapeForPrintingWithAConstCharPointer() {
|
TestResults test_EscapeForPrintingWithAConstCharPointer() {
|
||||||
TestResults results;
|
TestResults results;
|
||||||
auto escape_const_char_pointer = [](const char *value) -> string { return EscapeForPrinting(value); };
|
auto escape_const_char_pointer = [](const char *value) -> string { return EscapeForPrinting(value); };
|
||||||
results += execute_suite(make_test_suite(
|
results += ExecuteSuite(
|
||||||
"CPPUtils::EscapeForPrinting(const char*)",
|
MakeTestSuite("CPPUtils::EscapeForPrinting(const char*)",
|
||||||
escape_const_char_pointer,
|
escape_const_char_pointer,
|
||||||
{
|
{
|
||||||
make_test("should escape an empty string", (string) "", make_tuple("")),
|
MakeTest("should escape an empty string", (string) "", make_tuple("")),
|
||||||
make_test("should esacpe a string with no special characters",
|
MakeTest("should esacpe a string with no special characters",
|
||||||
(string) "This is a normal string.",
|
(string) "This is a normal string.",
|
||||||
make_tuple("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")),
|
MakeTest("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 within a string",
|
||||||
(string) "This string has an \\033 in it.",
|
(string) "This string has an \\033 in it.",
|
||||||
make_tuple("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 test_EscapeForPrintingWithAString() {
|
||||||
TestResults results;
|
TestResults results;
|
||||||
auto escape_string = [](const string &value) -> string { return EscapeForPrinting(value); };
|
auto escape_string = [](const string &value) -> string { return EscapeForPrinting(value); };
|
||||||
results += execute_suite(make_test_suite(
|
results += ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::EscapeForPrinting(const std::string&)",
|
"CPPUtils::EscapeForPrinting(const std::string&)",
|
||||||
escape_string,
|
escape_string,
|
||||||
{
|
{
|
||||||
make_test("should escape an empty string", (string) "", make_tuple((string) "")),
|
MakeTest("should escape an empty string", (string) "", make_tuple((string) "")),
|
||||||
make_test("should escape a string with no special characters",
|
MakeTest("should escape a string with no special characters",
|
||||||
(string) "This is a normal string.",
|
(string) "This is a normal string.",
|
||||||
make_tuple((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")),
|
MakeTest("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 within a string",
|
||||||
(string) "This string has an \\033 in it.",
|
(string) "This string has an \\033 in it.",
|
||||||
make_tuple((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() {
|
TestResults test_EscapeForPrintingWithAStringView() {
|
||||||
auto escape_string_view = [](const string_view &value) -> string { return EscapeForPrinting(value); };
|
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&)",
|
"CPPUtils::EscapeForPrinting(const std::string_view&)",
|
||||||
escape_string_view,
|
escape_string_view,
|
||||||
{
|
{
|
||||||
make_test("should escape an empty string", (string) "", make_tuple((string_view) "")),
|
MakeTest("should escape an empty string", (string) "", make_tuple((string_view) "")),
|
||||||
make_test("should escape a string with no special characters",
|
MakeTest("should escape a string with no special characters",
|
||||||
(string) "This is a normal string.",
|
(string) "This is a normal string.",
|
||||||
make_tuple((string_view) "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")),
|
MakeTest("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 within a string",
|
||||||
(string) "This string has an \\033 in it.",
|
(string) "This string has an \\033 in it.",
|
||||||
make_tuple((string_view) "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);
|
PrettyPrint(os, value);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(
|
||||||
"CPPUtils::PrettyPrint(std::ostream&, const char*)",
|
MakeTestSuite("CPPUtils::PrettyPrint(std::ostream&, const char*)",
|
||||||
pretty_print,
|
pretty_print,
|
||||||
{
|
{
|
||||||
make_test("should print \"\" for an empty string", (string) "\"\"", make_tuple("")),
|
MakeTest("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 \"hello world\"", (string) "\"hello world\"", make_tuple("hello world")),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,12 +128,12 @@ TestResults test_PrettyPrintWithAString() {
|
|||||||
PrettyPrint(os, value);
|
PrettyPrint(os, value);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::PrettyPrint(std::ostream&, const std::string&)",
|
"CPPUtils::PrettyPrint(std::ostream&, const std::string&)",
|
||||||
pretty_print,
|
pretty_print,
|
||||||
{
|
{
|
||||||
make_test("should print \"\" for an empty string", (string) "\"\"", make_tuple((string) "")),
|
MakeTest("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 \"hello world\"", (string) "\"hello world\"", make_tuple((string) "hello world")),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,13 +143,12 @@ TestResults test_PrettyPrintWithAStringView() {
|
|||||||
PrettyPrint(os, value);
|
PrettyPrint(os, value);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::PrettyPrint(std::ostream&, const std::string_view&)",
|
"CPPUtils::PrettyPrint(std::ostream&, const std::string_view&)",
|
||||||
pretty_print,
|
pretty_print,
|
||||||
{
|
{
|
||||||
make_test("should print \"\" for an empty string", (string) "\"\"", make_tuple((string_view) "")),
|
MakeTest("should print \"\" for an empty string", (string) "\"\"", make_tuple((string_view) "")),
|
||||||
make_test(
|
MakeTest("should print \"hello world\"", (string) "\"hello world\"", make_tuple((string_view) "hello world")),
|
||||||
"should print \"hello world\"", (string) "\"hello world\"", make_tuple((string_view) "hello world")),
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,13 +168,13 @@ TestResults test_PrettyPrintWithATuple() {
|
|||||||
}
|
}
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::PrettyPrint(std::ostream&, std::tuple)",
|
"CPPUtils::PrettyPrint(std::ostream&, std::tuple)",
|
||||||
pretty_print,
|
pretty_print,
|
||||||
{
|
{
|
||||||
make_test("should print a tuple of mixed types", (string) "[ 1, \"hello\", 9 ]", make_tuple(1)),
|
MakeTest("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)),
|
MakeTest("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 strings", (string) "[ \"one\", \"two\", \"three\" ]", make_tuple(3)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,18 +202,18 @@ TestResults test_PrettyPrintWithAnInitializerList() {
|
|||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
|
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::PrettyPrint(std::ostream&, std::initializer_list)",
|
"CPPUtils::PrettyPrint(std::ostream&, std::initializer_list)",
|
||||||
pretty_print,
|
pretty_print,
|
||||||
{
|
{
|
||||||
make_test(
|
MakeTest(
|
||||||
"should print an initializer_list of strings", (string) "[ \"one\", \"two\", \"three\" ]", make_tuple(1)),
|
"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)),
|
MakeTest("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)),
|
MakeTest("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 initializer_list of strings with four elements",
|
||||||
(string) "[ \"one\", \"two\", \"three\", \"four\" ]",
|
(string) "[ \"one\", \"two\", \"three\", \"four\" ]",
|
||||||
make_tuple(4)),
|
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 os.str();
|
||||||
};
|
};
|
||||||
|
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::PrettyPrint(std::ostream&, TContainer)",
|
"CPPUtils::PrettyPrint(std::ostream&, TContainer)",
|
||||||
pretty_print,
|
pretty_print,
|
||||||
{
|
{
|
||||||
make_test("should print a vector of integers", (string) "[ 1, 2, 3 ]", make_tuple(1)),
|
MakeTest("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)),
|
MakeTest("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)),
|
MakeTest("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 queue of strings", (string) "[ \"one\", \"two\", \"three\" ]", make_tuple(4)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,10 +270,10 @@ TestResults test_PrettyPrintWithSimpleTypes() {
|
|||||||
PrettyPrint(os, value);
|
PrettyPrint(os, value);
|
||||||
return os.str();
|
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,
|
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 {
|
auto pretty_print_float = [](float value) -> string {
|
||||||
@@ -283,10 +282,10 @@ TestResults test_PrettyPrintWithSimpleTypes() {
|
|||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
results +=
|
results +=
|
||||||
execute_suite(make_test_suite("CPPUtils::PrettyPrint(std::ostream&, const TItem&)",
|
ExecuteSuite(MakeTestSuite("CPPUtils::PrettyPrint(std::ostream&, const TItem&)",
|
||||||
pretty_print_float,
|
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 {
|
auto pretty_print_string = [](const string &value) -> string {
|
||||||
@@ -294,10 +293,10 @@ TestResults test_PrettyPrintWithSimpleTypes() {
|
|||||||
PrettyPrint(os, value);
|
PrettyPrint(os, value);
|
||||||
return os.str();
|
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,
|
pretty_print_string,
|
||||||
{
|
{
|
||||||
make_test("should print \"hello world\" for a string",
|
MakeTest("should print \"hello world\" for a string",
|
||||||
(string) "\"hello world\"",
|
(string) "\"hello world\"",
|
||||||
make_tuple((string) "hello world")),
|
make_tuple((string) "hello world")),
|
||||||
}));
|
}));
|
||||||
@@ -320,13 +319,13 @@ TestResults test_PrettyPrintWithAPair() {
|
|||||||
}
|
}
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::PrettyPrint(std::ostream&, const std::pair<T1, T2>&)",
|
"CPPUtils::PrettyPrint(std::ostream&, const std::pair<T1, T2>&)",
|
||||||
pretty_print,
|
pretty_print,
|
||||||
{
|
{
|
||||||
make_test("should print (1, 2) for a pair of ints", (string) "(1, 2)", make_tuple(1)),
|
MakeTest("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)),
|
MakeTest("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 (\"hello\", \"world\") for a pair of strings",
|
||||||
(string) "(\"hello\", \"world\")",
|
(string) "(\"hello\", \"world\")",
|
||||||
make_tuple(3)),
|
make_tuple(3)),
|
||||||
}));
|
}));
|
||||||
@@ -348,15 +347,15 @@ TestResults test_PrettyPrintWithSeparatorWithAConstCharPointer() {
|
|||||||
}
|
}
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(
|
return ExecuteSuite(
|
||||||
make_test_suite("CPPUtils::PrettyPrintWithSeparator(std::ostream&, const TChar*, Args&&...)",
|
MakeTestSuite("CPPUtils::PrettyPrintWithSeparator(std::ostream&, const TChar*, Args&&...)",
|
||||||
pretty_print,
|
pretty_print,
|
||||||
{
|
{
|
||||||
make_test("should print 1, 2, 3 for a list of ints", (string) "1, 2, 3", make_tuple(", ", 1)),
|
MakeTest("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 3.14; 42; \"hello world\" for a list of float, int and string",
|
||||||
(string) "3.14; 42; \"hello world\"",
|
(string) "3.14; 42; \"hello world\"",
|
||||||
make_tuple("; ", 2)),
|
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\"",
|
(string) "\"hello\" \"world\"",
|
||||||
make_tuple(" ", 3)),
|
make_tuple(" ", 3)),
|
||||||
}));
|
}));
|
||||||
@@ -378,15 +377,15 @@ TestResults test_PrettyPrintWithSeparatorWithAString() {
|
|||||||
}
|
}
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::PrettyPrintWithSeparator(std::ostream&, const TChar*, Args&&...)",
|
"CPPUtils::PrettyPrintWithSeparator(std::ostream&, const TChar*, Args&&...)",
|
||||||
pretty_print,
|
pretty_print,
|
||||||
{
|
{
|
||||||
make_test("should print 1 | 2 | 3 for a list of ints", (string) "1 | 2 | 3", make_tuple((string) " | ", 1)),
|
MakeTest("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 3.14 / 42 / \"hello world\" for a list of float, int and string",
|
||||||
(string) "3.14 / 42 / \"hello world\"",
|
(string) "3.14 / 42 / \"hello world\"",
|
||||||
make_tuple((string) " / ", 2)),
|
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\"",
|
(string) "\"hello\" - \"world\"",
|
||||||
make_tuple((string) " - ", 3)),
|
make_tuple((string) " - ", 3)),
|
||||||
}));
|
}));
|
||||||
@@ -408,16 +407,16 @@ TestResults test_PrettyPrintWithSeparatorWithAStringView() {
|
|||||||
}
|
}
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::PrettyPrintWithSeparator(std::ostream&, const TChar*, Args&&...)",
|
"CPPUtils::PrettyPrintWithSeparator(std::ostream&, const TChar*, Args&&...)",
|
||||||
pretty_print,
|
pretty_print,
|
||||||
{
|
{
|
||||||
make_test(
|
MakeTest(
|
||||||
"should print 1 | 2 | 3 for a list of ints", (string) "1 | 2 | 3", make_tuple((string_view) " | ", 1)),
|
"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\"",
|
(string) "3.14 / 42 / \"hello world\"",
|
||||||
make_tuple((string_view) " / ", 2)),
|
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\"",
|
(string) "\"hello\" - \"world\"",
|
||||||
make_tuple((string_view) " - ", 3)),
|
make_tuple((string_view) " - ", 3)),
|
||||||
}));
|
}));
|
||||||
@@ -444,5 +443,5 @@ int main(int argc, char *argv[]) {
|
|||||||
results += test_PrettyPrintWithSeparatorWithAString();
|
results += test_PrettyPrintWithSeparatorWithAString();
|
||||||
results += test_PrettyPrintWithSeparatorWithAStringView();
|
results += test_PrettyPrintWithSeparatorWithAStringView();
|
||||||
|
|
||||||
return results.failed() + results.errors();
|
return results.Failed() + results.Errors();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,9 +53,9 @@ using std::shared_ptr;
|
|||||||
using std::string;
|
using std::string;
|
||||||
using std::tuple;
|
using std::tuple;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
using TinyTest::execute_suite;
|
using TinyTest::ExecuteSuite;
|
||||||
using TinyTest::make_test;
|
using TinyTest::MakeTest;
|
||||||
using TinyTest::make_test_suite;
|
using TinyTest::MakeTestSuite;
|
||||||
using TinyTest::TestResults;
|
using TinyTest::TestResults;
|
||||||
string no_errors = "no errors";
|
string no_errors = "no errors";
|
||||||
typedef tuple<string, string, UINT> MessageBoxEvent;
|
typedef tuple<string, string, UINT> MessageBoxEvent;
|
||||||
@@ -302,51 +302,51 @@ TestResults test_WindowsLogger_LogMessage() {
|
|||||||
}
|
}
|
||||||
return GetErrors(errors);
|
return GetErrors(errors);
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::WindowsLogger::LogMessage(cosnt std::string&)",
|
"CPPUtils::WindowsLogger::LogMessage(cosnt std::string&)",
|
||||||
log_message,
|
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,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Debug,
|
make_tuple(Logger::MessageType::Debug,
|
||||||
"this is a message",
|
"this is a message",
|
||||||
"this is a message",
|
"this is a message",
|
||||||
"Debug",
|
"Debug",
|
||||||
MB_OK | MB_ICONEXCLAMATION)),
|
MB_OK | MB_ICONEXCLAMATION)),
|
||||||
make_test(
|
MakeTest(
|
||||||
"should log \"this is an error\" with title \"ERROR\"",
|
"should log \"this is an error\" with title \"ERROR\"",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(
|
make_tuple(
|
||||||
Logger::MessageType::Error, "this is an error", "this is an error", "ERROR", MB_OK | MB_ICONHAND)),
|
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,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Wtf,
|
make_tuple(Logger::MessageType::Wtf,
|
||||||
"what a terrible failure",
|
"what a terrible failure",
|
||||||
"what a terrible failure",
|
"what a terrible failure",
|
||||||
"How did you let this happen?",
|
"How did you let this happen?",
|
||||||
MB_OK | MB_ICONHAND)),
|
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,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Info,
|
make_tuple(Logger::MessageType::Info,
|
||||||
"this is some information",
|
"this is some information",
|
||||||
"this is some information",
|
"this is some information",
|
||||||
"Information",
|
"Information",
|
||||||
MB_OK | MB_ICONASTERISK)),
|
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,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Warning,
|
make_tuple(Logger::MessageType::Warning,
|
||||||
"this is a warning",
|
"this is a warning",
|
||||||
"this is a warning",
|
"this is a warning",
|
||||||
"Warning",
|
"Warning",
|
||||||
MB_OK | MB_ICONEXCLAMATION)),
|
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,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Verbose,
|
make_tuple(Logger::MessageType::Verbose,
|
||||||
"this is verbose",
|
"this is verbose",
|
||||||
"this is verbose",
|
"this is verbose",
|
||||||
"Verbose",
|
"Verbose",
|
||||||
MB_OK | MB_ICONASTERISK)),
|
MB_OK | MB_ICONASTERISK)),
|
||||||
make_test("should log \"unclassified message\" with title \"Unclassified\"",
|
MakeTest("should log \"unclassified message\" with title \"Unclassified\"",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple((Logger::MessageType)1000,
|
make_tuple((Logger::MessageType)1000,
|
||||||
"unclassified message",
|
"unclassified message",
|
||||||
@@ -374,53 +374,53 @@ TestResults test_WindowsLogger_LogErrorWithMessage() {
|
|||||||
}
|
}
|
||||||
return GetErrors(errors);
|
return GetErrors(errors);
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::WindowsLogger::LogError(const std::exception&)",
|
"CPPUtils::WindowsLogger::LogError(const std::exception&)",
|
||||||
log_error,
|
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,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Debug,
|
make_tuple(Logger::MessageType::Debug,
|
||||||
std::runtime_error("this is an exception"),
|
std::runtime_error("this is an exception"),
|
||||||
"Exception: this is an exception",
|
"Exception: this is an exception",
|
||||||
"Debug",
|
"Debug",
|
||||||
MB_OK | MB_ICONEXCLAMATION)),
|
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,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Error,
|
make_tuple(Logger::MessageType::Error,
|
||||||
std::runtime_error("this is an error"),
|
std::runtime_error("this is an error"),
|
||||||
"Exception: this is an error",
|
"Exception: this is an error",
|
||||||
"ERROR",
|
"ERROR",
|
||||||
MB_OK | MB_ICONHAND)),
|
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,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Wtf,
|
make_tuple(Logger::MessageType::Wtf,
|
||||||
std::runtime_error("what a terrible failure"),
|
std::runtime_error("what a terrible failure"),
|
||||||
"Exception: what a terrible failure",
|
"Exception: what a terrible failure",
|
||||||
"How did you let this happen?",
|
"How did you let this happen?",
|
||||||
MB_OK | MB_ICONHAND)),
|
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,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Info,
|
make_tuple(Logger::MessageType::Info,
|
||||||
std::runtime_error("this is some information"),
|
std::runtime_error("this is some information"),
|
||||||
"Exception: this is some information",
|
"Exception: this is some information",
|
||||||
"Information",
|
"Information",
|
||||||
MB_OK | MB_ICONASTERISK)),
|
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,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Warning,
|
make_tuple(Logger::MessageType::Warning,
|
||||||
std::runtime_error("this is a warning"),
|
std::runtime_error("this is a warning"),
|
||||||
"Exception: this is a warning",
|
"Exception: this is a warning",
|
||||||
"Warning",
|
"Warning",
|
||||||
MB_OK | MB_ICONEXCLAMATION)),
|
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,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Verbose,
|
make_tuple(Logger::MessageType::Verbose,
|
||||||
std::runtime_error("this is verbose"),
|
std::runtime_error("this is verbose"),
|
||||||
"Exception: this is verbose",
|
"Exception: this is verbose",
|
||||||
"Verbose",
|
"Verbose",
|
||||||
MB_OK | MB_ICONASTERISK)),
|
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,
|
no_errors,
|
||||||
make_tuple((Logger::MessageType)1000,
|
make_tuple((Logger::MessageType)1000,
|
||||||
std::runtime_error("unclassified message"),
|
std::runtime_error("unclassified message"),
|
||||||
@@ -449,11 +449,11 @@ TestResults test_WindowsLogger_LogErrorWithoutMessage() {
|
|||||||
}
|
}
|
||||||
return GetErrors(errors);
|
return GetErrors(errors);
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::WindowsLogger::LogError(const std::string&, const std::exception&)",
|
"CPPUtils::WindowsLogger::LogError(const std::string&, const std::exception&)",
|
||||||
log_error,
|
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,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Debug,
|
make_tuple(Logger::MessageType::Debug,
|
||||||
"this is a message",
|
"this is a message",
|
||||||
@@ -461,7 +461,7 @@ TestResults test_WindowsLogger_LogErrorWithoutMessage() {
|
|||||||
"Exception: this is an exception",
|
"Exception: this is an exception",
|
||||||
"Debug",
|
"Debug",
|
||||||
MB_OK | MB_ICONEXCLAMATION)),
|
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,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Error,
|
make_tuple(Logger::MessageType::Error,
|
||||||
"this is an error",
|
"this is an error",
|
||||||
@@ -469,7 +469,7 @@ TestResults test_WindowsLogger_LogErrorWithoutMessage() {
|
|||||||
"Exception: this is an exception",
|
"Exception: this is an exception",
|
||||||
"ERROR",
|
"ERROR",
|
||||||
MB_OK | MB_ICONHAND)),
|
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,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Wtf,
|
make_tuple(Logger::MessageType::Wtf,
|
||||||
"what a terrible failure",
|
"what a terrible failure",
|
||||||
@@ -477,7 +477,7 @@ TestResults test_WindowsLogger_LogErrorWithoutMessage() {
|
|||||||
"Exception: this is an exception",
|
"Exception: this is an exception",
|
||||||
"How did you let this happen?",
|
"How did you let this happen?",
|
||||||
MB_OK | MB_ICONHAND)),
|
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,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Info,
|
make_tuple(Logger::MessageType::Info,
|
||||||
"this is some information",
|
"this is some information",
|
||||||
@@ -485,7 +485,7 @@ TestResults test_WindowsLogger_LogErrorWithoutMessage() {
|
|||||||
"Exception: this is an exception",
|
"Exception: this is an exception",
|
||||||
"Information",
|
"Information",
|
||||||
MB_OK | MB_ICONASTERISK)),
|
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\"",
|
"\"Warning\"",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Warning,
|
make_tuple(Logger::MessageType::Warning,
|
||||||
@@ -494,7 +494,7 @@ TestResults test_WindowsLogger_LogErrorWithoutMessage() {
|
|||||||
"Exception: this is an exception",
|
"Exception: this is an exception",
|
||||||
"Warning",
|
"Warning",
|
||||||
MB_OK | MB_ICONEXCLAMATION)),
|
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,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Verbose,
|
make_tuple(Logger::MessageType::Verbose,
|
||||||
"this is verbose",
|
"this is verbose",
|
||||||
@@ -502,7 +502,7 @@ TestResults test_WindowsLogger_LogErrorWithoutMessage() {
|
|||||||
"Exception: this is an exception",
|
"Exception: this is an exception",
|
||||||
"Verbose",
|
"Verbose",
|
||||||
MB_OK | MB_ICONASTERISK)),
|
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,
|
no_errors,
|
||||||
make_tuple((Logger::MessageType)1000,
|
make_tuple((Logger::MessageType)1000,
|
||||||
"unclassified message",
|
"unclassified message",
|
||||||
@@ -522,6 +522,6 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
PrintResults(cout, results);
|
PrintResults(cout, results);
|
||||||
|
|
||||||
return results.failed() + results.errors();
|
return results.Failed() + results.Errors();
|
||||||
}
|
}
|
||||||
#endif // End defined(_WIN32)
|
#endif // End defined(_WIN32)
|
||||||
|
|||||||
Reference in New Issue
Block a user