Can I modify ctest via custom command line arguments?

Suppose I have a test defined like:

add_test(NAME myCoolTest  COMMAND testRunner normalArg)

I’d like to be able to modify myCoolTest when I call ctest, by doing something like:

ctest -R myCoolTest -D do-crazy=1

…which would then somehow result in running:

testRunner --do-crazy-option normalArg

I was hoping that some combination of ctest -D <var>:<type>=<value> and CTestCustom.cmake might allow me to alter the invoked test command somehow - however, there’s two problems with this approach:

  • It seems that I can’t access variables defined via ctest -D var=value from within CTestCustom.cmake
  • From within CTestCustom.cmake, I don’t know how (or if it’s possible) to modify myCoolTest (or any test)

Is there any way to customize test behavior by specifying command flags to ctest?

In theory, I know I could use env variables to modify behavior… however, since I don’t have direct access to testRunner in my example, I’d have to make a wrapper executable, testRunnerWrapper, which checks the env and then invokes testRunner, which I’d like to avoid if I can. Also, I always prefer using command flags over env vars if possible - it feels more explicit and discoverable…

Correct.

No, there’s no way to do this directly. You can instead wrap in a script that looks up the environment and modifies it in that way, but the add_test command line is set at configure time (or, rather, generate time as it could have generator expressions).

So I take it then that, even with CTestCustom.cmake, the only real way to customize a “standard” (ie, not using a “dashboard”) ctest run is via environment variables? There’s no command line flags that will let you do this?

I looked briefly into the -S option, but setting up a dashboard client seemed a bit more involved (and altered standard testing a bit more) than I’d like…

That’s my understanding, yes.