summaryrefslogtreecommitdiff
path: root/src/testing.c
diff options
context:
space:
mode:
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;
+}