Tests: Factor out common helper in RunCMake.file-DOWNLOAD cases

This commit is contained in:
Brad King
2022-11-17 17:38:31 -05:00
parent d6af54c473
commit 9dda7c276c
10 changed files with 34 additions and 27 deletions

View File

@@ -0,0 +1,15 @@
if(NOT "${CMAKE_CURRENT_SOURCE_DIR}" MATCHES "^/")
set(slash /)
endif()
set(url "file://${slash}${CMAKE_CURRENT_SOURCE_DIR}/input.png")
set(file ${CMAKE_CURRENT_BINARY_DIR}/output.png)
function(file_download)
file(DOWNLOAD "${url}"
${file} # leave unquoted
TIMEOUT 30
STATUS status
${ARGN}
)
message(STATUS "status='${status}'")
endfunction()

View File

@@ -1,11 +1,11 @@
^CMake Error at hash-mismatch.cmake:[0-9]+ \(file\):
file DOWNLOAD HASH mismatch
for file: \[.*/Tests/RunCMake/file-DOWNLOAD/hash-mismatch-build/hash-mismatch.txt\]
for file: \[.*/Tests/RunCMake/file-DOWNLOAD/hash-mismatch-build/output.png\]
expected hash: \[0123456789abcdef0123456789abcdef01234567\]
actual hash: \[da39a3ee5e6b4b0d3255bfef95601890afd80709\]
actual hash: \[67eee17f79d9ac557284fc0b8ad19f25723fb578\]
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)
+
status='1;HASH mismatch: expected: 0123456789abcdef0123456789abcdef01234567 actual: da39a3ee5e6b4b0d3255bfef95601890afd80709'$
status='1;HASH mismatch: expected: 0123456789abcdef0123456789abcdef01234567 actual: 67eee17f79d9ac557284fc0b8ad19f25723fb578'$

View File

@@ -1,10 +1,8 @@
if(NOT "${CMAKE_CURRENT_SOURCE_DIR}" MATCHES "^/")
set(slash /)
endif()
file(DOWNLOAD
"file://${slash}${CMAKE_CURRENT_SOURCE_DIR}/hash-mismatch.txt"
${CMAKE_CURRENT_BINARY_DIR}/hash-mismatch.txt
include(common.cmake)
file(DOWNLOAD ${url} ${file}
EXPECTED_HASH SHA1=0123456789abcdef0123456789abcdef01234567
TIMEOUT 30
STATUS status
)
message("status='${status}'")

Binary file not shown.

After

Width:  |  Height:  |  Size: 194 B

View File

@@ -1,4 +1,5 @@
^CMake Error at no-save-hash\.cmake:[0-9]+ \(file\):
^CMake Error at common\.cmake:[0-9]+ \(file\):
file DOWNLOAD cannot calculate hash if file is not saved\.
Call Stack \(most recent call first\):
no-save-hash.cmake:[0-9]+ \(file_download\)
CMakeLists\.txt:[0-9]+ \(include\)$

View File

@@ -1,8 +1,5 @@
if(NOT "${CMAKE_CURRENT_SOURCE_DIR}" MATCHES "^/")
set(slash /)
endif()
file(DOWNLOAD
"file://${slash}${CMAKE_CURRENT_SOURCE_DIR}/no-save-md5.txt"
EXPECTED_HASH MD5=55555555555555555555555555555555
STATUS status
)
include(common.cmake)
# Test downloading without saving to a file.
set(file "")
file_download(EXPECTED_HASH MD5=55555555555555555555555555555555)

View File

@@ -1,5 +1,6 @@
^CMake Warning \(dev\) at unused-argument.cmake:[0-9]+ \(file\):
^CMake Warning \(dev\) at common.cmake:[0-9]+ \(file\):
Unexpected argument: JUNK
Call Stack \(most recent call first\):
unused-argument.cmake:[0-9]+ \(file_download\)
CMakeLists.txt:[0-9]+ \(include\)
This warning is for project developers. Use -Wno-dev to suppress it.$

View File

@@ -1,8 +1,3 @@
if(NOT "${CMAKE_CURRENT_SOURCE_DIR}" MATCHES "^/")
set(slash /)
endif()
file(DOWNLOAD
"file://${slash}${CMAKE_CURRENT_SOURCE_DIR}/unused-argument.txt"
"${CMAKE_CURRENT_BINARY_DIR}/unused-argument.txt"
JUNK
)
include(common.cmake)
file_download(JUNK)