Allow more variety in unit test program file names

They can now be called test_*.cpp or *_test.cpp
This commit is contained in:
Roland Kaufmann 2013-02-22 09:40:40 +01:00
parent 77d214be8e
commit c16864e7a5
3 changed files with 24 additions and 9 deletions

View File

@ -237,7 +237,7 @@ cond_disable_test ("ERT")
# make datafiles necessary for tests available in output directory
opm_data (tests datafiles "${tests_DIR}" "*.xml")
opm_compile_satellites (opm-core tests "" "^test_([^/]*)$")
opm_compile_satellites (opm-core tests "" "${tests_REGEXP}")
# use this target to run all tests
add_custom_target (check

View File

@ -41,8 +41,19 @@ macro (opm_find_tests)
# every C++ program prefixed with test_ under tests/ directory should
# be automatically set up as a test
set (tests_DIR "tests")
file (GLOB_RECURSE tests_SOURCES "${tests_DIR}/test_*.cpp")
file (GLOB_RECURSE not_tests_SOURCES "${tests_DIR}/not-unit/test_*.cpp")
file (GLOB_RECURSE tests_SOURCES
"${tests_DIR}/test_*.cpp"
"${tests_DIR}/*_test.cpp"
)
file (GLOB_RECURSE not_tests_SOURCES
"${tests_DIR}/not-unit/test_*.cpp"
"${tests_DIR}/not-unit/*_test.cpp"
)
# how to retrieve the "fancy" name from the filename
set (tests_REGEXP
"^test_([^/]*)$"
"^([^/]*)_test$"
)
if (tests_SOURCES AND not_tests_SOURCES)
list (REMOVE_ITEM tests_SOURCES ${not_tests_SOURCES})
endif (tests_SOURCES AND not_tests_SOURCES)

View File

@ -64,19 +64,23 @@ macro (opm_compile_satellites opm satellite excl_all test_regexp)
# are we building a test? luckily, the testing framework doesn't
# require anything else, so we don't have to figure out where it
# should go in the library list
if (NOT ${test_regexp} STREQUAL "")
if (NOT "${test_regexp}" STREQUAL "")
set (_test_lib "${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}")
else (NOT ${test_regexp} STREQUAL "")
else (NOT "${test_regexp}" STREQUAL "")
set (_test_lib "")
endif (NOT ${test_regexp} STREQUAL "")
endif (NOT "${test_regexp}" STREQUAL "")
target_link_libraries (${_sat_NAME} ${${opm}_TARGET} ${${opm}_LIBRARIES} ${_test_lib})
strip_debug_symbols (${_sat_NAME} _sat_DEBUG)
list (APPEND ${satellite}_DEBUG ${_sat_DEBUG})
# variable with regular expression doubles as a flag for
# whether tests should be setup or not
if (NOT ${test_regexp} STREQUAL "")
string (REGEX REPLACE "${test_regexp}" "\\1" _sat_FANCY "${_sat_NAME}")
if (NOT "${test_regexp}" STREQUAL "")
foreach (_regexp IN ITEMS ${test_regexp})
if ("${_sat_NAME}" MATCHES "${_regexp}")
string (REGEX REPLACE "${_regexp}" "\\1" _sat_FANCY "${_sat_NAME}")
endif ("${_sat_NAME}" MATCHES "${_regexp}")
endforeach (_regexp)
get_target_property (_sat_LOC ${_sat_NAME} LOCATION)
if (CMAKE_VERSION VERSION_LESS "2.8.4")
add_test (
@ -90,7 +94,7 @@ macro (opm_compile_satellites opm satellite excl_all test_regexp)
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/${${satellite}_DIR}
)
endif (CMAKE_VERSION VERSION_LESS "2.8.4")
endif(NOT ${test_regexp} STREQUAL "")
endif(NOT "${test_regexp}" STREQUAL "")
endforeach (_sat_FILE)
endmacro (opm_compile_satellites opm prefix)