Skip to content

Commit

Permalink
cmake: Implement make check
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed May 2, 2023
1 parent 0218498 commit 284ece9
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ else()
endif()
endif()

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

add_subdirectory(src)
add_subdirectory(test)

Expand Down
20 changes: 20 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,24 @@ endif()

if(BUILD_TESTS)
add_subdirectory(test)

# https://gitlab.kitware.com/cmake/community/-/wikis/doc/tutorials/EmulateMakeCheck
if(TARGET bench_bitcoin)
set(run_bench_bitcoin COMMAND $<TARGET_FILE:bench_bitcoin> --sanity-check)
endif()

set(run_util_test_runner "")
if(TARGET bitcoin-util AND TARGET bitcoin-tx)
set(run_util_test_runner COMMAND echo "Running test/util/test_runner.py..." 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_custom_target(check
${run_bench_bitcoin}
${run_util_test_runner}
COMMAND echo "Running test/util/rpcauth-test.py..."
COMMAND ${PYTHON_COMMAND} ${CMAKE_BINARY_DIR}/test/util/rpcauth-test.py
COMMAND ${CMAKE_COMMAND} -E chdir test ${CMAKE_CTEST_COMMAND} -C "$<CONFIG>"
VERBATIM
)
add_dependencies(check test_bitcoin)
endif()
33 changes: 33 additions & 0 deletions src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,36 @@ if(ENABLE_WALLET)
target_link_libraries(test_bitcoin BerkeleyDB::BerkeleyDB)
endif()
endif()

function(add_boost_test source_file_name)
set(source_file_path "${CMAKE_CURRENT_SOURCE_DIR}/${source_file_name}")
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_name}"
COMMAND test_bitcoin --run_test=${test_suite_name} --catch_system_error=no
)
endif()
endfunction()

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

include(CTest)
enable_testing()
add_all_test_targets()

0 comments on commit 284ece9

Please sign in to comment.