| … | … | @@ -94,10 +94,8 @@ ENDIF (CYGWIN) |
| 94 | 94 | # =================================================================== |
| 95 | 95 | # Check for existence of various required, optional packages. |
| 96 | 96 | |
| 97 | FIND_PACKAGE(Cxxtest) | |
| 98 | IF (NOT CXXTEST_FOUND) | |
| 99 | MESSAGE(STATUS "CxxTest missing: needed for unit tests.") | |
| 100 | ENDIF (NOT CXXTEST_FOUND) | |
| 97 | # CxxTest setup (also provides OPENCOG_SETUP_TESTING macro) | |
| 98 | INCLUDE(OpenCogTestOptions) | |
| 101 | 99 | |
| 102 | 100 | # ------------------------------------------------------------- |
| 103 | 101 | # Look for GNU C++ backtrace. Needed for basic stack printing. |
| … | … | @@ -170,37 +168,8 @@ ADD_SUBDIRECTORY(etc) |
| 170 | 168 | ADD_SUBDIRECTORY(lib) |
| 171 | 169 | ADD_SUBDIRECTORY(opencog) |
| 172 | 170 | |
| 173 | IF (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") | |
| 203 | ENDIF (CXXTEST_FOUND) | |
| 171 | # Setup testing infrastructure (tests target, check target) | |
| 172 | OPENCOG_SETUP_TESTING() | |
| 204 | 173 | |
| 205 | 174 | ADD_CUSTOM_TARGET(cscope |
| 206 | 175 | COMMAND find opencog examples tests -name '*.cc' -o -name '*.h' -o -name '*.cxxtest' -o -name '*.scm' > ${CMAKE_SOURCE_DIR}/cscope.files |
| … | … | @@ -37,6 +37,7 @@ INSTALL(FILES |
| 37 | 37 | OpenCogGccOptions.cmake |
| 38 | 38 | OpenCogInstallOptions.cmake |
| 39 | 39 | OpenCogLibOptions.cmake |
| 40 | OpenCogTestOptions.cmake | |
| 40 | 41 | Summary.cmake |
| 41 | 42 | UseOCaml.cmake |
| 42 | 43 | COPYING-CMAKE-SCRIPTS |
| … | … | @@ -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 | ||
| 18 | FIND_PACKAGE(Cxxtest) | |
| 19 | IF (CXXTEST_FOUND) | |
| 20 | MESSAGE(STATUS "CxxTest found.") | |
| 21 | ELSE (CXXTEST_FOUND) | |
| 22 | MESSAGE(STATUS "CxxTest missing: needed for unit tests.") | |
| 23 | ENDIF (CXXTEST_FOUND) | |
| 24 | ||
| 25 | # ------------------------------------------------- | |
| 26 | # Main setup macro - call this after ADD_SUBDIRECTORY for main code | |
| 27 | ||
| 28 | MACRO(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) | |
| 57 | ENDMACRO(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 | ||
| 65 | MACRO(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) | |
| 74 | ENDMACRO(OPENCOG_ADD_TEST_TARGET) |