Unknown CMake command "get_test_property" in TEST_INCLUDE_FILES

I helping the Catch2 team with CTest label support (see Make catch tags work with ctest labels · Issue #1590 · catchorg/Catch2 · GitHub).

The catch_discover_tests CMake command that comes with Catch2 uses the TEST_INCLUDE_FILES command to run custom code when ctest runs. Calling get_test_property in one of the TEST_INCLUDE_FILES fails with the error:

$ ctest --print-labels
Test project /home/eric/work/tw-base/cmake-build-debug
CMake Error at /home/eric/work/tw-base/cmake-build-debug/tw/utils/test/utils-test_tests-b858cb2.cmake:64 (get_test_property):
  Unknown CMake command "get_test_property".
Call Stack (most recent call first):
  /home/eric/work/tw-base/cmake-build-debug/tw/utils/test/utils-test_include-b858cb2.cmake:2 (include)
  /home/eric/work/tw-base/cmake-build-debug/tw/utils/test/CTestTestfile.cmake:7 (include)
  /home/eric/work/tw-base/cmake-build-debug/tw/utils/CTestTestfile.cmake:7 (subdirs)
  /home/eric/work/tw-base/cmake-build-debug/tw/CTestTestfile.cmake:8 (subdirs)
  CTestTestfile.cmake:7 (subdirs)

The TEST_INCLUDE_FILES code looks like:

add_test( [==[utils:Binary Encoding]==] /home/eric/work/tw-base/cmake-build-debug/bin/tw-base-utils-test [==[Binary Encoding]==])
set_tests_properties( [==[utils:Binary Encoding]==] PROPERTIES WORKING_DIRECTORY /home/eric/work/tw-base/cmake-build-debug/tw/utils/test)
get_test_property( [==[utils:Binary Encoding]==] LABELS test_labels)
set_tests_properties( [==[utils:Binary Encoding]==] PROPERTIES LABELS Binary Pack ${test_labels})

Is this expected?

There is no get_test_property command. You should use get_property(outvar TEST "${testname}") instead.

It’s in the docs? https://cmake.org/cmake/help/latest/command/get_test_property.html

Oh, so it is. Hmm.

Oh. I see now. You’re using ctest. The set of commands available in CTest scripts is not the same. This is one such command that is not available there.

Interesting - is there a list of supported or unsupported commands in TEST_INCLUDE_FILES?

Another related issue - set_property(TEST test APPEND PROPERTY LABELS labels) fails in a TEST_INCLUDE_FILES. For example:

add_test( Testing /Users/eric/IdeaProjects/experiments-c/cmake-build-debug/bin/catch_example Testing)
set_tests_properties( Testing PROPERTIES WORKING_DIRECTORY /Users/eric/IdeaProjects/experiments-c/cmake-build-debug)
set_property(TEST Testing APPEND PROPERTY LABELS "example")

fails with

Test project /Users/eric/IdeaProjects/experiments-c/cmake-build-debug
CMake Error at /Users/eric/IdeaProjects/experiments-c/cmake-build-debug/catch_example_tests-b858cb2.cmake:9 (set_property):
  set_property given TEST names that do not exist:

    Testing

Call Stack (most recent call first):
  /Users/eric/IdeaProjects/experiments-c/cmake-build-debug/catch_example_include-b858cb2.cmake:2 (include)
  CTestTestfile.cmake:7 (include)

get_property(TEST test APPEND PROPERTY LABELS var) also fails in TEST_INCLUDE_FILES.

They both work fine in CMakeLists.txt.

Hrm, yeah, I don’t see it documented anywhere :frowning: . Let’s open an issue to get it documented.

@kyle.edwards You might know more since, IIRC, you added the “what commands are available where?” mechanisms to the code, but maybe that was just for CMake.

Done: https://gitlab.kitware.com/cmake/cmake/-/issues/22473

Thanks Ben!

I stumbled on the exact same problem. Until I noticed that apparently ctest only supports “Scripting Commands” (as what Craig Scott said in the issue).
In my case I wanted to know the WORKING_DIR from a gtest_discover_tests to support Ninja Multi-Config