diff options
| author | Martin Hořeňovský | 2026-08-10 11:45:08 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2026-08-10 11:53:22 +0200 |
| commit | 97ec4e8e2e4a86719701746d1cb2426f16292ff8 (patch) | |
| tree | ef8f99ce2dd607f360c3ae281c6b55786ff79596 /tests | |
| parent | 0136276e15e140cc332630dc83e2a77b796c5fa7 (diff) | |
| download | catch3-97ec4e8e2e4a86719701746d1cb2426f16292ff8.tar.gz | |
catch_discover_tests: Escape test-invariant parts of CTest script only once
Previously, the `catch_discover_tests` would prepare the entire CTest
command (e.g. `add_test(...)` or `set_tests_properties(...)`) first, and
then escape it when finished. However, this caused lot of the command args
to be escaped over and over again (e.g. executable name or Catch2's reporter
args), for no reason, as they were always the same, and thus their escaping
was always the same.
Until recently, the performance overhead didn't matter as there were many
spots which had quadratic runtime in number of tests. However, the recent
refactorings fixed these, and this commit now improves the throughput by
10-20%.
Also extended the benchmarked COUNTS in `benchmark_discovery.py`,
because the performance is now good enough that it is reasonable
to benchmark 16k tests.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | tests/TestScripts/DiscoverTests/TestPrepareCommandFragment.cmake (renamed from tests/TestScripts/DiscoverTests/TestPrepareCommand.cmake) | 28 |
2 files changed, 16 insertions, 16 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 573c38e7..5a74a9d0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -672,11 +672,11 @@ if(CATCH_ENABLE_CMAKE_HELPER_TESTS) LABELS "uses-python" ) - add_test(NAME "CMakeHelper::PrepareCommand" + add_test(NAME "CMakeHelper::PrepareCommandFragment" COMMAND "${CMAKE_COMMAND}" "-DCATCH_ADD_TESTS_SCRIPT=${CATCH_DIR}/extras/CatchAddTests.cmake" - -P "${CMAKE_CURRENT_LIST_DIR}/TestScripts/DiscoverTests/TestPrepareCommand.cmake" + -P "${CMAKE_CURRENT_LIST_DIR}/TestScripts/DiscoverTests/TestPrepareCommandFragment.cmake" ) add_test(NAME "CMakeHelper::DecomposeJsonArray" diff --git a/tests/TestScripts/DiscoverTests/TestPrepareCommand.cmake b/tests/TestScripts/DiscoverTests/TestPrepareCommandFragment.cmake index f02bb409..cfcaf0d1 100644 --- a/tests/TestScripts/DiscoverTests/TestPrepareCommand.cmake +++ b/tests/TestScripts/DiscoverTests/TestPrepareCommandFragment.cmake @@ -1,12 +1,12 @@ # SPDX-License-Identifier: BSL-1.0 -# Unit tests for `prepare_command` helper in `extras/CatchAddTests.cmake`. +# Unit tests for `prepare_command_fragment` helper in `extras/CatchAddTests.cmake`. # # Yes, we are at the stage where the script helpers need unit tests. # # Run as # cmake -DCATCH_ADD_TESTS_SCRIPT=/path/to/extras/CatchAddTests.cmake \ -# -P TestPrepareCommand.cmake +# -P TestPrepareCommandFragment.cmake cmake_minimum_required(VERSION 3.19) @@ -37,25 +37,25 @@ function(expect_equal description actual expected) endif() endfunction() -prepare_command(add_test SimpleName /path/to/tests) -expect_equal("Simple arg, no quotes" "${_Command}" "add_test( SimpleName /path/to/tests)\n") +prepare_command_fragment(test_fragment SimpleName /path/to/tests) +expect_equal("Simple arg, no quotes" "${test_fragment}" " SimpleName /path/to/tests") -prepare_command(add_test "Name with spaces") -expect_equal("Spaces in arg, needs quotes" "${_Command}" "add_test( [==[Name with spaces]==])\n") +prepare_command_fragment(test_fragment "Name with spaces") +expect_equal("Spaces in arg, needs quotes" "${test_fragment}" " [==[Name with spaces]==]") -prepare_command(set_tests_properties Foo PROPERTIES LABELS "tagA\;tagB\;tagC") +prepare_command_fragment(test_fragment Foo PROPERTIES LABELS "tagA\;tagB\;tagC") expect_equal("semicolons in argument are kept and quoted" - "${_Command}" "set_tests_properties( Foo PROPERTIES LABELS [==[tagA\;tagB\;tagC]==])\n") + "${test_fragment}" " Foo PROPERTIES LABELS [==[tagA\;tagB\;tagC]==]") -set(_Command "PRE-EXISTING") -prepare_command(set_tests_properties Foo PROPERTIES BAR baz) -expect_equal("_Command var does no accumulate commands" - "${_Command}" "set_tests_properties( Foo PROPERTIES BAR baz)\n") +set(test_fragment "PRE-EXISTING") +prepare_command_fragment(test_fragment Foo PROPERTIES BAR baz) +expect_equal("out var does no accumulate commands" + "${test_fragment}" " Foo PROPERTIES BAR baz") if(_failures GREATER 0) - message(FATAL_ERROR "${_failures} prepare_command test(s) failed") + message(FATAL_ERROR "${_failures} prepare_command_fragment test(s) failed") else() - message(STATUS "All prepare_command tests passed") + message(STATUS "All prepare_command_fragment tests passed") endif() |