Skip to content

GoogleTest: Add handling for square brackets in test names

If a test name contains a square bracket (due to parameters) then it breaks gtest_discovery_test() function in some not-so-predictable way. That happens due to the special meaning these brackets have in the CMake language and they can't be escaped universally.

So the following treatment has been implemented:

  • Every occurrence of ('[' | ']') in a test name gets replaced with the corresponding placeholder ("_osb" | "_csb") before the Google Test output processing and gets replaced back before adding a new test to CTest, keeping the original test name intact in the CTest output. The placeholders are chosen that way to minimize the chance of clashing with something in the user tests but even if the default ones would clash with something then they are enhanced to not clash with anything (hence "_*" at the placeholder's end).
  • The GTest output gets searched for the default test name guards ("[=[" | "]=]") and if they are found a new one gets generated until the one is found which can safely encompass any test name. The search is quite simple: find the least amount of '=' which would allow escaping any test.
  • The resulting ${TEST_LIST} variable will contain every test but tests with square brackets as there is no way to make sure such tests won't break the list altogether.

Fixes: #23039 (closed)
Topic-rename: GoogleTest-discover-sq-brackets

Edited by Brad King

Merge request reports