aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--src/gistatic.c23
-rw-r--r--src/tar.c24
-rw-r--r--src/tests-lib.c26
-rw-r--r--src/tests-lib.h8
-rw-r--r--tests/resources/assets/repo/style.css1
-rw-r--r--tests/resources/assets/style.css1
7 files changed, 58 insertions, 31 deletions
diff --git a/Makefile b/Makefile
index ccdd358..1a4a771 100644
--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,7 @@ LDLIBS = -lgit2
sed -e 's:@VERSION@:$(VERSION):g' -e 's:@DATE@:$(DATE):g' < $< > $@
.c.t:
- $(CC) $(CFLAGS) $(LDFLAGS) -DTEST -o $@ $< $(LDLIBS)
+ $(CC) $(CFLAGS) $(LDFLAGS) -DTEST -o $@ $< src/tests-lib.o $(LDLIBS)
manpages.en.in = \
@@ -33,7 +33,7 @@ objects = $(sources:.c=.o)
tests = $(sources:.c=.t)
-all: src/config.h $(manpages) src/gistatic libgistatic.a
+all: src/config.h src/tests-lib.o src/gistatic libgistatic.a $(manpages)
src/gistatic: $(objects) src/main.o
@@ -52,7 +52,7 @@ src/config.h:
printf '\n#endif\n' >> $@
$(objects): src/config.h
-$(tests): src/config.h
+$(tests): src/config.h src/tests-lib.h src/tests-lib.o
src/gistatic.o: src/gistatic.h src/tar.o src/tar.h
src/main.o: src/gistatic.h src/gistatic.o
diff --git a/src/gistatic.c b/src/gistatic.c
index 2630992..fee87ee 100644
--- a/src/gistatic.c
+++ b/src/gistatic.c
@@ -17,27 +17,7 @@
#ifdef TEST
-#define COLOUR_RESET "\033[0m"
-#define COLOUR_GREEN "\033[0;32m"
-#define COLOUR_YELLOW "\033[0;33m"
-
-static void test_start(const char *const name) {
- assert(fprintf(stderr, "%s():\n", name) > 0);
-}
-
-static void testing(const char *const message) {
- assert(
- fprintf(
- stderr,
- COLOUR_YELLOW "testing" COLOUR_RESET ": %s...",
- message
- ) > 0
- );
-}
-
-static void test_ok(void) {
- assert(fprintf(stderr, " " COLOUR_GREEN "OK" COLOUR_RESET ".\n") > 0);
-}
+#include "tests-lib.h"
#endif
@@ -239,7 +219,6 @@ static const char *const STYLE_STR = ""
"\n"
" .logo {\n"
" color: white;\n"
- "\n"
" }\n"
"}\n"
"\n"
diff --git a/src/tar.c b/src/tar.c
index 6e231b0..63aebe8 100644
--- a/src/tar.c
+++ b/src/tar.c
@@ -1,18 +1,34 @@
#include "config.h"
#include "tar.h"
+
#ifdef TEST
+
+#include "tests-lib.h"
+
+#include <stdbool.h>
#include <stdlib.h>
-#endif
+#include <assert.h>
-#ifdef TEST
-static void unit_tests(void) {
-}
#endif
+
void a(void) { }
#ifdef TEST
+static void test_a(void) {
+ test_start("test_a:");
+ {
+ testing("a");
+ assert(true);
+ test_ok();
+ }
+}
+
+static void unit_tests(void) {
+ test_a();
+}
+
int main(void) {
unit_tests();
return EXIT_SUCCESS;
diff --git a/src/tests-lib.c b/src/tests-lib.c
new file mode 100644
index 0000000..21e6a8f
--- /dev/null
+++ b/src/tests-lib.c
@@ -0,0 +1,26 @@
+#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..fef72ef
--- /dev/null
+++ b/src/tests-lib.h
@@ -0,0 +1,8 @@
+#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/tests/resources/assets/repo/style.css b/tests/resources/assets/repo/style.css
index 6a5a4e2..3a51849 100644
--- a/tests/resources/assets/repo/style.css
+++ b/tests/resources/assets/repo/style.css
@@ -28,7 +28,6 @@
.logo {
color: white;
-
}
}
diff --git a/tests/resources/assets/style.css b/tests/resources/assets/style.css
index 6a5a4e2..3a51849 100644
--- a/tests/resources/assets/style.css
+++ b/tests/resources/assets/style.css
@@ -28,7 +28,6 @@
.logo {
color: white;
-
}
}