Browse Source

seperated tests target into seperate targets for running tests and coverage

T. Meissner 3 years ago
parent
commit
7db34e79ce
2 changed files with 49 additions and 37 deletions
  1. 25
    18
      tdd_for_embedded_c/chapter02/Makefile
  2. 24
    19
      tdd_for_embedded_c/chapter03/Makefile

+ 25
- 18
tdd_for_embedded_c/chapter02/Makefile View File

@@ -6,18 +6,18 @@
6 6
 
7 7
 #We try to detect the OS we are running on, and adjust commands as needed
8 8
 ifeq ($(OS),Windows_NT)
9
-	CLEANUP = del /F /Q
10
-	MKDIR = mkdir
11
-	TARGET_EXTENSION=.exe
9
+	CLEANUP          := del /F /Q
10
+	MKDIR            := mkdir
11
+	TARGET_EXTENSION := .exe
12 12
 else
13
-	CLEANUP = rm -rf
14
-	MKDIR = mkdir -p
15
-	TARGET_EXTENSION=
13
+	CLEANUP          := rm -rf
14
+	MKDIR            := mkdir -p
15
+	TARGET_EXTENSION :=
16 16
 endif
17 17
 
18 18
 
19
-UNITY_ROOT=../../../../../Git/Unity
20
-C_COMPILER=gcc
19
+UNITY_ROOT := ../../../../Unity
20
+C_COMPILER := gcc
21 21
 
22 22
 CFLAGS = -std=c11
23 23
 CFLAGS += -Wall
@@ -40,33 +40,40 @@ CFLAGS += -g
40 40
 CFLAGS += -ftest-coverage
41 41
 CFLAGS += -fprofile-arcs
42 42
 
43
-TARGET_BASE=test_sprintf
44
-TARGET = $(TARGET_BASE)$(TARGET_EXTENSION)
45
-SRC_FILES=\
43
+TARGET_BASE := test_sprintf
44
+TARGET       = $(TARGET_BASE)$(TARGET_EXTENSION)
45
+
46
+SRC_FILES = \
46 47
 	$(UNITY_ROOT)/extras/fixture/src/unity_fixture.c \
47 48
 	$(UNITY_ROOT)/src/unity.c \
48 49
 	../test/SprintfTest.c \
49 50
 	../test/SprintfTestRunner.c \
50 51
 	../test/AllTests.c
51
-INC_DIRS=-I$(UNITY_ROOT)/src -I$(UNITY_ROOT)/extras/fixture/src
52
-SYMBOLS=
53 52
 
53
+INC_DIRS = -I$(UNITY_ROOT)/src -I$(UNITY_ROOT)/extras/fixture/src
54
+SYMBOLS  =
54 55
 
55
-all: clean tests
56 56
 
57
+all: clean tests cover
57 58
 
58
-.PHONY: tests
59
-tests: build/$(TARGET)
60 59
 
61 60
 build/$(TARGET):	test/*.c
61
+	@$(MKDIR) build
62
+	@$(MKDIR) build/cover
62 63
 	@echo "Compiling"; cd build; $(C_COMPILER) $(CFLAGS) $(INC_DIRS) $(SYMBOLS) $(SRC_FILES) -o $(TARGET)
64
+
65
+.PHONY: tests
66
+tests: build/$(TARGET)
63 67
 	@echo "Running tests"; ./build/$(TARGET)
68
+
69
+.PHONY: cover
70
+cover: tests
64 71
 	@echo "Preparing coverage"; cp build/*.gc* test/
65
-	@echo "Running coverage"; cd test; gcovr -r . -b -p --html --html-details -o ../build/cover/$(TARGET).html
72
+	@echo "Running coverage"; cd test; gcovr -r . -b -p --html --html-details -o ../build/cover/test.html
66 73
 	@echo "Clearing intermediate files"; rm test/*.gc* build/*.gc*
67 74
 
68 75
 
69 76
 .PHONY: clean
70 77
 clean:
71
-	@echo "Cleaning $<"; $(CLEANUP) build/$(TARGET) build/cover/*
78
+	@echo "Cleaning $<"; $(CLEANUP) build
72 79
 

+ 24
- 19
tdd_for_embedded_c/chapter03/Makefile View File

@@ -6,18 +6,18 @@
6 6
 
7 7
 #We try to detect the OS we are running on, and adjust commands as needed
8 8
 ifeq ($(OS),Windows_NT)
9
-	CLEANUP = del /F /Q
10
-	MKDIR = mkdir
11
-	TARGET_EXTENSION=.exe
9
+	CLEANUP          := del /F /Q
10
+	MKDIR            := mkdir
11
+	TARGET_EXTENSION := .exe
12 12
 else
13
-	CLEANUP = rm -rf
14
-	MKDIR = mkdir -p
15
-	TARGET_EXTENSION=
13
+	CLEANUP          := rm -rf
14
+	MKDIR            := mkdir -p
15
+	TARGET_EXTENSION :=
16 16
 endif
17 17
 
18 18
 
19
-UNITY_ROOT=../../../../../Git/Unity
20
-C_COMPILER=gcc
19
+UNITY_ROOT := ../../../../Unity
20
+C_COMPILER := gcc
21 21
 
22 22
 CFLAGS = -std=c11
23 23
 CFLAGS += -Wall
@@ -40,9 +40,10 @@ CFLAGS += -g
40 40
 CFLAGS += -ftest-coverage
41 41
 CFLAGS += -fprofile-arcs
42 42
 
43
-TARGET_BASE=test_leddriver
44
-TARGET = $(TARGET_BASE)$(TARGET_EXTENSION)
45
-SRC_FILES=\
43
+TARGET_BASE := test_leddriver
44
+TARGET       = $(TARGET_BASE)$(TARGET_EXTENSION)
45
+
46
+SRC_FILES = \
46 47
 	$(UNITY_ROOT)/extras/fixture/src/unity_fixture.c \
47 48
 	$(UNITY_ROOT)/src/unity.c \
48 49
 	../test/LedDriverTest.c \
@@ -50,19 +51,24 @@ SRC_FILES=\
50 51
 	../test/AllTests.c \
51 52
 	../src/LedDriver.c
52 53
 
53
-INC_DIRS=-I$(UNITY_ROOT)/src -I$(UNITY_ROOT)/extras/fixture/src
54
-SYMBOLS=
54
+INC_DIRS = -I$(UNITY_ROOT)/src -I$(UNITY_ROOT)/extras/fixture/src
55
+SYMBOLS  =
55 56
 
56 57
 
57
-all: clean tests
58
+all: clean tests cover
58 59
 
59 60
 
60
-.PHONY: tests
61
-tests: build/$(TARGET)
62
-
63 61
 build/$(TARGET):	test/*.c src/*.h src/*.c
62
+	@$(MKDIR) build
63
+	@$(MKDIR) build/cover
64 64
 	@echo "Compiling"; cd build; $(C_COMPILER) $(CFLAGS) $(INC_DIRS) $(SYMBOLS) $(SRC_FILES) -o $(TARGET)
65
+
66
+.PHONY: tests
67
+tests: build/$(TARGET)
65 68
 	@echo "Running tests"; ./build/$(TARGET)
69
+
70
+.PHONY: cover
71
+cover: tests
66 72
 	@echo "Preparing coverage"; cp build/LedDriver.gc* src/
67 73
 	@echo "Running coverage"; cd src; gcovr -r . -b -p --html --html-details -o ../build/cover/test.html
68 74
 	@echo "Clearing intermediate files"; rm src/*.gc* build/*.gc*
@@ -70,5 +76,4 @@ build/$(TARGET):	test/*.c src/*.h src/*.c
70 76
 
71 77
 .PHONY: clean
72 78
 clean:
73
-	@echo "Cleaning $<"; $(CLEANUP) build/$(TARGET) build/*.* build/cover/*
74
-
79
+	@echo "Cleaning $<"; $(CLEANUP) build