add_test to support generator expressions?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

add_test to support generator expressions?

Chris Green
Hi,

I have a function cet_test(), which allows a user to specify the details
of a test which will be executed via a wrapper, cet_exec_test. It calls
the CMake add_test() macro to set this up. The user may subsequently set
the SKIP_RETURN_CODE property on this test, which must be communicated
to cet_exec_test() so that it can notify CMake if the test requirements
are violated. I attempted to do this with:

add_test(NAME ${target}
         ...
         COMMAND cet_exec_test ... --skip-return-code $<TARGET_PROPERTY:${target},SKIP_RETURN_CODE>
         ...)

but this resulted in an error. Am I using generator expressions wrongly
in this case, or does add_test() not support them? Is there something
else I can do?

Thanks for any help,

Chris.

--
Chris Green <[hidden email]>, FNAL CS/SCD/ADSS/SSI/TAC;

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: add_test to support generator expressions?

Chris Green
Hi,

I should add that I am using CMake 3.3.2.

Sorry for the omission,
Chris.

On 10/26/15 2:29 PM, Chris Green wrote:

> Hi,
>
> I have a function cet_test(), which allows a user to specify the
> details of a test which will be executed via a wrapper, cet_exec_test.
> It calls the CMake add_test() macro to set this up. The user may
> subsequently set the SKIP_RETURN_CODE property on this test, which
> must be communicated to cet_exec_test() so that it can notify CMake if
> the test requirements are violated. I attempted to do this with:
>
> add_test(NAME ${target}
>      ...
>      COMMAND cet_exec_test ... --skip-return-code
> $<TARGET_PROPERTY:${target},SKIP_RETURN_CODE>
>      ...)
>
> but this resulted in an error. Am I using generator expressions
> wrongly in this case, or does add_test() not support them? Is there
> something else I can do?
>
> Thanks for any help,
>
> Chris.

--
Chris Green <[hidden email]>, FNAL CS/SCD/ADSS/SSI/TAC;

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: add_test to support generator expressions?

Nils Gladitz-2
In reply to this post by Chris Green
On 26.10.2015 20:29, Chris Green wrote:

> Hi,
>
> I have a function cet_test(), which allows a user to specify the
> details of a test which will be executed via a wrapper, cet_exec_test.
> It calls the CMake add_test() macro to set this up. The user may
> subsequently set the SKIP_RETURN_CODE property on this test, which
> must be communicated to cet_exec_test() so that it can notify CMake if
> the test requirements are violated. I attempted to do this with:
>
> add_test(NAME ${target}
>      ...
>      COMMAND cet_exec_test ... --skip-return-code
> $<TARGET_PROPERTY:${target},SKIP_RETURN_CODE>
>      ...)
>
> but this resulted in an error. Am I using generator expressions
> wrongly in this case, or does add_test() not support them? Is there
> something else I can do?

You did not mention what the error actually is but ...

add_test() does support generator expressions in the command (as long as
you are using the NAME/COMMAND signature; which you are).
Tests are not targets; hence TARGET_PROPERTY does not work here unless
you also happen to have an actual target with the same name as the test
(which is possible but can't be inferred from your snippet) and you set
the property of that target rather than the test.

Nils

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: add_test to support generator expressions?

Chris Green
Ah, I see. It appears I was unclear on the difference between target and
test. What I actually want is the *test* property SKIP_RETURN_CODE,
which there does not seem to be any way to access via a generator
expression. Looks like I'm out of look, unless this is an upcoming feature?

Thanks for the clarification,

Chris.

On 10/26/15 3:20 PM, Nils Gladitz wrote:

> On 26.10.2015 20:29, Chris Green wrote:
>> Hi,
>>
>> I have a function cet_test(), which allows a user to specify the
>> details of a test which will be executed via a wrapper,
>> cet_exec_test. It calls the CMake add_test() macro to set this up.
>> The user may subsequently set the SKIP_RETURN_CODE property on this
>> test, which must be communicated to cet_exec_test() so that it can
>> notify CMake if the test requirements are violated. I attempted to do
>> this with:
>>
>> add_test(NAME ${target}
>>      ...
>>      COMMAND cet_exec_test ... --skip-return-code
>> $<TARGET_PROPERTY:${target},SKIP_RETURN_CODE>
>>      ...)
>>
>> but this resulted in an error. Am I using generator expressions
>> wrongly in this case, or does add_test() not support them? Is there
>> something else I can do?
>
> You did not mention what the error actually is but ...
>
> add_test() does support generator expressions in the command (as long
> as you are using the NAME/COMMAND signature; which you are).
> Tests are not targets; hence TARGET_PROPERTY does not work here unless
> you also happen to have an actual target with the same name as the
> test (which is possible but can't be inferred from your snippet) and
> you set the property of that target rather than the test.
>
> Nils
>

--
Chris Green <[hidden email]>, FNAL CS/SCD/ADSS/SSI/TAC;
'phone (630) 840-2167; Skype: chris.h.green;
IM: [hidden email], chissgreen (AIM),
chris.h.green (Google Talk).

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: add_test to support generator expressions?

Nils Gladitz-2
On 10/27/2015 02:33 PM, Chris Green wrote:
> Ah, I see. It appears I was unclear on the difference between target
> and test. What I actually want is the *test* property
> SKIP_RETURN_CODE, which there does not seem to be any way to access
> via a generator expression. Looks like I'm out of look, unless this is
> an upcoming feature?

I haven't heard of anyone working on this and it is certainly too late
for 3.4 but if you make it a feature request on the issue tracker you
might be lucky and someone might pick it up eventually.
Or better yet you could consider contributing it yourself. [1]

Nils

[1] https://cmake.org/gitweb?p=cmake.git;a=blob;f=CONTRIBUTING.rst
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: add_test to support generator expressions?

Stephen Kelly-2
In reply to this post by Chris Green
Chris Green wrote:

> Ah, I see. It appears I was unclear on the difference between target and
> test. What I actually want is the *test* property SKIP_RETURN_CODE,
> which there does not seem to be any way to access via a generator
> expression. Looks like I'm out of look, unless this is an upcoming
> feature?

Generator expressions are generally only useful for things which are
determined at generate-time.

Can't you just read the test property at configure-time instead? You're the
one setting the property, right?

Thanks,

Steve.


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: add_test to support generator expressions?

Nils Gladitz-2
On 27.10.2015 19:58, Stephen Kelly wrote:

> Chris Green wrote:
>
>> Ah, I see. It appears I was unclear on the difference between target and
>> test. What I actually want is the *test* property SKIP_RETURN_CODE,
>> which there does not seem to be any way to access via a generator
>> expression. Looks like I'm out of look, unless this is an upcoming
>> feature?
> Generator expressions are generally only useful for things which are
> determined at generate-time.
>
> Can't you just read the test property at configure-time instead? You're the
> one setting the property, right?

Deferring evaluation to generation time does have the advantage that you
can set and change properties at any point after the test has been
created and you can still be sure that the test is invoked with the
final value.

Without the generator expression reading the property at configuration
time is not really an option because the test's properties will not
exist before add_test() and the test command itself is what was
referring to that property.

You'd have to reorder logic so that the parameter for --skip-return-code
is known before add_test() (and use e.g. variables or (custom) target
properties).

Nils

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: add_test to support generator expressions?

Stephen Kelly-2
Nils Gladitz wrote:

> On 27.10.2015 19:58, Stephen Kelly wrote:
>> Chris Green wrote:
>>
>>> Ah, I see. It appears I was unclear on the difference between target and
>>> test. What I actually want is the *test* property SKIP_RETURN_CODE,
>>> which there does not seem to be any way to access via a generator
>>> expression. Looks like I'm out of look, unless this is an upcoming
>>> feature?
>> Generator expressions are generally only useful for things which are
>> determined at generate-time.
>>
>> Can't you just read the test property at configure-time instead? You're
>> the one setting the property, right?
>
> Deferring evaluation to generation time does have the advantage that you
> can set and change properties at any point after the test has been
> created and you can still be sure that the test is invoked with the
> final value.

Right. What I missed is that Chris seems to be making an interface for other
unknown downstreams to use (a cet_test function).

It would be possible to require the user of cet_test to specify the
SKIP_RETURN_CODE in a parameter, but there would be unexpected behavior if
someone omitted that parameter and wrote

 cet_test(mytest ...)
 set_test_property(mytest PROPERTIES SKIP_RETURN_CODE ...)

instead.

A lot of effort went into cmake targets to make wrappers like
kde4_add_executable/kde4_add_library unnecessary, and generator expressions
were a part of that.

Perhaps it makes sense to put similar effort into making add_test wrappers
unnecessary, and generator expressions for test properties could be part of
that.

However, I don't have so much experience with doing beyond-basic things with
ctest, so I don't know what kinds of issues arise which lead people to
create wrappers like that, so I probably can't be of much help.

Thanks,

Steve.


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake