aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/logerr.c67
-rw-r--r--src/logerr.h34
-rw-r--r--src/remembering.c5
-rw-r--r--src/tests-lib.c29
-rw-r--r--src/tests-lib.h13
-rw-r--r--src/unit-test.h8
6 files changed, 145 insertions, 11 deletions
diff --git a/src/logerr.c b/src/logerr.c
new file mode 100644
index 0000000..029ed7f
--- /dev/null
+++ b/src/logerr.c
@@ -0,0 +1,67 @@
+#include "config.h"
+#include "logerr.h"
+
+#include <stdio.h>
+
+
+void
+logerr_file(
+ const char *const s,
+ const char *const msg,
+ const char *const file,
+ const int lineno
+) {
+ fprintf(
+ stderr,
+ "%s:%s:%d: %s: %s\n",
+ PROGNAME,
+ file,
+ lineno,
+ s,
+ msg
+ );
+}
+
+void
+logerrs_file(
+ const char *const pre,
+ const char *const mid,
+ const char *const post,
+ const char *const msg,
+ const char *const file,
+ const int lineno
+) {
+ fprintf(
+ stderr,
+ "%s:%s:%d: %s%s%s: %s\n",
+ PROGNAME,
+ file,
+ lineno,
+ pre,
+ mid,
+ post,
+ msg
+ );
+}
+
+void
+logerrl_file(
+ const char *const pre,
+ const size_t mid,
+ const char *const post,
+ const char *const msg,
+ const char *const file,
+ int lineno
+) {
+ fprintf(
+ stderr,
+ "%s:%s:%d: %s%ld%s: %s\n",
+ PROGNAME,
+ file,
+ lineno,
+ pre,
+ mid,
+ post,
+ msg
+ );
+}
diff --git a/src/logerr.h b/src/logerr.h
new file mode 100644
index 0000000..47228ab
--- /dev/null
+++ b/src/logerr.h
@@ -0,0 +1,34 @@
+#ifndef GISTATIC_LOGERR_H
+#define GISTATIC_LOGERR_H
+
+#include <stddef.h>
+
+void
+logerr_file(
+ const char *const s,
+ const char *const msg,
+ const char *const file,
+ const int lineno
+);
+
+void
+logerrs_file(
+ const char *const pre,
+ const char *const mid,
+ const char *const post,
+ const char *const msg,
+ const char *const file,
+ const int lineno
+);
+
+void
+logerrl_file(
+ const char *const pre,
+ const size_t mid,
+ const char *const post,
+ const char *const msg,
+ const char *const file,
+ const int lineno
+);
+
+#endif
diff --git a/src/remembering.c b/src/remembering.c
index 108d246..b35f798 100644
--- a/src/remembering.c
+++ b/src/remembering.c
@@ -1,6 +1,4 @@
-#ifndef _POSIX_C_SOURCE
-#define _POSIX_C_SOURCE 200809L
-#endif
+#include "config.h"
#include <stdlib.h>
#include <stdio.h>
@@ -12,6 +10,7 @@
#ifdef TEST
#include "unit-test.h"
+#include "tests-lib.h"
#include <stdbool.h>
#include <errno.h>
#endif
diff --git a/src/tests-lib.c b/src/tests-lib.c
new file mode 100644
index 0000000..a9d229a
--- /dev/null
+++ b/src/tests-lib.c
@@ -0,0 +1,29 @@
+#include "config.h"
+#include "tests-lib.h"
+#include <stdio.h>
+#include <assert.h>
+
+#define COLOUR_RESET "\033[0m"
+#define COLOUR_GREEN "\033[0;32m"
+#define COLOUR_YELLOW "\033[0;33m"
+
+void
+test_start(const char *const name) {
+ assert(fprintf(stderr, "%s():\n", name) > 0);
+}
+
+void
+testing(const char *const message) {
+ assert(
+ fprintf(
+ stderr,
+ COLOUR_YELLOW "testing" COLOUR_RESET ": %s...",
+ message
+ ) > 0
+ );
+}
+
+void
+test_ok(void) {
+ assert(fprintf(stderr, " " COLOUR_GREEN "OK" COLOUR_RESET ".\n") > 0);
+}
diff --git a/src/tests-lib.h b/src/tests-lib.h
new file mode 100644
index 0000000..1ceab27
--- /dev/null
+++ b/src/tests-lib.h
@@ -0,0 +1,13 @@
+#ifndef GISTATIC_TESTS_LIB_H
+#define GISTATIC_TESTS_LIB_H
+
+void
+test_start(const char *const name);
+
+void
+testing(const char *const message);
+
+void
+test_ok(void);
+
+#endif
diff --git a/src/unit-test.h b/src/unit-test.h
index 02922f7..2188f9f 100644
--- a/src/unit-test.h
+++ b/src/unit-test.h
@@ -8,14 +8,6 @@
#define COLOUR_GREEN "\033[0;32m"
#define COLOUR_YELLOW "\033[0;33m"
-void testing(const char *const message) {
- fprintf(stderr, COLOUR_YELLOW "testing" COLOUR_RESET ": %s...", message);
-}
-
-void test_ok() {
- fprintf(stderr, " " COLOUR_GREEN "OK" COLOUR_RESET ".\n");
-}
-
#define ASSERT_MSG "\n" COLOUR_RED "ERROR" COLOUR_RESET ": "
#define assertf(A, M, ...) if (!(A)) { fprintf(stderr, (ASSERT_MSG M "\n"), __VA_ARGS__); assert(A); }
#define asserte(A) if (!(A)) { fprintf(stderr, ASSERT_MSG "\n"); assert(A); }