CTest: Add support for custom test properties in ctest --show-only=json-v1
From what I can see here, ctest currently dumps only predefined list of test properties to JSON format. In my case, tests declared with add_test contain custom properties defined with define_property and set with set_property. Unfortunately, such metadata can't be exported from CMake with ctest --show-only=json-v1
command.
Example application can be found below.
CMakeLists.txt:
project(my_project)
cmake_minimum_required(VERSION 3.16)
include(CTest)
define_property(TEST PROPERTY MY_PROPERTY BRIEF_DOCS "brief docs" FULL_DOCS "full docs")
add_test(
NAME my_test_name
COMMAND ${CMAKE_COMMAND} --help
)
set_property(
TEST my_test_name
PROPERTY MY_PROPERTY
my_data_1
my_data_2
)
get_property(MY_VAR TEST my_test_name PROPERTY MY_PROPERTY)
message(STATUS "MY_VAR: ${MY_VAR}")
CMake:
developer@ltowarek-desk:~/workspace/cmake_test$ cmake -B build -S .
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- MY_VAR: my_data_1;my_data_2
-- Configuring done
-- Generating done
-- Build files have been written to: /home/developer/workspace/cmake_test/build
CTest:
developer@ltowarek-desk:~/workspace/cmake_test/build$ ctest --show-only=json-v1
{
"backtraceGraph" :
{
"commands" :
[
"add_test"
],
"files" :
[
"/home/developer/workspace/cmake_test/CMakeLists.txt"
],
"nodes" :
[
{
"file" : 0
},
{
"command" : 0,
"file" : 0,
"line" : 8,
"parent" : 0
}
]
},
"kind" : "ctestInfo",
"tests" :
[
{
"backtrace" : 1,
"command" :
[
"/usr/bin/cmake",
"--help"
],
"name" : "my_test_name",
"properties" :
[
{
"name" : "WORKING_DIRECTORY",
"value" : "/home/developer/workspace/cmake_test/build"
}
]
}
],
"version" :
{
"major" : 1,
"minor" : 0
}
}
BTW, exactly the same problem is also mentioned in CMake Test Explorer extension for Visual Studio Code. Their workaround is to declare custom properties inside ENVIRONMENT
property.
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information