What changed, and why it matters
This commit adds a new CMake helper file used to automatically find and register test cases during the build process. It does not change any cryptographic code, wallet handling, network logic, or user-facing behavior. It is purely a build/test infrastructure addition.
No security action required. Review as normal build-system maintenance if desired.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit introduces cmake/DiscoverTests.cmake, implementing a CMake function discover_tests() that runs a test executable at build time to discover individual tests, then generates CTest include files. It uses cmake_parse_arguments, execute_process, file(GENERATE/WRITE), and set_property(DIRECTORY APPEND PROPERTY TEST_INCLUDE_FILES). No source code, cryptographic primitives, or runtime behavior are modified.
Changed components
cmake/DiscoverTests.cmakeInspect captured patch +71 / −0
diff --git a/cmake/DiscoverTests.cmake b/cmake/DiscoverTests.cmake
new file mode 100644
index 0000000..683780a
--- /dev/null
+++ b/cmake/DiscoverTests.cmake
@@ -0,0 +1,71 @@
+# TODO: rework/remove once test discovery is implemented upstream:
+# https://gitlab.kitware.com/cmake/cmake/-/issues/26920
+function(discover_tests target)
+ set(options "")
+ set(oneValueArgs DISCOVERY_MATCH TEST_NAME_REPLACEMENT TEST_ARGS_REPLACEMENT)
+ set(multiValueArgs DISCOVERY_ARGS PROPERTIES)
+ cmake_parse_arguments(PARSE_ARGV 1 arg "${options}" "${oneValueArgs}" "${multiValueArgs}")
+
+ set(file_base ${CMAKE_CURRENT_BINARY_DIR}/${target})
+ set(include_file ${file_base}_include.cmake)
+
+ set(properties_content)
+ list(LENGTH arg_PROPERTIES properties_len)
+ if(properties_len GREATER "0")
+ set(properties_content " set_tests_properties(\"\${test_name}\" PROPERTIES\n")
+ math(EXPR num_properties "${properties_len} / 2")
+ foreach(i RANGE 0 ${num_properties} 2)
+ math(EXPR value_index "${i} + 1")
+ list(GET arg_PROPERTIES ${i} name)
+ list(GET arg_PROPERTIES ${value_index} value)
+ string(APPEND properties_content " \"${name}\" \"${value}\"\n")
+ endforeach()
+ string(APPEND properties_content " )\n")
+ endif()
+
+ string(CONCAT include_content
+ "set(runner [[$<TARGET_FILE:${target}>]])\n"
+ "set(launcher [[$<TARGET_PROPERTY:${target},TEST_LAUNCHER>]])\n"
+ "set(emulator [[$<$<BOOL:${CMAKE_CROSSCOMPILING}>:$<TARGET_PROPERTY:${target},CROSSCOMPILING_EMULATOR>>]])\n"
+ "\n"
+ "execute_process(\n"
+ " COMMAND \${launcher} \${emulator} \${runner} ${arg_DISCOVERY_ARGS}\n"
+ " OUTPUT_VARIABLE output OUTPUT_STRIP_TRAILING_WHITESPACE\n"
+ " ERROR_VARIABLE output ERROR_STRIP_TRAILING_WHITESPACE\n"
+ " RESULT_VARIABLE result\n"
+ ")\n"
+ "\n"
+ "if(NOT result EQUAL 0)\n"
+ " add_test([[${target}_DISCOVERY_FAILURE]] \${launcher} \${emulator} \${runner} ${arg_DISCOVERY_ARGS})\n"
+ "else()\n"
+ " string(REPLACE \"\\n\" \";\" lines \"\${output}\")\n"
+ " foreach(line IN LISTS lines)\n"
+ " if(line MATCHES \"${arg_DISCOVERY_MATCH}\")\n"
+ " string(REGEX REPLACE \"${arg_DISCOVERY_MATCH}\" \"${arg_TEST_NAME_REPLACEMENT}\" test_name \"\${line}\")\n"
+ " string(REGEX REPLACE \"${arg_DISCOVERY_MATCH}\" \"${arg_TEST_ARGS_REPLACEMENT}\" test_args \"\${line}\")\n"
+ " separate_arguments(test_args)\n"
+ " add_test(\"\${test_name}\" \${launcher} \${emulator} \${runner} \${test_args})\n"
+ ${properties_content}
+ " endif()\n"
+ " endforeach()\n"
+ "endif()\n"
+ )
+
+ get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+ if(is_multi_config)
+ file(GENERATE
+ OUTPUT ${file_base}_include-$<CONFIG>.cmake
+ CONTENT "${include_content}"
+ )
+ file(WRITE ${include_file}
+ "include(\"${file_base}_include-\${CTEST_CONFIGURATION_TYPE}.cmake\")"
+ )
+ else()
+ file(GENERATE
+ OUTPUT ${include_file}
+ CONTENT "${include_content}"
+ )
+ endif()
+
+ set_property(DIRECTORY APPEND PROPERTY TEST_INCLUDE_FILES ${include_file})
+endfunction()
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.