From: Tim Kientzle Date: Thu, 7 May 2026 05:02:15 +0000 (-0700) Subject: Fix CMake-based testing X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f833d13e6df8d37f97e3d7123a96121b0124ce22;p=thirdparty%2Flibarchive.git Fix CMake-based testing --- diff --git a/CMakeLists.txt b/CMakeLists.txt index edc9a0d77..8ea5aaa4b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -374,6 +374,38 @@ MACRO (GENERATE_LIST_H _listfile _cmlist _target __list_sources) # Attaching list.h to the target tells CMake to build it before compiling. TARGET_SOURCES(${_target} PRIVATE "${_listfile}") ENDMACRO (GENERATE_LIST_H) + +# +# +# +MACRO(DISCOVER_TESTS _component __list_sources) + IF(ENABLE_TEST) + SET(_sources ${ARGV}) + LIST(REMOVE_AT _sources 0) + FOREACH(_src ${_sources}) + IF(_src MATCHES "test_[^/]+\\.c$") + FILE(STRINGS "${_src}" _lines REGEX "^DEFINE_TEST\(.*\)") + FOREACH(_line ${_lines}) + STRING(REGEX MATCH "DEFINE_TEST\((.*)\)" _full_match ${_line}) + # CMake REGEX seems to handle ( and \( rather inconsistently... + # So we go through an extra dance to definitively strip the parens + STRING(REPLACE "(" "" _test_name_with_paren "${CMAKE_MATCH_1}") + STRING(REPLACE ")" "" _test_name "${_test_name_with_paren}") + SET(_full_test_name "${_component}_${_test_name}") + MESSAGE("Found test ${_full_test_name} command ${_component}_test") + ADD_TEST(NAME ${_full_test_name} + COMMAND ${_component}_test -vv + -r ${CMAKE_CURRENT_SOURCE_DIR} + -s + ${_test_name}) + SET_TESTS_PROPERTIES(${_full_test_name} PROPERTIES SKIP_RETURN_CODE 2) + + ENDFOREACH() + ENDIF() + endforeach() + ENDIF(ENABLE_TEST) +ENDMACRO(DISCOVER_TESTS __sources) + # # Generate installation rules for man pages. # diff --git a/cat/test/CMakeLists.txt b/cat/test/CMakeLists.txt index 75180e285..1d5634146 100644 --- a/cat/test/CMakeLists.txt +++ b/cat/test/CMakeLists.txt @@ -3,7 +3,7 @@ # ############################################ # -# How to build bsdtar_test +# How to build bsdcat_test # ############################################ IF(ENABLE_CAT AND ENABLE_TEST) @@ -55,21 +55,8 @@ IF(ENABLE_CAT AND ENABLE_TEST) SET_PROPERTY(DIRECTORY APPEND PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}) - # list.h has a line DEFINE_TEST(testname) for every - # test. We can use that to define the tests for cmake by - # defining a DEFINE_TEST macro and reading list.h in. - MACRO (DEFINE_TEST _testname) - ADD_TEST( - NAME bsdcat_${_testname} - COMMAND bsdcat_test -vv - -p $ - -r ${CMAKE_CURRENT_SOURCE_DIR} - -s - ${_testname}) - SET_TESTS_PROPERTIES(bsdcat_${_testname} PROPERTIES SKIP_RETURN_CODE 2) - ENDMACRO (DEFINE_TEST _testname) + DISCOVER_TESTS(bsdcat ${bsdcat_test_SOURCES}) - INCLUDE(${CMAKE_CURRENT_BINARY_DIR}/list.h OPTIONAL) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/test_utils) INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/cat/test) diff --git a/cpio/test/CMakeLists.txt b/cpio/test/CMakeLists.txt index dad046414..bb1455ec9 100644 --- a/cpio/test/CMakeLists.txt +++ b/cpio/test/CMakeLists.txt @@ -88,21 +88,8 @@ IF(ENABLE_CPIO AND ENABLE_TEST) SET_PROPERTY(DIRECTORY APPEND PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}) - # list.h has a line DEFINE_TEST(testname) for every - # test. We can use that to define the tests for cmake by - # defining a DEFINE_TEST macro and reading list.h in. - MACRO (DEFINE_TEST _testname) - ADD_TEST( - NAME bsdcpio_${_testname} - COMMAND bsdcpio_test -vv - -p $ - -r ${CMAKE_CURRENT_SOURCE_DIR} - -s - ${_testname}) - SET_TESTS_PROPERTIES(bsdcpio_${_testname} PROPERTIES SKIP_RETURN_CODE 2) - ENDMACRO (DEFINE_TEST _testname) + DISCOVER_TESTS(bsdcpio ${bsdcpio_test_SOURCES}) - INCLUDE(${CMAKE_CURRENT_BINARY_DIR}/list.h OPTIONAL) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/test_utils) INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/cpio/test) diff --git a/libarchive/test/CMakeLists.txt b/libarchive/test/CMakeLists.txt index 617b6ace3..fc20dc5c0 100644 --- a/libarchive/test/CMakeLists.txt +++ b/libarchive/test/CMakeLists.txt @@ -353,20 +353,8 @@ IF(ENABLE_TEST) SET_PROPERTY(DIRECTORY APPEND PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}) - # list.h has a line DEFINE_TEST(testname) for every - # test. We can use that to define the tests for cmake by - # defining a DEFINE_TEST macro and reading list.h in. - MACRO (DEFINE_TEST _testname) - ADD_TEST( - NAME libarchive_${_testname} - COMMAND libarchive_test -vv - -r ${CMAKE_CURRENT_SOURCE_DIR} - -s - ${_testname}) - SET_TESTS_PROPERTIES(libarchive_${_testname} PROPERTIES SKIP_RETURN_CODE 2) - ENDMACRO (DEFINE_TEST _testname) + DISCOVER_TESTS(libarchive ${libarchive_test_SOURCES}) - INCLUDE(${CMAKE_CURRENT_BINARY_DIR}/list.h OPTIONAL) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/test_utils) INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/libarchive/test) diff --git a/tar/test/CMakeLists.txt b/tar/test/CMakeLists.txt index 47def97fe..5318c24c0 100644 --- a/tar/test/CMakeLists.txt +++ b/tar/test/CMakeLists.txt @@ -109,21 +109,8 @@ IF(ENABLE_TAR AND ENABLE_TEST) SET_PROPERTY(DIRECTORY APPEND PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}) - # list.h has a line DEFINE_TEST(testname) for every - # test. We can use that to define the tests for cmake by - # defining a DEFINE_TEST macro and reading list.h in. - MACRO (DEFINE_TEST _testname) - ADD_TEST( - NAME bsdtar_${_testname} - COMMAND bsdtar_test -vv - -p $ - -r ${CMAKE_CURRENT_SOURCE_DIR} - -s - ${_testname}) - SET_TESTS_PROPERTIES(bsdtar_${_testname} PROPERTIES SKIP_RETURN_CODE 2) - ENDMACRO (DEFINE_TEST _testname) + DISCOVER_TESTS(bsdtar ${bsdtar_test_SOURCES}) - INCLUDE(${CMAKE_CURRENT_BINARY_DIR}/list.h OPTIONAL) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/test_utils) INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/tar/test) diff --git a/unzip/test/CMakeLists.txt b/unzip/test/CMakeLists.txt index 00d232a5f..c2bbfa1b2 100644 --- a/unzip/test/CMakeLists.txt +++ b/unzip/test/CMakeLists.txt @@ -56,21 +56,8 @@ IF(ENABLE_UNZIP AND ENABLE_TEST) SET_PROPERTY(DIRECTORY APPEND PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}) - # list.h has a line DEFINE_TEST(testname) for every - # test. We can use that to define the tests for cmake by - # defining a DEFINE_TEST macro and reading list.h in. - MACRO (DEFINE_TEST _testname) - ADD_TEST( - NAME bsdunzip_${_testname} - COMMAND bsdunzip_test -vv - -p $ - -r ${CMAKE_CURRENT_SOURCE_DIR} - -s - ${_testname}) - SET_TESTS_PROPERTIES(bsdunzip_${_testname} PROPERTIES SKIP_RETURN_CODE 2) - ENDMACRO (DEFINE_TEST _testname) + DISCOVER_TESTS(bsdunzip ${bsdunzip_test_SOURCES}) - INCLUDE(${CMAKE_CURRENT_BINARY_DIR}/list.h OPTIONAL) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/test_utils) INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/unzip/test)