From 44d56f5311f98a8955c67638e7520963dbd4d845 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sun, 12 Jan 2025 00:14:03 -0300 Subject: Revamp lib, simplify it a bit and address some FIXMEs --- src/testing.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'src/testing.c') diff --git a/src/testing.c b/src/testing.c index f3239e0..d0b65db 100644 --- a/src/testing.c +++ b/src/testing.c @@ -1,4 +1,4 @@ -#include "config.h" +#include #include #include @@ -7,6 +7,7 @@ #include "testing.h" + #define COLOUR_RESET "\033[0m" #define COLOUR_GREEN "\033[0;32m" #define COLOUR_YELLOW "\033[0;33m" @@ -14,6 +15,10 @@ static const char ENVVAR_NAME[] = "NO_COLOUR"; +static FILE * +STREAM = NULL; + + static bool show_colour(void) { @@ -23,20 +28,26 @@ show_colour(void) { void test_start(const char *const name) { - (void)fprintf(stderr, "%s:\n", name); + if (STREAM == NULL) { + STREAM = stderr; + } + (void)fprintf(STREAM, "%s:\n", name); } void testing(const char *const message) { + if (STREAM == NULL) { + STREAM = stderr; + } if (show_colour()) { (void)fprintf( - stderr, + STREAM, COLOUR_YELLOW "testing" COLOUR_RESET ": %s... ", message ); } else { (void)fprintf( - stderr, + STREAM, "testing: %s...", message ); @@ -45,9 +56,17 @@ testing(const char *const message) { void test_ok(void) { + if (STREAM == NULL) { + STREAM = stderr; + } if (show_colour()) { - (void)fprintf(stderr, COLOUR_GREEN "OK" COLOUR_RESET ".\n"); + (void)fprintf(STREAM, COLOUR_GREEN "OK" COLOUR_RESET ".\n"); } else { - (void)fprintf(stderr, " OK.\n"); + (void)fprintf(STREAM, " OK.\n"); } } + +void +test_set_stream(FILE *stream) { + STREAM = stream; +} -- cgit v1.2.3