Repeated arguments to set_tests_properties() work, should it be documented?
I just discovered by accident that the following actually works and is quite useful (EDIT: not quite, see this comment further below):
set_tests_properties(SomeTest
PROPERTIES
ENVIRONMENT SOME_VAR=xxx
ENVIRONMENT ANOTHER_VAR=yyy
)
I believe what's happening is that in cmCTestTestHandler::SetTestsProperties()
, when we encounter the ENVIRONMENT
property name, we call cmExpandList(val, rt.Environment)
. That call appends to rt.Environment
, so if the ENVIRONMENT
keyword is given multiple times like in the above example, the environment variable settings accumulate.
As it turns out, this is really useful for gtest_discover_tests()
. The syntax of that command supports a PROPERTIES
keyword, which has name value
pairs after it. The problem we have is that our name
is ENVIRONMENT
and our value
should support a list of env_var=something
items. But this only works in this case if we have no more than one item in the list. In other words, we can't actually set more than one environment variable this way. Except we can! If we repeat the ENVIRONMENT
keyword as the property name, the env_var=something
values accumulate, which is exactly the behavior we want. It means the following actually works:
gtest_discover_tests(someTarget
PROPERTIES
ENVIRONMENT SOME_VAR=xxx
ENVIRONMENT ANOTHER_VAR=xxx
)
We end up with both SOME_VAR
and ANOTHER_VAR
getting set to the values we specified. Until now, I thought the only way to set multiple environment variables for a test was to write a script that is loaded and processed at test time (i.e. using the TEST_INCLUDE_FILES
directory property). But with the above discovery, it seems we don't have to go that far to achieve the goal.
I expect the same would also apply to ENVIRONMENT_MODIFICATION
too. I haven't tested it, but it looks like it uses exactly the same sort of implementation.
So my question is, since this is already released behavior, and since it is rather useful, should we officially document it as supported? If so, I think we should document it for both set_tests_properties()
and gtest_discover_tests()
(EDIT: I didn't test minimally enough, it is only gtest_discover_tests()
that exhibits this behavior, so that's the only one we might document this for).