Commit 4befecc7 authored by Brad King's avatar Brad King

ExternalData: Add tests covering interfaces and errors

Add a Module.ExternalData test to verify data retrieval and test
argument DATA{} references.

Add a RunCMake.ExternalData test to verify error handling and automatic
transformation of a raw data to a content link and staged object.
parent bcd25808
......@@ -312,6 +312,18 @@ if(BUILD_TESTING)
ADD_TEST_MACRO(Module.CheckTypeSize CheckTypeSize)
add_test(Module.ExternalData ${CMAKE_CTEST_COMMAND}
--build-and-test
"${CMake_SOURCE_DIR}/Tests/Module/ExternalData"
"${CMake_BINARY_DIR}/Tests/Module/ExternalData"
--build-generator ${CMAKE_TEST_GENERATOR}
--build-project ExternalDataTest
--build-makeprogram ${CMAKE_TEST_MAKEPROGRAM}
--force-new-ctest-process
--test-command ${CMAKE_CTEST_COMMAND} -C \${CTEST_CONFIGURATION_TYPE} -V
)
list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Module/ExternalData")
ADD_TEST_MACRO(Module.GenerateExportHeader GenerateExportHeader)
if (APPLE OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
......
cmake_minimum_required(VERSION 2.8.10.20130115)
project(ExternalDataTest NONE)
include(CTest)
include(ExternalData)
set(ExternalData_URL_TEMPLATES
"file:///${CMAKE_CURRENT_SOURCE_DIR}/%(algo)/%(hash)"
)
set(ExternalData_BINARY_ROOT "${CMAKE_CURRENT_BINARY_DIR}/ExternalData")
file(REMOVE_RECURSE ${ExternalData_BINARY_ROOT}) # clean test
ExternalData_Add_Test(Data1
NAME Data1Check
COMMAND ${CMAKE_COMMAND}
-D Data=DATA{Data.dat}
-D SeriesA=DATA{SeriesA.dat,:}
-D SeriesB=DATA{SeriesB.dat,:}
-D SeriesC=DATA{SeriesC.dat,:}
-D SeriesD=DATA{SeriesD.dat,:}
-D SeriesAn=DATA{SeriesAn1.dat,:}
-D SeriesBn=DATA{SeriesBn_1.dat,:}
-D SeriesCn=DATA{SeriesCn.1.dat,:}
-D SeriesDn=DATA{SeriesDn-1.dat,:}
-D Paired=DATA{PairedA.dat,PairedB.dat}
-D Meta=DATA{MetaTop.dat,REGEX:Meta[ABC].dat}
-P ${CMAKE_CURRENT_SOURCE_DIR}/Data1Check.cmake
)
ExternalData_Add_Target(Data1)
add_subdirectory(Data2)
add_subdirectory(Data3)
8c018830e3efa5caf3c7415028335a57
file(STRINGS "${Data}" lines LIMIT_INPUT 1024)
if(NOT "x${lines}" STREQUAL "xInput file already transformed.")
message(SEND_ERROR "Input file:\n ${Data}\ndoes not have expected content, but [[${lines}]]")
endif()
set(SeriesAn1 "1\\.dat")
set(SeriesBn1 "_1\\.dat")
set(SeriesCn1 "\\.1\\.dat")
set(SeriesDn1 "-1\\.dat")
set(SeriesAl 1 2 3)
set(SeriesBl _1 _2 _3)
set(SeriesCl .1 .2 .3)
set(SeriesDl -1 -2 -3)
foreach(s A B C D)
foreach(n "" ${Series${s}l})
string(REGEX REPLACE "\\.dat$" "${n}.dat" file "${Series${s}}")
if(NOT EXISTS "${file}")
message(SEND_ERROR "Input file:\n ${file}\ndoes not exist!")
endif()
endforeach()
endforeach()
foreach(s A B C D)
foreach(n ${Series${s}l})
string(REGEX REPLACE "${Series${s}n1}$" "${n}.dat" file "${Series${s}n}")
if(NOT EXISTS "${file}")
message(SEND_ERROR "Input file:\n ${file}\ndoes not exist!")
endif()
endforeach()
endforeach()
foreach(n A B)
string(REGEX REPLACE "A\\.dat$" "${n}.dat" file "${Paired}")
if(NOT EXISTS "${file}")
message(SEND_ERROR "Input file:\n ${file}\ndoes not exist!")
endif()
endforeach()
foreach(n Top A B C)
string(REGEX REPLACE "Top\\.dat$" "${n}.dat" file "${Meta}")
if(NOT EXISTS "${file}")
message(SEND_ERROR "Input file:\n ${file}\ndoes not exist!")
endif()
endforeach()
8c018830e3efa5caf3c7415028335a57
set(ExternalData_SERIES_PARSE "([0-9]+)(_\\.my\\.dat)$")
set(ExternalData_SERIES_MATCH "[0-9]+")
ExternalData_Add_Test(Data2
NAME Data2Check
COMMAND ${CMAKE_COMMAND}
-D Data2=DATA{../Data2.dat}
-D SeriesC=DATA{SeriesC_1_.my.dat,:}
-P ${CMAKE_CURRENT_SOURCE_DIR}/Data2Check.cmake
)
ExternalData_Add_Target(Data2)
if(NOT EXISTS "${Data2}")
message(SEND_ERROR "Input file:\n ${Data2}\ndoes not exist!")
endif()
foreach(n 1 2 3)
string(REGEX REPLACE "_1_\\.my\\.dat$" "_${n}_.my.dat" SeriesCFile "${SeriesC}")
if(NOT EXISTS "${SeriesCFile}")
message(SEND_ERROR "Input file:\n ${SeriesCFile}\ndoes not exist!")
endif()
endforeach()
set(Store0 ${CMAKE_BINARY_DIR}/ExternalData/Other)
set(Store1 ${CMAKE_BINARY_DIR}/ExternalData/Objects)
set(ExternalData_OBJECT_STORES ${Store0} ${Store1})
ExternalData_Add_Test(Data3
NAME Data3Check
COMMAND ${CMAKE_COMMAND}
-D Data=DATA{Data.dat}
-D Other=DATA{Other.dat}
-D Store0=${Store0}
-D Store1=${Store1}
-P ${CMAKE_CURRENT_SOURCE_DIR}/Data3Check.cmake
)
ExternalData_Add_Target(Data3)
add_dependencies(Data3 Data1 Data2)
8c018830e3efa5caf3c7415028335a57
if(NOT EXISTS "${Data}")
message(SEND_ERROR "Input file:\n ${Data}\ndoes not exist!")
endif()
if(NOT EXISTS "${Other}")
message(SEND_ERROR "Input file:\n ${Other}\ndoes not exist!")
endif()
# Verify that the 'Data' object was found in the second store location left
# from Data1 target downloads and that the 'Other' object was downloaded to
# our first store location. Neither object should exist in the other store.
foreach(should_exist
"${Store0}/MD5/aaad162b85f60d1eb57ca71a23e8efd7"
"${Store1}/MD5/8c018830e3efa5caf3c7415028335a57"
)
if(NOT EXISTS ${should_exist})
message(SEND_ERROR "Store file:\n ${should_exist}\nshould exist!")
endif()
endforeach()
foreach(should_not_exist
"${Store0}/MD5/8c018830e3efa5caf3c7415028335a57"
"${Store1}/MD5/aaad162b85f60d1eb57ca71a23e8efd7"
)
if(EXISTS ${should_not_exist})
message(SEND_ERROR "Store file:\n ${should_not_exist}\nshould not exist!")
endif()
endforeach()
aaad162b85f60d1eb57ca71a23e8efd7
9d980b06c2f0fec3d4872d68175b9822
8f4add4581551facf27237e6577fd662
c1030719c95f3435d8abc39c0d442946
08cfcf221f76ace7b906b312284e73d7
401767f22a456b3522953722090a2c36
ecfa1ecd417d4253af81ae04d1bd6581
f41c94425d01ecbbee70440b951cb058
31eff09e84fca01415f8cd9d82ec432b
f7ab5a04aae9cb9a520e70b20b9c8ed7
30ba0acdee9096b3b9fc6c69362c6b42
31eff09e84fca01415f8cd9d82ec432b
f7ab5a04aae9cb9a520e70b20b9c8ed7
30ba0acdee9096b3b9fc6c69362c6b42
f41c94425d01ecbbee70440b951cb058
31eff09e84fca01415f8cd9d82ec432b
f7ab5a04aae9cb9a520e70b20b9c8ed7
30ba0acdee9096b3b9fc6c69362c6b42
31eff09e84fca01415f8cd9d82ec432b
f7ab5a04aae9cb9a520e70b20b9c8ed7
30ba0acdee9096b3b9fc6c69362c6b42
31eff09e84fca01415f8cd9d82ec432b
f7ab5a04aae9cb9a520e70b20b9c8ed7
30ba0acdee9096b3b9fc6c69362c6b42
f41c94425d01ecbbee70440b951cb058
31eff09e84fca01415f8cd9d82ec432b
f7ab5a04aae9cb9a520e70b20b9c8ed7
30ba0acdee9096b3b9fc6c69362c6b42
31eff09e84fca01415f8cd9d82ec432b
f7ab5a04aae9cb9a520e70b20b9c8ed7
30ba0acdee9096b3b9fc6c69362c6b42
f41c94425d01ecbbee70440b951cb058
31eff09e84fca01415f8cd9d82ec432b
f7ab5a04aae9cb9a520e70b20b9c8ed7
30ba0acdee9096b3b9fc6c69362c6b42
......@@ -46,6 +46,7 @@ macro(add_RunCMake_test test)
endmacro()
add_RunCMake_test(CMP0019)
add_RunCMake_test(ExternalData)
add_RunCMake_test(GeneratorExpression)
add_RunCMake_test(TargetPropertyGeneratorExpressions)
add_RunCMake_test(Languages)
......
CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
Unknown hash algorithm specified by ExternalData_LINK_CONTENT:
BAD
Call Stack \(most recent call first\):
.*
BadHashAlgo1.cmake:3 \(ExternalData_Expand_Arguments\)
CMakeLists.txt:3 \(include\)
include(ExternalData)
set(ExternalData_LINK_CONTENT BAD)
ExternalData_Expand_Arguments(Data args DATA{BadHashAlgo1.txt})
Sample input file that should not be transformed.
CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
Unknown option "Bad/Option" in argument
DATA{Data.txt,Bad/Option}
Call Stack \(most recent call first\):
.*
BadOption1.cmake:2 \(ExternalData_Add_Test\)
CMakeLists.txt:3 \(include\)
include(ExternalData)
ExternalData_Add_Test(Data
NAME Test
COMMAND ${CMAKE_COMMAND} -E echo DATA{Data.txt,Bad/Option}
)
CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
Unknown option "Bad:Option" in argument
DATA{Data.txt,Bad:Option}
Call Stack \(most recent call first\):
.*
BadOption2.cmake:2 \(ExternalData_Add_Test\)
CMakeLists.txt:3 \(include\)
include(ExternalData)
ExternalData_Add_Test(Data
NAME Test
COMMAND ${CMAKE_COMMAND} -E echo DATA{Data.txt,Bad:Option}
)
CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
ExternalData_SERIES_PARSE is set to
NotASeriesRegex
which is not of the form
\(<number>\)\(<suffix>\)\$
Fix the regular expression or set variables
ExternalData_SERIES_PARSE_PREFIX = <prefix> regex group number, if any
ExternalData_SERIES_PARSE_NUMBER = <number> regex group number
ExternalData_SERIES_PARSE_SUFFIX = <suffix> regex group number
Call Stack \(most recent call first\):
.*
BadSeries1.cmake:3 \(ExternalData_Expand_Arguments\)
CMakeLists.txt:3 \(include\)
include(ExternalData)
set(ExternalData_SERIES_PARSE NotASeriesRegex)
ExternalData_Expand_Arguments(Data args DATA{Data.txt,:})
CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
Data file referenced by argument
DATA{Data.txt,:}
corresponds to path
Data.txt
that does not match regular expression
\(x\)\(y\)\$
Call Stack \(most recent call first\):
.*
BadSeries2.cmake:3 \(ExternalData_Expand_Arguments\)
CMakeLists.txt:3 \(include\)
include(ExternalData)
set(ExternalData_SERIES_PARSE "(x)(y)$")
ExternalData_Expand_Arguments(Data args DATA{Data.txt,:})
CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
Series option ":" not allowed with associated files.
Call Stack \(most recent call first\):
.*
BadSeries3.cmake:2 \(ExternalData_Expand_Arguments\)
CMakeLists.txt:3 \(include\)
include(ExternalData)
ExternalData_Expand_Arguments(Data args DATA{PairA.txt,PairB.txt,:})
cmake_minimum_required(VERSION 2.8)
project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)
e8bb14af900b998b5a3df7e21dd07d58
CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
Data file referenced by argument
DATA{Directory1}
corresponds to source tree path
Directory1
that does not exist as a file \(with or without an extension\)!
Call Stack \(most recent call first\):
.*
Directory1.cmake:3 \(ExternalData_Add_Test\)
CMakeLists.txt:3 \(include\)
include(CTest)
include(ExternalData)
ExternalData_Add_Test(Data
NAME Test
COMMAND ${CMAKE_COMMAND} -E echo DATA{Directory1}
)
CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
Data file reference in argument
DATA{Directory2/}
may not end in a slash!
Call Stack \(most recent call first\):
.*
Directory2.cmake:3 \(ExternalData_Add_Test\)
CMakeLists.txt:3 \(include\)
include(CTest)
include(ExternalData)
ExternalData_Add_Test(Data
NAME Test
COMMAND ${CMAKE_COMMAND} -E echo DATA{Directory2/}
)
e8bb14af900b998b5a3df7e21dd07d58
CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
Data file referenced by argument
DATA{Directory3/\*}
corresponds to source tree path
Directory3/.
that does not exist as a file \(with or without an extension\)!
Call Stack \(most recent call first\):
.*
Directory3.cmake:3 \(ExternalData_Add_Test\)
CMakeLists.txt:3 \(include\)
include(CTest)
include(ExternalData)
ExternalData_Add_Test(Data
NAME Test
COMMAND ${CMAKE_COMMAND} -E echo DATA{Directory3/*}
)
-- Linked ToLink.txt.md5 to ExternalData MD5/c18ff9804c8deec9eaeb17063cda8b7b
-- Raw data correctly transformed to content link!
-- Staged content exists!
include(ExternalData)
set(ExternalData_LINK_CONTENT MD5)
set(ExternalData_SOURCE_ROOT ${CMAKE_CURRENT_BINARY_DIR})
set(ExternalData_BINARY_ROOT ${CMAKE_CURRENT_BINARY_DIR}/ExternalData)
set(input ${CMAKE_CURRENT_BINARY_DIR}/ToLink.txt)
set(output ${CMAKE_CURRENT_BINARY_DIR}/ExternalData/ToLink.txt)
set(staged "${CMAKE_CURRENT_BINARY_DIR}/.ExternalData_MD5_c18ff9804c8deec9eaeb17063cda8b7b")
file(REMOVE ${staged})
file(REMOVE ${input}.md5)
file(WRITE ${input} "To be transformed into a content link.")
ExternalData_Expand_Arguments(Data args DATA{${input}})
if("x${args}" STREQUAL "x${output}")
message(STATUS "Raw data correctly transformed to content link!")
else()
message(FATAL_ERROR "Data reference transformed to:\n ${args}\n"
"but we expected:\n ${output}")
endif()
if(EXISTS "${staged}")
message(STATUS "Staged content exists!")
else()
message(FATAL_ERROR "Staged content missing!")
endif()
CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
Data file referenced by argument
DATA{MissingData.txt}
corresponds to source tree path
MissingData.txt
that does not exist as a file \(with or without an extension\)!
Call Stack \(most recent call first\):
.*
MissingData.cmake:2 \(ExternalData_Add_Test\)
CMakeLists.txt:3 \(include\)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment