dedup/tests/main.cpp

55 lines
1.5 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 YELLOW "\033[1;93m"
#define AQUA "\033[1;36m"
#define RESET "\033[;1m"
int main(int argc, char** argv) {
auto start = std::chrono::high_resolution_clock::now();
testdef* startit = &__start_testlist, *endit = &__stop_testlist;
int failcount = 0;
int skipcount = 0;
int testcount = endit-startit;
int testnumber = 0;
// go through back -> front (tests are inserted in reverse order)
for(testdef* it = startit + testcount-1; it >= startit; --it) {
printf("\033[1mRunning test: %d/%d " AQUA "%s " RESET, ++testnumber, testcount, it->name);
// run test
int result = TESTFAILED;
try {
result = (it->testf)();
} catch(std::exception& e) {
std::cout << "catched exception: \"" << e.what() << "\" " << std::flush;
} catch(...) {}
if(result == TESTGOOD) {
printf(GREEN "succeeded" RESET "!\n");
} else if(result == TESTSKIPPED) {
printf(YELLOW "skipped" RESET "!\n");
skipcount++;
} else {
printf(RED "failed" RESET "\n");
failcount++;
}
}
const char* color = (failcount > 0 ? RED : GREEN); // red or green
printf("%s%d" RESET "/%d failed (" YELLOW "%d " RESET "skipped)\n", color, failcount, testcount, skipcount);
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;
}