54 lines
1.1 KiB
C
54 lines
1.1 KiB
C
#include "tester.h"
|
|
#include "aliases.h"
|
|
#include "termcolour.h"
|
|
#include "str8.h"
|
|
#include <stdarg.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
internal void handle_test_result(TestFuncResult result);
|
|
|
|
void run_tests(TestFunc *func1, ...) {
|
|
printf("\n");
|
|
|
|
handle_test_result(func1());
|
|
|
|
va_list args;
|
|
va_start(args, func1);
|
|
|
|
TestFunc *func = va_arg(args, TestFunc *);
|
|
|
|
while (func) {
|
|
TestFuncResult result = func();
|
|
handle_test_result(result);
|
|
|
|
func = va_arg(args, TestFunc *);
|
|
}
|
|
|
|
va_end(args);
|
|
|
|
printf("\n");
|
|
}
|
|
|
|
internal void handle_test_result(TestFuncResult result) {
|
|
TerminalColour colour;
|
|
Str8 result_text;
|
|
|
|
if (result.passed) {
|
|
colour = WAPP_TERM_COLOUR_FG_BR_GREEN;
|
|
result_text = wapp_str8_lit("PASSED");
|
|
} else {
|
|
colour = WAPP_TERM_COLOUR_FG_BR_RED;
|
|
result_text = wapp_str8_lit("FAILED");
|
|
}
|
|
|
|
printf("[");
|
|
wapp_shell_termcolour_print_text(&result_text, colour);
|
|
wapp_shell_termcolour_clear_colour();
|
|
printf("] " WAPP_STR8_SPEC "\n", wapp_str8_varg(result.name));
|
|
|
|
if (!result.passed) {
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|