Merge pull request #233 from StefanBruens/optional_supplemental_tests

Make tests depending on supplemental_test_files optional
This commit is contained in:
Daniel Lemire 2024-01-28 10:08:33 -05:00 committed by GitHub
commit 7cbbcee6ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 12 deletions

View File

@ -5,16 +5,18 @@ cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
include(FetchContent) include(FetchContent)
option(SYSTEM_DOCTEST "Use system copy of doctest" OFF) option(SYSTEM_DOCTEST "Use system copy of doctest" OFF)
option(FASTFLOAT_SUPPLEMENTAL_TESTS "Run supplemental tests" ON)
if (NOT SYSTEM_DOCTEST) if (NOT SYSTEM_DOCTEST)
FetchContent_Declare(doctest FetchContent_Declare(doctest
GIT_REPOSITORY https://github.com/onqtam/doctest.git GIT_REPOSITORY https://github.com/onqtam/doctest.git
GIT_TAG v2.4.10) GIT_TAG v2.4.10)
endif() endif()
if (FASTFLOAT_SUPPLEMENTAL_TESTS)
FetchContent_Declare(supplemental_test_files FetchContent_Declare(supplemental_test_files
GIT_REPOSITORY https://github.com/fastfloat/supplemental_test_files.git GIT_REPOSITORY https://github.com/fastfloat/supplemental_test_files.git
GIT_TAG origin/main) GIT_TAG origin/main)
endif()
# FetchContent_MakeAvailable() was only introduced in 3.14 # FetchContent_MakeAvailable() was only introduced in 3.14
@ -27,15 +29,19 @@ if (NOT SYSTEM_DOCTEST)
add_subdirectory(${doctest_SOURCE_DIR} ${doctest_BINARY_DIR}) add_subdirectory(${doctest_SOURCE_DIR} ${doctest_BINARY_DIR})
endif() endif()
endif() endif()
add_library(supplemental-data INTERFACE)
if (FASTFLOAT_SUPPLEMENTAL_TESTS)
FetchContent_GetProperties(supplemental_test_files) FetchContent_GetProperties(supplemental_test_files)
if(NOT supplemental_test_files_POPULATED) if(NOT supplemental_test_files_POPULATED)
message(STATUS "Tests enabled. Retrieving test files.") message(STATUS "Supplemental tests enabled. Retrieving test files.")
FetchContent_Populate(supplemental_test_files) FetchContent_Populate(supplemental_test_files)
message(STATUS "Test files retrieved.") message(STATUS "Supplemental test files retrieved.")
add_subdirectory(${supplemental_test_files_SOURCE_DIR} ${supplemental_test_files_BINARY_DIR}) add_subdirectory(${supplemental_test_files_SOURCE_DIR} ${supplemental_test_files_BINARY_DIR})
endif() endif()
add_library(supplemental-data INTERFACE)
target_compile_definitions(supplemental-data INTERFACE SUPPLEMENTAL_TEST_DATA_DIR="${supplemental_test_files_BINARY_DIR}/data") target_compile_definitions(supplemental-data INTERFACE SUPPLEMENTAL_TEST_DATA_DIR="${supplemental_test_files_BINARY_DIR}/data")
endif()
function(fast_float_add_cpp_test TEST_NAME) function(fast_float_add_cpp_test TEST_NAME)
add_executable(${TEST_NAME} ${TEST_NAME}.cpp) add_executable(${TEST_NAME} ${TEST_NAME}.cpp)
if(CMAKE_CROSSCOMPILING) if(CMAKE_CROSSCOMPILING)
@ -67,6 +73,9 @@ if (FASTFLOAT_CONSTEXPR_TESTS)
else() else()
target_compile_features(basictest PRIVATE cxx_std_17) target_compile_features(basictest PRIVATE cxx_std_17)
endif() endif()
if (FASTFLOAT_SUPPLEMENTAL_TESTS)
target_compile_definitions(basictest PRIVATE FASTFLOAT_SUPPLEMENTAL_TESTS)
endif()
fast_float_add_cpp_test(long_test) fast_float_add_cpp_test(long_test)
fast_float_add_cpp_test(powersoffive_hardround) fast_float_add_cpp_test(powersoffive_hardround)

View File

@ -246,6 +246,7 @@ TEST_CASE("parse_negative_zero") {
CHECK(float64_parsed == 0x8000'0000'0000'0000); CHECK(float64_parsed == 0x8000'0000'0000'0000);
} }
#if FASTFLOAT_SUPPLEMENTAL_TESTS
// C++ 17 because it is otherwise annoying to browse all files in a directory. // C++ 17 because it is otherwise annoying to browse all files in a directory.
// We also only run these tests on little endian systems. // We also only run these tests on little endian systems.
#if (FASTFLOAT_CPLUSPLUS >= 201703L) && (FASTFLOAT_IS_BIG_ENDIAN == 0) && !defined(FASTFLOAT_ODDPLATFORM) #if (FASTFLOAT_CPLUSPLUS >= 201703L) && (FASTFLOAT_IS_BIG_ENDIAN == 0) && !defined(FASTFLOAT_ODDPLATFORM)
@ -336,6 +337,7 @@ TEST_CASE("supplemental") {
} }
} }
#endif #endif
#endif
TEST_CASE("leading_zeroes") { TEST_CASE("leading_zeroes") {
constexpr const uint64_t bit = 1; constexpr const uint64_t bit = 1;