Wrote log formatters for jtest. Cleaned up test running code.

This commit is contained in:
2024-06-25 11:05:14 -04:00
parent e04b742954
commit b8df31dd50
3 changed files with 83 additions and 22 deletions

View File

@@ -32,7 +32,7 @@ CPMAddPackage(
CPMAddPackage(
NAME jlog
URL https://git.redacted.cc/josh/jlog/archive/Prerelease-5.zip
URL https://git.redacted.cc/josh/jlog/archive/Prerelease-8.zip
)

View File

@@ -30,6 +30,49 @@ namespace jtest {
int passedtests;
int failedtests;
std::vector<jlog::token> log_test_format(const std::string& testname, const std::string& file, int line, bool passed)
{
std::vector<jlog::token> wtokens;
auto head = jlog::token{.colorCode = jlog::ansi_escape_codes::FG_WHITE, .content ="JTEST"};
auto filedata = jlog::token{.content = std::format("{}:{}", file, line)};
std::vector<jlog::token> teststate;
if (passed)
{
teststate.push_back(jlog::token{.colorCode = jlog::ansi_escape_codes::FG_GREEN, .content = testname});
teststate.push_back(jlog::token{.content = "Passed:", .delimiter = ""});
} else
{
teststate.push_back(jlog::token{.colorCode = jlog::ansi_escape_codes::FG_RED, .content = testname});
teststate.push_back(jlog::token{.content = "Failed:", .delimiter = ""});
}
auto raninfo = jlog::token{.content = std::format("{}/{}", rantests, testlist.size())};
wtokens.push_back(head);
wtokens.push_back(filedata);
wtokens.insert(wtokens.end(), teststate.begin(), teststate.end());
wtokens.push_back(raninfo);
return wtokens;
}
std::vector<jlog::token> log_test_tracking_format()
{
auto head = jlog::token{.colorCode = jlog::ansi_escape_codes::FG_WHITE, .content = "JTEST"};
auto tracking = jlog::token{.content = std::format("Tests Ran: [{}/{}] Failed: [{}/{}] Passed: [{}/{}]",
rantests,
testlist.size(),
failedtests,
rantests,
passedtests,
rantests),
.delimiter = ""};
return {head, tracking};
}
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));
@@ -46,31 +89,44 @@ namespace jtest {
bool test(const std::string& testname, const std::function<void()>& callback, const std::string& file, int line)
{
bool passed = true;
try
{
callback();
} catch(const std::exception& e)
{
passed = false;
}
rantests++;
if (passed)
{
passedtests++;
} else
{
failedtests++;
}
jlog::log(log_test_format(testname, file, line, passed));
return passed;
/*
try {
callback();
} catch(const std::exception& e) {
rantests++;
failedtests++;
jlog::log({
{.colorCode = jlog::ansi_escape_codes::FG_WHITE, .content ="JTEST"},
{.content = std::format("{}:{}", file, line)},
{.colorCode = jlog::ansi_escape_codes::FG_RED, .content = testname},
{.content = "Failed:", .delimiter = ""},
{.content = std::format("{}/{}", rantests, testlist.size())},
});
jlog::log(log_test_format(testname, file, line, false));
return false;
}
rantests++;
passedtests++;
jlog::log({
{.colorCode = jlog::ansi_escape_codes::FG_WHITE, .content ="JTEST"},
{.content = std::format("{}:{}", file, line)},
{.colorCode = jlog::ansi_escape_codes::FG_GREEN, .content = testname},
{.content = "Passed:", .delimiter = ""},
{.content = std::format("{}/{}", rantests, testlist.size())},
});
jlog::log(log_test_format(testname, file, line, true));
return true;
*/
}
// Storing a global vector with all the tests should allow us to loop through all the tests
@@ -85,21 +141,19 @@ namespace jtest {
//i++;
}
jlog::log({
//{.content = std::format("{}:{}", file, line)},
{.colorCode = jlog::ansi_escape_codes::FG_WHITE, .content = "JTEST"},
{.content = std::format("Tests Ran: [{}/{}] Failed: [{}/{}] Passed: [{}/{}]", rantests, testlist.size(), failedtests, rantests, passedtests, rantests), .delimiter = ""},
});
//USINFO(std::format("Tests Ran: [{}/{}] Failed: [{}/{}] Passed: [{}/{}]", rantests, testlist.size(), failedtests, rantests, passedtests, rantests))
jlog::log(log_test_tracking_format());
/*
if (passedtests == rantests)
{
USINFO("All tests passed congratulations! Do you wanna cookie?");
//USINFO("All tests passed congratulations! Do you wanna cookie?");
jlog::log({
//{.content = std::format("{}:{}", file, line)},
{.colorCode = jlog::ansi_escape_codes::FG_WHITE, .content = "JTEST"},
{.colorCode = jlog::ansi_escape_codes::FG_GREEN, .content = "All tests passed congratulations! Do you wanna cookie?", .delimiter = ""},
});
}
*/
}
}

View File

@@ -30,6 +30,13 @@ int main(int argc, char** argv)
//jtest::check(2+2 == 4);
});
/*
TEST("Test4", []
{
assert(false);
});
*/
/*
TEST("LMAO");
TEST("KEKERINO")