Skip to content

Commit 9e48907

Browse files
committed
Cleanup dependencies in unit test builds, check number of tests
1 parent e575a53 commit 9e48907

File tree

4 files changed

+43
-25
lines changed

4 files changed

+43
-25
lines changed

jbmc/unit/Makefile

Lines changed: 17 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
22

33
# Source files for test utilities
44
SRC = $(CPROVER_DIR)/unit/unit_tests.cpp \
@@ -64,16 +64,13 @@ 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

7976
# We need to link bmc.o to the unit test, so here's everything it depends on...
@@ -141,16 +138,23 @@ OBJ += $(CPROVER_LIBS) \
141138
$(CPROVER_DIR)/unit/testing-utils/testing-utils$(LIBEXT) \
142139
java-testing-utils/java-testing-utils$(LIBEXT)
143140

144-
TESTS = unit_tests$(EXEEXT) \
145-
# 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)
146147

147-
CLEANFILES = $(TESTS)
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
148151

149-
all: cprover.dir cprover-testing-utils.dir jprover.dir java-testing-utils.dir
150-
$(MAKE) $(MAKEARGS) $(TESTS)
152+
all: $(CATCH_TEST)
151153

152-
test: all
153-
$(foreach test,$(TESTS), (echo Running: $(test); ./$(test)) &&) true
154+
test: $(CATCH_TEST)
155+
if ! ./$(CATCH_TEST) -l | grep -q "^$(N_CATCH_TESTS) test cases" ; then \
156+
./$(CATCH_TEST) -l ; fi
157+
./$(CATCH_TEST)
154158

155159

156160
###############################################################################

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: 21 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
22

33
# Source files for test utilities
44
SRC = unit_tests.cpp \
@@ -56,7 +56,7 @@ 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

6262
# We need to link bmc.o to the unit test, so here's everything it depends on...
@@ -110,17 +110,30 @@ CPROVER_LIBS =../src/ansi-c/ansi-c$(LIBEXT) \
110110

111111
OBJ += $(CPROVER_LIBS) testing-utils/testing-utils$(LIBEXT)
112112

113-
TESTS = unit_tests$(EXEEXT) \
114-
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) \
115122
# Empty last line
116123

117-
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
118129

119-
all: cprover.dir testing-utils.dir
120-
$(MAKE) $(MAKEARGS) $(TESTS)
130+
all: $(CATCH_TEST) $(TESTS)
121131

122-
test: all
132+
test: $(CATCH_TEST) $(TESTS)
123133
$(foreach test,$(TESTS), (echo Running: $(test); ./$(test)) &&) true
134+
if ! ./$(CATCH_TEST) -l | grep -q "^$(N_CATCH_TESTS) test cases" ; then \
135+
./$(CATCH_TEST) -l ; fi
136+
./$(CATCH_TEST)
124137

125138

126139
###############################################################################

0 commit comments

Comments
 (0)