Skip to content

Commit 8c49bc2

Browse files
committed
Cleanup dependencies in unit test builds, check number of tests
1 parent a608875 commit 8c49bc2

File tree

4 files changed

+42
-25
lines changed

4 files changed

+42
-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...
@@ -126,16 +123,23 @@ OBJ += $(CPROVER_LIBS) \
126123
$(CPROVER_DIR)/unit/testing-utils/testing-utils$(LIBEXT) \
127124
java-testing-utils/java-testing-utils$(LIBEXT)
128125

129-
TESTS = unit_tests$(EXEEXT) \
130-
# Empty last line
126+
CATCH_TEST = unit_tests$(EXEEXT)
127+
N_CATCH_TESTS = $(shell \
128+
cat $$(find . -name "*.cpp" ) | \
129+
grep -c -E "(SCENARIO|TEST_CASE)")
130+
131+
CLEANFILES = $(CATCH_TEST) java-testing-utils/java-testing-utils$(LIBEXT)
131132

132-
CLEANFILES = $(TESTS)
133+
# only add a dependency for libraries to avoid triggering implicit rules, which
134+
# would cause unnecessary rebuilds
135+
$(filter %$(LIBEXT), CPROVER_LIBS): jprover.dir
133136

134-
all: cprover.dir cprover-testing-utils.dir jprover.dir java-testing-utils.dir
135-
$(MAKE) $(MAKEARGS) $(TESTS)
137+
all: $(CATCH_TEST)
136138

137-
test: all
138-
$(foreach test,$(TESTS), (echo Running: $(test); ./$(test)) &&) true
139+
test: $(CATCH_TEST)
140+
if ! ./$(CATCH_TEST) -l | grep -q "^$(N_CATCH_TESTS) test cases" ; then \
141+
./$(CATCH_TEST) -l ; fi
142+
./$(CATCH_TEST)
139143

140144

141145
###############################################################################

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: 20 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...
@@ -97,17 +97,29 @@ CPROVER_LIBS =../src/ansi-c/ansi-c$(LIBEXT) \
9797

9898
OBJ += $(CPROVER_LIBS) testing-utils/testing-utils$(LIBEXT)
9999

100-
TESTS = unit_tests$(EXEEXT) \
101-
miniBDD$(EXEEXT) \
100+
CATCH_TEST = unit_tests$(EXEEXT)
101+
N_CATCH_TESTS = $(shell \
102+
cat $$(find . -name "*.cpp" \
103+
-and -not -name "miniBDD_new.cpp" \
104+
-and -not -name "catch_example.cpp") | \
105+
grep -c -E "(SCENARIO|TEST_CASE)")
106+
107+
TESTS = miniBDD$(EXEEXT) \
102108
# Empty last line
103109

104-
CLEANFILES = $(TESTS)
110+
CLEANFILES = $(CATCH_TEST) $(TESTS) testing-utils/testing-utils$(LIBEXT)
111+
112+
# only add a dependency for libraries to avoid triggering implicit rules, which
113+
# would cause unnecessary rebuilds
114+
$(filter %$(LIBEXT), CPROVER_LIBS): cprover.dir
105115

106-
all: cprover.dir testing-utils.dir
107-
$(MAKE) $(MAKEARGS) $(TESTS)
116+
all: $(CATCH_TEST) $(TESTS)
108117

109-
test: all
118+
test: $(CATCH_TEST) $(TESTS)
110119
$(foreach test,$(TESTS), (echo Running: $(test); ./$(test)) &&) true
120+
if ! ./$(CATCH_TEST) -l | grep -q "^$(N_CATCH_TESTS) test cases" ; then \
121+
./$(CATCH_TEST) -l ; fi
122+
./$(CATCH_TEST)
111123

112124

113125
###############################################################################

0 commit comments

Comments
 (0)