add_test.rst 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. add_test
  2. --------
  3. Add a test to the project with the specified arguments.
  4. ::
  5. add_test(testname Exename arg1 arg2 ... )
  6. If the ENABLE_TESTING command has been run, this command adds a test
  7. target to the current directory. If ENABLE_TESTING has not been run,
  8. this command does nothing. The tests are run by the testing subsystem
  9. by executing Exename with the specified arguments. Exename can be
  10. either an executable built by this project or an arbitrary executable
  11. on the system (like tclsh). The test will be run with the current
  12. working directory set to the CMakeList.txt files corresponding
  13. directory in the binary tree. Tests added using this signature do not
  14. support generator expressions.
  15. ::
  16. add_test(NAME <name> [CONFIGURATIONS [Debug|Release|...]]
  17. [WORKING_DIRECTORY dir]
  18. COMMAND <command> [arg1 [arg2 ...]])
  19. Add a test called <name>. The test name may not contain spaces,
  20. quotes, or other characters special in CMake syntax. If COMMAND
  21. specifies an executable target (created by add_executable) it will
  22. automatically be replaced by the location of the executable created at
  23. build time. If a CONFIGURATIONS option is given then the test will be
  24. executed only when testing under one of the named configurations. If
  25. a WORKING_DIRECTORY option is given then the test will be executed in
  26. the given directory.
  27. Arguments after COMMAND may use "generator expressions" with the syntax
  28. ``$<...>``. See the :manual:`cmake-generator-expressions(7)` manual for
  29. available expressions.
  30. Note that tgt is not added as a dependency of the target this
  31. expression is evaluated on.
  32. ::
  33. $<TARGET_POLICY:pol> = '1' if the policy was NEW when the 'head' target was created, else '0'. If the policy was not set, the warning message for the policy will be emitted. This generator expression only works for a subset of policies.
  34. $<INSTALL_PREFIX> = Content of the install prefix when the target is exported via INSTALL(EXPORT) and empty otherwise.
  35. Boolean expressions:
  36. ::
  37. $<AND:?[,?]...> = '1' if all '?' are '1', else '0'
  38. $<OR:?[,?]...> = '0' if all '?' are '0', else '1'
  39. $<NOT:?> = '0' if '?' is '1', else '1'
  40. where '?' is always either '0' or '1'.
  41. Example usage:
  42. ::
  43. add_test(NAME mytest
  44. COMMAND testDriver --config $<CONFIGURATION>
  45. --exe $<TARGET_FILE:myexe>)
  46. This creates a test "mytest" whose command runs a testDriver tool
  47. passing the configuration name and the full path to the executable
  48. file produced by target "myexe".