This commit is contained in:
Tom Hicks
2025-04-09 20:26:37 -07:00
parent 4a44495abc
commit 415bdfcd3c
2 changed files with 87 additions and 4 deletions

View File

@@ -111,6 +111,9 @@ if(NOT TINYTEST_USE_SYSTEM_CPPUTILS)
set(CPPUTILS_ENABLE_TESTING OFF CACHE BOOL "Disable CPPUtils testing framework" FORCE)
set(CPPUTILS_SKIP_GOOGLETEST ON CACHE BOOL "Disable Google Test fetching in CPPUtils" FORCE)
# Define these globally to prevent any test registration
set(CMAKE_DISABLE_TESTING ON CACHE INTERNAL "")
FetchContent_Declare(
cpputils
GIT_REPOSITORY https://github.com/headhunter45/cpp-utils.git
@@ -168,11 +171,36 @@ endif()
# Re-enable testing for TinyTest
set(BUILD_TESTING ON CACHE BOOL "Enable testing for TinyTest" FORCE)
set(CMAKE_DISABLE_TESTING OFF CACHE INTERNAL "")
# Include testing support - AFTER cpputils is added
include(CTest)
enable_testing()
# Clear all existing tests to avoid running CPPUtils tests
execute_process(
COMMAND ${CMAKE_COMMAND} -E echo "Removing any existing tests"
COMMAND ${CMAKE_CTEST_COMMAND} --force-new-ctest-process -N
OUTPUT_VARIABLE ALL_TESTS
)
file(WRITE "${CMAKE_BINARY_DIR}/CTestTestfile.cmake" "# CTest test file - Generated by CMake\n")
# Create a hook to explicitly remove any CPPUtils tests before running our own
file(WRITE "${CMAKE_BINARY_DIR}/RemoveCPPUtilsTests.cmake" [[
file(GLOB_RECURSE cpputils_ctests
"${CMAKE_BINARY_DIR}/_deps/cpputils-build/*/CTestTestfile.cmake"
"${CMAKE_BINARY_DIR}/_deps/cpputils-build/CTestTestfile.cmake"
)
foreach(ctest_file ${cpputils_ctests})
file(WRITE "${ctest_file}" "# CPPUtils tests disabled\n")
endforeach()
]])
# Execute the hook to remove CPPUtils tests
execute_process(
COMMAND ${CMAKE_COMMAND} -P "${CMAKE_BINARY_DIR}/RemoveCPPUtilsTests.cmake"
)
# TinyTest library - renamed to avoid conflicts
add_library(tinytest_lib ${TINYTEST_LIBRARY_TYPE}
tinytest.cpp
@@ -271,6 +299,16 @@ if(BUILD_TESTING)
# Explicitly set the test list to prevent picking up other tests
set_property(GLOBAL PROPERTY TEST_INCLUDE_FILES "")
# Add a special label to our test so we can run only our tests
set_tests_properties(tinytest_test PROPERTIES LABELS "TinyTest")
# Update the root CTestTestfile.cmake to only include our test
file(WRITE "${CMAKE_BINARY_DIR}/CTestTestfile.cmake"
"# TinyTest test file - Generated by CMake\n"
"add_test(tinytest_test \"${CMAKE_BINARY_DIR}/tinytest_test\")\n"
"set_tests_properties(tinytest_test PROPERTIES LABELS \"TinyTest\")\n"
)
endif()
endif()