|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
#include <cstddef> // size_t |
|
|
|
|
#include <cstdint> // uint32_t |
|
|
|
|
#include <cstdio> // fclose, fopen, printf, stdout |
|
|
|
|
#include <cstdio> // fclose, fopen, printf, stdout |
|
|
|
|
#include <string> |
|
|
|
|
#include <vector> |
|
|
|
|
|
|
|
|
|
#include "testsuite.h" |
|
|
|
|
#include "util/timer.h" |
|
|
|
@ -20,30 +21,55 @@ TestSuite::~TestSuite()
|
|
|
|
|
|
|
|
|
|
void TestSuite::run() |
|
|
|
|
{ |
|
|
|
|
printf("TestSuite: %d cases have been added!\n", (int)m_cases.size()); |
|
|
|
|
const char* escapePass = "\033[42;30;1m"; |
|
|
|
|
const char* escapeFail = "\033[41;1m"; |
|
|
|
|
const char* escapeGreen = "\033[32m"; |
|
|
|
|
const char* escapeGrey = "\033[37m"; |
|
|
|
|
const char* escapeRed = "\033[31m"; |
|
|
|
|
const char* escapeReset = "\033[0m"; |
|
|
|
|
|
|
|
|
|
size_t caseFailedCount = 0; |
|
|
|
|
printf("\n"); |
|
|
|
|
printf("---- Running %zu Test Cases ----\n", m_cases.size()); |
|
|
|
|
|
|
|
|
|
Util::Timer totalTimer; |
|
|
|
|
|
|
|
|
|
for (auto& testCase : m_cases) { |
|
|
|
|
printf("Start %s\n", testCase.name()); |
|
|
|
|
size_t caseFailedCount = 0; |
|
|
|
|
for (std::vector<TestCase>::size_type i = 0; i < m_cases.size(); ++i) { |
|
|
|
|
|
|
|
|
|
printf(" START %s (%zu/%zu)\n", m_cases.at(i).name(), i + 1, m_cases.size()); |
|
|
|
|
m_currentTestCasePassed = true; |
|
|
|
|
|
|
|
|
|
Util::Timer caseTimer; |
|
|
|
|
testCase.function()(); |
|
|
|
|
printf(" %s, %luns\n", testCase.name(), caseTimer.elapsedNanoseconds()); |
|
|
|
|
m_cases.at(i).function()(); |
|
|
|
|
double elapsed = caseTimer.elapsedNanoseconds(); |
|
|
|
|
|
|
|
|
|
if (!m_currentTestCasePassed) { |
|
|
|
|
std::string state; |
|
|
|
|
if (m_currentTestCasePassed) { |
|
|
|
|
state.append(escapePass); |
|
|
|
|
state.append(" PASS "); |
|
|
|
|
state.append(escapeReset); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
caseFailedCount++; |
|
|
|
|
state.append(escapeFail); |
|
|
|
|
state.append(" FAIL "); |
|
|
|
|
state.append(escapeReset); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
printf("%s %s %s(", state.c_str(), m_cases.at(i).name(), escapeGrey); |
|
|
|
|
Util::Timer::fancyPrint(elapsed); |
|
|
|
|
printf(")%s\n", escapeReset); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
uint32_t percentagePassed = (1 - caseFailedCount / (float)m_cases.size()) * 100; |
|
|
|
|
printf("Passed %d%% of tests\n", percentagePassed); |
|
|
|
|
printf("\n"); |
|
|
|
|
printf("Tests: %s%zu failed%s, %s%zu passed%s, %zu total\n", |
|
|
|
|
escapeRed, caseFailedCount, escapeReset, |
|
|
|
|
escapeGreen, m_cases.size() - caseFailedCount, escapeReset, |
|
|
|
|
m_cases.size()); |
|
|
|
|
|
|
|
|
|
float elapsed = totalTimer.elapsedNanoseconds() / 1000000.0; |
|
|
|
|
printf("Elapsed: %.3f milliseconds\n", elapsed); |
|
|
|
|
printf("Time: "); |
|
|
|
|
Util::Timer::fancyPrint(totalTimer.elapsedNanoseconds()); |
|
|
|
|
printf("\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} // namespace Test
|
|
|
|
|