Skip to content

Commit f32ae14

Browse files
committed
Cleanup dependencies in unit test builds, check number of tests
1 parent f1ff4fe commit f32ae14

File tree

4 files changed

+53
-25
lines changed

4 files changed

+53
-25
lines changed

jbmc/unit/Makefile

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: all cprover.dir jprover.dir testing-utils.dir java-testing-utils.dir test
1+
.PHONY: all jprover.dir test java-testing-utils-clean
22

33
# Source files for test utilities
44
SRC = $(CPROVER_DIR)/unit/unit_tests.cpp \
@@ -64,18 +64,18 @@ include ../src/config.inc
6464
include $(CPROVER_DIR)/src/config.inc
6565
include $(CPROVER_DIR)/src/common
6666

67-
cprover.dir:
68-
$(MAKE) $(MAKEARGS) -C $(CPROVER_DIR)/src
69-
7067
jprover.dir:
7168
$(MAKE) $(MAKEARGS) -C ../src
7269

73-
cprover-testing-utils.dir:
70+
$(CPROVER_DIR)/unit/testing-utils/testing-utils$(LIBEXT): jprover.dir
7471
$(MAKE) $(MAKEARGS) -C $(CPROVER_DIR)/unit/testing-utils
7572

76-
java-testing-utils.dir:
73+
java-testing-utils/java-testing-utils$(LIBEXT): jprover.dir
7774
$(MAKE) $(MAKEARGS) -C java-testing-utils
7875

76+
java-testing-utils-clean:
77+
$(MAKE) $(MAKEARGS) -C java-testing-utils clean
78+
7979
# We need to link bmc.o to the unit test, so here's everything it depends on...
8080
BMC_DEPS =$(CPROVER_DIR)/src/cbmc/all_properties$(OBJEXT) \
8181
$(CPROVER_DIR)/src/cbmc/bmc$(OBJEXT) \
@@ -138,16 +138,25 @@ OBJ += $(CPROVER_LIBS) \
138138
$(CPROVER_DIR)/unit/testing-utils/testing-utils$(LIBEXT) \
139139
java-testing-utils/java-testing-utils$(LIBEXT)
140140

141-
TESTS = unit_tests$(EXEEXT) \
142-
# Empty last line
141+
CATCH_TEST = unit_tests$(EXEEXT)
142+
N_CATCH_TESTS = $(shell \
143+
cat $$(find . -name "*.cpp" ) | \
144+
grep -c -E "(SCENARIO|TEST_CASE)")
145+
146+
CLEANFILES = $(CATCH_TEST) java-testing-utils/java-testing-utils$(LIBEXT)
147+
148+
# only add a dependency for libraries to avoid triggering implicit rules, which
149+
# would cause unnecessary rebuilds
150+
$(filter %$(LIBEXT), CPROVER_LIBS): jprover.dir
143151

144-
CLEANFILES = $(TESTS)
152+
all: $(CATCH_TEST)
145153

146-
all: cprover.dir cprover-testing-utils.dir jprover.dir java-testing-utils.dir
147-
$(MAKE) $(MAKEARGS) $(TESTS)
154+
clean: java-testing-utils-clean
148155

149-
test: all
150-
$(foreach test,$(TESTS), (echo Running: $(test); ./$(test)) &&) true
156+
test: $(CATCH_TEST)
157+
if ! ./$(CATCH_TEST) -l | grep -q "^$(N_CATCH_TESTS) test cases" ; then \
158+
./$(CATCH_TEST) -l ; fi
159+
./$(CATCH_TEST)
151160

152161

153162
###############################################################################

src/ansi-c/Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ cprover_library.inc: library/converter$(EXEEXT) library/*.c
115115
%.inc: %.h file_converter$(EXEEXT)
116116
./file_converter$(EXEEXT) < $< > $@
117117

118-
cprover_library.cpp: cprover_library.inc
119-
120118
ansi_c_internal_additions$(OBJEXT): $(BUILTIN_FILES)
121119

122120
generated_files: \

src/cpp/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ all: cpp$(LIBEXT)
5959

6060
###############################################################################
6161

62+
# extra dependencies
63+
cprover_library$(OBJEXT): cprover_library.inc
64+
65+
###############################################################################
66+
6267
../ansi-c/library/converter$(EXEEXT): ../ansi-c/library/converter.cpp
6368
$(MAKE) -C ../ansi-c library/converter$(EXEEXT)
6469

@@ -69,8 +74,6 @@ library_check: library/*.c
6974
cprover_library.inc: ../ansi-c/library/converter$(EXEEXT) library/*.c
7075
cat library/*.c | ../ansi-c/library/converter$(EXEEXT) > $@
7176

72-
cprover_library.cpp: cprover_library.inc
73-
7477
generated_files: cprover_library.inc
7578

7679
###############################################################################

unit/Makefile

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: all cprover.dir testing-utils.dir test
1+
.PHONY: all cprover.dir test testing-utils-clean
22

33
# Source files for test utilities
44
SRC = unit_tests.cpp \
@@ -56,9 +56,12 @@ include ../src/common
5656
cprover.dir:
5757
$(MAKE) $(MAKEARGS) -C ../src
5858

59-
testing-utils.dir:
59+
testing-utils/testing-utils$(LIBEXT): cprover.dir
6060
$(MAKE) $(MAKEARGS) -C testing-utils
6161

62+
testing-utils-clean:
63+
$(MAKE) $(MAKEARGS) -C testing-utils clean
64+
6265
# We need to link bmc.o to the unit test, so here's everything it depends on...
6366
BMC_DEPS =../src/cbmc/all_properties$(OBJEXT) \
6467
../src/cbmc/bmc$(OBJEXT) \
@@ -107,17 +110,32 @@ CPROVER_LIBS =../src/ansi-c/ansi-c$(LIBEXT) \
107110

108111
OBJ += $(CPROVER_LIBS) testing-utils/testing-utils$(LIBEXT)
109112

110-
TESTS = unit_tests$(EXEEXT) \
111-
miniBDD$(EXEEXT) \
113+
CATCH_TEST = unit_tests$(EXEEXT)
114+
N_CATCH_TESTS = $(shell \
115+
cat $$(find . -name "*.cpp" \
116+
-and -not -name "miniBDD_new.cpp" \
117+
-and -not -name "catch_example.cpp" \
118+
-a -not -name "expr_undefined_casts.cpp") | \
119+
grep -c -E "(SCENARIO|TEST_CASE)")
120+
121+
TESTS = miniBDD$(EXEEXT) \
112122
# Empty last line
113123

114-
CLEANFILES = $(TESTS)
124+
CLEANFILES = $(CATCH_TEST) $(TESTS) testing-utils/testing-utils$(LIBEXT)
125+
126+
# only add a dependency for libraries to avoid triggering implicit rules, which
127+
# would cause unnecessary rebuilds
128+
$(filter %$(LIBEXT), CPROVER_LIBS): cprover.dir
129+
130+
all: $(CATCH_TEST) $(TESTS)
115131

116-
all: cprover.dir testing-utils.dir
117-
$(MAKE) $(MAKEARGS) $(TESTS)
132+
clean: testing-utils-clean
118133

119-
test: all
134+
test: $(CATCH_TEST) $(TESTS)
120135
$(foreach test,$(TESTS), (echo Running: $(test); ./$(test)) &&) true
136+
if ! ./$(CATCH_TEST) -l | grep -q "^$(N_CATCH_TESTS) test cases" ; then \
137+
./$(CATCH_TEST) -l ; fi
138+
./$(CATCH_TEST)
121139

122140

123141
###############################################################################

0 commit comments

Comments
 (0)