Start on rewrite
This commit is contained in:
@@ -24,15 +24,15 @@ include(cmake/CPM.cmake)
|
||||
file(GLOB_RECURSE jtest_HEADERS "include/jtest/*.h" "include/jtest/*.hpp")
|
||||
file(GLOB_RECURSE jtest_SRC "src/jtest/*.c" "src/jtest/*.cpp")
|
||||
|
||||
# TODO: Fix Event needing to be included too, it should be an automatically-managed depencency of jlog!!!
|
||||
CPMAddPackage(
|
||||
NAME Event
|
||||
URL https://git.redacted.cc/josh/Event/archive/Release-6.zip
|
||||
)
|
||||
# TODO: Fix Unit needing to be included too, it should be an automatically-managed depencency of jlog!!!
|
||||
#CPMAddPackage(
|
||||
# NAME Unit
|
||||
# URL https://git.redacted.cc/josh/Event/archive/Release-6.zip
|
||||
#)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME jlog
|
||||
URL https://git.redacted.cc/josh/jlog/archive/Prerelease-12.zip
|
||||
URL https://git.redacted.cc/josh/jlog/archive/Prerelease-13.zip
|
||||
)
|
||||
|
||||
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <source_location>
|
||||
#include <jlog/jlog.hpp>
|
||||
|
||||
//#define NDEBUG for disabling assert, but tests still end up passing.
|
||||
@@ -12,6 +13,129 @@
|
||||
// have this file primarily expose the macros intended for users
|
||||
|
||||
namespace jtest {
|
||||
jlog::Logger JTestLog{"JTEST"};
|
||||
|
||||
|
||||
class Test {
|
||||
public:
|
||||
explicit Test(const std::string& name, std::function<void()> callback, std::source_location location = std::source_location::current()) {
|
||||
this->name = name;
|
||||
this->callback = callback;
|
||||
this->location = location;
|
||||
};
|
||||
public:
|
||||
void operator () () { callback(); }; // <-- This will run our test and catch any exceptions. No it wont
|
||||
std::string Name() { return name; };
|
||||
std::source_location Location() { return location; };
|
||||
protected:
|
||||
std::string name;
|
||||
std::function<void()> callback;
|
||||
std::source_location location;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
//class TestConnection;
|
||||
class Unit;
|
||||
|
||||
class TestConnection {
|
||||
private:
|
||||
//using delegate = std::function<void()>;
|
||||
using delegate = Test;
|
||||
public:
|
||||
TestConnection(Unit *creator, delegate cb);
|
||||
void Invoke();
|
||||
delegate GetDelegate();
|
||||
private:
|
||||
Unit * owner;
|
||||
delegate callback;
|
||||
bool active = true;
|
||||
};
|
||||
|
||||
TestConnection::TestConnection(Unit *creator, TestConnection::delegate cb) : owner(creator), callback(std::move(cb)) {}
|
||||
void TestConnection::Invoke() { callback(); }
|
||||
Test TestConnection::GetDelegate() { return callback; }
|
||||
|
||||
class Unit {
|
||||
public:
|
||||
using delegate = Test;
|
||||
using connection = TestConnection;
|
||||
using test_ptr = std::shared_ptr<connection>;
|
||||
public:
|
||||
void Invoke();
|
||||
void operator()();
|
||||
connection Connect(delegate callback);
|
||||
connection operator+=(delegate callback);
|
||||
private:
|
||||
std::vector<test_ptr> tests;
|
||||
uint64_t testCounter = 0;
|
||||
};
|
||||
|
||||
void Unit::Invoke() {
|
||||
for (test_ptr &connection_ptr: this->tests) {
|
||||
|
||||
//connection_ptr->Invoke();
|
||||
bool passed = true;
|
||||
try { connection_ptr->Invoke(); }
|
||||
catch(const std::exception& e)
|
||||
{ passed = false; }
|
||||
catch(...) // <- Basically covers all exception cases. GTest does something similar
|
||||
{ passed = false; }
|
||||
|
||||
Test d = connection_ptr->GetDelegate();
|
||||
if(!passed)
|
||||
JTestLog(std::format("{} - FAILED", d.Name()), d.Location());
|
||||
else
|
||||
JTestLog(std::format("{} - PASSED", d.Name()), d.Location());
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::operator()() { Invoke();}
|
||||
|
||||
TestConnection Unit::Connect(delegate callback)
|
||||
{
|
||||
test_ptr retval(new connection(this, callback));
|
||||
this->tests.push_back(retval);
|
||||
return *retval;
|
||||
}
|
||||
|
||||
TestConnection Unit::operator+=(Unit::delegate callback) { return Connect(callback); }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
class Unit {
|
||||
public:
|
||||
Unit Tests;
|
||||
public:
|
||||
Unit(const std::string& group_name) { name = group_name; };
|
||||
public:
|
||||
void operator () () { Tests(); }
|
||||
//void Test(const std::string& name, std::function<void()> callback, std::source_location location = std::source_location::current()) = {};
|
||||
protected:
|
||||
std::string name;
|
||||
//std::vector<Test> tests;
|
||||
//int rantests;
|
||||
//int passedtests;
|
||||
//int failedtests;
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/// Structure to store test meta-data, as tests are initially registered, and ran later.
|
||||
struct testdef
|
||||
|
43
main.cpp
43
main.cpp
@@ -12,47 +12,22 @@
|
||||
#include <jtest/jtest.hpp>
|
||||
#include <cassert>
|
||||
|
||||
void TestA() { jtest::check("Bruh" == "Bruh"); }
|
||||
void TestB() { jtest::check(6*6 == 36); }
|
||||
void TestC() { jtest::check(6+9 == 69); }
|
||||
//void TestA() { jtest::check("Bruh" == "Bruh"); }
|
||||
//void TestB() { jtest::check(6*6 == 36); }
|
||||
//void TestC() { jtest::check(6+9 == 69); }
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
TEST("Test1", []{
|
||||
jtest::check(2+2 == 4);
|
||||
});
|
||||
jtest::Unit ThisDick;
|
||||
|
||||
TEST("Test2", [] {
|
||||
//jtest::check(2+2 == 5);
|
||||
jtest::check(2+2 == 4);
|
||||
});
|
||||
ThisDick += jtest::Test("bawls", []{ printf("FUCK1\n"); });
|
||||
|
||||
TEST("Test3", []
|
||||
{
|
||||
jtest::check(6+9 == 69);
|
||||
//jtest::check(2+2 == 4);
|
||||
});
|
||||
ThisDick += jtest::Test("more bawls1", []{ printf("FUCK2\n"); });
|
||||
|
||||
ThisDick += jtest::Test("more bawls2", []{ throw("OH GOD OH FUCK"); });
|
||||
|
||||
TEST("Test4", []
|
||||
{
|
||||
//assert(69 == 9);//, "FUCKING COCK"); stil figuring out
|
||||
});
|
||||
ThisDick += jtest::Test("more bawls3", []{ throw("OH GOD OH FUCK2"); });
|
||||
|
||||
TEST("Test5", []
|
||||
{
|
||||
throw std::runtime_error("HOLY SHIT");
|
||||
});
|
||||
|
||||
TEST("Test6", []
|
||||
{
|
||||
throw std::exception();
|
||||
});
|
||||
|
||||
TEST("TestGroup::A", TestA);
|
||||
TEST("TestGroup::B", TestB);
|
||||
TEST("TestGroup::C", TestC);
|
||||
|
||||
jtest::run_tests();
|
||||
ThisDick();
|
||||
}
|
@@ -4,6 +4,8 @@
|
||||
#include <jtest/jtest.hpp>
|
||||
namespace jtest {
|
||||
|
||||
|
||||
/*
|
||||
// Globals for test tracking
|
||||
std::vector<testdef> testlist;
|
||||
int rantests;
|
||||
@@ -115,6 +117,7 @@ namespace jtest {
|
||||
|
||||
jtest::log(log_test_tracking_format());
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user