summaryrefslogtreecommitdiffstats
path: root/Modules/GoogleTestAddTests.cmake
diff options
context:
space:
mode:
authorStefan Floeren <stefan.floeren@smartronic.de>2020-04-30 12:52:31 (GMT)
committerStefan Floeren <stefan.floeren@smartronic.de>2020-05-05 07:23:17 (GMT)
commit839a1010a3e2123e197e2c9e0ed8e5ad58988622 (patch)
treeff370c048cbf6e71fd75db1e215984f9b1c7b499 /Modules/GoogleTestAddTests.cmake
parent671daf1998659c948fc0de9e6f16a367c47c7145 (diff)
downloadCMake-839a1010a3e2123e197e2c9e0ed8e5ad58988622.zip
CMake-839a1010a3e2123e197e2c9e0ed8e5ad58988622.tar.gz
CMake-839a1010a3e2123e197e2c9e0ed8e5ad58988622.tar.bz2
GoogleTestAddTests: Fix output processing
The function gtest_discover_tests calls the passed test executable with the parameter --gtest_list_tests and parses the output to find all tests. In case of value-parameterized tests ([1]), the test values are included in the output. While test names are alphanumeric, the values can contain arbitrary content. First, the output is separated into lines with `foreach`. Included semi-colons breaks this and need to get escaped. Afterwards, the testname is passed on to the `add_command` helper. This helper was converted into a macro in commit dac201442d (GoogleTest: Optimize gtest_discover_tests, 2020-02-18). As a macro, its arguments are re-evaluated. Therefore we need to escape `\`, `;` and to prevent unwanted variable expansion `$`. Fixes: #20661 [1] <https://github.com/google/googletest/blob/0eea2e9/googletest/docs/advanced.md#value-parameterized-tests>
Diffstat (limited to 'Modules/GoogleTestAddTests.cmake')
-rw-r--r--Modules/GoogleTestAddTests.cmake20
1 files changed, 16 insertions, 4 deletions
diff --git a/Modules/GoogleTestAddTests.cmake b/Modules/GoogleTestAddTests.cmake
index 499332f..4af62ed 100644
--- a/Modules/GoogleTestAddTests.cmake
+++ b/Modules/GoogleTestAddTests.cmake
@@ -83,6 +83,8 @@ function(gtest_discover_tests_impl)
)
endif()
+ # Preserve semicolon in test-parameters
+ string(REPLACE [[;]] [[\;]] output "${output}")
string(REPLACE "\n" ";" output "${output}")
# Parse output
@@ -114,9 +116,19 @@ function(gtest_discover_tests_impl)
else()
unset(TEST_XML_OUTPUT_PARAM)
endif()
+
+ # sanitize test name for further processing downstream
+ set(testname "${prefix}${pretty_suite}.${pretty_test}${suffix}")
+ # escape \
+ string(REPLACE [[\]] [[\\]] testname "${testname}")
+ # escape ;
+ string(REPLACE [[;]] [[\;]] testname "${testname}")
+ # escape $
+ string(REPLACE [[$]] [[\$]] testname "${testname}")
+
# ...and add to script
add_command(add_test
- "${prefix}${pretty_suite}.${pretty_test}${suffix}"
+ "${testname}"
${_TEST_EXECUTOR}
"${_TEST_EXECUTABLE}"
"--gtest_filter=${suite}.${test}"
@@ -126,18 +138,18 @@ function(gtest_discover_tests_impl)
)
if(suite MATCHES "^DISABLED" OR test MATCHES "^DISABLED")
add_command(set_tests_properties
- "${prefix}${pretty_suite}.${pretty_test}${suffix}"
+ "${testname}"
PROPERTIES DISABLED TRUE
)
endif()
add_command(set_tests_properties
- "${prefix}${pretty_suite}.${pretty_test}${suffix}"
+ "${testname}"
PROPERTIES
WORKING_DIRECTORY "${_TEST_WORKING_DIR}"
SKIP_REGULAR_EXPRESSION "\\\\[ SKIPPED \\\\]"
${properties}
)
- list(APPEND tests_buffer "${prefix}${pretty_suite}.${pretty_test}${suffix}")
+ list(APPEND tests_buffer "${testname}")
list(LENGTH tests_buffer tests_buffer_length)
if(${tests_buffer_length} GREATER "250")
flush_tests_buffer()