]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix CMake-based testing
authorTim Kientzle <kientzle@acm.org>
Thu, 7 May 2026 05:02:15 +0000 (22:02 -0700)
committerTim Kientzle <kientzle@acm.org>
Thu, 7 May 2026 05:02:15 +0000 (22:02 -0700)
CMakeLists.txt
cat/test/CMakeLists.txt
cpio/test/CMakeLists.txt
libarchive/test/CMakeLists.txt
tar/test/CMakeLists.txt
unzip/test/CMakeLists.txt

index edc9a0d7744d309117bdbdb53357626127e8f699..8ea5aaa4bb6e325d27c6b90c0ecdd5c4ffb9c2ff 100644 (file)
@@ -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.
 #
index 75180e285b60c514fdc9539516ff3cb0fd05d08f..1d56341460203b41711b1ddfe6dece8dd406d172 100644 (file)
@@ -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 $<TARGET_FILE:bsdcat>
-                          -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)
index dad046414e39c5a3a799005fb9a7ed9f0dc44806..bb1455ec9c9274f367343f40aa3bf335ddda8352 100644 (file)
@@ -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 $<TARGET_FILE:bsdcpio>
-                           -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)
index 617b6ace374779a848dec8c29297d7b1036bd3e7..fc20dc5c04d0bea9f5d97884e20d54090734040b 100644 (file)
@@ -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)
index 47def97fe2b2d63a932ca5bcbc0d4017e7f6ba26..5318c24c077e69740fa6a47c163769877a6d2393 100644 (file)
@@ -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 $<TARGET_FILE:bsdtar>
-                          -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)
index 00d232a5f46273549680daed2cf67ad94348b148..c2bbfa1b27bfbe78bb93da0f2a7e645bef484e4d 100644 (file)
@@ -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 $<TARGET_FILE:bsdunzip>
-                           -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)