summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorEvgeniy Shcherbina <ixsci@pm.me>2022-02-09 08:26:51 (GMT)
committerBrad King <brad.king@kitware.com>2022-02-11 14:03:40 (GMT)
commit61929f936f3a834a99762aafaf79f9f1ce9cf6d6 (patch)
tree03c1e35e1de566fbc7912c07f6d2305f13e5330f /Tests
parenta15cc7706da8f4a1833539be3f37fbc63ee20e36 (diff)
downloadCMake-61929f936f3a834a99762aafaf79f9f1ce9cf6d6.zip
CMake-61929f936f3a834a99762aafaf79f9f1ce9cf6d6.tar.gz
CMake-61929f936f3a834a99762aafaf79f9f1ce9cf6d6.tar.bz2
GoogleTest: Fix escaping in test names
Due to add_command() being a macro it introduced excessive and nonobvious escaping in different parts of the script. Because of one of such places the resulting script would have an erroneous ${TEST_LIST} if the user data (in test parameters) had a semicolon. To eliminate this non-obvious escaping, add_command() was converted to function. Updated the escaping accordingly. Fixes: #23059
Diffstat (limited to 'Tests')
-rw-r--r--Tests/RunCMake/GoogleTest/GoogleTest-discovery-check-test-list.cmake6
-rw-r--r--Tests/RunCMake/GoogleTest/GoogleTest-discovery-flush-script-check-list.cmake5
-rw-r--r--Tests/RunCMake/GoogleTest/GoogleTestDiscoveryFlushScript.cmake14
-rw-r--r--Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTestList.cmake14
-rw-r--r--Tests/RunCMake/GoogleTest/RunCMakeTest.cmake54
-rw-r--r--Tests/RunCMake/GoogleTest/flush_script_test.cpp19
-rw-r--r--Tests/RunCMake/GoogleTest/test_list_test.cpp18
7 files changed, 130 insertions, 0 deletions
diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-discovery-check-test-list.cmake b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-check-test-list.cmake
new file mode 100644
index 0000000..94169e7
--- /dev/null
+++ b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-check-test-list.cmake
@@ -0,0 +1,6 @@
+list(LENGTH test_list_test_TESTS LIST_SIZE)
+set(EXPECTED_SIZE 2)
+if(NOT LIST_SIZE EQUAL ${EXPECTED_SIZE})
+ message("TEST_LIST should have ${EXPECTED_SIZE} elements but it has ${LIST_SIZE}")
+ message("The unexpected list: [${test_list_test_TESTS}]")
+endif()
diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-discovery-flush-script-check-list.cmake b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-flush-script-check-list.cmake
new file mode 100644
index 0000000..1ae222f
--- /dev/null
+++ b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-flush-script-check-list.cmake
@@ -0,0 +1,5 @@
+list(LENGTH flush_script_test_TESTS LIST_SIZE)
+set(EXPECTED_LIST_SIZE 4)
+if(NOT LIST_SIZE EQUAL ${EXPECTED_LIST_SIZE})
+ message("TEST_LIST should have ${EXPECTED_LIST_SIZE} elements but it has ${LIST_SIZE}")
+endif()
diff --git a/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryFlushScript.cmake b/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryFlushScript.cmake
new file mode 100644
index 0000000..2c138c7
--- /dev/null
+++ b/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryFlushScript.cmake
@@ -0,0 +1,14 @@
+enable_language(CXX)
+include(GoogleTest)
+
+enable_testing()
+
+include(xcode_sign_adhoc.cmake)
+
+add_executable(flush_script_test flush_script_test.cpp)
+xcode_sign_adhoc(flush_script_test)
+gtest_discover_tests(
+ flush_script_test
+)
+set_property(DIRECTORY APPEND PROPERTY TEST_INCLUDE_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/GoogleTest-discovery-flush-script-check-list.cmake)
diff --git a/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTestList.cmake b/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTestList.cmake
new file mode 100644
index 0000000..5f4f859
--- /dev/null
+++ b/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTestList.cmake
@@ -0,0 +1,14 @@
+enable_language(CXX)
+include(GoogleTest)
+
+enable_testing()
+
+include(xcode_sign_adhoc.cmake)
+
+add_executable(test_list_test test_list_test.cpp)
+xcode_sign_adhoc(test_list_test)
+gtest_discover_tests(
+ test_list_test
+)
+set_property(DIRECTORY APPEND PROPERTY TEST_INCLUDE_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/GoogleTest-discovery-check-test-list.cmake)
diff --git a/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake b/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake
index 33a4b43..695f562 100644
--- a/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake
+++ b/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake
@@ -236,6 +236,58 @@ function(run_GoogleTest_discovery_multi_config)
endfunction()
+function(run_GoogleTest_discovery_test_list DISCOVERY_MODE)
+ # Use a single build tree for a few tests without cleaning.
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-test-list-build)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
+ set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
+ endif()
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+ file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+
+ run_cmake_with_options(GoogleTestDiscoveryTestList -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE})
+
+ run_cmake_command(GoogleTest-discovery-test-list-build
+ ${CMAKE_COMMAND}
+ --build .
+ --config Debug
+ --target test_list_test
+ )
+
+ run_cmake_command(GoogleTest-discovery-test-list-test
+ ${CMAKE_CTEST_COMMAND}
+ -C Debug
+ --no-label-summary
+ )
+endfunction()
+
+function(run_GoogleTest_discovery_flush_script DISCOVERY_MODE)
+ # Use a single build tree for a few tests without cleaning.
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-flush-script-build)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
+ set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
+ endif()
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+ file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+
+ run_cmake_with_options(GoogleTestDiscoveryFlushScript -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE})
+
+ run_cmake_command(GoogleTest-discovery-flush-script-build
+ ${CMAKE_COMMAND}
+ --build .
+ --config Debug
+ --target flush_script_test
+ )
+
+ run_cmake_command(GoogleTest-discovery-flush-script-test
+ ${CMAKE_CTEST_COMMAND}
+ -C Debug
+ --no-label-summary
+ )
+endfunction()
+
foreach(DISCOVERY_MODE POST_BUILD PRE_TEST)
message("Testing ${DISCOVERY_MODE} discovery mode via CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE global override...")
run_GoogleTest(${DISCOVERY_MODE})
@@ -246,6 +298,8 @@ foreach(DISCOVERY_MODE POST_BUILD PRE_TEST)
NOT "${DISCOVERY_MODE};${RunCMake_GENERATOR}" MATCHES "^POST_BUILD;Visual Studio 9")
run_GoogleTest_discovery_arg_change(${DISCOVERY_MODE})
endif()
+ run_GoogleTest_discovery_test_list(${DISCOVERY_MODE})
+ run_GoogleTest_discovery_flush_script(${DISCOVERY_MODE})
endforeach()
if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
diff --git a/Tests/RunCMake/GoogleTest/flush_script_test.cpp b/Tests/RunCMake/GoogleTest/flush_script_test.cpp
new file mode 100644
index 0000000..9473bb5
--- /dev/null
+++ b/Tests/RunCMake/GoogleTest/flush_script_test.cpp
@@ -0,0 +1,19 @@
+#include <iostream>
+#include <string>
+
+int main(int argc, char** argv)
+{
+ // Note: GoogleTest.cmake doesn't actually depend on Google Test as such;
+ // it only requires that we produces output in the expected format when
+ // invoked with --gtest_list_tests. Thus, we fake that here. This allows us
+ // to test the module without actually needing Google Test.
+ if (argc > 1 && std::string(argv[1]) == "--gtest_list_tests") {
+ std::cout << "flush_script_test.\n";
+ const size_t flushThreshold = 50000;
+ const size_t testCaseNum = 4;
+ std::string testName(flushThreshold / (testCaseNum - 1), 'T');
+ for (size_t i = 0; i < testCaseNum; ++i)
+ std::cout << " " << testName.c_str() << "\n";
+ }
+ return 0;
+}
diff --git a/Tests/RunCMake/GoogleTest/test_list_test.cpp b/Tests/RunCMake/GoogleTest/test_list_test.cpp
new file mode 100644
index 0000000..c9f9512
--- /dev/null
+++ b/Tests/RunCMake/GoogleTest/test_list_test.cpp
@@ -0,0 +1,18 @@
+#include <iostream>
+#include <string>
+
+int main(int argc, char** argv)
+{
+ // Note: GoogleTest.cmake doesn't actually depend on Google Test as such;
+ // it only requires that we produces output in the expected format when
+ // invoked with --gtest_list_tests. Thus, we fake that here. This allows us
+ // to test the module without actually needing Google Test.
+ if (argc > 1 && std::string(argv[1]) == "--gtest_list_tests") {
+ std::cout << "test_list_test/test.\n";
+ std::cout << " case/0 # GetParam() = \"semicolon;\"\n";
+ std::cout << " case/1 # GetParam() = 'osb['\n";
+ std::cout << " case/2 # GetParam() = 'csb]'\n";
+ std::cout << " case/3 # GetParam() = 'S p a c e s'\n";
+ }
+ return 0;
+}