diff options
Diffstat (limited to '')
-rw-r--r-- | .gitignore | 5 | ||||
-rw-r--r-- | Makefile | 70 | ||||
-rw-r--r-- | src/gistatic.c | 10 | ||||
-rw-r--r-- | src/gistatic.h | 4 | ||||
-rw-r--r-- | src/main.c | 15 | ||||
-rw-r--r-- | src/tar.c | 32 | ||||
-rw-r--r-- | src/tar.h | 5 | ||||
-rwxr-xr-x | tests/build-sample.sh | 4 | ||||
-rwxr-xr-x | tests/integration.sh | 5 |
9 files changed, 74 insertions, 76 deletions
@@ -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 @@ -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 @@ -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); } @@ -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 @@ -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 |