[CMake] Setup/tear down steps for CTest

Craig Scott craig.scott at crascit.com
Sat Aug 20 20:32:54 EDT 2016


Let's say a project defines a bunch of tests which require setup and tear
down steps before/after all the tests are run (not each individual test,
I'm talking here about one setup before all tests are run and one tear down
after all tests have finished). While this could be done by a script
driving CTest itself, it is less desirable since different platforms may
need different driver scripts and this seems like something CTest should be
able to handle itself (if the setup/tear down steps use parts of the build,
that only strengthens the case to have them handled by CMake/CTest
directly).

It is possible to abuse the DEPENDS test property and define setup and tear
down "tests" which are not really tests but which perform the necessary
steps. While this mostly works, it is not ideal and in particular it
doesn't work with CTest's --rerun-failed option. I'm wondering if there's
currently a better way of telling CMake/CTest about a setup step which must
be run before some particular set of test cases and a tear down step after
they are all done. The tear down step needs to be performed regardless of
whether any of the real test cases pass or fail.

The motivating case is to start up and shutdown a service which a (subset
of) test cases need running. That service is expensive to set up and hence
it isn't feasible to start it up and shut it down for every test case
individually.

Any ideas?

-- 
Craig Scott
Melbourne, Australia
http://crascit.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160821/91436408/attachment.html>


More information about the CMake mailing list