From e0d3339e655049cc44e27861a5c65ce0dc2ef39a Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 29 Apr 2009 13:13:58 -0400 Subject: [PATCH] ENH: Test file(COPY) failure cases This tests some cases of bad arguments to the file(COPY) signature. It checks that the proper error messages are produced. --- Tests/CMakeTests/CMakeLists.txt | 1 + Tests/CMakeTests/File-Copy-BadArg.cmake | 1 + Tests/CMakeTests/File-Copy-BadPerm.cmake | 1 + Tests/CMakeTests/File-Copy-BadRegex.cmake | 1 + Tests/CMakeTests/File-Copy-EarlyArg.cmake | 1 + Tests/CMakeTests/File-Copy-LateArg.cmake | 1 + Tests/CMakeTests/File-Copy-NoDest.cmake | 1 + Tests/CMakeTests/File-Copy-NoFile.cmake | 1 + Tests/CMakeTests/FileTest.cmake.in | 50 +++++++++++++++++++++++ 9 files changed, 58 insertions(+) create mode 100644 Tests/CMakeTests/File-Copy-BadArg.cmake create mode 100644 Tests/CMakeTests/File-Copy-BadPerm.cmake create mode 100644 Tests/CMakeTests/File-Copy-BadRegex.cmake create mode 100644 Tests/CMakeTests/File-Copy-EarlyArg.cmake create mode 100644 Tests/CMakeTests/File-Copy-LateArg.cmake create mode 100644 Tests/CMakeTests/File-Copy-NoDest.cmake create mode 100644 Tests/CMakeTests/File-Copy-NoFile.cmake create mode 100644 Tests/CMakeTests/FileTest.cmake.in diff --git a/Tests/CMakeTests/CMakeLists.txt b/Tests/CMakeTests/CMakeLists.txt index e197302c42..62e61331b9 100644 --- a/Tests/CMakeTests/CMakeLists.txt +++ b/Tests/CMakeTests/CMakeLists.txt @@ -17,6 +17,7 @@ AddCMakeTest(Toolchain "") AddCMakeTest(GetFilenameComponentRealpath "") AddCMakeTest(Version "") AddCMakeTest(Message "") +AddCMakeTest(File "") SET(GetPrerequisites_PreArgs "-DCTEST_CONFIGURATION_TYPE:STRING=\\\${CTEST_CONFIGURATION_TYPE}" diff --git a/Tests/CMakeTests/File-Copy-BadArg.cmake b/Tests/CMakeTests/File-Copy-BadArg.cmake new file mode 100644 index 0000000000..91952fc60f --- /dev/null +++ b/Tests/CMakeTests/File-Copy-BadArg.cmake @@ -0,0 +1 @@ +file(COPY FileTest.cmake DESTINATION tmp PATTERN * BADARG) diff --git a/Tests/CMakeTests/File-Copy-BadPerm.cmake b/Tests/CMakeTests/File-Copy-BadPerm.cmake new file mode 100644 index 0000000000..b5cc42f00b --- /dev/null +++ b/Tests/CMakeTests/File-Copy-BadPerm.cmake @@ -0,0 +1 @@ +file(COPY FileTest.cmake DESTINATION tmp FILE_PERMISSIONS BADPERM) diff --git a/Tests/CMakeTests/File-Copy-BadRegex.cmake b/Tests/CMakeTests/File-Copy-BadRegex.cmake new file mode 100644 index 0000000000..41340f6230 --- /dev/null +++ b/Tests/CMakeTests/File-Copy-BadRegex.cmake @@ -0,0 +1 @@ +file(COPY FileTest.cmake DESTINATION tmp REGEX "(") diff --git a/Tests/CMakeTests/File-Copy-EarlyArg.cmake b/Tests/CMakeTests/File-Copy-EarlyArg.cmake new file mode 100644 index 0000000000..03993de387 --- /dev/null +++ b/Tests/CMakeTests/File-Copy-EarlyArg.cmake @@ -0,0 +1 @@ +file(COPY FileTest.cmake DESTINATION tmp PERMISSIONS) diff --git a/Tests/CMakeTests/File-Copy-LateArg.cmake b/Tests/CMakeTests/File-Copy-LateArg.cmake new file mode 100644 index 0000000000..43d216874e --- /dev/null +++ b/Tests/CMakeTests/File-Copy-LateArg.cmake @@ -0,0 +1 @@ +file(COPY FileTest.cmake DESTINATION tmp PATTERN * FILE_PERMISSIONS) diff --git a/Tests/CMakeTests/File-Copy-NoDest.cmake b/Tests/CMakeTests/File-Copy-NoDest.cmake new file mode 100644 index 0000000000..f6c6c6d7ea --- /dev/null +++ b/Tests/CMakeTests/File-Copy-NoDest.cmake @@ -0,0 +1 @@ +file(COPY FileTest.cmake) diff --git a/Tests/CMakeTests/File-Copy-NoFile.cmake b/Tests/CMakeTests/File-Copy-NoFile.cmake new file mode 100644 index 0000000000..d5853d3963 --- /dev/null +++ b/Tests/CMakeTests/File-Copy-NoFile.cmake @@ -0,0 +1 @@ +file(COPY does_not_exist.txt DESTINATION tmp) diff --git a/Tests/CMakeTests/FileTest.cmake.in b/Tests/CMakeTests/FileTest.cmake.in new file mode 100644 index 0000000000..c46138c420 --- /dev/null +++ b/Tests/CMakeTests/FileTest.cmake.in @@ -0,0 +1,50 @@ +set(Copy-BadArg-RESULT 1) +set(Copy-BadArg-STDERR "unknown argument \"BADARG\"") +set(Copy-BadPerm-RESULT 1) +set(Copy-BadPerm-STDERR "COPY given invalid permission \"BADPERM\"") +set(Copy-BadRegex-RESULT 1) +set(Copy-BadRegex-STDERR "could not compile REGEX") +set(Copy-EarlyArg-RESULT 1) +set(Copy-EarlyArg-STDERR "option PERMISSIONS may not appear before") +set(Copy-LateArg-RESULT 1) +set(Copy-LateArg-STDERR "option FILE_PERMISSIONS may not appear after") +set(Copy-NoDest-RESULT 1) +set(Copy-NoDest-STDERR "given no DESTINATION") +set(Copy-NoFile-RESULT 1) +set(Copy-NoFile-STDERR "COPY cannot find .*/does_not_exist\\.txt") + +foreach(test + Copy-BadArg + Copy-BadPerm + Copy-BadRegex + Copy-EarlyArg + Copy-LateArg + Copy-NoDest + Copy-NoFile + ) + message(STATUS "Test ${test}...") + execute_process( + COMMAND ${CMAKE_COMMAND} -P + "@CMAKE_CURRENT_SOURCE_DIR@/File-${test}.cmake" + WORKING_DIRECTORY "@CMAKE_CURRENT_BINARY_DIR@" + OUTPUT_VARIABLE stdout + ERROR_VARIABLE stderr + RESULT_VARIABLE result + ) + string(REGEX REPLACE "\n" "\n out> " out " out> ${stdout}") + string(REGEX REPLACE "\n" "\n err> " err " err> ${stderr}") + if(NOT "${result}" STREQUAL ${${test}-RESULT}) + message(FATAL_ERROR + "Test ${test} result is [${result}], not [${${test}-RESULT}].\n" + "Test ${test} output:\n" + "${out}\n" + "${err}") + endif() + if(${test}-STDERR AND NOT "${err}" MATCHES "${${test}-STDERR}") + message(FATAL_ERROR + "Test ${test} stderr does not match\n ${${test}-STDERR}\n" + "Test ${test} output:\n" + "${out}\n" + "${err}") + endif() +endforeach()