mirror of
https://github.com/catchorg/Catch2.git
synced 2026-09-08 19:54:35 -04:00
97ec4e8e2e
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.
62 lines
2.0 KiB
CMake
62 lines
2.0 KiB
CMake
# SPDX-License-Identifier: BSL-1.0
|
|
|
|
# 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 TestPrepareCommandFragment.cmake
|
|
|
|
|
|
cmake_minimum_required(VERSION 3.19)
|
|
|
|
if(NOT DEFINED CATCH_ADD_TESTS_SCRIPT)
|
|
message(FATAL_ERROR "Missing argument `CATCH_ADD_TESTS_SCRIPT`")
|
|
endif()
|
|
|
|
if(NOT EXISTS "${CATCH_ADD_TESTS_SCRIPT}")
|
|
message(FATAL_ERROR "Cannot find CatchAddTests.cmake at '${CATCH_ADD_TESTS_SCRIPT}'")
|
|
endif()
|
|
|
|
# Pull in the helper functions. Without `TEST_EXECUTABLE` being defined,
|
|
# `catch_discover_tests_impl` is not called.
|
|
include("${CATCH_ADD_TESTS_SCRIPT}")
|
|
|
|
set(_failures 0)
|
|
|
|
function(expect_equal description actual expected)
|
|
if(actual STREQUAL expected)
|
|
message(" [PASS] ${description}")
|
|
else()
|
|
message(" [FAIL] ${description}")
|
|
message(" expected: [${expected}]")
|
|
message(" actual: [${actual}]")
|
|
math(EXPR _n "${_failures} + 1")
|
|
set(_failures "${_n}" PARENT_SCOPE)
|
|
endif()
|
|
endfunction()
|
|
|
|
prepare_command_fragment(test_fragment SimpleName /path/to/tests)
|
|
expect_equal("Simple arg, no quotes" "${test_fragment}" " SimpleName /path/to/tests")
|
|
|
|
prepare_command_fragment(test_fragment "Name with spaces")
|
|
expect_equal("Spaces in arg, needs quotes" "${test_fragment}" " [==[Name with spaces]==]")
|
|
|
|
prepare_command_fragment(test_fragment Foo PROPERTIES LABELS "tagA\;tagB\;tagC")
|
|
expect_equal("semicolons in argument are kept and quoted"
|
|
"${test_fragment}" " Foo PROPERTIES LABELS [==[tagA\;tagB\;tagC]==]")
|
|
|
|
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_fragment test(s) failed")
|
|
else()
|
|
message(STATUS "All prepare_command_fragment tests passed")
|
|
endif()
|