From 2e9d8300dee5bf0e6f6836e4f063b96c1fcbf4b2 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Wed, 10 Oct 2018 12:03:43 +0200 Subject: [PATCH] Include full c source to assert static objects To assert static objects, we either have to add a method into the object under test itself and recompile on a test run with the activated test method (but also recompile after tests, so that method is gone on release builds). Alternatively we can include the whole .c file in our test infrastructure and save the object in the test directory. So there's no necessity to clean it up prior to a release build and it's contained away. This requires, that the test folder isn't excluded in coveralls. --- .travis.yml | 4 ++-- Makefile | 5 ++++- test/icon.c | 6 +----- test/markup.c | 6 +----- test/notification.c | 5 ++--- test/option_parser.c | 6 +----- test/utils.c | 4 +--- 7 files changed, 12 insertions(+), 24 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4cf6e64..de3d0ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,7 @@ matrix: include: - compiler: gcc after_success: - - coveralls --exclude 'test' + - coveralls - compiler: clang after_success: - - coveralls --exclude 'test' --gcov llvm-cov --gcov-options gcov + - coveralls --gcov llvm-cov --gcov-options gcov diff --git a/Makefile b/Makefile index 69deeca..8b9a919 100644 --- a/Makefile +++ b/Makefile @@ -96,8 +96,11 @@ test-coverage-report: test-coverage --html-details \ -o docs/internal/coverage/index.html +test/%.o: test/%.c src/%.c + ${CC} -o $@ -c $< ${CFLAGS} + test/test: ${OBJ} ${TEST_OBJ} - ${CC} -o ${@} ${TEST_OBJ} ${OBJ} ${CFLAGS} ${LDFLAGS} + ${CC} -o ${@} ${TEST_OBJ} $(filter-out ${TEST_OBJ:test/%=src/%},${OBJ}) ${CFLAGS} ${LDFLAGS} .PHONY: doc doc-doxygen doc: docs/dunst.1 diff --git a/test/icon.c b/test/icon.c index 180a324..616bef6 100644 --- a/test/icon.c +++ b/test/icon.c @@ -1,9 +1,5 @@ +#include "../src/icon.c" #include "greatest.h" -#include "../src/icon.h" -#include "../src/utils.h" - -#include -#include #define ICONPREFIX "/data/icons/path" diff --git a/test/markup.c b/test/markup.c index b00888d..c4afa8d 100644 --- a/test/markup.c +++ b/test/markup.c @@ -1,10 +1,6 @@ +#include "src/markup.c" #include "greatest.h" -#include -#include - -#include "src/markup.h" - TEST test_markup_strip(void) { char *ptr; diff --git a/test/notification.c b/test/notification.c index b6afe2f..893d279 100644 --- a/test/notification.c +++ b/test/notification.c @@ -1,10 +1,9 @@ +#include "src/notification.c" #include "greatest.h" -#include "src/notification.h" + #include "src/option_parser.h" #include "src/settings.h" -#include - TEST test_notification_is_duplicate_field(char **field, struct notification *a, struct notification *b) diff --git a/test/option_parser.c b/test/option_parser.c index 3b942d8..bb44954 100644 --- a/test/option_parser.c +++ b/test/option_parser.c @@ -1,10 +1,6 @@ +#include "src/option_parser.c" #include "greatest.h" -#include -#include - -#include "src/option_parser.h" - TEST test_next_section(void) { const char *section = NULL; diff --git a/test/utils.c b/test/utils.c index 91e99fb..04cd223 100644 --- a/test/utils.c +++ b/test/utils.c @@ -1,7 +1,5 @@ +#include "src/utils.c" #include "greatest.h" -#include "src/utils.h" - -#include TEST test_string_replace_char(void) {