FileTest.cmake.in 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. set(Copy-BadArg-RESULT 1)
  2. set(Copy-BadArg-STDERR "unknown argument \"BADARG\"")
  3. set(Copy-BadPerm-RESULT 1)
  4. set(Copy-BadPerm-STDERR "COPY given invalid permission \"BADPERM\"")
  5. set(Copy-BadRegex-RESULT 1)
  6. set(Copy-BadRegex-STDERR "could not compile REGEX")
  7. set(Copy-EarlyArg-RESULT 1)
  8. set(Copy-EarlyArg-STDERR "option PERMISSIONS may not appear before")
  9. set(Copy-LateArg-RESULT 1)
  10. set(Copy-LateArg-STDERR "option FILE_PERMISSIONS may not appear after")
  11. set(Copy-NoDest-RESULT 1)
  12. set(Copy-NoDest-STDERR "given no DESTINATION")
  13. set(Copy-NoFile-RESULT 1)
  14. set(Copy-NoFile-STDERR "COPY cannot find .*/does_not_exist\\.txt")
  15. foreach(test
  16. Copy-BadArg
  17. Copy-BadPerm
  18. Copy-BadRegex
  19. Copy-EarlyArg
  20. Copy-LateArg
  21. Copy-NoDest
  22. Copy-NoFile
  23. )
  24. message(STATUS "Test ${test}...")
  25. execute_process(
  26. COMMAND ${CMAKE_COMMAND} -P
  27. "@CMAKE_CURRENT_SOURCE_DIR@/File-${test}.cmake"
  28. WORKING_DIRECTORY "@CMAKE_CURRENT_BINARY_DIR@"
  29. OUTPUT_VARIABLE stdout
  30. ERROR_VARIABLE stderr
  31. RESULT_VARIABLE result
  32. )
  33. string(REGEX REPLACE "\n" "\n out> " out " out> ${stdout}")
  34. string(REGEX REPLACE "\n" "\n err> " err " err> ${stderr}")
  35. if(NOT "${result}" STREQUAL ${${test}-RESULT})
  36. message(FATAL_ERROR
  37. "Test ${test} result is [${result}], not [${${test}-RESULT}].\n"
  38. "Test ${test} output:\n"
  39. "${out}\n"
  40. "${err}")
  41. endif()
  42. if(${test}-STDERR AND NOT "${err}" MATCHES "${${test}-STDERR}")
  43. message(FATAL_ERROR
  44. "Test ${test} stderr does not match\n ${${test}-STDERR}\n"
  45. "Test ${test} output:\n"
  46. "${out}\n"
  47. "${err}")
  48. endif()
  49. endforeach()