README.rst 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. This directory contains tests that run CMake to configure a project
  2. but do not actually build anything. To add a test:
  3. 1. Add a subdirectory named for the test, say ``<Test>/``.
  4. 2. In ``./CMakeLists.txt`` call ``add_RunCMake_test`` and pass the
  5. test directory name ``<Test>``.
  6. 3. Create script ``<Test>/RunCMakeTest.cmake`` in the directory containing::
  7. include(RunCMake)
  8. run_cmake(SubTest1)
  9. ...
  10. run_cmake(SubTestN)
  11. where ``SubTest1`` through ``SubTestN`` are sub-test names each
  12. corresponding to an independent CMake run and project configuration.
  13. One may also add calls of the form::
  14. run_cmake_command(SubTestI ${CMAKE_COMMAND} ...)
  15. to fully customize the test case command-line.
  16. Alternatively, if the test is to cover running ``ctest -S`` then use::
  17. include(RunCTest)
  18. run_ctest(SubTest1)
  19. ...
  20. run_ctest(SubTestN)
  21. and create ``test.cmake.in``, ``CTestConfig.cmake.in``, and
  22. ``CMakeLists.txt.in`` files to be configured for each case.
  23. 4. Create file ``<Test>/CMakeLists.txt`` in the directory containing::
  24. cmake_minimum_required(...)
  25. project(${RunCMake_TEST} NONE) # or languages needed
  26. include(${RunCMake_TEST}.cmake)
  27. where ``${RunCMake_TEST}`` is literal. A value for ``RunCMake_TEST``
  28. will be passed to CMake by the ``run_cmake`` macro when running each
  29. sub-test.
  30. 5. Create a ``<Test>/<SubTest>.cmake`` file for each sub-test named
  31. above containing the actual test code. Optionally create files
  32. containing expected test results:
  33. ``<SubTest>-result.txt``
  34. Regex matching expected process result, if not ``0``
  35. ``<SubTest>-stdout.txt``
  36. Regex matching expected stdout content
  37. ``<SubTest>-stderr.txt``
  38. Regex matching expected stderr content, if not ``^$``
  39. ``<SubTest>-check.cmake``
  40. Custom result check.
  41. Note that trailing newlines will be stripped from actual and expected
  42. test output before matching against the stdout and stderr expressions.
  43. The code in ``<SubTest>-check.cmake`` may use variables
  44. ``RunCMake_TEST_SOURCE_DIR``
  45. Top of test source tree
  46. ``RunCMake_TEST_BINARY_DIR``
  47. Top of test binary tree
  48. and an failure must store a message in ``RunCMake_TEST_FAILED``.