summaryrefslogtreecommitdiff
path: root/src/testing.c
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2025-01-12 00:14:03 -0300
committerEuAndreh <eu@euandre.org>2025-01-12 14:27:57 -0300
commit44d56f5311f98a8955c67638e7520963dbd4d845 (patch)
treefbb2c58c79f1730ff62c83cef116fb5c0e035dfe /src/testing.c
parentReplace src/config.h with <s.h>; incorporate changes from other projects (diff)
downloadpindaiba-44d56f5311f98a8955c67638e7520963dbd4d845.tar.gz
pindaiba-44d56f5311f98a8955c67638e7520963dbd4d845.tar.xz
Revamp lib, simplify it a bit and address some FIXMEs
Diffstat (limited to 'src/testing.c')
-rw-r--r--src/testing.c31
1 files changed, 25 insertions, 6 deletions
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 <s.h>
#include <stdbool.h>
#include <stdio.h>
@@ -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;
+}