From 273ce0c1860c49add897534c29864627137f03c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B9=E8=80=8C=E9=9D=99?= Date: Wed, 19 Jun 2024 05:55:49 +0000 Subject: [PATCH] add test cmake --- CMakeLists.txt | 5 +++++ tests/CMakeLists.txt | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 tests/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a4c4450..3e592320 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000..bff5517c --- /dev/null +++ b/tests/CMakeLists.txt @@ -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 $ ${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()