From a58054b0137c46f826cee86e145e427389a21884 Mon Sep 17 00:00:00 2001 From: mvandervoord Date: Mon, 16 Mar 2020 19:33:51 -0400 Subject: [PATCH] Update makefile to run tests. tweak broken tests. --- test/Makefile | 107 ++++++++++++++++++++++++++--- test/tests/self_assessment_utils.h | 15 ++++ test/tests/test_unity_floats.c | 5 -- test/tests/test_unity_integers.c | 10 --- 4 files changed, 114 insertions(+), 23 deletions(-) diff --git a/test/Makefile b/test/Makefile index e6ca9e0..d8d10d2 100644 --- a/test/Makefile +++ b/test/Makefile @@ -21,7 +21,14 @@ DEFINES += -D UNITY_OUTPUT_CHAR_HEADER_DECLARATION=putcharSpy\(int\) DEFINES += -D UNITY_OUTPUT_FLUSH=flushSpy DEFINES += -D UNITY_OUTPUT_FLUSH_HEADER_DECLARATION=flushSpy\(void\) DEFINES += $(UNITY_SUPPORT_64) $(UNITY_INCLUDE_DOUBLE) -SRC = ../src/unity.c tests/testunity.c build/testunityRunner.c +SRC1 = ../src/unity.c tests/test_unity_arrays.c build/test_unity_arraysRunner.c +SRC2 = ../src/unity.c tests/test_unity_core.c build/test_unity_coreRunner.c +SRC3 = ../src/unity.c tests/test_unity_doubles.c build/test_unity_doublesRunner.c +SRC4 = ../src/unity.c tests/test_unity_floats.c build/test_unity_floatsRunner.c +SRC5 = ../src/unity.c tests/test_unity_integers.c build/test_unity_integersRunner.c +SRC6 = ../src/unity.c tests/test_unity_integers_64.c build/test_unity_integers_64Runner.c +SRC7 = ../src/unity.c tests/test_unity_memory.c build/test_unity_memoryRunner.c +SRC8 = ../src/unity.c tests/test_unity_strings.c build/test_unity_stringsRunner.c INC_DIR = -I ../src COV_FLAGS = -fprofile-arcs -ftest-coverage -I ../../src BUILD_DIR = build @@ -31,17 +38,80 @@ TARGET = build/testunity-cov.exe # For verbose output of all the tests, run 'make test'. default: coverage .PHONY: default coverage test clean -coverage: $(BUILD_DIR)/testunityRunner.c +coverage: $(SRC1) $(SRC2) $(SRC3) $(SRC4) $(SRC5) $(SRC6) $(SRC7) $(SRC8) cd $(BUILD_DIR) && \ - $(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC), ../$i) $(COV_FLAGS) -o ../$(TARGET) + $(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC1), ../$i) $(COV_FLAGS) -o ../$(TARGET) + rm -f $(BUILD_DIR)/*.gcda + ./$(TARGET) | grep 'Tests\|]]]' -A1 + cd $(BUILD_DIR) && \ + gcov unity.c | head -3 + grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true + cd $(BUILD_DIR) && \ + $(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC2), ../$i) $(COV_FLAGS) -o ../$(TARGET) + rm -f $(BUILD_DIR)/*.gcda + ./$(TARGET) | grep 'Tests\|]]]' -A1 + cd $(BUILD_DIR) && \ + gcov unity.c | head -3 + grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true + cd $(BUILD_DIR) && \ + $(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC3), ../$i) $(COV_FLAGS) -o ../$(TARGET) + rm -f $(BUILD_DIR)/*.gcda + ./$(TARGET) | grep 'Tests\|]]]' -A1 + cd $(BUILD_DIR) && \ + gcov unity.c | head -3 + grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true + cd $(BUILD_DIR) && \ + $(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC4), ../$i) $(COV_FLAGS) -o ../$(TARGET) + rm -f $(BUILD_DIR)/*.gcda + ./$(TARGET) | grep 'Tests\|]]]' -A1 + cd $(BUILD_DIR) && \ + gcov unity.c | head -3 + grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true + cd $(BUILD_DIR) && \ + $(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC5), ../$i) $(COV_FLAGS) -o ../$(TARGET) + rm -f $(BUILD_DIR)/*.gcda + ./$(TARGET) | grep 'Tests\|]]]' -A1 + cd $(BUILD_DIR) && \ + gcov unity.c | head -3 + grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true + cd $(BUILD_DIR) && \ + $(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC6), ../$i) $(COV_FLAGS) -o ../$(TARGET) + rm -f $(BUILD_DIR)/*.gcda + ./$(TARGET) | grep 'Tests\|]]]' -A1 + cd $(BUILD_DIR) && \ + gcov unity.c | head -3 + grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true + cd $(BUILD_DIR) && \ + $(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC7), ../$i) $(COV_FLAGS) -o ../$(TARGET) + rm -f $(BUILD_DIR)/*.gcda + ./$(TARGET) | grep 'Tests\|]]]' -A1 + cd $(BUILD_DIR) && \ + gcov unity.c | head -3 + grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true + cd $(BUILD_DIR) && \ + $(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC8), ../$i) $(COV_FLAGS) -o ../$(TARGET) rm -f $(BUILD_DIR)/*.gcda ./$(TARGET) | grep 'Tests\|]]]' -A1 cd $(BUILD_DIR) && \ gcov unity.c | head -3 grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true -test: $(BUILD_DIR)/testunityRunner.c - $(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC) -o $(TARGET) +test: $(SRC1) $(SRC2) $(SRC3) $(SRC4) $(SRC5) $(SRC6) $(SRC7) $(SRC8) + $(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC1) -o $(TARGET) + ./$(TARGET) + $(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC2) -o $(TARGET) + ./$(TARGET) + $(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC3) -o $(TARGET) + ./$(TARGET) + $(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC4) -o $(TARGET) + ./$(TARGET) + $(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC5) -o $(TARGET) + ./$(TARGET) + $(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC6) -o $(TARGET) + ./$(TARGET) + $(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC7) -o $(TARGET) + ./$(TARGET) + $(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC8) -o $(TARGET) ./$(TARGET) # Compile only, for testing that preprocessor detection works @@ -50,8 +120,29 @@ intDetection: $(CC) $(CFLAGS) $(INC_DIR) $(UNITY_C_ONLY) -D UNITY_EXCLUDE_STDINT_H $(CC) $(CFLAGS) $(INC_DIR) $(UNITY_C_ONLY) -D UNITY_EXCLUDE_LIMITS_H -$(BUILD_DIR)/testunityRunner.c: tests/testunity.c | $(BUILD_DIR) - awk $(AWK_SCRIPT) tests/testunity.c > $@ +$(BUILD_DIR)/test_unity_arraysRunner.c: tests/test_unity_arrays.c | $(BUILD_DIR) + awk $(AWK_SCRIPT) tests/test_unity_arrays.c > $@ + +$(BUILD_DIR)/test_unity_coreRunner.c: tests/test_unity_core.c | $(BUILD_DIR) + awk $(AWK_SCRIPT) tests/test_unity_core.c > $@ + +$(BUILD_DIR)/test_unity_doublesRunner.c: tests/test_unity_doubles.c | $(BUILD_DIR) + awk $(AWK_SCRIPT) tests/test_unity_doubles.c > $@ + +$(BUILD_DIR)/test_unity_floatsRunner.c: tests/test_unity_floats.c | $(BUILD_DIR) + awk $(AWK_SCRIPT) tests/test_unity_floats.c > $@ + +$(BUILD_DIR)/test_unity_integersRunner.c: tests/test_unity_integers.c | $(BUILD_DIR) + awk $(AWK_SCRIPT) tests/test_unity_integers.c > $@ + +$(BUILD_DIR)/test_unity_integers_64Runner.c: tests/test_unity_integers_64.c | $(BUILD_DIR) + awk $(AWK_SCRIPT) tests/test_unity_integers_64.c > $@ + +$(BUILD_DIR)/test_unity_memoryRunner.c: tests/test_unity_memory.c | $(BUILD_DIR) + awk $(AWK_SCRIPT) tests/test_unity_memory.c > $@ + +$(BUILD_DIR)/test_unity_stringsRunner.c: tests/test_unity_strings.c | $(BUILD_DIR) + awk $(AWK_SCRIPT) tests/test_unity_strings.c > $@ AWK_SCRIPT=\ '/^void test/{ declarations[d++]=$$0; gsub(/\(?void\)? ?/,""); tests[t++]=$$0; line[u++]=NR } \ @@ -65,4 +156,4 @@ $(BUILD_DIR): mkdir -p $(BUILD_DIR) clean: - rm -f $(TARGET) $(BUILD_DIR)/*.gc* $(BUILD_DIR)/testunityRunner.c + rm -f $(TARGET) $(BUILD_DIR)/*.gc* $(BUILD_DIR)/test_unity_*Runner.c diff --git a/test/tests/self_assessment_utils.h b/test/tests/self_assessment_utils.h index e708387..14ee402 100644 --- a/test/tests/self_assessment_utils.h +++ b/test/tests/self_assessment_utils.h @@ -129,4 +129,19 @@ void flushSpy(void) if (flushSpyEnabled){ flushSpyCalls++; } } +#define TEST_ASSERT_EQUAL_PRINT_NUMBERS(expected, actual) { \ + startPutcharSpy(); UnityPrintNumber((actual)); endPutcharSpy(); \ + TEST_ASSERT_EQUAL_STRING((expected), getBufferPutcharSpy()); \ + } + +#define TEST_ASSERT_EQUAL_PRINT_UNSIGNED_NUMBERS(expected, actual) { \ + startPutcharSpy(); UnityPrintNumberUnsigned((actual)); endPutcharSpy(); \ + TEST_ASSERT_EQUAL_STRING((expected), getBufferPutcharSpy()); \ + } + +#define TEST_ASSERT_EQUAL_PRINT_FLOATING(expected, actual) { \ + startPutcharSpy(); UnityPrintFloat((actual)); endPutcharSpy(); \ + TEST_ASSERT_EQUAL_STRING((expected), getBufferPutcharSpy()); \ + } + #endif \ No newline at end of file diff --git a/test/tests/test_unity_floats.c b/test/tests/test_unity_floats.c index bbf761a..0444ee3 100644 --- a/test/tests/test_unity_floats.c +++ b/test/tests/test_unity_floats.c @@ -694,11 +694,6 @@ void testNotEqualFloatEachEqualLengthZero(void) #endif } -#define TEST_ASSERT_EQUAL_PRINT_FLOATING(expected, actual) { \ - startPutcharSpy(); UnityPrintFloat((actual)); endPutcharSpy(); \ - TEST_ASSERT_EQUAL_STRING((expected), getBufferPutcharSpy()); \ - } - void testFloatPrinting(void) { #if defined(UNITY_EXCLUDE_FLOAT_PRINT) || defined(UNITY_INCLUDE_DOUBLE) || !defined(USING_OUTPUT_SPY) diff --git a/test/tests/test_unity_integers.c b/test/tests/test_unity_integers.c index 3359bc7..ce8bdb0 100644 --- a/test/tests/test_unity_integers.c +++ b/test/tests/test_unity_integers.c @@ -2816,16 +2816,6 @@ void testHexPrintsUpToMaxNumberOfNibbles(void) #endif } -#define TEST_ASSERT_EQUAL_PRINT_NUMBERS(expected, actual) { \ - startPutcharSpy(); UnityPrintNumber((actual)); endPutcharSpy(); \ - TEST_ASSERT_EQUAL_STRING((expected), getBufferPutcharSpy()); \ - } - -#define TEST_ASSERT_EQUAL_PRINT_UNSIGNED_NUMBERS(expected, actual) { \ - startPutcharSpy(); UnityPrintNumberUnsigned((actual)); endPutcharSpy(); \ - TEST_ASSERT_EQUAL_STRING((expected), getBufferPutcharSpy()); \ - } - void testPrintNumbers32(void) { #ifndef USING_OUTPUT_SPY