Wrapping tests discovered by gtest_discover_tests into a wrapper.

Hello, everyone.

So, gtest_discover_tests() runs my gtest-test --gtest_list_tests, and defines a separate ctest test for each result.

Now I want to run those tests wrapped in a script. That is, instead of running gtest-test --gtest_list_tests , I want ctest to run my_wrapper.sh gtest-test --gtest_list_tests .

Presumably, in the wrapper I would do something like
perf record --output=/tmp/whatever “$@”

I guess, I can do gtest_discover_tests() with my wrapper, and pass the actual test executable in EXTRA_ARGS, and make my own scanner for the presence of --gtest_list_tests and other args in the non-extra args, but it might be a little crutchy.

Any ideas how to do it better?

There is a change on CMake master already which adds a new TEST_LAUNCHER test property and corresponding CMAKE_TEST_LAUNCHER variable. It will appear in CMake 3.29.0, and the release cycle for that will probably start in a couple of weeks. One could mount an argument that perhaps that property should also be used when obtaining the test list by running some-exe --gtest_list_tests. Here’s the relevant change:


@brad.king It would be considerably simpler to decide whether this should be included in the test discovery step of gtest_discover_tests() before the 3.29.0 release than to try to change that behavior later with a policy. If we put a change in now to make the test discovery use the launcher as well, then that means we can say from the beginning that it is the launcher’s responsibility to handle it. Thoughts?

Please open an issue to propose that.

Done, new issue created here: https://gitlab.kitware.com/cmake/cmake/-/issues/25603