Skip to content

Commit

Permalink
cmake: Include CTest
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed May 19, 2023
1 parent cb19814 commit a112470
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,14 @@ else()
endif()
endif()

find_package(Python3 3.8 COMPONENTS Interpreter)
set(PYTHON_COMMAND ${Python3_EXECUTABLE})

add_subdirectory(src)
add_subdirectory(test)

include(cmake/tests.cmake)

message("\n")
message("Configure summary")
message("=================")
Expand Down
55 changes: 55 additions & 0 deletions cmake/tests.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright (c) 2023 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

include(CTest)

if(TARGET bitcoin-util AND TARGET bitcoin-tx)
add_test(NAME util_test_runner
COMMAND ${CMAKE_COMMAND} -E env BITCOINUTIL=$<TARGET_FILE:bitcoin-util> BITCOINTX=$<TARGET_FILE:bitcoin-tx> ${PYTHON_COMMAND} ${CMAKE_BINARY_DIR}/test/util/test_runner.py
)
endif()

add_test(NAME util_rpcauth_test
COMMAND ${PYTHON_COMMAND} ${CMAKE_BINARY_DIR}/test/util/rpcauth-test.py
)

if(TARGET bench_bitcoin)
add_test(NAME bench_sanity_check_high_priority
COMMAND bench_bitcoin -sanity-check -priority-level=high
)
endif()

if(TARGET test_bitcoin)
function(add_boost_test source_dir source_file)
set(source_file_path ${source_dir}/${source_file})
if(NOT EXISTS ${source_file_path})
return()
endif()

file(READ "${source_file_path}" source_file_content)
string(REGEX
MATCH "(BOOST_FIXTURE_TEST_SUITE|BOOST_AUTO_TEST_SUITE)\\(([A-Za-z0-9_]+)"
test_suite_macro "${source_file_content}"
)
string(REGEX
REPLACE "(BOOST_FIXTURE_TEST_SUITE|BOOST_AUTO_TEST_SUITE)\\(" ""
test_suite_name "${test_suite_macro}"
)
if(test_suite_name)
add_test(NAME ${test_suite_name}:${source_file}
COMMAND test_bitcoin --run_test=${test_suite_name} --catch_system_error=no
)
endif()
endfunction()

function(add_all_test_targets)
get_target_property(test_source_dir test_bitcoin SOURCE_DIR)
get_target_property(test_sources test_bitcoin SOURCES)
foreach(test_source ${test_sources})
add_boost_test(${test_source_dir} ${test_source})
endforeach()
endfunction()

add_all_test_targets()
endif()

0 comments on commit a112470

Please sign in to comment.