Start of test tracking by using global vector variable and some goofiness.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#pragma once
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <jlog/jlog.hpp>
|
||||
|
||||
namespace jtest {
|
||||
@@ -10,6 +11,23 @@ namespace jtest {
|
||||
// Requirements
|
||||
//
|
||||
|
||||
// Can't we just store a struct in a global vector per test?
|
||||
// -maxine
|
||||
struct testdef
|
||||
{
|
||||
const std::string& testname;
|
||||
const std::function<void()>& callback;
|
||||
const std::string file; // <- & is not needed here -maxine
|
||||
int line;
|
||||
};
|
||||
|
||||
std::vector<testdef> testlist;
|
||||
|
||||
void definetest(const std::string& testname, const std::function<void()>& callback, const std::string& file, int line)
|
||||
{
|
||||
testlist.push_back(testdef(testname, callback, file, line));
|
||||
}
|
||||
|
||||
bool check(bool condition) {
|
||||
if (!condition)
|
||||
throw std::runtime_error("Test check failed!!");
|
||||
@@ -37,10 +55,22 @@ namespace jtest {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Storing a global vector with all the tests should allow us to loop through all the tests
|
||||
// We can also possibly do more tracing and allow other fancy features.
|
||||
// -maxine
|
||||
void run_tests() {
|
||||
for (int i = 1; const testdef& td : testlist)
|
||||
{
|
||||
test(td.testname, td.callback, td.file, td.line);
|
||||
USINFO("Tests ran: " + std::to_string(i) + "/" + std::to_string(testlist.size()));
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#define TEST(a, b) jtest::test(a, b, __FILE__, __LINE__);
|
||||
//#define TEST(a, b) jtest::test(a, b, __FILE__, __LINE__);
|
||||
// Same definition as before essentially, but points to a different function which adds the test to the global vector.
|
||||
// -maxine
|
||||
#define TEST(a, b) jtest::definetest(a, b, __FILE__, __LINE__);
|
||||
|
7
main.cpp
7
main.cpp
@@ -17,6 +17,7 @@
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
|
||||
TEST("Test1", []{
|
||||
jtest::check(2+2 == 4);
|
||||
});
|
||||
@@ -25,6 +26,12 @@ int main(int argc, char** argv)
|
||||
jtest::check(2+2 == 5);
|
||||
});
|
||||
|
||||
/*
|
||||
TEST("LMAO");
|
||||
TEST("KEKERINO")
|
||||
TEST(":)")
|
||||
*/
|
||||
|
||||
// Doesn't actually do anything yet
|
||||
jtest::run_tests();
|
||||
}
|
@@ -1,3 +1,7 @@
|
||||
//
|
||||
// Created by dawsh on 6/16/24.
|
||||
//
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user