[CMake] How can I run tests using a wrapper script

Michael Hertling mhertling at online.de
Fri Nov 4 17:34:23 EDT 2011


On 11/04/2011 10:13 PM, EXT-York, Gantry wrote:
> I'm new to cmake.
> 
> I'm trying to define some unit tests in CMakeLists.txt.    I need to run utest1, utest2, utest3 and so forth, but I need to run them through a wrapper script called run_utest.  run_utest is used to intercept some output and report it to a website.  We do not use cdash.
> 
> I'm trying to do this with the
> 
> add_executable( utest1 )
> add_test(
>     NAME utest1
>     COMMAND /fully/qualified/path/run_utest  --report  utest1
> )
> 
> The problem is that the add_test command treats run_utest as the command but the following arguments are treated as arguments.  ctest -V even shows that they are quoted.  utest1 does not get treated as if it is an executable.
> 
> So what I get is
> 
> /fully/qualified/path/run_utest "-report" "utest1"
> 
> instead of
> 
> /fully/qualified/path/run_utest -report /path/to/utuest1
> 
> Needless to say it won't run.

ADD_TEST() expands only the actual COMMAND w.r.t. an executable's
full path but not the COMMAND's arguments. However, you might use
generator expressions for this purpose:

ADD_EXECUTABLE(utest1)
ADD_TEST(NAME utest1
    COMMAND /fully/qualified/path/run_utest
        --report $<TARGET_FILE:utest1>)

'hope that helps.

Regards,

Michael


More information about the CMake mailing list