OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-cogutil commits / 5702f8d

Move cxxtest boilerplate out of the way
5702f8d5128bf93c59f6bdfc2f240dbbc1e4de11
by Linas Vepstas <linasvepstas@gmail.com> · 2025-12-19T01:58:23.000Z

Changed files (3) +79 -35

CMakeLists.txt +4 -35
……@@ -94,10 +94,8 @@ ENDIF (CYGWIN)
9494# ===================================================================
9595# Check for existence of various required, optional packages.
9696
97FIND_PACKAGE(Cxxtest)
98IF (NOT CXXTEST_FOUND)
99 MESSAGE(STATUS "CxxTest missing: needed for unit tests.")
100ENDIF (NOT CXXTEST_FOUND)
97# CxxTest setup (also provides OPENCOG_SETUP_TESTING macro)
98INCLUDE(OpenCogTestOptions)
10199
102100# -------------------------------------------------------------
103101# Look for GNU C++ backtrace. Needed for basic stack printing.
……@@ -170,37 +168,8 @@ ADD_SUBDIRECTORY(etc)
170168ADD_SUBDIRECTORY(lib)
171169ADD_SUBDIRECTORY(opencog)
172170
173IF (CXXTEST_FOUND)
174 # Enable CTest support so that 'ctest' command works
175 ENABLE_TESTING()
176 ADD_CUSTOM_TARGET(tests)
177 ADD_SUBDIRECTORY(tests EXCLUDE_FROM_ALL)
178 IF (CMAKE_BUILD_TYPE STREQUAL "Coverage")
179 # doing coverage stuff while running tests if this is the Coverage build
180 ADD_CUSTOM_TARGET(check
181 # TODO lcov should be found by cmake first
182 # TODO set it up so that we can pick to run coverage per test, or
183 # combined across all tests (the latter is MUCH faster). Use a define?
184 # There is coverage specific stuff in AddCxxTest.cmake now...
185 # -
186 WORKING_DIRECTORY tests
187 COMMAND ${CMAKE_CTEST_COMMAND} --force-new-ctest-process $(ARGS)
188 # This script combines the coverage analysis of each test,
189 # then creates html in tests/lcov
190 # Note: this should now be run separately...
191 #COMMAND ${PROJECT_SOURCE_DIR}/scripts/combine_lcov.sh
192 COMMENT "Running tests with coverage..."
193 )
194 ELSE (CMAKE_BUILD_TYPE STREQUAL "Coverage")
195 # If this is a build with coverage enabled then test normally
196 ADD_CUSTOM_TARGET(check
197 DEPENDS tests
198 WORKING_DIRECTORY tests
199 COMMAND ${CMAKE_CTEST_COMMAND} --force-new-ctest-process $(ARGS)
200 COMMENT "Running tests..."
201 )
202 ENDIF (CMAKE_BUILD_TYPE STREQUAL "Coverage")
203ENDIF (CXXTEST_FOUND)
171# Setup testing infrastructure (tests target, check target)
172OPENCOG_SETUP_TESTING()
204173
205174ADD_CUSTOM_TARGET(cscope
206175 COMMAND find opencog examples tests -name '*.cc' -o -name '*.h' -o -name '*.cxxtest' -o -name '*.scm' > ${CMAKE_SOURCE_DIR}/cscope.files
cmake/CMakeLists.txt +1 -0
……@@ -37,6 +37,7 @@ INSTALL(FILES
3737 OpenCogGccOptions.cmake
3838 OpenCogInstallOptions.cmake
3939 OpenCogLibOptions.cmake
40 OpenCogTestOptions.cmake
4041 Summary.cmake
4142 UseOCaml.cmake
4243 COPYING-CMAKE-SCRIPTS
cmake/OpenCogTestOptions.cmake +74 -0
……@@ -0,0 +1,74 @@
1# -------------------------------------------------
2# OpenCog Testing Configuration
3#
4# This module provides common CxxTest setup for all OpenCog projects.
5# It finds CxxTest, sets up the testing infrastructure, and provides
6# helper macros for creating test targets.
7#
8# Usage in downstream projects:
9# INCLUDE(OpenCogTestOptions)
10# ... add subdirectories for main code ...
11# OPENCOG_SETUP_TESTING() # Sets up tests target and check target
12# # Optionally add project-specific test targets:
13# OPENCOG_ADD_TEST_TARGET(test_foo tests/foo "Running foo tests...")
14
15# -------------------------------------------------
16# Find CxxTest
17
18FIND_PACKAGE(Cxxtest)
19IF (CXXTEST_FOUND)
20 MESSAGE(STATUS "CxxTest found.")
21ELSE (CXXTEST_FOUND)
22 MESSAGE(STATUS "CxxTest missing: needed for unit tests.")
23ENDIF (CXXTEST_FOUND)
24
25# -------------------------------------------------
26# Main setup macro - call this after ADD_SUBDIRECTORY for main code
27
28MACRO(OPENCOG_SETUP_TESTING)
29 IF (CXXTEST_FOUND)
30 # Enable CTest support so that 'ctest' command works
31 ENABLE_TESTING()
32
33 # Create the 'tests' target that all test executables depend on
34 ADD_CUSTOM_TARGET(tests)
35
36 # Add tests subdirectory (excluded from default 'all' target)
37 ADD_SUBDIRECTORY(tests EXCLUDE_FROM_ALL)
38
39 # Create the 'check' target with coverage support
40 IF (CMAKE_BUILD_TYPE STREQUAL "Coverage")
41 # Coverage build: run tests with coverage collection
42 ADD_CUSTOM_TARGET(check
43 WORKING_DIRECTORY tests
44 COMMAND ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --output-on-failure $(ARGS)
45 COMMENT "Running tests with coverage..."
46 )
47 ELSE (CMAKE_BUILD_TYPE STREQUAL "Coverage")
48 # Normal build: just run tests
49 ADD_CUSTOM_TARGET(check
50 DEPENDS tests
51 WORKING_DIRECTORY tests
52 COMMAND ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --output-on-failure $(ARGS)
53 COMMENT "Running tests..."
54 )
55 ENDIF (CMAKE_BUILD_TYPE STREQUAL "Coverage")
56 ENDIF (CXXTEST_FOUND)
57ENDMACRO(OPENCOG_SETUP_TESTING)
58
59# -------------------------------------------------
60# Helper macro to add project-specific test targets
61#
62# Usage: OPENCOG_ADD_TEST_TARGET(target_name working_directory comment)
63# Example: OPENCOG_ADD_TEST_TARGET(test_query tests/query "Running query tests...")
64
65MACRO(OPENCOG_ADD_TEST_TARGET _target_name _working_dir _comment)
66 IF (CXXTEST_FOUND)
67 ADD_CUSTOM_TARGET(${_target_name}
68 DEPENDS tests
69 WORKING_DIRECTORY ${_working_dir}
70 COMMAND ${CMAKE_CTEST_COMMAND} $(ARGS)
71 COMMENT ${_comment}
72 )
73 ENDIF (CXXTEST_FOUND)
74ENDMACRO(OPENCOG_ADD_TEST_TARGET)