[cmake-developers] Run program/command before test

Roman Wüger roman.wueger at gmx.at
Wed Feb 17 04:32:18 EST 2016


Hi Nils,

great thanks.

Regards
Roman 

> Am 17.02.2016 um 09:09 schrieb Nils Gladitz <nilsgladitz at gmail.com>:
> 
>> On 17.02.2016 07:58, Roman Wüger wrote:
>> Ok thanks
>> 
>> Would it be an opinion to have a COMMAND parameter for the add_test function like execute_process where every COMMAND must return the exit code and this would be ored?
>> 
>> add_test(MyTest COMMAND myserver --port 80
>>                               COMMAND mytest
>>                               COMMAND myserver --graceful-shutdown)
>> 
>> Or
>> 
>> add_test(MyTest PRE_COMMAND myserver --port 80
>>                               COMMAND mytest
>>                               POST_COMMAND myserver --graceful-shutdown)
> 
> What you could already do is wrap your test in a cmake script.
> 
> E.g.
> 
>    add_test(NAME MyTest
>        COMMAND ${CMAKE_COMMAND} -DACTUAL_TEST=$<TARGET_FILE:mytest> -P ${CMAKE_CURRENT_SOURCE_DIR}/mywrapper.cmake
>    )
> 
> Where mywrapper.cmake could do something like:
> 
>    execute_process(COMMAND mysever --port 80 ...)
> 
>    execute_process(COMMAND ${ACTUAL_TEST} ....)
> 
>    execute_process(COMMAND mysever --graceful-shutdown)
> 
> To have the test fail you could call message(FATAL_ERROR "...")
> 
> For this to work myserver would have to daemonize/fork (but I assume that is the case given your example).
> 
> Nils


More information about the cmake-developers mailing list