[cmake-developers] Run program/command before test

Nils Gladitz nilsgladitz at gmail.com
Wed Feb 17 03:09:18 EST 2016


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