tests: print elapsed time to run a test

This commit is contained in:
Recep Aslantas
2019-09-12 17:10:31 +03:00
parent 176cc28510
commit 80c2b3712d

View File

@@ -9,12 +9,14 @@
#include "tests.h" #include "tests.h"
#include <stdlib.h> #include <stdlib.h>
#include <time.h>
int int
main(int argc, const char * argv[]) { main(int argc, const char * argv[]) {
test_entry_t *entry; test_entry_t *entry;
test_status_t st; test_status_t st;
int32_t i, count, passed, failed; int32_t i, count, passed, failed;
double start, end, elapsed;
passed = failed = 0; passed = failed = 0;
count = sizeof(tests) / sizeof(tests[0]); count = sizeof(tests) / sizeof(tests[0]);
@@ -22,8 +24,11 @@ main(int argc, const char * argv[]) {
fprintf(stderr, CYAN "\nWelcome to cglm tests\n\n" RESET); fprintf(stderr, CYAN "\nWelcome to cglm tests\n\n" RESET);
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
entry = tests + i; entry = tests + i;
st = entry->entry(); start = clock();
st = entry->entry();
end = clock();
elapsed = (end - start) / CLOCKS_PER_SEC;
if (!st.status) { if (!st.status) {
fprintf(stderr, fprintf(stderr,
@@ -39,10 +44,14 @@ main(int argc, const char * argv[]) {
failed++; failed++;
} else { } else {
fprintf(stderr, fprintf(stderr, GREEN " ✔︎" RESET " %s - " , entry->name);
GREEN " ✔︎" RESET " %s\n"
, if (elapsed > 0.01)
entry->name); fprintf(stderr, YELLOW "%.2f", elapsed);
else
fprintf(stderr, "0");
fprintf(stderr, "s\n" RESET);
passed++; passed++;
} }
} }
@@ -58,7 +67,7 @@ main(int argc, const char * argv[]) {
MAGENTA "%d" RESET " tests are runned, " MAGENTA "%d" RESET " tests are runned, "
GREEN "%d" RESET " %s passed, " GREEN "%d" RESET " %s passed, "
RED "%d" RESET " %s failed\n\n" RESET, RED "%d" RESET " %s failed\n\n" RESET,
passed + failed, count,
passed, passed,
passed > 1 ? "are" : "is", passed > 1 ? "are" : "is",
failed, failed,