lolautoaccept/tests/main.cpp

44 lines
1.1 KiB
C++

#include <stdio.h>
#include "test.h"
#include <map>
#include <string>
#include <chrono>
#define RED "\033[1;91m"
#define GREEN "\033[1;92m"
#define AQUA "\033[1;36m"
#define RESET "\033[;1m"
extern std::map<std::string, test_t> tests;
void loadTests();
int main(int argc, char** argv) {
auto start = std::chrono::high_resolution_clock::now();
loadTests();
int failcount = 0;
int testcount = tests.size();
int testnumber = 0;
for(std::map<std::string, test_t>::iterator current = tests.begin(); current != tests.end(); ++current) {
printf("\033[1mRunning test: %d/%d " AQUA "%s " RESET, ++testnumber, testcount, current->first.c_str());
if((current->second)()) {
printf(GREEN "succeeded" RESET "!\n");
} else {
printf(RED "failed" RESET "\n");
failcount++;
}
}
const char* color = (failcount > 0 ? RED : GREEN); // red or green
printf("%s%d" RESET "/%d failed\n", color, failcount, testcount);
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> t = end - start;
printf("Testing took: %fms\n", (t.count() * 1000));
return failcount > 0;
}