Initial test bootstrap.
This commit is contained in:
parent
6c618749f1
commit
4b308f6c32
94 changed files with 2543 additions and 681 deletions
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "String.h"
|
||||
#include "Pointer.h"
|
||||
#include <functional>
|
||||
|
||||
class TestCase
|
||||
|
@ -9,7 +9,7 @@ class TestCase
|
|||
public:
|
||||
using TestCaseFunction = std::function<void()>;
|
||||
|
||||
TestCase(const std::string& name, const std::string& tags, TestCaseFunction func)
|
||||
TestCase(const String& name, const String& tags, TestCaseFunction func)
|
||||
: mTestFunction(func),
|
||||
mName(name),
|
||||
mTags(tags)
|
||||
|
@ -19,12 +19,12 @@ public:
|
|||
|
||||
virtual ~TestCase() = default;
|
||||
|
||||
const std::string& getName() const
|
||||
const String& getName() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
const std::string& getTags() const
|
||||
const String& getTags() const
|
||||
{
|
||||
return mTags;
|
||||
}
|
||||
|
@ -38,8 +38,8 @@ public:
|
|||
TestCaseFunction mTestFunction{nullptr};
|
||||
|
||||
private:
|
||||
std::string mName;
|
||||
std::string mTags;
|
||||
String mName;
|
||||
String mTags;
|
||||
|
||||
};
|
||||
using TestCasePtr = std::unique_ptr<TestCase>;
|
||||
using TestCasePtr = Ptr<TestCase>;
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
#include "TestCaseRunner.h"
|
||||
|
||||
#include "FileLogger.h"
|
||||
#include "TestUiApplication.h"
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "ConsoleLogger.h"
|
||||
//#include "TestUiApplication.h"
|
||||
|
||||
bool TestCaseRunner::sLastTestFailed = false;
|
||||
std::string TestCaseRunner::sFailureLine = {};
|
||||
String TestCaseRunner::sFailureLine = {};
|
||||
|
||||
TestCaseRunner::TestCaseRunner()
|
||||
{
|
||||
|
@ -19,6 +17,7 @@ TestCaseRunner::~TestCaseRunner()
|
|||
|
||||
}
|
||||
|
||||
/*
|
||||
TestUiApplication* TestCaseRunner::getTestApplication()
|
||||
{
|
||||
return mTestApplication;
|
||||
|
@ -28,6 +27,7 @@ void TestCaseRunner::setTestApplication(TestUiApplication* app)
|
|||
{
|
||||
mTestApplication = app;
|
||||
}
|
||||
*/
|
||||
|
||||
TestCaseRunner& TestCaseRunner::getInstance()
|
||||
{
|
||||
|
@ -35,26 +35,26 @@ TestCaseRunner& TestCaseRunner::getInstance()
|
|||
return instance;
|
||||
}
|
||||
|
||||
void TestCaseRunner::addTestCase(const std::string& label, const std::string& tag, TestCase::TestCaseFunction func)
|
||||
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 std::string& line)
|
||||
void TestCaseRunner::markTestFailure(const String& line)
|
||||
{
|
||||
sLastTestFailed = true;
|
||||
sFailureLine = line;
|
||||
}
|
||||
|
||||
bool TestCaseRunner::run(const std::vector<std::string>& args)
|
||||
bool TestCaseRunner::run(const Vector<String>& args)
|
||||
{
|
||||
std::string test_to_run;
|
||||
String test_to_run;
|
||||
if (args.size() > 0 )
|
||||
{
|
||||
test_to_run = args[0];
|
||||
}
|
||||
FileLogger::GetInstance().disable();
|
||||
//FileLogger::GetInstance().disable();
|
||||
for (auto test_case : mCases)
|
||||
{
|
||||
if (!test_to_run.empty())
|
||||
|
@ -66,41 +66,22 @@ bool TestCaseRunner::run(const std::vector<std::string>& args)
|
|||
}
|
||||
|
||||
sLastTestFailed = false;
|
||||
std::cout << "TestFramework: Running Test - " << test_case->getName() << std::endl;
|
||||
|
||||
try
|
||||
{
|
||||
test_case->run();
|
||||
}
|
||||
catch (const std::runtime_error& re)
|
||||
{
|
||||
std::cout << "Failed with runtime error: " << re.what() << std::endl;
|
||||
mFailingTests.push_back(test_case->getName());
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::cout << "Failed with exception: " << e.what() << std::endl;
|
||||
mFailingTests.push_back(test_case->getName());
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
std::cout << "Failed with unknown exception" << std::endl;
|
||||
mFailingTests.push_back(test_case->getName());
|
||||
};
|
||||
|
||||
ConsoleLogger::logLine("TestFramework: Running Test - %s", test_case->getName().raw());
|
||||
test_case->run();
|
||||
|
||||
if (sLastTestFailed)
|
||||
{
|
||||
std::cout << "Failed at line: " << sFailureLine << std::endl;
|
||||
ConsoleLogger::logLine("Failed at line %s", sFailureLine.raw());
|
||||
mFailingTests.push_back(test_case->getName());
|
||||
}
|
||||
}
|
||||
|
||||
if (mFailingTests.size() > 0)
|
||||
{
|
||||
std::cout << mFailingTests.size() << " failing tests: " << std::endl;
|
||||
ConsoleLogger::logLine("%d failing tests", mFailingTests.size());
|
||||
for(const auto& name : mFailingTests)
|
||||
{
|
||||
std::cout << name << std::endl;
|
||||
ConsoleLogger::logLine(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
#include "TestCase.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "Vector.h"
|
||||
#include "String.h"
|
||||
|
||||
class TestUiApplication;
|
||||
|
||||
|
@ -16,20 +16,20 @@ public:
|
|||
|
||||
~TestCaseRunner();
|
||||
|
||||
TestUiApplication* getTestApplication();
|
||||
//TestUiApplication* getTestApplication();
|
||||
|
||||
void addTestCase(const std::string& label, const std::string& tag, TestCase::TestCaseFunction func);
|
||||
void addTestCase(const String& label, const String& tag, TestCase::TestCaseFunction func);
|
||||
|
||||
void markTestFailure(const std::string& line);
|
||||
void markTestFailure(const String& line);
|
||||
|
||||
bool run(const std::vector<std::string>& args);
|
||||
bool run(const Vector<String>& args);
|
||||
|
||||
void setTestApplication(TestUiApplication* app);
|
||||
//void setTestApplication(TestUiApplication* app);
|
||||
private:
|
||||
|
||||
TestUiApplication* mTestApplication{ nullptr };
|
||||
std::vector<std::string> mFailingTests;
|
||||
//TestUiApplication* mTestApplication{ nullptr };
|
||||
Vector<String> mFailingTests;
|
||||
static bool sLastTestFailed;
|
||||
static std::string sFailureLine;
|
||||
std::vector<TestCase*> mCases;
|
||||
static String sFailureLine;
|
||||
Vector<TestCase*> mCases;
|
||||
};
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
struct Holder
|
||||
{
|
||||
Holder(const std::string& name, const std::string& tags, std::function<void()> func)
|
||||
Holder(const String& name, const String& tags, std::function<void()> func)
|
||||
{
|
||||
TestCaseRunner::getInstance().addTestCase(name, tags, func);
|
||||
}
|
||||
|
@ -19,8 +19,8 @@ struct Holder
|
|||
#define REQUIRE(predicate) \
|
||||
if(!bool(predicate)) \
|
||||
{ \
|
||||
TestCaseRunner::getInstance().markTestFailure(std::to_string(__LINE__) + " with check: '" + std::string(#predicate) + "'"); \
|
||||
return; \
|
||||
const auto msg = String::to_string(__LINE__) + String(" with check: '") + String(#predicate) + String("'"); \
|
||||
TestCaseRunner::getInstance().markTestFailure(msg); \
|
||||
} \
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "TestDataLocations.h"
|
||||
//#include "TestDataLocations.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue