From 8112dda4e852d3cc8658a82cd1fb376287815bfc Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Wed, 27 Jul 2016 10:45:53 +0100 Subject: [PATCH] make should fail in case of test failure --- Makefile | 12 +++++++----- tests/c/minunit.h | 1 + tests/c/test_error_string.c | 4 ++-- tests/c/test_hashes_length.c | 12 +++++------- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index b1cff16..709c665 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ SRCS = src/errors.c src/hashes.c OBJS = $(SRCS:.c=.o) src/%.o: src/%.c - $(CC) $(CFLAGS) -c -I include $^ -o $@ + $(CC) $(CFLAGS) -c -I include $< -o $@ all: $(TARGET_LIB) $(TARGET_BIN) @@ -44,11 +44,13 @@ test: $(TEST_BINS) @for t in $^; do \ echo; \ echo '***' "$$t.c" '***'; \ - "./$$t" || printf "\n!!! TEST FAILURE !!!\n"; \ - done + "./$$t" || ERROR=1; \ + done; \ + echo; \ + [ "$${ERROR-0}" -eq "1" ] && exit 1 -tests/c/test_%.o: tests/c/test_%.c - $(CC) $(CFLAGS) -c -I include $^ -o $@ +tests/c/test_%.o: tests/c/test_%.c tests/c/minunit.h + $(CC) $(CFLAGS) -c -I include $< -o $@ tests/c/test_%: tests/c/test_%.o $(TARGET_LIB) $(CC) $(LDFLAGS) $^ -o $@ diff --git a/tests/c/minunit.h b/tests/c/minunit.h index 4a36485..825fbf8 100644 --- a/tests/c/minunit.h +++ b/tests/c/minunit.h @@ -11,6 +11,7 @@ int main(void) { char *result = mu_all_tests(); if (result != NULL) { printf("error: %s\n", result); + printf("!!! TEST FAILURE !!!\n"); } else { printf("ALL TESTS PASSED\n"); diff --git a/tests/c/test_error_string.c b/tests/c/test_error_string.c index 79d881e..1b219f8 100644 --- a/tests/c/test_error_string.c +++ b/tests/c/test_error_string.c @@ -9,8 +9,8 @@ char error_buf[256]; static char *test_error_messages_exist(void) { int i = -1; for (; i > MH_E_LAST; i--) { - sprintf(error_buf, "error: code %d has no message", i); - mu_assert(error_buf, strlen(mh_error_string((mh_error) i))); + sprintf(error_buf, "error code %d has no message", i); + mu_assert(error_buf, strlen(mh_error_string((mh_error) i)) > 0); } return NULL; diff --git a/tests/c/test_hashes_length.c b/tests/c/test_hashes_length.c index dd702b6..56af2c5 100644 --- a/tests/c/test_hashes_length.c +++ b/tests/c/test_hashes_length.c @@ -10,13 +10,11 @@ static char *test_all_hashes_have_lengths(void) { int i = 0; int length = 0; for (; i < MH_H_COUNT; i++) { - length = mh_hash_default_length(i); - if (length <= 0) { - sprintf(error_buf, "mh_hash_default_length: hash %d" - " returned invalid (%d) default length", - i, length); - return error_buf; - } + length = mh_hash_default_length((mh_hash) i); + sprintf(error_buf, "mh_hash_default_length: hash %d" + " returned invalid (%d) default length", + i, length); + mu_assert(error_buf, length > 0); } return NULL; }