add_test.rst 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. add_test
  2. --------
  3. Add a test to the project to be run by :manual:`ctest(1)`.
  4. ::
  5. add_test(NAME <name> COMMAND <command> [<arg>...]
  6. [CONFIGURATIONS <config>...]
  7. [WORKING_DIRECTORY <dir>])
  8. Add a test called ``<name>``. The test name may not contain spaces,
  9. quotes, or other characters special in CMake syntax. The options are:
  10. ``COMMAND``
  11. Specify the test command-line. If ``<command>`` specifies an
  12. executable target (created by :command:`add_executable`) it will
  13. automatically be replaced by the location of the executable created
  14. at build time.
  15. ``CONFIGURATIONS``
  16. Restrict execution of the test only to the named configurations.
  17. ``WORKING_DIRECTORY``
  18. Set the :prop_test:`WORKING_DIRECTORY` test property to
  19. specify the working directory in which to execute the test.
  20. If not specified the test will be run with the current working
  21. directory set to the build directory corresponding to the
  22. current source directory.
  23. The ``COMMAND`` and ``WORKING_DIRECTORY`` options may use "generator
  24. expressions" with the syntax ``$<...>``. See the
  25. :manual:`cmake-generator-expressions(7)` manual for available expressions.
  26. Example usage::
  27. add_test(NAME mytest
  28. COMMAND testDriver --config $<CONFIGURATION>
  29. --exe $<TARGET_FILE:myexe>)
  30. This creates a test ``mytest`` whose command runs a ``testDriver`` tool
  31. passing the configuration name and the full path to the executable
  32. file produced by target ``myexe``.
  33. .. note::
  34. CMake will generate tests only if the :command:`enable_testing`
  35. command has been invoked. The :module:`CTest` module invokes the
  36. command automatically when the ``BUILD_TESTING`` option is ``ON``.
  37. ---------------------------------------------------------------------
  38. ::
  39. add_test(<name> <command> [<arg>...])
  40. Add a test called ``<name>`` with the given command-line. Unlike
  41. the above ``NAME`` signature no transformation is performed on the
  42. command-line to support target names or generator expressions.