Skip to content

Commit

Permalink
[FIXUP] cmake: Inline test definitions with target definitions
Browse files Browse the repository at this point in the history
This is a move-only change.
  • Loading branch information
hebasto committed Jul 23, 2024
1 parent ad99612 commit eadb850
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 71 deletions.
71 changes: 0 additions & 71 deletions cmake/tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,74 +13,3 @@ if(PYTHON_COMMAND)
COMMAND ${PYTHON_COMMAND} ${CMAKE_BINARY_DIR}/test/util/rpcauth-test.py
)
endif()

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_file)
if(NOT EXISTS ${source_file})
return()
endif()

file(READ "${source_file}" 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}
COMMAND test_bitcoin --run_test=${test_suite_name} --catch_system_error=no
)
set_property(TEST ${test_suite_name} PROPERTY
SKIP_REGULAR_EXPRESSION "no test cases matching filter" "Skipping"
)
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})
cmake_path(IS_RELATIVE test_source result)
if(result)
cmake_path(APPEND test_source_dir ${test_source} OUTPUT_VARIABLE test_source)
endif()
add_boost_test(${test_source})
endforeach()
endfunction()

add_all_test_targets()
endif()

if(TARGET unitester)
add_test(NAME univalue_test
COMMAND unitester
)
endif()

if(TARGET object)
add_test(NAME univalue_object_test
COMMAND object
)
endif()

if(TARGET test_bitcoin-qt)
add_test(NAME test_bitcoin-qt
COMMAND test_bitcoin-qt
)
if(WIN32 AND VCPKG_TARGET_TRIPLET)
# On Windows, vcpkg configures Qt with `-opengl dynamic`, which makes
# the "minimal" platform plugin unusable due to internal Qt bugs.
set_tests_properties(test_bitcoin-qt PROPERTIES
ENVIRONMENT "QT_QPA_PLATFORM=windows"
)
endif()
endif()
4 changes: 4 additions & 0 deletions src/bench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ if(ENABLE_WALLET)
target_link_libraries(bench_bitcoin bitcoin_wallet)
endif()

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

install(TARGETS bench_bitcoin
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
11 changes: 11 additions & 0 deletions src/qt/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ if(NOT QT_IS_STATIC)
)
endif()

add_test(NAME test_bitcoin-qt
COMMAND test_bitcoin-qt
)
if(WIN32 AND VCPKG_TARGET_TRIPLET)
# On Windows, vcpkg configures Qt with `-opengl dynamic`, which makes
# the "minimal" platform plugin unusable due to internal Qt bugs.
set_tests_properties(test_bitcoin-qt PROPERTIES
ENVIRONMENT "QT_QPA_PLATFORM=windows"
)
endif()

install(TARGETS test_bitcoin-qt
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT GUI
Expand Down
38 changes: 38 additions & 0 deletions src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,44 @@ if(WITH_MULTIPROCESS)
target_link_libraries(test_bitcoin bitcoin_ipc_test)
endif()

function(add_boost_test source_file)
if(NOT EXISTS ${source_file})
return()
endif()

file(READ "${source_file}" 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}
COMMAND test_bitcoin --run_test=${test_suite_name} --catch_system_error=no
)
set_property(TEST ${test_suite_name} PROPERTY
SKIP_REGULAR_EXPRESSION "no test cases matching filter" "Skipping"
)
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})
cmake_path(IS_RELATIVE test_source result)
if(result)
cmake_path(APPEND test_source_dir ${test_source} OUTPUT_VARIABLE test_source)
endif()
add_boost_test(${test_source})
endforeach()
endfunction()

add_all_test_targets()

install(TARGETS test_bitcoin
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
6 changes: 6 additions & 0 deletions src/univalue/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ if(BUILD_TESTS)
core_interface
univalue
)
add_test(NAME univalue_test
COMMAND unitester
)

add_executable(object test/object.cpp)
target_link_libraries(object
PRIVATE
core_interface
univalue
)
add_test(NAME univalue_object_test
COMMAND object
)
endif()

0 comments on commit eadb850

Please sign in to comment.