forked from catchorg/Catch2
Support TEST_{PREFIX,SUFFIX} with leading/trailing whitespace
Closes #2149
This commit is contained in:
+4
-4
@@ -231,8 +231,8 @@ function(catch_discover_tests TARGET)
|
||||
-D "TEST_SPEC=${_TEST_SPEC}"
|
||||
-D "TEST_EXTRA_ARGS=${_EXTRA_ARGS}"
|
||||
-D "TEST_PROPERTIES=${_PROPERTIES}"
|
||||
-D "TEST_PREFIX=${_TEST_PREFIX}"
|
||||
-D "TEST_SUFFIX=${_TEST_SUFFIX}"
|
||||
-D "TEST_PREFIX='${_TEST_PREFIX}'"
|
||||
-D "TEST_SUFFIX='${_TEST_SUFFIX}'"
|
||||
-D "TEST_LIST=${_TEST_LIST}"
|
||||
-D "TEST_REPORTER=${_REPORTER}"
|
||||
-D "TEST_OUTPUT_DIR=${_OUTPUT_DIR}"
|
||||
@@ -277,8 +277,8 @@ function(catch_discover_tests TARGET)
|
||||
" TEST_SPEC" " [==[" "${_TEST_SPEC}" "]==]" "\n"
|
||||
" TEST_EXTRA_ARGS" " [==[" "${_EXTRA_ARGS}" "]==]" "\n"
|
||||
" TEST_PROPERTIES" " [==[" "${_PROPERTIES}" "]==]" "\n"
|
||||
" TEST_PREFIX" " [==[" "${_TEST_PREFIX}" "]==]" "\n"
|
||||
" TEST_SUFFIX" " [==[" "${_TEST_SUFFIX}" "]==]" "\n"
|
||||
" TEST_PREFIX" " [==['" "${_TEST_PREFIX}" "']==]" "\n"
|
||||
" TEST_SUFFIX" " [==['" "${_TEST_SUFFIX}" "']==]" "\n"
|
||||
" TEST_LIST" " [==[" "${_TEST_LIST}" "]==]" "\n"
|
||||
" TEST_REPORTER" " [==[" "${_REPORTER}" "]==]" "\n"
|
||||
" TEST_OUTPUT_DIR" " [==[" "${_OUTPUT_DIR}" "]==]" "\n"
|
||||
|
||||
@@ -235,8 +235,10 @@ function(catch_discover_tests_impl)
|
||||
set(_WriteToFileThreshold 50000)
|
||||
|
||||
set(add_tags "${_ADD_TAGS_AS_LABELS}")
|
||||
set(prefix "${_TEST_PREFIX}")
|
||||
set(suffix "${_TEST_SUFFIX}")
|
||||
# TEST_{PREFIX,SUFFIX} is enclosed in single quotes to keep ensure
|
||||
# leading/trailing whitespace isn't trimmed by CMake's argument passing.
|
||||
string(REGEX REPLACE "^'(.*)'$" "\\1" prefix "${_TEST_PREFIX}")
|
||||
string(REGEX REPLACE "^'(.*)'$" "\\1" suffix "${_TEST_SUFFIX}")
|
||||
set(spec ${_TEST_SPEC})
|
||||
set(extra_args ${_TEST_EXTRA_ARGS})
|
||||
set(properties ${_TEST_PROPERTIES})
|
||||
|
||||
@@ -15,6 +15,8 @@ if(CMAKE_VERSION GREATER_EQUAL 3.27)
|
||||
endif()
|
||||
catch_discover_tests(
|
||||
tests
|
||||
TEST_PREFIX " prefix "
|
||||
TEST_SUFFIX " suffix "
|
||||
ADD_TAGS_AS_LABELS
|
||||
DISCOVERY_MODE PRE_TEST
|
||||
${extra_args}
|
||||
|
||||
@@ -21,6 +21,11 @@ TestInfo = namedtuple('TestInfo', ['name', 'tags'])
|
||||
|
||||
cmake_version_regex = re.compile(r'cmake version (\d+)\.(\d+)\.(\d+)')
|
||||
|
||||
# Note that these both intentionally include preceding/trailing space,
|
||||
# which should not get stripped.
|
||||
CTEST_NAME_PREFIX = ' prefix '
|
||||
CTEST_NAME_SUFFIX = ' suffix '
|
||||
|
||||
def get_cmake_version():
|
||||
result = subprocess.run(['cmake', '--version'],
|
||||
capture_output = True,
|
||||
@@ -221,7 +226,7 @@ def extract_tests_list_from_ctest_script(build_path: str) -> List[str]:
|
||||
print(f'stdout: {err.stdout}')
|
||||
exit(4)
|
||||
|
||||
lines = result.stdout.strip().split('\n')
|
||||
lines = [x for x in result.stdout.split('\n') if x.strip()]
|
||||
test_num_line = lines[0]
|
||||
test_lines = lines[1:]
|
||||
|
||||
@@ -281,7 +286,7 @@ if __name__ == '__main__':
|
||||
print(f"{len(catch_test_names)} tests matched in CTest listing")
|
||||
|
||||
test_list_names = sorted(extract_tests_list_from_ctest_script(build_path))
|
||||
expected_names = sorted(info.name for info in raw_catch_test_names)
|
||||
expected_names = sorted(CTEST_NAME_PREFIX + info.name + CTEST_NAME_SUFFIX for info in raw_catch_test_names)
|
||||
if test_list_names != expected_names:
|
||||
print("TEST_LIST variable (tests_TESTS) does not match Catch2 test listing!")
|
||||
for name in test_list_names:
|
||||
|
||||
Reference in New Issue
Block a user