RunCMakeTest.cmake 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. include(RunCTest)
  2. function(run_DisableNotRunTest)
  3. set(CASE_CMAKELISTS_SUFFIX_CODE [[
  4. add_test(NAME DisabledTest COMMAND notACommand --version)
  5. add_test(NAME NotRunTest COMMAND invalidCommand --version)
  6. set_tests_properties(SuccessfulTest PROPERTIES DISABLED false)
  7. set_tests_properties(DisabledTest PROPERTIES DISABLED true)
  8. ]])
  9. run_ctest(DisableNotRunTest)
  10. endfunction()
  11. run_DisableNotRunTest()
  12. function(run_DisableFailingTest)
  13. set(CASE_CMAKELISTS_SUFFIX_CODE [[
  14. set(someFile "${CMAKE_CURRENT_SOURCE_DIR}/test.cmake")
  15. add_test(NAME FailingTest
  16. COMMAND ${CMAKE_COMMAND} -E compare_files "${someFile}" "${someFile}xxx")
  17. add_test(NAME DisabledFailingTest
  18. COMMAND ${CMAKE_COMMAND} -E compare_files "${someFile}" "${someFile}xxx")
  19. set_tests_properties(FailingTest PROPERTIES DISABLED false)
  20. set_tests_properties(DisabledFailingTest PROPERTIES DISABLED true)
  21. ]])
  22. run_ctest(DisableFailingTest)
  23. endfunction()
  24. run_DisableFailingTest()
  25. function(run_DisableSetupTest)
  26. set(CASE_CMAKELISTS_SUFFIX_CODE [[
  27. add_test(NAME DisabledTest COMMAND "${CMAKE_COMMAND}" --version)
  28. add_test(NAME SuccessfulCleanupTest COMMAND "${CMAKE_COMMAND}" --version)
  29. set_tests_properties(DisabledTest PROPERTIES DISABLED true
  30. FIXTURES_SETUP "Foo")
  31. set_tests_properties(SuccessfulTest PROPERTIES FIXTURES_REQUIRED "Foo")
  32. set_tests_properties(SuccessfulCleanupTest PROPERTIES FIXTURES_CLEANUP "Foo")
  33. ]])
  34. run_ctest(DisableSetupTest)
  35. endfunction()
  36. run_DisableSetupTest()
  37. function(run_DisableRequiredTest)
  38. set(CASE_CMAKELISTS_SUFFIX_CODE [[
  39. add_test(NAME DisabledTest COMMAND "${CMAKE_COMMAND}" --version)
  40. add_test(NAME SuccessfulCleanupTest COMMAND "${CMAKE_COMMAND}" --version)
  41. set_tests_properties(SuccessfulTest PROPERTIES FIXTURES_SETUP "Foo")
  42. set_tests_properties(DisabledTest PROPERTIES DISABLED true
  43. FIXTURES_REQUIRED "Foo")
  44. set_tests_properties(SuccessfulCleanupTest PROPERTIES FIXTURES_CLEANUP "Foo")
  45. ]])
  46. run_ctest(DisableRequiredTest)
  47. endfunction()
  48. run_DisableRequiredTest()
  49. function(run_DisableCleanupTest)
  50. set(CASE_CMAKELISTS_SUFFIX_CODE [[
  51. add_test(NAME CleanupTest COMMAND "${CMAKE_COMMAND}" --version)
  52. set_tests_properties(SuccessfulTest PROPERTIES FIXTURES_REQUIRED "Foo")
  53. set_tests_properties(CleanupTest PROPERTIES DISABLED true
  54. FIXTURES_CLEANUP "Foo")
  55. ]])
  56. run_ctest(DisableCleanupTest)
  57. endfunction()
  58. run_DisableCleanupTest()
  59. # Consider a fixture that has a setup test, a cleanup test and a disabled test
  60. # which requires that fixture. Limit the test list with a regular expression
  61. # that matches the disabled test but not the setup or cleanup tests, so the
  62. # initial set of tests to be executed contains just the disabled test. Since
  63. # the only test requiring the fixture is disabled, CTest should not
  64. # automatically add in the setup and cleanup tests for the fixture, since no
  65. # enabled test requires them.
  66. function(run_DisableAllTests)
  67. set(CASE_CMAKELISTS_SUFFIX_CODE [[
  68. add_test(NAME SetupTest COMMAND "${CMAKE_COMMAND}" --version)
  69. add_test(NAME CleanupTest COMMAND "${CMAKE_COMMAND}" --version)
  70. set_tests_properties(SetupTest PROPERTIES FIXTURES_SETUP "Foo")
  71. set_tests_properties(SuccessfulTest PROPERTIES DISABLED true
  72. FIXTURES_REQUIRED "Foo")
  73. set_tests_properties(CleanupTest PROPERTIES FIXTURES_CLEANUP "Foo")
  74. ]])
  75. run_ctest(DisableAllTests -R Successful)
  76. endfunction()
  77. run_DisableAllTests()