stuff-from-scratch/test/test_utils/TestCaseRunner.cpp
2023-12-20 16:58:22 +00:00

89 lines
1.8 KiB
C++

#include "TestCaseRunner.h"
#include "FileLogger.h"
#include "Logger.h"
//#include "TestUiApplication.h"
bool TestCaseRunner::sLastTestFailed = false;
String TestCaseRunner::sFailureLine = {};
TestCaseRunner::TestCaseRunner()
{
}
TestCaseRunner::~TestCaseRunner()
{
}
/*
TestUiApplication* TestCaseRunner::getTestApplication()
{
return mTestApplication;
}
void TestCaseRunner::setTestApplication(TestUiApplication* app)
{
mTestApplication = app;
}
*/
TestCaseRunner& TestCaseRunner::getInstance()
{
static TestCaseRunner instance;
return instance;
}
void TestCaseRunner::addTestCase(const String& label, const String& tag, TestCase::TestCaseFunction func)
{
auto test_case = new TestCase(label, tag, func);
mCases.push_back(test_case);
}
void TestCaseRunner::markTestFailure(const String& line)
{
sLastTestFailed = true;
sFailureLine = line;
}
bool TestCaseRunner::run(const Vector<String>& args)
{
String test_to_run;
if (args.size() > 0 )
{
test_to_run = args[0];
}
//FileLogger::GetInstance().disable();
for (auto test_case : mCases)
{
if (!test_to_run.empty())
{
if (test_case->getName() != test_to_run)
{
continue;
}
}
sLastTestFailed = false;
LOG_INFO("TestFramework: Running Test - " << test_case->getName());
test_case->run();
if (sLastTestFailed)
{
LOG_INFO("Failed at line: " << sFailureLine);
mFailingTests.push_back(test_case->getName());
}
}
if (mFailingTests.size() > 0)
{
LOG_INFO(String::fmt("%d failing tests", mFailingTests.size()));
for(const auto& name : mFailingTests)
{
LOG_INFO(name);
}
}
return true;
}