summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorCraig Scott <craig.scott@crascit.com>2024-11-09 02:34:07 (GMT)
committerBrad King <brad.king@kitware.com>2024-11-12 15:22:21 (GMT)
commit9a24c1e8022de70eab6046adbaa7e9427af75a9e (patch)
treebed3cceb87977d9e2987733a1ba61d1bfc45e105 /Tests
parente22c8383b9ae4f27a78f7a8849693c03ca29c7bb (diff)
downloadCMake-9a24c1e8022de70eab6046adbaa7e9427af75a9e.zip
CMake-9a24c1e8022de70eab6046adbaa7e9427af75a9e.tar.gz
CMake-9a24c1e8022de70eab6046adbaa7e9427af75a9e.tar.bz2
GoogleTest: Clear script content buffer on flush and flush less often
There's no need to check if flushing is needed after every command is added to the variable holding the script content. It is enough to only check once per test name. This simplifies the flushing logic, removing the need for a separate flush_script() command. Previously, we were not clearing the flushed script contents in all cases, but this is now rigorously enforced at the one location where flushing is performed. Also simplify the flushing of the list of test names, since that too doesn't need a separate command. It is simpler and safer to handle that directly inline where the one call to flush_tests_buffer() was previously being made. Fixes: #26431
Diffstat (limited to 'Tests')
-rw-r--r--Tests/RunCMake/GoogleTest/GoogleTest-discovery-flush-script-check-list.cmake5
-rw-r--r--Tests/RunCMake/GoogleTest/GoogleTest-discovery-flush-script-check-list.cmake.in34
-rw-r--r--Tests/RunCMake/GoogleTest/GoogleTestDiscoveryFlushScript.cmake8
-rw-r--r--Tests/RunCMake/GoogleTest/flush_script_test.cpp9
4 files changed, 46 insertions, 10 deletions
diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-discovery-flush-script-check-list.cmake b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-flush-script-check-list.cmake
deleted file mode 100644
index 1ae222f..0000000
--- a/Tests/RunCMake/GoogleTest/GoogleTest-discovery-flush-script-check-list.cmake
+++ /dev/null
@@ -1,5 +0,0 @@
-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/GoogleTest-discovery-flush-script-check-list.cmake.in b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-flush-script-check-list.cmake.in
new file mode 100644
index 0000000..b334d2b
--- /dev/null
+++ b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-flush-script-check-list.cmake.in
@@ -0,0 +1,34 @@
+set(expected_number_of_tests 12)
+
+# Check the flushing of the test names buffer
+list(LENGTH flush_script_test_TESTS num_test_names)
+if(NOT num_test_names EQUAL expected_number_of_tests)
+ message(FATAL_ERROR
+ "Test name list has wrong number of test names:\n"
+ " Expected: ${expected_number_of_tests}\n"
+ " Actual: ${num_test_names}"
+ )
+endif()
+
+# Check the flushing of the script content variable.
+# Note that flushing errors would repeat a test name, so such errors are not
+# uncovered by checking the name buffer flushing above.
+
+# PRE_TEST can have a config-specific tests file, POST_BUILD never does
+set(tests_file "@CMAKE_CURRENT_BINARY_DIR@/flush_script_test[1]_tests-Debug.cmake")
+if(NOT EXISTS "${tests_file}")
+ set(tests_file "@CMAKE_CURRENT_BINARY_DIR@/flush_script_test[1]_tests.cmake")
+endif()
+if(NOT EXISTS "${tests_file}")
+ message(FATAL_ERROR "Tests file is missing")
+endif()
+
+file(STRINGS "${tests_file}" add_test_lines REGEX "^add_test" ENCODING UTF-8)
+list(LENGTH add_test_lines num_add_test_lines)
+if(NOT num_add_test_lines EQUAL expected_number_of_tests)
+ message(FATAL_ERROR
+ "Test script has wrong number of add_test() calls:\n"
+ " Expected: ${expected_number_of_tests}\n"
+ " Actual: ${num_add_test_lines}"
+ )
+endif()
diff --git a/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryFlushScript.cmake b/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryFlushScript.cmake
index 2c138c7..b537a5f 100644
--- a/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryFlushScript.cmake
+++ b/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryFlushScript.cmake
@@ -10,5 +10,11 @@ xcode_sign_adhoc(flush_script_test)
gtest_discover_tests(
flush_script_test
)
+
+configure_file(GoogleTest-discovery-flush-script-check-list.cmake.in
+ check-test-lists.cmake
+ @ONLY
+)
set_property(DIRECTORY APPEND PROPERTY TEST_INCLUDE_FILES
- ${CMAKE_CURRENT_SOURCE_DIR}/GoogleTest-discovery-flush-script-check-list.cmake)
+ ${CMAKE_CURRENT_BINARY_DIR}/check-test-lists.cmake
+)
diff --git a/Tests/RunCMake/GoogleTest/flush_script_test.cpp b/Tests/RunCMake/GoogleTest/flush_script_test.cpp
index 9473bb5..f032dda 100644
--- a/Tests/RunCMake/GoogleTest/flush_script_test.cpp
+++ b/Tests/RunCMake/GoogleTest/flush_script_test.cpp
@@ -10,10 +10,11 @@ int main(int argc, char** argv)
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";
+ const size_t flushAfter = 4;
+ const size_t testCaseNum = 3 * flushAfter;
+ std::string testName(flushThreshold / flushAfter, 'T');
+ for (size_t i = 1; i <= testCaseNum; ++i)
+ std::cout << " t" << i << testName.c_str() << "\n";
}
return 0;
}