Clean up some test files.
This commit is contained in:
parent
1adc9272f8
commit
b45385e8c7
51 changed files with 485 additions and 281 deletions
9
test/test_utils/CMakeLists.txt
Normal file
9
test/test_utils/CMakeLists.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
add_library(test_utils SHARED
|
||||
TestCase.h
|
||||
TestCaseRunner.cpp
|
||||
)
|
||||
|
||||
target_include_directories(test_utils PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
target_link_libraries(test_utils core)
|
|
@ -1,14 +1,27 @@
|
|||
#include "TestCaseRunner.h"
|
||||
|
||||
#include "FileLogger.h"
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
bool TestCaseRunner::sLastTestFailed = false;
|
||||
std::string TestCaseRunner::sFailureLine = {};
|
||||
|
||||
TestCaseRunner::TestCaseRunner()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TestCaseRunner::~TestCaseRunner()
|
||||
{
|
||||
for (auto testCase : mCases)
|
||||
{
|
||||
//delete testCase;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TestCaseRunner& TestCaseRunner::getInstance()
|
||||
{
|
||||
static TestCaseRunner instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void TestCaseRunner::addTestCase(const std::string& label, const std::string& tag, TestCase::TestCaseFunction func)
|
||||
|
@ -17,28 +30,35 @@ void TestCaseRunner::addTestCase(const std::string& label, const std::string& ta
|
|||
mCases.push_back(test_case);
|
||||
}
|
||||
|
||||
void TestCaseRunner::markTestFailure(const std::string& line)
|
||||
{
|
||||
sLastTestFailed = true;
|
||||
sFailureLine = line;
|
||||
}
|
||||
|
||||
bool TestCaseRunner::run()
|
||||
{
|
||||
FileLogger::GetInstance().disable();
|
||||
for (auto test_case : mCases)
|
||||
{
|
||||
sLastTestFailed = false;
|
||||
std::cout << "TestFramework: Running Test - " << test_case->getName() << std::endl;
|
||||
test_case->run();
|
||||
}
|
||||
|
||||
bool testsPassed = true;
|
||||
/*
|
||||
for(const auto& test : mCases)
|
||||
{
|
||||
std::cout << "Running " << test->getName() << std::endl;
|
||||
const auto result = test->Run();
|
||||
if (!result)
|
||||
if (sLastTestFailed)
|
||||
{
|
||||
std::cout << test->getName() << " Failed" << std::endl;
|
||||
testsPassed = false;
|
||||
break;
|
||||
std::cout << "Failed at line: " << sLastTestFailed << std::endl;
|
||||
mFailingTests.push_back(test_case->getName());
|
||||
}
|
||||
}
|
||||
return testsPassed;
|
||||
*/
|
||||
|
||||
if (mFailingTests.size() > 0)
|
||||
{
|
||||
std::cout << mFailingTests.size() << " failing tests: " << std::endl;
|
||||
for(const auto& name : mFailingTests)
|
||||
{
|
||||
std::cout << name << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -8,20 +8,21 @@
|
|||
class TestCaseRunner
|
||||
{
|
||||
public:
|
||||
TestCaseRunner() = default;
|
||||
TestCaseRunner();
|
||||
|
||||
static TestCaseRunner& getInstance()
|
||||
{
|
||||
static TestCaseRunner instance;
|
||||
return instance;
|
||||
}
|
||||
static TestCaseRunner& getInstance();
|
||||
|
||||
~TestCaseRunner();
|
||||
|
||||
void addTestCase(const std::string& label, const std::string& tag, TestCase::TestCaseFunction func);
|
||||
|
||||
void markTestFailure(const std::string& line);
|
||||
|
||||
bool run();
|
||||
|
||||
private:
|
||||
std::vector<std::string> mFailingTests;
|
||||
static bool sLastTestFailed;
|
||||
static std::string sFailureLine;
|
||||
std::vector<TestCase*> mCases;
|
||||
};
|
||||
|
|
|
@ -16,3 +16,13 @@ struct Holder
|
|||
static void Test##NAME() \
|
||||
|
||||
|
||||
#define REQUIRE(predicate) \
|
||||
if(!predicate) \
|
||||
{ \
|
||||
TestCaseRunner::getInstance().markTestFailure(std::to_string(__LINE__)); \
|
||||
return; \
|
||||
} \
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue