add test cmake

This commit is contained in:
方而静 2024-06-19 05:55:49 +00:00
parent f06f7e21c9
commit 273ce0c186
2 changed files with 22 additions and 0 deletions

View File

@ -64,6 +64,11 @@ if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
set(PK_IS_MAIN TRUE)
option(PK_BUILD_SHARED_LIB "Build shared library" OFF)
option(PK_BUILD_STATIC_LIB "Build static library" OFF)
include(CTest)
if (BUILD_TESTING)
add_subdirectory(tests/)
endif()
else()
set(PK_IS_MAIN FALSE)
option(PK_BUILD_SHARED_LIB "Build shared library" OFF)

17
tests/CMakeLists.txt Normal file
View File

@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.10)
function(pkpy_add_test pyfile)
get_filename_component(test_name ${pyfile} NAME_WE)
add_test(
NAME ${test_name}
COMMAND $<TARGET_FILE:main> ${pyfile}
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/..
)
message("Added test " ${test_name})
endfunction()
file(GLOB PK_PYTHON_TESTCASES_FILES RELATIVE ${CMAKE_CURRENT_LIST_DIR}/.. "*.py")
foreach(pyfile ${PK_PYTHON_TESTCASES_FILES})
pkpy_add_test(${pyfile})
endforeach()