diff options
author | EuAndreh <eu@euandre.org> | 2021-08-22 11:21:07 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2021-08-22 11:42:34 -0300 |
commit | 3a4b3fa01b6ead1e23434c533302a2a9fddfd89e (patch) | |
tree | 5a4f5b1e9e5d78e057ed2b49d6d94269dd586a98 /src | |
parent | src/gistatic.c: Remove .logo bogus color attribute (diff) | |
download | gistatic-3a4b3fa01b6ead1e23434c533302a2a9fddfd89e.tar.gz gistatic-3a4b3fa01b6ead1e23434c533302a2a9fddfd89e.tar.xz |
Have a single top-level main for running unit-tests
Instead of each .c file becoming a self-standing .t executable file,
and being run for executing the unit tests local to the file, now each
.c becomes a .to object (akin to a .o object, but one where the -DTEST
flag is given to the compiler). After that, all the .to objects are
linked together in a gistatic-tests executable, in a equivalent way
that all .o files get linked together in a gistatic executable.
This change was necessary in order to allow dependencies between
objects. The next task will be making a tar of a repository tree
checkout, and src/gistatic.{o,to} will start depending on
src/tar.{o,to}. If each file has its own main function when -DTEST is
given, then I wont be able to link them together.
I took the opportunity that I had to change the Makefile, and I
improved the dependency between targets and dependencies greatly. From
what I can tell now, it is correct.
Diffstat (limited to '')
-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 |
5 files changed, 27 insertions, 39 deletions
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 |