new testing
This commit is contained in:
parent
82804630b2
commit
28b38f2734
|
@ -1,26 +1,43 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
//tests
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
test_t tests[] = {NULL};
|
#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) {
|
int main(int argc, char** argv) {
|
||||||
|
auto start = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
|
loadTests();
|
||||||
|
|
||||||
test_t* current = tests;
|
|
||||||
int failcount = 0;
|
int failcount = 0;
|
||||||
int testcount = 0;
|
int testcount = tests.size();
|
||||||
for(; *current; current++) {
|
int testnumber = 0;
|
||||||
testcount++;
|
for(std::map<std::string, test_t>::iterator current = tests.begin(); current != tests.end(); ++current) {
|
||||||
printf("\033[1mRunning test number: %d ", testcount);
|
printf("\033[1mRunning test: %d/%d " AQUA "%s " RESET, ++testnumber, testcount, current->first.c_str());
|
||||||
if((*current)()) {
|
if((current->second)()) {
|
||||||
printf("\033[1;92msucceeded\033[0;1m!\n");
|
printf(GREEN "succeeded" RESET "!\n");
|
||||||
} else {
|
} else {
|
||||||
printf("\033[1;91mfailed\033[0;1m\n");
|
printf(RED "failed" RESET "\n");
|
||||||
failcount++;
|
failcount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\033[1;93m%d\033[0;1m/%d failed\n", failcount, testcount);
|
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;
|
return failcount > 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
#include "test.h"
|
||||||
|
|
||||||
|
TEST(ABC) {
|
||||||
|
CMPASSERT(1, true);
|
||||||
|
|
||||||
|
} TESTEND
|
||||||
|
|
||||||
|
TEST(CDE) {
|
||||||
|
CMPASSERT(0, true);
|
||||||
|
|
||||||
|
} TESTEND
|
|
@ -5,8 +5,13 @@
|
||||||
|
|
||||||
#define TESTDATA "./tests/data/"
|
#define TESTDATA "./tests/data/"
|
||||||
|
|
||||||
|
#define TESTNAME(NAME) test_##NAME
|
||||||
|
#define TESTFUNC(NAME) bool TESTNAME(NAME)()
|
||||||
|
#define TEST(NAME) TESTFUNC(NAME) {
|
||||||
|
#define TESTEND return TESTGOOD; }
|
||||||
|
|
||||||
#define ASSERT(BED, ERR) if(!(BED)) { std::cout << __FILE__ << ":" << __LINE__ << " " << ERR << std::endl; return TESTFAILED; }
|
#define ASSERT(BED, ERR) if(!(BED)) { std::cout << __FILE__ << ":" << __LINE__ << " " << ERR << std::endl; return TESTFAILED; }
|
||||||
#define CMPASSERTE(A, B, ERR) if( !((A) == (B))) { std::cout << __FILE__ << ":" << __LINE__ << " is: \"" << (A) << "\" should: \"" << (B) << "\""<< std::endl; return TESTFAILED; }
|
#define CMPASSERTE(A, B, ERR) if( !((A) == (B))) { std::cout << __FILE__ << ":" << __LINE__ << " is: \"" << (A) << "\" should: \"" << (B) << "\""<< std::endl; return TESTFAILED; }
|
||||||
#define CMPASSERT(A, B) CMPASSERTE(A, B, "")
|
#define CMPASSERT(A, B) CMPASSERTE(A, B, "")
|
||||||
|
|
||||||
typedef int (*test_t)();
|
typedef bool (*test_t)();
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
#include "test.h"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#define REGISTERTEST(NAME) tests.insert({#NAME, TESTNAME(NAME)})
|
||||||
|
|
||||||
|
TESTFUNC(ABC);
|
||||||
|
TESTFUNC(CDE);
|
||||||
|
|
||||||
|
std::map<std::string, test_t> tests;
|
||||||
|
|
||||||
|
void loadTests() {
|
||||||
|
REGISTERTEST(ABC);
|
||||||
|
REGISTERTEST(CDE);
|
||||||
|
}
|
Loading…
Reference in New Issue