aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore5
-rw-r--r--Makefile70
-rw-r--r--src/gistatic.c10
-rw-r--r--src/gistatic.h4
-rw-r--r--src/main.c15
-rw-r--r--src/tar.c32
-rw-r--r--src/tar.h5
-rwxr-xr-xtests/build-sample.sh4
-rwxr-xr-xtests/integration.sh5
9 files changed, 74 insertions, 76 deletions
diff --git a/.gitignore b/.gitignore
index dc7a5fa..8a60a57 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,9 +1,10 @@
/public/
/src/config.h
-/src/gistatic
/libgistatic.a
+/gistatic
+/gistatic-tests
/src/*.o
-/src/*.t
+/src/*.to
*.mo
*.po~
/doc/*.1
diff --git a/Makefile b/Makefile
index 607f910..7f6c4e9 100644
--- a/Makefile
+++ b/Makefile
@@ -9,13 +9,13 @@ TRANSLATIONS = pt fr eo
CONTRIBLANGS =
LDLIBS = -lgit2
-.SUFFIXES: .in .t
+.SUFFIXES: .in .to
.in:
sed -e 's:@VERSION@:$(VERSION):g' -e 's:@DATE@:$(DATE):g' < $< > $@
-.c.t:
- $(CC) $(CFLAGS) $(LDFLAGS) -DTEST -o $@ $< src/tests-lib.o $(LDLIBS)
+.c.to:
+ $(CC) $(CFLAGS) $(LDFLAGS) -DTEST -o $@ -c $< $(LDLIBS)
manpages.en.in = \
@@ -29,50 +29,60 @@ manpages = $(manpages.in:.in=)
sources = \
src/tar.c \
src/gistatic.c
-objects = $(sources:.c=.o)
-tests = $(sources:.c=.t)
+lib-objects = $(sources:.c=.o)
+all-objects = $(lib-objects) src/main.o
+t-objects = $(sources:.c=.to) src/tests-lib.to src/main.to
-all: src/config.h src/tests-lib.o src/gistatic libgistatic.a $(manpages)
+all: gistatic libgistatic.a $(manpages)
+gistatic: $(all-objects)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(all-objects) $(LDLIBS)
-src/gistatic: $(objects) src/main.o
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(objects) src/main.o $(LDLIBS)
+gistatic-tests: $(t-objects)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(t-objects) $(LDLIBS)
-libgistatic.a: $(objects)
- $(AR) $(ARFLAGS) $@ $(objects)
+libgistatic.a: $(lib-objects)
+ $(AR) $(ARFLAGS) $@ $(lib-objects)
src/config.h:
- touch $@
printf '#ifndef GISTATIC_CONFIG_H\n' >> $@
printf '#define GISTATIC_CONFIG_H\n\n' >> $@
printf '#define _POSIX_C_SOURCE 200809L\n' >> $@
printf '#define VERSION "$(VERSION)"\n' >> $@
printf '#define DATE "$(DATE)"\n' >> $@
- printf '\n#endif\n' >> $@
-
-$(objects): 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
-
-
-check: all $(tests)
- rm -f tests/resources/repositories/repo-1/.git
- rm -f tests/resources/repositories/repo-2/.git
- ln -s .gitdir tests/resources/repositories/repo-1/.git
- ln -s .gitdir tests/resources/repositories/repo-2/.git
+ printf '\n' >> $@
+ printf '#endif\n' >> $@
+
+$(all-objects) $(t-objects): src/config.h
+src/tests-lib.to: src/tests-lib.h
+src/tar.o src/tar.to: src/tar.h
+src/gistatic.o src/gistatic.to: src/gistatic.h
+src/gistatic.o: src/tar.o
+src/gistatic.to: src/tar.to
+src/main.o src/main.to: src/tar.h src/gistatic.h
+src/main.o: src/tar.o src/gistatic.o
+src/main.to: src/tar.to src/gistatic.to
+
+tests/resources/repositories/repo-1/.git \
+tests/resources/repositories/repo-2/.git:
+ ln -s .gitdir $@
+
+check: all gistatic-tests \
+ tests/resources/repositories/repo-1/.git \
+ tests/resources/repositories/repo-2/.git
sh tests/build-sample.sh
- for t in $(tests); do ./$$t; done
+ ./gistatic-tests
sh tests/assert-catgets.sh src/*.c
sh tests/integration.sh
sh tests/c-lint.sh src/*.c
clean:
- rm -rf public/ $(manpages) README.*.md CHANGELOG.*.md messages.mo \
- vgcore.* tmp/ src/config.h \
- src/*.o src/*.t src/gistatic libgistatic.a \
- tests/resources/repositories/repo-1/.git \
+ rm -rf \
+ public/ $(manpages) README.*.md CHANGELOG.*.md messages.mo \
+ vgcore.* tmp/ src/config.h src/*.o src/*.to \
+ libgistatic.a gistatic gistatic-tests \
+ tests/resources/repositories/repo-1/.git \
tests/resources/repositories/repo-2/.git
install: all
@@ -80,7 +90,7 @@ install: all
$(DESTDIR)$(PREFIX)/bin \
$(DESTDIR)$(PREFIX)/lib \
$(DESTDIR)$(PREFIX)/include
- cp src/gistatic $(DESTDIR)$(PREFIX)/bin
+ cp gistatic $(DESTDIR)$(PREFIX)/bin
cp libgistatic.a $(DESTDIR)$(PREFIX)/lib
cp src/gistatic.h $(DESTDIR)$(PREFIX)/include
sh doc/manpages.sh -ip $(DESTDIR)$(MANPREFIX) $(manpages)
diff --git a/src/gistatic.c b/src/gistatic.c
index a2b10fc..0a65b6c 100644
--- a/src/gistatic.c
+++ b/src/gistatic.c
@@ -1,4 +1,5 @@
#include "config.h"
+#include "tar.h"
#include "gistatic.h"
#include <stdlib.h>
@@ -2046,7 +2047,7 @@ cleanup:
}
#ifdef TEST
-static void unit_tests(){
+void unit_tests_gistatic(void) {
dump_translatable_strings();
git_libgit2_init();
@@ -2182,10 +2183,3 @@ cleanup:
}
return ret;
}
-
-#ifdef TEST
-int main(void) {
- unit_tests();
- return EXIT_SUCCESS;
-}
-#endif
diff --git a/src/gistatic.h b/src/gistatic.h
index 03c02f6..7e022fa 100644
--- a/src/gistatic.h
+++ b/src/gistatic.h
@@ -3,4 +3,8 @@
int gistatic_main(int argc, char *argv[]);
+#ifdef TEST
+void unit_tests_gistatic(void);
+#endif
+
#endif
diff --git a/src/main.c b/src/main.c
index 52c749f..34214ea 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,5 +1,20 @@
+#include "tar.h"
#include "gistatic.h"
+#include <stdlib.h>
+
+#ifdef TEST
+static void unit_tests(void) {
+ unit_tests_tar();
+ unit_tests_gistatic();
+}
+#endif
+
int main(int argc, char *argv[]) {
+#ifdef TEST
+ unit_tests();
+ return EXIT_SUCCESS;
+#endif
+
return gistatic_main(argc, argv);
}
diff --git a/src/tar.c b/src/tar.c
index 63aebe8..43a580c 100644
--- a/src/tar.c
+++ b/src/tar.c
@@ -1,36 +1,6 @@
#include "config.h"
#include "tar.h"
-
#ifdef TEST
-
-#include "tests-lib.h"
-
-#include <stdbool.h>
-#include <stdlib.h>
-#include <assert.h>
-
-#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;
-}
+void unit_tests_tar(void) {}
#endif
diff --git a/src/tar.h b/src/tar.h
index 09d1c18..29c75bc 100644
--- a/src/tar.h
+++ b/src/tar.h
@@ -1,3 +1,8 @@
#ifndef GISTATIC_TAR_H
#define GISTATIC_TAR_H
+
+#ifdef TEST
+void unit_tests_tar(void);
+#endif
+
#endif
diff --git a/tests/build-sample.sh b/tests/build-sample.sh
index e7057e0..bc544b8 100755
--- a/tests/build-sample.sh
+++ b/tests/build-sample.sh
@@ -1,9 +1,9 @@
#!/bin/sh
set -eu
-./src/gistatic -i -o tmp/ tests/resources/repositories/*
+./gistatic -i -o tmp/ tests/resources/repositories/*
for r in tests/resources/repositories/* $PWD; do
NAME="$(basename "$r")"
mkdir -p "tmp/$NAME"
- ./src/gistatic -u "https://example.com/$NAME" -o "tmp/$NAME" "$r"
+ ./gistatic -u "https://example.com/$NAME" -o "tmp/$NAME" "$r"
done
diff --git a/tests/integration.sh b/tests/integration.sh
index 58dde94..8fa13e9 100755
--- a/tests/integration.sh
+++ b/tests/integration.sh
@@ -20,8 +20,7 @@ test_index_generation() {
OUT="$(mkstemp)"
ERR="$(mkstemp)"
DIR="$(mkdtemp)"
- ./src/gistatic -i -o "$DIR" tests/resources/repositories/* \
- 1>"$OUT" 2>"$ERR"
+ ./gistatic -i -o "$DIR" tests/resources/repositories/* 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_empty_stdout
assert_empty_stderr
@@ -40,7 +39,7 @@ test_repo_generation() {
OUT="$(mkstemp)"
ERR="$(mkstemp)"
DIR="$(mkdtemp)"
- ./src/gistatic -o "$DIR" -u https://example.com/ \
+ ./gistatic -o "$DIR" -u https://example.com/ \
tests/resources/repositories/repo-1 1>"$OUT" 2>"$ERR"
STATUS=$?
assert_empty_stdout