mirror of
https://github.com/recp/cglm.git
synced 2026-01-05 22:59:12 +00:00
test: improve runner output and add assert helper for inline functions
This commit is contained in:
@@ -10,25 +10,43 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
main(int argc, const char * argv[]) {
|
||||
test_entry_t *entry;
|
||||
test_status_t st;
|
||||
int32_t i, count, passed, failed;
|
||||
double start, end, elapsed;
|
||||
int32_t i, count, passed, failed, maxlen;
|
||||
double start, end, elapsed, total;
|
||||
|
||||
passed = failed = 0;
|
||||
passed = failed = maxlen = 0;
|
||||
total = 0.0;
|
||||
count = sizeof(tests) / sizeof(tests[0]);
|
||||
|
||||
|
||||
fprintf(stderr, CYAN "\nWelcome to cglm tests\n\n" RESET);
|
||||
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
int32_t len;
|
||||
|
||||
entry = tests + i;
|
||||
len = (int32_t)strlen(entry->name);
|
||||
|
||||
maxlen = GLM_MAX(maxlen, len);
|
||||
}
|
||||
|
||||
maxlen += 5;
|
||||
|
||||
fprintf(stderr,
|
||||
BOLDWHITE " %-*s %-*s\n",
|
||||
maxlen, "Test Name", maxlen, "Elapsed Time");
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
entry = tests + i;
|
||||
start = clock();
|
||||
st = entry->entry();
|
||||
end = clock();
|
||||
elapsed = (end - start) / CLOCKS_PER_SEC;
|
||||
total += elapsed;
|
||||
|
||||
if (!st.status) {
|
||||
fprintf(stderr,
|
||||
@@ -44,14 +62,14 @@ main(int argc, const char * argv[]) {
|
||||
|
||||
failed++;
|
||||
} else {
|
||||
fprintf(stderr, GREEN " ✔︎" RESET " %s - " , entry->name);
|
||||
fprintf(stderr, GREEN " ✔︎" RESET " %-*s ", maxlen, entry->name);
|
||||
|
||||
if (elapsed > 0.01)
|
||||
fprintf(stderr, YELLOW "%.2f", elapsed);
|
||||
fprintf(stderr, YELLOW "%.2fs", elapsed);
|
||||
else
|
||||
fprintf(stderr, "0");
|
||||
|
||||
fprintf(stderr, "s\n" RESET);
|
||||
fprintf(stderr, "\n" RESET);
|
||||
passed++;
|
||||
}
|
||||
}
|
||||
@@ -61,12 +79,13 @@ main(int argc, const char * argv[]) {
|
||||
}
|
||||
|
||||
fprintf(stderr,
|
||||
CYAN "\ncglm test results:\n" RESET
|
||||
"------------------\n"
|
||||
CYAN "\ncglm test results (%0.2fs):\n" RESET
|
||||
"--------------------------\n"
|
||||
|
||||
MAGENTA "%d" RESET " tests are runned, "
|
||||
GREEN "%d" RESET " %s passed, "
|
||||
RED "%d" RESET " %s failed\n\n" RESET,
|
||||
total,
|
||||
count,
|
||||
passed,
|
||||
passed > 1 ? "are" : "is",
|
||||
|
||||
Reference in New Issue
Block a user