mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-09 19:37:27 -03:00
cmake: Create test suite for ctest
This commit is contained in:
parent
959370bd76
commit
ab2e99b0d9
4 changed files with 69 additions and 2 deletions
|
@ -213,6 +213,9 @@ try_append_cxx_flags("-fno-extended-identifiers" TARGET core_interface SKIP_LINK
|
|||
# -fstack-reuse=none for all gcc builds. (Only gcc understands this flag).
|
||||
try_append_cxx_flags("-fstack-reuse=none" TARGET core_interface)
|
||||
|
||||
if(BUILD_TESTS)
|
||||
enable_testing()
|
||||
endif()
|
||||
# TODO: The `CMAKE_SKIP_BUILD_RPATH` variable setting can be deleted
|
||||
# in the future after reordering Guix script commands to
|
||||
# perform binary checks after the installation step.
|
||||
|
|
|
@ -41,8 +41,8 @@ set(SECP256K1_DISABLE_SHARED ON CACHE BOOL "" FORCE)
|
|||
set(SECP256K1_ENABLE_MODULE_ECDH OFF CACHE BOOL "" FORCE)
|
||||
set(SECP256K1_ENABLE_MODULE_RECOVERY ON CACHE BOOL "" FORCE)
|
||||
set(SECP256K1_BUILD_BENCHMARK OFF CACHE BOOL "" FORCE)
|
||||
set(SECP256K1_BUILD_TESTS OFF CACHE BOOL "" FORCE)
|
||||
set(SECP256K1_BUILD_EXHAUSTIVE_TESTS OFF CACHE BOOL "" FORCE)
|
||||
set(SECP256K1_BUILD_TESTS ${BUILD_TESTS} CACHE BOOL "" FORCE)
|
||||
set(SECP256K1_BUILD_EXHAUSTIVE_TESTS ${BUILD_TESTS} CACHE BOOL "" FORCE)
|
||||
set(SECP256K1_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
|
||||
# We want to build libsecp256k1 with the most tested RelWithDebInfo configuration.
|
||||
enable_language(C)
|
||||
|
|
|
@ -153,3 +153,41 @@ target_link_libraries(test_bitcoin
|
|||
Boost::headers
|
||||
$<TARGET_NAME_IF_EXISTS:libevent::libevent>
|
||||
)
|
||||
|
||||
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()
|
||||
|
|
|
@ -13,3 +13,29 @@ target_include_directories(univalue
|
|||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
)
|
||||
target_link_libraries(univalue PRIVATE core_interface)
|
||||
|
||||
if(BUILD_TESTS)
|
||||
add_executable(unitester test/unitester.cpp)
|
||||
target_compile_definitions(unitester
|
||||
PRIVATE
|
||||
JSON_TEST_SRC=\"${CMAKE_CURRENT_SOURCE_DIR}/test\"
|
||||
)
|
||||
target_link_libraries(unitester
|
||||
PRIVATE
|
||||
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()
|
||||
|
|
Loading…
Reference in a new issue