CMake: build unit test runner

This commit is contained in:
rdb 2026-01-24 14:07:42 +01:00
parent c2760c88c6
commit ebb556a866
2 changed files with 23 additions and 11 deletions

View File

@ -109,6 +109,7 @@ option(BUILD_DIRECT "Build the direct source tree." ON)
option(BUILD_PANDATOOL "Build the pandatool source tree." ON)
option(BUILD_CONTRIB "Build the contrib source tree." ON)
option(BUILD_MODELS "Build/install the built-in models." ON)
option(BUILD_TESTS "Build unit test runner." ON)
option(BUILD_TOOLS "Build binary tools." ON)
# Include Panda3D packages
@ -166,17 +167,8 @@ if(BUILD_MODELS)
COMPONENT Models DESTINATION ${CMAKE_INSTALL_DATADIR}/panda3d)
endif()
if(INTERROGATE_PYTHON_INTERFACE)
# If we built the Python interface, run the test suite. Note, we do NOT test
# for pytest before adding this test. If the user doesn't have pytest, we'd
# like for the tests to fail.
# In the Coverage configuration, we also require pytest-cov
add_test(NAME pytest
COMMAND "${PYTHON_EXECUTABLE}" -m pytest "${PROJECT_SOURCE_DIR}/tests"
$<$<CONFIG:Coverage>:--cov=.>
WORKING_DIRECTORY "${PANDA_OUTPUT_DIR}")
if(BUILD_TESTS)
add_subdirectory(tests "${CMAKE_BINARY_DIR}/tests")
endif()
# Generate the Panda3DConfig.cmake file so find_package(Panda3D) works, and

20
tests/CMakeLists.txt Normal file
View File

@ -0,0 +1,20 @@
if(NOT INTERROGATE_PYTHON_INTERFACE)
return()
endif()
add_executable(run_pytest main.c)
target_link_libraries(run_pytest panda)
target_link_libraries(run_pytest Python::Python)
# Note, we do NOT test for pytest before adding this test. If the user doesn't
# have pytest, we'd like for the tests to fail.
# In the Coverage configuration, we also require pytest-cov
# To prevent an empty argument from being passed in in non-Coverage builds,
# which will sometimes cause pytest to read all tests in the current directory,
# substitute a nonsensical argument that will be ignored instead
add_test(NAME pytest COMMAND run_pytest tests $<IF:$<CONFIG:Coverage>,--cov=.,--ignore=nonexistent>
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
set_tests_properties(pytest PROPERTIES ENVIRONMENT "PYTHONPATH=${PANDA_OUTPUT_DIR}")