Merge topic 'file_download_filename'

c0da651c09 file(DOWNLOAD): Don't fail if given just a filename to write to
b56d429324 Tests: Fix CMake.FileDownload test failures not reported
3bc73803b4 Tests: Fix CMake.FileDownload test in presence of proxy
1352585301 Tests: Extend CMake.FileDownload test internal timeouts

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !4159
This commit is contained in:
Brad King
2020-01-16 15:25:53 +00:00
committed by Kitware Robot
4 changed files with 72 additions and 17 deletions

View File

@@ -1707,7 +1707,8 @@ bool HandleDownloadCommand(std::vector<std::string> const& args,
// as we receive downloaded bits from curl...
//
std::string dir = cmSystemTools::GetFilenamePath(file);
if (!cmSystemTools::FileExists(dir) && !cmSystemTools::MakeDirectory(dir)) {
if (!dir.empty() && !cmSystemTools::FileExists(dir) &&
!cmSystemTools::MakeDirectory(dir)) {
std::string errstring = "DOWNLOAD error: cannot create directory '" + dir +
"' - Specify file by full path name and verify that you "
"have directory creation and file write privileges.";

View File

@@ -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

View File

@@ -1,23 +1,50 @@
# We do not contact any real URLs, but do try a bogus one.
# Remove any proxy configuration that may change behavior.
unset(ENV{http_proxy})
unset(ENV{https_proxy})
set(timeout 4)
if(NOT "@CMAKE_CURRENT_SOURCE_DIR@" MATCHES "^/")
set(slash /)
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 2
TIMEOUT ${timeout}
STATUS status
)
__reportIfWrongStatus("${status}" 0)
message(STATUS "FileDownload:2")
file(DOWNLOAD
${url}
${dir}/file2.png
TIMEOUT 2
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,
@@ -31,82 +58,108 @@ message(STATUS "FileDownload:3")
file(DOWNLOAD
${url}
${dir}/file3.png
TIMEOUT 2
TIMEOUT ${timeout}
STATUS status
EXPECTED_MD5 dbd330d52f4dbd60115d4191904ded92
)
__reportIfWrongStatus("${status}" 0)
message(STATUS "FileDownload:4")
file(DOWNLOAD
${url}
${dir}/file3.png
TIMEOUT 2
TIMEOUT ${timeout}
STATUS status
EXPECTED_HASH SHA1=67eee17f79d9ac557284fc0b8ad19f25723fb578
)
__reportIfWrongStatus("${status}" 0)
message(STATUS "FileDownload:5")
file(DOWNLOAD
${url}
${dir}/file3.png
TIMEOUT 2
TIMEOUT ${timeout}
STATUS status
EXPECTED_HASH SHA224=ba283726bbb602776818b463943189afd91836cb7ee5dd6e2c7b5ae4
)
__reportIfWrongStatus("${status}" 0)
message(STATUS "FileDownload:6")
file(DOWNLOAD
${url}
${dir}/file3.png
TIMEOUT 2
TIMEOUT ${timeout}
STATUS status
EXPECTED_HASH SHA256=cf3334b1275071e1da6e8c396ccb72cf1b2388d8c937526f3af26230affb9423
)
__reportIfWrongStatus("${status}" 0)
message(STATUS "FileDownload:7")
file(DOWNLOAD
${url}
${dir}/file3.png
TIMEOUT 2
TIMEOUT ${timeout}
STATUS status
EXPECTED_HASH SHA384=43a5d13978d97c660db44481aee0604cb4ff6ca0775cd5c2cd68cd8000e107e507c4caf6c228941231041e282ffb8950
)
__reportIfWrongStatus("${status}" 0)
message(STATUS "FileDownload:8")
file(DOWNLOAD
${url}
${dir}/file3.png
TIMEOUT 2
TIMEOUT ${timeout}
STATUS status
EXPECTED_HASH SHA512=6984e0909a1018030ccaa418e3be1654223cdccff0fe6adc745f9aea7e377f178be53b9fc7d54a6f81c2b62ef9ddcd38ba1978fedf4c5e7139baaf355eefad5b
)
__reportIfWrongStatus("${status}" 0)
message(STATUS "FileDownload:9")
file(DOWNLOAD
${url}
${dir}/file3.png
TIMEOUT 2
TIMEOUT ${timeout}
STATUS status
EXPECTED_HASH MD5=dbd330d52f4dbd60115d4191904ded92
)
__reportIfWrongStatus("${status}" 0)
message(STATUS "FileDownload:10")
file(DOWNLOAD
${url}
${dir}/file3.png
TIMEOUT 2
TIMEOUT ${timeout}
STATUS status
EXPECTED_MD5 dbd330d52f4dbd60115d4191904ded92
)
__reportIfWrongStatus("${status}" 0)
# Print status because we check its message too
message(STATUS "${status}")
message(STATUS "FileDownload:11")
file(DOWNLOAD
badhostname.png
${dir}/file11.png
TIMEOUT 2
TIMEOUT ${timeout}
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}")
__reportIfWrongStatus("${status}" 6) # 6 corresponds to an unresolvable host name
message(STATUS "FileDownload:12")
set(absFile "@CMAKE_CURRENT_BINARY_DIR@/file12.png")
if(EXISTS "${absFile}")
file(RENAME ${absFile} "${absFile}_beingRemoved")
file(REMOVE "${absFile}_beingRemoved")
endif()
file(DOWNLOAD
${url}
file12.png
TIMEOUT ${timeout}
EXPECTED_MD5 dbd330d52f4dbd60115d4191904ded92
STATUS status
)
__reportIfWrongStatus("${status}" 0)
if(NOT EXISTS file12.png)
message(SEND_ERROR "file12.png not downloaded: ${status}")
endif()

View File

@@ -183,7 +183,7 @@ elseif(testname STREQUAL to_native_path) # pass
elseif(testname STREQUAL download_wrong_number_of_args) # fail
file(DOWNLOAD zzzz://bogus/ffff)
elseif(testname STREQUAL download_file_with_no_path) # fail
elseif(testname STREQUAL download_file_with_no_path) # pass
file(DOWNLOAD zzzz://bogus/ffff ffff)
elseif(testname STREQUAL download_missing_time) # fail