summaryrefslogtreecommitdiffstats
path: root/Tests/CMakeTests
diff options
context:
space:
mode:
authorCraig Scott <craig.scott@crascit.com>2019-12-23 10:34:04 (GMT)
committerBrad King <brad.king@kitware.com>2020-01-15 15:03:35 (GMT)
commitb56d429324330a9eb8d3c1860333969140851dd7 (patch)
treea02454967b5e4b5fc6eb5aa092214bc6523b5f43 /Tests/CMakeTests
parent3bc73803b4e460410fff71e2c11e0aad116e8763 (diff)
downloadCMake-b56d429324330a9eb8d3c1860333969140851dd7.zip
CMake-b56d429324330a9eb8d3c1860333969140851dd7.tar.gz
CMake-b56d429324330a9eb8d3c1860333969140851dd7.tar.bz2
Tests: Fix CMake.FileDownload test failures not reported
Because the PASS_REGULAR_EXPRESSION test property is set, the exit code of the test is ignored, so we can't just rely on using message(SEND_ERROR) or the command itself failing. We have to add an explicit error message for all unexpected status codes and check for such messages with a FAIL_REGULAR_EXPRESSION.
Diffstat (limited to 'Tests/CMakeTests')
-rw-r--r--Tests/CMakeTests/CMakeLists.txt3
-rw-r--r--Tests/CMakeTests/FileDownloadTest.cmake.in36
2 files changed, 34 insertions, 5 deletions
diff --git a/Tests/CMakeTests/CMakeLists.txt b/Tests/CMakeTests/CMakeLists.txt
index 1619081..e32d693 100644
--- a/Tests/CMakeTests/CMakeLists.txt
+++ b/Tests/CMakeTests/CMakeLists.txt
@@ -33,8 +33,9 @@ AddCMakeTest(While "")
AddCMakeTest(CMakeHostSystemInformation "")
AddCMakeTest(FileDownload "")
-set_property(TEST CMake.FileDownload PROPERTY
+set_tests_properties(CMake.FileDownload PROPERTIES
PASS_REGULAR_EXPRESSION "file already exists with expected MD5 sum"
+ FAIL_REGULAR_EXPRESSION "Unexpected status"
)
AddCMakeTest(FileDownloadBadHash "")
set_property(TEST CMake.FileDownloadBadHash PROPERTY
diff --git a/Tests/CMakeTests/FileDownloadTest.cmake.in b/Tests/CMakeTests/FileDownloadTest.cmake.in
index f795eb1..6c1ee75 100644
--- a/Tests/CMakeTests/FileDownloadTest.cmake.in
+++ b/Tests/CMakeTests/FileDownloadTest.cmake.in
@@ -11,20 +11,40 @@ endif()
set(url "file://${slash}@CMAKE_CURRENT_SOURCE_DIR@/FileDownloadInput.png")
set(dir "@CMAKE_CURRENT_BINARY_DIR@/downloads")
+# Beware Windows asynchronous file/directory removal, rename and then
+# remove the renamed dir so we can be certain the dir isn't there when
+# we get to the file() commands below
+if(EXISTS "${dir}")
+ file(RENAME ${dir} "${dir}_beingRemoved")
+ file(REMOVE_RECURSE "${dir}_beingRemoved")
+endif()
+
+function(__reportIfWrongStatus statusPair expectedStatusCode)
+ list(GET statusPair 0 statusCode)
+ if(NOT statusCode EQUAL expectedStatusCode)
+ message(SEND_ERROR
+ "Unexpected status: ${statusCode}, expected: ${expectedStatusCode}")
+ endif()
+endfunction()
+
message(STATUS "FileDownload:1")
file(DOWNLOAD
${url}
${dir}/file1.png
TIMEOUT ${timeout}
+ STATUS status
)
+__reportIfWrongStatus("${status}" 0)
message(STATUS "FileDownload:2")
file(DOWNLOAD
${url}
${dir}/file2.png
TIMEOUT ${timeout}
+ STATUS status
SHOW_PROGRESS
)
+__reportIfWrongStatus("${status}" 0)
# Two calls in a row, exactly the same arguments.
# Since downloaded file should exist already for 2nd call,
@@ -39,8 +59,10 @@ file(DOWNLOAD
${url}
${dir}/file3.png
TIMEOUT ${timeout}
+ STATUS status
EXPECTED_MD5 dbd330d52f4dbd60115d4191904ded92
)
+__reportIfWrongStatus("${status}" 0)
message(STATUS "FileDownload:4")
file(DOWNLOAD
@@ -50,6 +72,7 @@ file(DOWNLOAD
STATUS status
EXPECTED_HASH SHA1=67eee17f79d9ac557284fc0b8ad19f25723fb578
)
+__reportIfWrongStatus("${status}" 0)
message(STATUS "FileDownload:5")
file(DOWNLOAD
@@ -59,6 +82,7 @@ file(DOWNLOAD
STATUS status
EXPECTED_HASH SHA224=ba283726bbb602776818b463943189afd91836cb7ee5dd6e2c7b5ae4
)
+__reportIfWrongStatus("${status}" 0)
message(STATUS "FileDownload:6")
file(DOWNLOAD
@@ -68,6 +92,7 @@ file(DOWNLOAD
STATUS status
EXPECTED_HASH SHA256=cf3334b1275071e1da6e8c396ccb72cf1b2388d8c937526f3af26230affb9423
)
+__reportIfWrongStatus("${status}" 0)
message(STATUS "FileDownload:7")
file(DOWNLOAD
@@ -77,6 +102,7 @@ file(DOWNLOAD
STATUS status
EXPECTED_HASH SHA384=43a5d13978d97c660db44481aee0604cb4ff6ca0775cd5c2cd68cd8000e107e507c4caf6c228941231041e282ffb8950
)
+__reportIfWrongStatus("${status}" 0)
message(STATUS "FileDownload:8")
file(DOWNLOAD
@@ -86,6 +112,8 @@ file(DOWNLOAD
STATUS status
EXPECTED_HASH SHA512=6984e0909a1018030ccaa418e3be1654223cdccff0fe6adc745f9aea7e377f178be53b9fc7d54a6f81c2b62ef9ddcd38ba1978fedf4c5e7139baaf355eefad5b
)
+__reportIfWrongStatus("${status}" 0)
+
message(STATUS "FileDownload:9")
file(DOWNLOAD
${url}
@@ -94,6 +122,7 @@ file(DOWNLOAD
STATUS status
EXPECTED_HASH MD5=dbd330d52f4dbd60115d4191904ded92
)
+__reportIfWrongStatus("${status}" 0)
message(STATUS "FileDownload:10")
file(DOWNLOAD
@@ -103,6 +132,8 @@ file(DOWNLOAD
STATUS status
EXPECTED_MD5 dbd330d52f4dbd60115d4191904ded92
)
+__reportIfWrongStatus("${status}" 0)
+# Print status because we check its message too
message(STATUS "${status}")
message(STATUS "FileDownload:11")
@@ -113,7 +144,4 @@ file(DOWNLOAD
STATUS status
)
message(STATUS "${status}")
-list(GET status 0 status_code)
-if(NOT ${status_code} EQUAL 6)
- message(SEND_ERROR "error: expected status code 6 for bad host name, got: ${status_code}")
-endif()
+__reportIfWrongStatus("${status}" 6) # 6 corresponds to an unresolvable host name