diff options
author | Brad King <brad.king@kitware.com> | 2013-03-12 19:40:37 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2013-03-12 20:33:19 (GMT) |
commit | 1823ab4d76d8efe79bed85328a3f8c74c7d625bd (patch) | |
tree | c94f72f7b3918c53f142414c4c95826f115c272a /Tests/RunCMake | |
parent | 51fc4fb3c1bd22f038b1d6b51e039296bbc258c3 (diff) | |
download | CMake-1823ab4d76d8efe79bed85328a3f8c74c7d625bd.zip CMake-1823ab4d76d8efe79bed85328a3f8c74c7d625bd.tar.gz CMake-1823ab4d76d8efe79bed85328a3f8c74c7d625bd.tar.bz2 |
ExternalData: Preserve escaped semicolons during argument expansion
The CMake language implicitly flattens lists so a ";" in a list element
must be escaped with a backslash. List expansion removes backslashes
escaping semicolons to leave raw semicolons in the values. Teach
ExternalData_Add_Test and ExternalData_Expand_Arguments to re-escape
semicolons found in list elements so the resulting argument lists work
as if constructed directly by the set() command.
For example:
ExternalData_Add_Test(Data NAME test1 COMMAND ... "a\\;b")
ExternalData_Expand_Arguments(Data args2 "c\\;d")
add_test(NAME test2 COMMAND ... ${args2})
should be equivalent to
set(args1 "a\\;b")
add_test(NAME test1 COMMAND ... ${args1})
set(args2 "c\\;d")
add_test(NAME test2 COMMAND ... ${args2})
which is equivalent to
add_test(NAME test1 COMMAND ... "a;b")
add_test(NAME test2 COMMAND ... "c;d")
Note that it is not possible to make ExternalData_Add_Test act exactly
like add_test when quoted arguments contain semicolons because the CMake
language flattens lists when constructing function ARGN values. This
re-escape approach at least allows test arguments to have semicolons.
While at it, teach ExternalData APIs to not transform "DATA{...;...}"
arguments because the contained semicolons are non-sensical.
Suggested-by: Jean-Christophe Fillion-Robin <jchris.fillionr@kitware.com>
Diffstat (limited to 'Tests/RunCMake')
-rw-r--r-- | Tests/RunCMake/ExternalData/RunCMakeTest.cmake | 3 | ||||
-rw-r--r-- | Tests/RunCMake/ExternalData/Semicolon1-stdout.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/ExternalData/Semicolon1.cmake | 14 | ||||
-rw-r--r-- | Tests/RunCMake/ExternalData/Semicolon2-stdout.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/ExternalData/Semicolon2.cmake | 14 | ||||
-rw-r--r-- | Tests/RunCMake/ExternalData/Semicolon3-stdout.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/ExternalData/Semicolon3.cmake | 12 |
7 files changed, 46 insertions, 0 deletions
diff --git a/Tests/RunCMake/ExternalData/RunCMakeTest.cmake b/Tests/RunCMake/ExternalData/RunCMakeTest.cmake index 5ee46c9..ceb2ecf 100644 --- a/Tests/RunCMake/ExternalData/RunCMakeTest.cmake +++ b/Tests/RunCMake/ExternalData/RunCMakeTest.cmake @@ -21,4 +21,7 @@ run_cmake(NormalData2) run_cmake(NormalData3) run_cmake(NormalDataSub1) run_cmake(NotUnderRoot) +run_cmake(Semicolon1) +run_cmake(Semicolon2) +run_cmake(Semicolon3) run_cmake(SubDirectory1) diff --git a/Tests/RunCMake/ExternalData/Semicolon1-stdout.txt b/Tests/RunCMake/ExternalData/Semicolon1-stdout.txt new file mode 100644 index 0000000..361baeb --- /dev/null +++ b/Tests/RunCMake/ExternalData/Semicolon1-stdout.txt @@ -0,0 +1 @@ +-- Data arguments correctly transformed! diff --git a/Tests/RunCMake/ExternalData/Semicolon1.cmake b/Tests/RunCMake/ExternalData/Semicolon1.cmake new file mode 100644 index 0000000..c832860 --- /dev/null +++ b/Tests/RunCMake/ExternalData/Semicolon1.cmake @@ -0,0 +1,14 @@ +include(ExternalData) +set(ExternalData_URL_TEMPLATES + "file:///${CMAKE_CURRENT_SOURCE_DIR}/%(algo)/%(hash)" + ) +set(input Data.txt) +set(output ${CMAKE_CURRENT_BINARY_DIR}/Data.txt) +ExternalData_Expand_Arguments(Data args DATA{${input}} "a\\;b" "c;d" DATA{${input}}) +set(expect "${output};a\\;b;c;d;${output}") +if("x${args}" STREQUAL "x${expect}") + message(STATUS "Data arguments correctly transformed!") +else() + message(FATAL_ERROR "Data arguments transformed to:\n ${args}\n" + "but we expected:\n ${expect}") +endif() diff --git a/Tests/RunCMake/ExternalData/Semicolon2-stdout.txt b/Tests/RunCMake/ExternalData/Semicolon2-stdout.txt new file mode 100644 index 0000000..361baeb --- /dev/null +++ b/Tests/RunCMake/ExternalData/Semicolon2-stdout.txt @@ -0,0 +1 @@ +-- Data arguments correctly transformed! diff --git a/Tests/RunCMake/ExternalData/Semicolon2.cmake b/Tests/RunCMake/ExternalData/Semicolon2.cmake new file mode 100644 index 0000000..1a1ae5f --- /dev/null +++ b/Tests/RunCMake/ExternalData/Semicolon2.cmake @@ -0,0 +1,14 @@ +include(ExternalData) +set(ExternalData_URL_TEMPLATES + "file:///${CMAKE_CURRENT_SOURCE_DIR}/%(algo)/%(hash)" + ) +set(input Data.txt) +set(output ${CMAKE_CURRENT_BINARY_DIR}/Data.txt) +ExternalData_Expand_Arguments(Data args "DATA{${input}};a\\;b;c;d;DATA{${input}}") +set(expect "${output};a\\;b;c;d;${output}") +if("x${args}" STREQUAL "x${expect}") + message(STATUS "Data arguments correctly transformed!") +else() + message(FATAL_ERROR "Data arguments transformed to:\n ${args}\n" + "but we expected:\n ${expect}") +endif() diff --git a/Tests/RunCMake/ExternalData/Semicolon3-stdout.txt b/Tests/RunCMake/ExternalData/Semicolon3-stdout.txt new file mode 100644 index 0000000..ca4a360 --- /dev/null +++ b/Tests/RunCMake/ExternalData/Semicolon3-stdout.txt @@ -0,0 +1 @@ +-- Data arguments correctly not transformed! diff --git a/Tests/RunCMake/ExternalData/Semicolon3.cmake b/Tests/RunCMake/ExternalData/Semicolon3.cmake new file mode 100644 index 0000000..2ae99da --- /dev/null +++ b/Tests/RunCMake/ExternalData/Semicolon3.cmake @@ -0,0 +1,12 @@ +include(ExternalData) +set(ExternalData_URL_TEMPLATES + "file:///${CMAKE_CURRENT_SOURCE_DIR}/%(algo)/%(hash)" + ) +set(input "DATA{a;b}") +ExternalData_Expand_Arguments(Data args "${input}") +if("x${args}" STREQUAL "x${input}") + message(STATUS "Data arguments correctly not transformed!") +else() + message(FATAL_ERROR "Data arguments transformed to:\n ${args}\n" + "but we expected:\n ${input}") +endif() |