ctkMacroSimpleTestWithData.cmake 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #! Usage:
  2. #! \code
  3. #! SIMPLE_TEST_WITH_DATA(<testname> <baseline_relative_location> [argument1 ...])
  4. #! \endcode
  5. #!
  6. #! This macro add a test using the complete add_test signature specifying target using
  7. #! $<TARGET_FILE:...> generator expression. Optionnal test argument(s) can be passed
  8. #! after specifying the <testname>.
  9. #!
  10. #! <baseline_relative_location> parameter should corresponds to a subfolder located in <CTKData_DIR>/Baseline
  11. #!
  12. #! Variables named KIT and CTKData_DIR are expected to be defined in the current scope.
  13. #!
  14. #! KIT variable usually matches the value of PROJECT_NAME.
  15. #!
  16. #! The macro also associates a label to the test based on the current value of KIT.
  17. #!
  18. #! The following parameter will be passed to the test:
  19. #! <ul>
  20. #! <li>-D <CTKData_DIR>/Data</li>
  21. #! <li>-V <CTKData_DIR>/Baseline/<baseline_relative_location></li>
  22. #! <li>-T <PROJECT_BINARY_DIR>/Testing/Temporary</li>
  23. #! </ul>
  24. #!
  25. #! \sa http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:add_test
  26. #! \sa http://www.cmake.org/cmake/help/cmake-2-8-docs.html#variable:PROJECT_NAME
  27. #!
  28. #! \ingroup CMakeUtilities
  29. macro(SIMPLE_TEST_WITH_DATA testname baseline_relative_location)
  30. if("${KIT}" STREQUAL "")
  31. message(FATAL_ERROR "error: KIT variable is not set !")
  32. endif()
  33. if(NOT TARGET ${KIT}CppTests)
  34. message(FATAL_ERROR "error: ${KIT}CppTests target does NOT exist !")
  35. endif()
  36. if(NOT EXISTS "${CTKData_DIR}/Data")
  37. message(FATAL_ERROR "error: <CTKData_DIR>/Data corresponds to an non-existing directory. [<CTKData_DIR>/Data: ${CTKData_DIR}/Data]")
  38. endif()
  39. if(NOT EXISTS "${CTKData_DIR}/Baseline/${baseline_relative_location}")
  40. message(FATAL_ERROR "error: <CTKData_DIR>/Baseline/<baseline_relative_location> corresponds to an non-existing file or directory. [<CTKData_DIR>/Baseline/<baseline_relative_location>: ${CTKData_DIR}/Baseline/${baseline_relative_location}]")
  41. endif()
  42. add_test(NAME ${testname} COMMAND $<TARGET_FILE:${KIT}CppTests> ${testname}
  43. -D "${CTKData_DIR}/Data"
  44. -V "${CTKData_DIR}/Baseline/${baseline_relative_location}"
  45. -T "${PROJECT_BINARY_DIR}/Testing/Temporary"
  46. ${ARGN}
  47. )
  48. set_property(TEST ${testname} PROPERTY LABELS ${KIT})
  49. endmacro()