Author: rinrab
Date: Mon Nov 25 14:09:00 2024
New Revision: 1922086
URL: http://svn.apache.org/viewvc?rev=1922086&view=rev
Log:
cmake tests: add an option that enumerates all subtests in all pytest
modules, and adds them separately.
This allows us to run a single test, which is most useful for developers
using IDEs with CTest integrated, like Visual Studio. They will be able
to browse all tests and their statuses directly in the test explorer,
without having to view the entire test log.
* CMakeLists.txt
(EXPAND_TESTS option): Declare option.
(add_py_test): Factor this function out.
(if EXPAND_TESTS): Run `./build/run_tests.py --list` to list all tests
in a module, regex test numbers from the output, enumerate them using
foreach(), add `${py_test_path}#${test_num}` CTest on each iteration.
(else EXPAND_TESTS): Simply invoke add_py_test() for entire test module;
this keeps the same behaviour as there was before, if the option is
disabled.
### This makes configure step too slow if the option is enabled. Can we
### prevent regeneration of the tests list if these files haven't been
### changed? Probably, I'll look at this a bit more, if we consider this
### as an issue.
###
### However, when I measured the time taken to configure CMake, I got just
### 6.5s with the option enabled, against 0.8s when it has been disabled...
Modified:
subversion/trunk/CMakeLists.txt
Modified: subversion/trunk/CMakeLists.txt
URL:
http://svn.apache.org/viewvc/subversion/trunk/CMakeLists.txt?rev=1922086&r1=1922085&r2=1922086&view=diff
==============================================================================
--- subversion/trunk/CMakeLists.txt (original)
+++ subversion/trunk/CMakeLists.txt Mon Nov 25 14:09:00 2024
@@ -75,6 +75,7 @@ option(SVN_ENABLE_SVNXX "Enable compilat
option(SVN_ENABLE_PROGRAMS "Build Subversion programs (such as svn.exe)" ON)
cmake_dependent_option(SVN_ENABLE_TOOLS "Build Subversion tools" ON
"SVN_ENABLE_TESTS" OFF)
option(SVN_ENABLE_TESTS "Build Subversion test-suite" OFF)
+option(EXPAND_TESTS "Expand tests; This will slow-down configuration, but you
will have an ability to run any subtest" OFF)
option(SVN_ENABLE_APACHE_MODULES "Build modules for Apache HTTPD" OFF)
option(SVN_ENABLE_SWIG_PERL "Enable Subversion SWIG bindings for Perl" OFF)
@@ -768,21 +769,14 @@ include("build/cmake/targets.cmake")
if(SVN_ENABLE_TESTS)
find_package(Python3 COMPONENTS Interpreter REQUIRED)
+ set(run_tests_script "${CMAKE_CURRENT_SOURCE_DIR}/build/run_tests.py")
- file(GLOB PYTHON_TESTS
- "subversion/tests/cmdline/*_tests.py"
- )
-
- foreach(py_test_path ${PYTHON_TESTS})
- # Keep `.py'.
- get_filename_component(py_test_name ${py_test_path} NAME_WLE)
- set(binary_dir $<TARGET_FILE_DIR:svn>)
-
+ function(add_py_test name prog)
add_test(
NAME
- "cmdline.${py_test_name}"
+ "${name}"
COMMAND
- "${Python3_EXECUTABLE}"
"${CMAKE_CURRENT_SOURCE_DIR}/build/run_tests.py"
+ "${Python3_EXECUTABLE}" "${run_tests_script}"
--bin ${binary_dir}
--tools-bin ${binary_dir}
--verbose
@@ -790,8 +784,47 @@ if(SVN_ENABLE_TESTS)
--set-log-level=WARNING
${CMAKE_CURRENT_SOURCE_DIR}
${binary_dir}
- ${py_test_path}
+ "${prog}"
)
+ endfunction()
+
+ file(GLOB PYTHON_TESTS
+ "subversion/tests/cmdline/*_tests.py"
+ )
+
+ foreach(py_test_path ${PYTHON_TESTS})
+ # Keep `.py'.
+ get_filename_component(py_test_name ${py_test_path} NAME_WLE)
+ set(binary_dir $<TARGET_FILE_DIR:svn>)
+
+ if(EXPAND_TESTS)
+ message("Listing tests in ${py_test_name}")
+ execute_process(
+ COMMAND
+ "${Python3_EXECUTABLE}" "${run_tests_script}"
+ --log-to-stdout
+ --list
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${binary_dir}
+ ${py_test_path}
+ OUTPUT_VARIABLE tests_list_output
+ )
+ string(REGEX MATCHALL "\n *([0-9]+)" tests_list ${tests_list_output})
+
+ foreach(test_num ${tests_list})
+ string(REGEX MATCH "([0-9]+)" test_num ${test_num})
+
+ add_py_test(
+ "cmdline.${py_test_name}.${test_num}"
+ "${py_test_path}#${test_num}"
+ )
+ endforeach()
+ else()
+ add_py_test(
+ "cmdline.${py_test_name}"
+ "${py_test_path}"
+ )
+ endif()
endforeach()
endif()