Use UnitTest-Cpp library for testing
This commit is contained in:
parent
79d018ffb4
commit
b8bcf58a29
53 changed files with 1046 additions and 1383 deletions
|
|
@ -1,79 +0,0 @@
|
|||
|
||||
#include "Testing.hpp"
|
||||
#include "Utils.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace tp;
|
||||
|
||||
Testing tp::gTesting;
|
||||
|
||||
void Testing::startTest(const char* name) {
|
||||
auto newNode = new (malloc(sizeof(TestingNode))) TestingNode{ {}, {}, name, mCurrent };
|
||||
mCurrent->mSubTests.pushBack(newNode);
|
||||
mCurrent = mCurrent->mSubTests.last()->data;
|
||||
}
|
||||
|
||||
void Testing::endTest() {
|
||||
if (mCurrent->mParent) {
|
||||
mCurrent = mCurrent->mParent;
|
||||
}
|
||||
}
|
||||
|
||||
void Testing::addFailedCheck(const FailedCheck& info) {
|
||||
auto lastRecord = &mCurrent->mFailedChecks.last()->data;
|
||||
if (lastRecord && lastRecord->failedCheck.file == info.file && lastRecord->failedCheck.line == info.line) {
|
||||
lastRecord->times++;
|
||||
return;
|
||||
}
|
||||
mCurrent->mFailedChecks.pushBack({ info, 1 });
|
||||
}
|
||||
|
||||
void Testing::reportState() {
|
||||
mRootTest.updateState();
|
||||
|
||||
printf("\n");
|
||||
mRootTest.report();
|
||||
}
|
||||
|
||||
bool Testing::hasFailed() {
|
||||
mRootTest.updateState();
|
||||
return mRootTest.mHasFailed;
|
||||
}
|
||||
|
||||
void Testing::setRootName(const char* name) { mRootTest.mName = name; }
|
||||
|
||||
void Testing::TestingNode::updateState() {
|
||||
for (auto child : mSubTests) {
|
||||
child->updateState();
|
||||
mHasFailed = child->mHasFailed;
|
||||
if (mHasFailed) return;
|
||||
}
|
||||
mHasFailed = mFailedChecks.length();
|
||||
}
|
||||
|
||||
void Testing::TestingNode::report(const char* path) const {
|
||||
if (!mHasFailed) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto newPath = path ? std::string(path) + "/" + mName : std::string(mName);
|
||||
|
||||
for (auto check : mFailedChecks) {
|
||||
auto failedCheck = &check.data().failedCheck;
|
||||
auto times = check.data().times;
|
||||
printf("%s Failed - (%s) %s:%llu x%i\n", newPath.c_str(), failedCheck->expression, failedCheck->file, failedCheck->line, (halni) times);
|
||||
}
|
||||
|
||||
for (const auto& child : mSubTests) {
|
||||
child->report(newPath.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
Testing::TestingNode::~TestingNode() {
|
||||
for (const auto& child : mSubTests) {
|
||||
child.data()->~TestingNode();
|
||||
free(child.data());
|
||||
}
|
||||
}
|
||||
|
|
@ -3,8 +3,6 @@
|
|||
|
||||
#include "ContainersCommon.hpp"
|
||||
|
||||
#include "Testing.hpp"
|
||||
|
||||
#include <ctime>
|
||||
#include <random>
|
||||
|
||||
|
|
@ -19,10 +17,6 @@ static bool initialize(const tp::ModuleManifest*) {
|
|||
|
||||
static void deinitialize(const tp::ModuleManifest*) {
|
||||
deinitializeCallStackCapture();
|
||||
tp::gTesting.reportState();
|
||||
if (tp::gTesting.hasFailed()) {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
namespace tp {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue