Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1# TODO: rework/remove once test discovery is implemented upstream:2# https://gitlab.kitware.com/cmake/cmake/-/issues/269203function(discover_tests target)4set(options "")5set(oneValueArgs DISCOVERY_MATCH TEST_NAME_REPLACEMENT TEST_ARGS_REPLACEMENT)6set(multiValueArgs DISCOVERY_ARGS PROPERTIES)7cmake_parse_arguments(PARSE_ARGV 1 arg "${options}" "${oneValueArgs}" "${multiValueArgs}")9set(file_base ${CMAKE_CURRENT_BINARY_DIR}/${target})10set(include_file ${file_base}_include.cmake)12set(properties_content)13list(LENGTH arg_PROPERTIES properties_len)14if(properties_len GREATER "0")15set(properties_content " set_tests_properties(\"\${test_name}\" PROPERTIES\n")16math(EXPR num_properties "${properties_len} / 2")17foreach(i RANGE 0 ${num_properties} 2)18math(EXPR value_index "${i} + 1")19list(GET arg_PROPERTIES ${i} name)20list(GET arg_PROPERTIES ${value_index} value)21string(APPEND properties_content " \"${name}\" \"${value}\"\n")22endforeach()23string(APPEND properties_content " )\n")24endif()26string(CONCAT include_content27"set(runner [[$<TARGET_FILE:${target}>]])\n"28"set(launcher [[$<TARGET_PROPERTY:${target},TEST_LAUNCHER>]])\n"29"set(emulator [[$<$<BOOL:${CMAKE_CROSSCOMPILING}>:$<TARGET_PROPERTY:${target},CROSSCOMPILING_EMULATOR>>]])\n"30"\n"31"execute_process(\n"32" COMMAND \${launcher} \${emulator} \${runner} ${arg_DISCOVERY_ARGS}\n"33" OUTPUT_VARIABLE output OUTPUT_STRIP_TRAILING_WHITESPACE\n"34" ERROR_VARIABLE output ERROR_STRIP_TRAILING_WHITESPACE\n"35" RESULT_VARIABLE result\n"36")\n"37"\n"38"if(NOT result EQUAL 0)\n"39" add_test([[${target}_DISCOVERY_FAILURE]] \${launcher} \${emulator} \${runner} ${arg_DISCOVERY_ARGS})\n"40"else()\n"41" string(REPLACE \"\\n\" \";\" lines \"\${output}\")\n"42" foreach(line IN LISTS lines)\n"43" if(line MATCHES \"${arg_DISCOVERY_MATCH}\")\n"44" string(REGEX REPLACE \"${arg_DISCOVERY_MATCH}\" \"${arg_TEST_NAME_REPLACEMENT}\" test_name \"\${line}\")\n"45" string(REGEX REPLACE \"${arg_DISCOVERY_MATCH}\" \"${arg_TEST_ARGS_REPLACEMENT}\" test_args \"\${line}\")\n"46" separate_arguments(test_args)\n"47" add_test(\"\${test_name}\" \${launcher} \${emulator} \${runner} \${test_args})\n"48${properties_content}49" endif()\n"50" endforeach()\n"51"endif()\n"52)54get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)55if(is_multi_config)56file(GENERATE57OUTPUT ${file_base}_include-$<CONFIG>.cmake58CONTENT "${include_content}"59)60file(WRITE ${include_file}61"include(\"${file_base}_include-\${CTEST_CONFIGURATION_TYPE}.cmake\")"62)63else()64file(GENERATE65OUTPUT ${include_file}66CONTENT "${include_content}"67)68endif()70set_property(DIRECTORY APPEND PROPERTY TEST_INCLUDE_FILES ${include_file})71endfunction()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.