#include #include #include #include #include "testing.h" #define COLOUR_RESET "\033[0m" #define COLOUR_GREEN "\033[0;32m" #define COLOUR_YELLOW "\033[0;33m" static const char ENVVAR_NAME[] = "NO_COLOUR"; static FILE * STREAM = NULL; static bool show_colour(void) { const char *const no_colour = getenv(ENVVAR_NAME); return (no_colour == NULL) || (no_colour[0] == '\0'); } void test_start(const char *const 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( STREAM, COLOUR_YELLOW "testing" COLOUR_RESET ": %s... ", message ); } else { (void)fprintf( STREAM, "testing: %s...", message ); } } void test_ok(void) { if (STREAM == NULL) { STREAM = stderr; } if (show_colour()) { (void)fprintf(STREAM, COLOUR_GREEN "OK" COLOUR_RESET ".\n"); } else { (void)fprintf(STREAM, " OK.\n"); } } void test_set_stream(FILE *stream) { STREAM = stream; }