Files
wizapp-stdlib/src/testing/tester/tester.c
T
Abdelrahman Said 9029e21a4f
Release / release (push) Successful in 4s
Update str8 printf spec
2026-09-19 11:37:55 +01:00

56 lines
1.2 KiB
C

// vim:fileencoding=utf-8:foldmethod=marker
#include "tester.h"
#include "../../common/aliases/aliases.h"
#include "../../os/shell/termcolour/termcolour.h"
#include "../../base/strings/str8/str8.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
wp_intern void handleTestResult(WpTestFuncResult result);
void runTests(WpTestFunc *func1, ...) {
printf("\n");
handleTestResult(func1());
va_list args;
va_start(args, func1);
WpTestFunc *func = va_arg(args, WpTestFunc *);
while (func) {
WpTestFuncResult result = func();
handleTestResult(result);
func = va_arg(args, WpTestFunc *);
}
va_end(args);
printf("\n");
}
wp_intern void handleTestResult(WpTestFuncResult result) {
WpTerminalColour colour;
WpStr8 result_text = wpStr8Buf(64);
if (result.passed) {
colour = WP_TERM_COLOUR_FG_BR_GREEN;
wpStr8CopyCstrCapped(&result_text, "PASSED");
} else {
colour = WP_TERM_COLOUR_FG_BR_RED;
wpStr8CopyCstrCapped(&result_text, "FAILED");
}
printf("[");
wpShellTermcolourPrintText(&result_text, colour);
wpShellTermcolourClearColour();
printf("] %" WP_STR8_SPEC "\n", wpStr8Varg(result.name));
if (!result.passed) {
exit(EXIT_FAILURE);
}
}