Updates tests to work with the latest TinyTest.

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

View File

@@ -53,9 +53,9 @@ using std::shared_ptr;
using std::string;
using std::tuple;
using std::vector;
using TinyTest::execute_suite;
using TinyTest::make_test;
using TinyTest::make_test_suite;
using TinyTest::ExecuteSuite;
using TinyTest::MakeTest;
using TinyTest::MakeTestSuite;
using TinyTest::TestResults;
string no_errors = "no errors";
typedef tuple<string, string, UINT> MessageBoxEvent;
@@ -302,57 +302,57 @@ TestResults test_WindowsLogger_LogMessage() {
}
return GetErrors(errors);
};
return execute_suite(make_test_suite(
return ExecuteSuite(MakeTestSuite(
"CPPUtils::WindowsLogger::LogMessage(cosnt std::string&)",
log_message,
{
make_test("should log \"this is a message\" with title \"Debug\"",
no_errors,
make_tuple(Logger::MessageType::Debug,
"this is a message",
"this is a message",
"Debug",
MB_OK | MB_ICONEXCLAMATION)),
make_test(
MakeTest("should log \"this is a message\" with title \"Debug\"",
no_errors,
make_tuple(Logger::MessageType::Debug,
"this is a message",
"this is a message",
"Debug",
MB_OK | MB_ICONEXCLAMATION)),
MakeTest(
"should log \"this is an error\" with title \"ERROR\"",
no_errors,
make_tuple(
Logger::MessageType::Error, "this is an error", "this is an error", "ERROR", MB_OK | MB_ICONHAND)),
make_test("should log \"what a terrible failure\" with title \"How did you let this happen?\"",
no_errors,
make_tuple(Logger::MessageType::Wtf,
"what a terrible failure",
"what a terrible failure",
"How did you let this happen?",
MB_OK | MB_ICONHAND)),
make_test("should log \"this is some information\" with title \"Information\"",
no_errors,
make_tuple(Logger::MessageType::Info,
"this is some information",
"this is some information",
"Information",
MB_OK | MB_ICONASTERISK)),
make_test("should log \"this is a warning\" with title \"Warning\"",
no_errors,
make_tuple(Logger::MessageType::Warning,
"this is a warning",
"this is a warning",
"Warning",
MB_OK | MB_ICONEXCLAMATION)),
make_test("should log \"this is verbose\" with title \"Verbose\"",
no_errors,
make_tuple(Logger::MessageType::Verbose,
"this is verbose",
"this is verbose",
"Verbose",
MB_OK | MB_ICONASTERISK)),
make_test("should log \"unclassified message\" with title \"Unclassified\"",
no_errors,
make_tuple((Logger::MessageType)1000,
"unclassified message",
"unclassified message",
"Unclassified",
MB_OK | MB_ICONASTERISK)),
MakeTest("should log \"what a terrible failure\" with title \"How did you let this happen?\"",
no_errors,
make_tuple(Logger::MessageType::Wtf,
"what a terrible failure",
"what a terrible failure",
"How did you let this happen?",
MB_OK | MB_ICONHAND)),
MakeTest("should log \"this is some information\" with title \"Information\"",
no_errors,
make_tuple(Logger::MessageType::Info,
"this is some information",
"this is some information",
"Information",
MB_OK | MB_ICONASTERISK)),
MakeTest("should log \"this is a warning\" with title \"Warning\"",
no_errors,
make_tuple(Logger::MessageType::Warning,
"this is a warning",
"this is a warning",
"Warning",
MB_OK | MB_ICONEXCLAMATION)),
MakeTest("should log \"this is verbose\" with title \"Verbose\"",
no_errors,
make_tuple(Logger::MessageType::Verbose,
"this is verbose",
"this is verbose",
"Verbose",
MB_OK | MB_ICONASTERISK)),
MakeTest("should log \"unclassified message\" with title \"Unclassified\"",
no_errors,
make_tuple((Logger::MessageType)1000,
"unclassified message",
"unclassified message",
"Unclassified",
MB_OK | MB_ICONASTERISK)),
}));
}
@@ -374,59 +374,59 @@ TestResults test_WindowsLogger_LogErrorWithMessage() {
}
return GetErrors(errors);
};
return execute_suite(make_test_suite(
return ExecuteSuite(MakeTestSuite(
"CPPUtils::WindowsLogger::LogError(const std::exception&)",
log_error,
{
make_test("should log \"Exception: this is an exception\" with title \"Debug\"",
no_errors,
make_tuple(Logger::MessageType::Debug,
std::runtime_error("this is an exception"),
"Exception: this is an exception",
"Debug",
MB_OK | MB_ICONEXCLAMATION)),
make_test("should log \"Exception: this is an error\" with title \"ERROR\"",
no_errors,
make_tuple(Logger::MessageType::Error,
std::runtime_error("this is an error"),
"Exception: this is an error",
"ERROR",
MB_OK | MB_ICONHAND)),
make_test("should log \"Exception: what a terrible failure\" with title \"How did you let this happen?\"",
no_errors,
make_tuple(Logger::MessageType::Wtf,
std::runtime_error("what a terrible failure"),
"Exception: what a terrible failure",
"How did you let this happen?",
MB_OK | MB_ICONHAND)),
make_test("should log \"Exception: this is some information\" with title \"Information\"",
no_errors,
make_tuple(Logger::MessageType::Info,
std::runtime_error("this is some information"),
"Exception: this is some information",
"Information",
MB_OK | MB_ICONASTERISK)),
make_test("should log \"Exception: this is a warning\" with title \"Warning\"",
no_errors,
make_tuple(Logger::MessageType::Warning,
std::runtime_error("this is a warning"),
"Exception: this is a warning",
"Warning",
MB_OK | MB_ICONEXCLAMATION)),
make_test("should log \"Exception: this is verbose\" with title \"Verbose\"",
no_errors,
make_tuple(Logger::MessageType::Verbose,
std::runtime_error("this is verbose"),
"Exception: this is verbose",
"Verbose",
MB_OK | MB_ICONASTERISK)),
make_test("should log \"Exception: unclassified message\" with title \"Unclassified\"",
no_errors,
make_tuple((Logger::MessageType)1000,
std::runtime_error("unclassified message"),
"Exception: unclassified message",
"Unclassified",
MB_OK | MB_ICONASTERISK)),
MakeTest("should log \"Exception: this is an exception\" with title \"Debug\"",
no_errors,
make_tuple(Logger::MessageType::Debug,
std::runtime_error("this is an exception"),
"Exception: this is an exception",
"Debug",
MB_OK | MB_ICONEXCLAMATION)),
MakeTest("should log \"Exception: this is an error\" with title \"ERROR\"",
no_errors,
make_tuple(Logger::MessageType::Error,
std::runtime_error("this is an error"),
"Exception: this is an error",
"ERROR",
MB_OK | MB_ICONHAND)),
MakeTest("should log \"Exception: what a terrible failure\" with title \"How did you let this happen?\"",
no_errors,
make_tuple(Logger::MessageType::Wtf,
std::runtime_error("what a terrible failure"),
"Exception: what a terrible failure",
"How did you let this happen?",
MB_OK | MB_ICONHAND)),
MakeTest("should log \"Exception: this is some information\" with title \"Information\"",
no_errors,
make_tuple(Logger::MessageType::Info,
std::runtime_error("this is some information"),
"Exception: this is some information",
"Information",
MB_OK | MB_ICONASTERISK)),
MakeTest("should log \"Exception: this is a warning\" with title \"Warning\"",
no_errors,
make_tuple(Logger::MessageType::Warning,
std::runtime_error("this is a warning"),
"Exception: this is a warning",
"Warning",
MB_OK | MB_ICONEXCLAMATION)),
MakeTest("should log \"Exception: this is verbose\" with title \"Verbose\"",
no_errors,
make_tuple(Logger::MessageType::Verbose,
std::runtime_error("this is verbose"),
"Exception: this is verbose",
"Verbose",
MB_OK | MB_ICONASTERISK)),
MakeTest("should log \"Exception: unclassified message\" with title \"Unclassified\"",
no_errors,
make_tuple((Logger::MessageType)1000,
std::runtime_error("unclassified message"),
"Exception: unclassified message",
"Unclassified",
MB_OK | MB_ICONASTERISK)),
}));
}
@@ -449,67 +449,67 @@ TestResults test_WindowsLogger_LogErrorWithoutMessage() {
}
return GetErrors(errors);
};
return execute_suite(make_test_suite(
return ExecuteSuite(MakeTestSuite(
"CPPUtils::WindowsLogger::LogError(const std::string&, const std::exception&)",
log_error,
{
make_test("should log \"Exception: this is an exception\" with title \"Debug\"",
no_errors,
make_tuple(Logger::MessageType::Debug,
"this is a message",
std::runtime_error("this is an exception"),
"Exception: this is an exception",
"Debug",
MB_OK | MB_ICONEXCLAMATION)),
make_test("should log \"Exception: this is an exception\" with title \"ERROR\"",
no_errors,
make_tuple(Logger::MessageType::Error,
"this is an error",
std::runtime_error("this is an exception"),
"Exception: this is an exception",
"ERROR",
MB_OK | MB_ICONHAND)),
make_test("should log \"Exception: this is an exception\" with title \"How did you let this happen?\"",
no_errors,
make_tuple(Logger::MessageType::Wtf,
"what a terrible failure",
std::runtime_error("this is an exception"),
"Exception: this is an exception",
"How did you let this happen?",
MB_OK | MB_ICONHAND)),
make_test("should log \"Exception this is an exception\" with title \"Information\"",
no_errors,
make_tuple(Logger::MessageType::Info,
"this is some information",
std::runtime_error("this is an exception"),
"Exception: this is an exception",
"Information",
MB_OK | MB_ICONASTERISK)),
make_test("should log \"Exception: this is a warning with caught exception this is an exception\" with title "
"\"Warning\"",
no_errors,
make_tuple(Logger::MessageType::Warning,
"this is a warning",
std::runtime_error("this is an exception"),
"Exception: this is an exception",
"Warning",
MB_OK | MB_ICONEXCLAMATION)),
make_test("should log \"Exception: this is an exception\" with title \"Verbose\"",
no_errors,
make_tuple(Logger::MessageType::Verbose,
"this is verbose",
std::runtime_error("this is an exception"),
"Exception: this is an exception",
"Verbose",
MB_OK | MB_ICONASTERISK)),
make_test("should log \"Exception: this is an exception\" with title \"Unclassified\"",
no_errors,
make_tuple((Logger::MessageType)1000,
"unclassified message",
std::runtime_error("this is an exception"),
"Exception: this is an exception",
"Unclassified",
MB_OK | MB_ICONASTERISK)),
MakeTest("should log \"Exception: this is an exception\" with title \"Debug\"",
no_errors,
make_tuple(Logger::MessageType::Debug,
"this is a message",
std::runtime_error("this is an exception"),
"Exception: this is an exception",
"Debug",
MB_OK | MB_ICONEXCLAMATION)),
MakeTest("should log \"Exception: this is an exception\" with title \"ERROR\"",
no_errors,
make_tuple(Logger::MessageType::Error,
"this is an error",
std::runtime_error("this is an exception"),
"Exception: this is an exception",
"ERROR",
MB_OK | MB_ICONHAND)),
MakeTest("should log \"Exception: this is an exception\" with title \"How did you let this happen?\"",
no_errors,
make_tuple(Logger::MessageType::Wtf,
"what a terrible failure",
std::runtime_error("this is an exception"),
"Exception: this is an exception",
"How did you let this happen?",
MB_OK | MB_ICONHAND)),
MakeTest("should log \"Exception this is an exception\" with title \"Information\"",
no_errors,
make_tuple(Logger::MessageType::Info,
"this is some information",
std::runtime_error("this is an exception"),
"Exception: this is an exception",
"Information",
MB_OK | MB_ICONASTERISK)),
MakeTest("should log \"Exception: this is a warning with caught exception this is an exception\" with title "
"\"Warning\"",
no_errors,
make_tuple(Logger::MessageType::Warning,
"this is a warning",
std::runtime_error("this is an exception"),
"Exception: this is an exception",
"Warning",
MB_OK | MB_ICONEXCLAMATION)),
MakeTest("should log \"Exception: this is an exception\" with title \"Verbose\"",
no_errors,
make_tuple(Logger::MessageType::Verbose,
"this is verbose",
std::runtime_error("this is an exception"),
"Exception: this is an exception",
"Verbose",
MB_OK | MB_ICONASTERISK)),
MakeTest("should log \"Exception: this is an exception\" with title \"Unclassified\"",
no_errors,
make_tuple((Logger::MessageType)1000,
"unclassified message",
std::runtime_error("this is an exception"),
"Exception: this is an exception",
"Unclassified",
MB_OK | MB_ICONASTERISK)),
}));
}
@@ -522,6 +522,6 @@ int main(int argc, char *argv[]) {
PrintResults(cout, results);
return results.failed() + results.errors();
return results.Failed() + results.Errors();
}
#endif // End defined(_WIN32)