tests: Add variable expansion tests

There are some corner cases in variable expansion which would be nice to
capture before going and rewriting the variable expansion code. The
majority of these are related to configuring files and strings with '@'
in them in conjunction with @ONLY being specified. Another is testing
for '(' usage inside of ENV variable references based on whether it is
quoted or not.
This commit is contained in:
Ben Boeckel 2014-02-07 17:53:31 -05:00
parent c0bbefbfe7
commit a9bdef2dda
25 changed files with 130 additions and 0 deletions

View File

@ -0,0 +1 @@
-->wrong<--

View File

@ -0,0 +1,9 @@
set(right "wrong")
set(var "\${right}")
# Expanded here.
set(ref "@var@")
# 'right' is dereferenced because 'var' was dereferenced when
# assigning to 'ref' above.
string(CONFIGURE "${ref}" output)
message("-->${output}<--")

View File

@ -0,0 +1 @@
-->\${right}<--

View File

@ -0,0 +1,8 @@
set(right "wrong")
set(var "\${right}")
# Expanded here.
set(ref "@var@")
# No dereference done at all.
string(CONFIGURE "${ref}" output @ONLY)
message("-->${output}<--")

View File

@ -0,0 +1,5 @@
-->==>\${right}<==
==><==
==>\${var}<==
==>\${empty}<==
<--

View File

@ -0,0 +1,9 @@
set(right "wrong")
set(var "\${right}")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/atfile.txt.in"
"${CMAKE_CURRENT_BINARY_DIR}/atfile.txt"
@ONLY)
file(READ "${CMAKE_CURRENT_BINARY_DIR}/atfile.txt" output)
message("-->${output}<--")

View File

@ -0,0 +1 @@
-->\${right}<--

View File

@ -0,0 +1,8 @@
# Literal since 'var' is not defined.
set(ref "@var@")
set(right "wrong")
set(var "\${right}")
# 'var' is dereferenced here.
string(CONFIGURE "${ref}" output)
message("-->${output}<--")

View File

@ -0,0 +1 @@
-->\${right}<--

View File

@ -0,0 +1,8 @@
# Literal since 'var' is not defined.
set(ref "@var@")
set(right "wrong")
set(var "\${right}")
# 'var' is dereferenced, but now 'right'
string(CONFIGURE "${ref}" output @ONLY)
message("-->${output}<--")

View File

@ -0,0 +1,5 @@
-->==>\${right}<==
==><==
==>\${right}<==
==><==
<--

View File

@ -0,0 +1,8 @@
set(right "wrong")
set(var "\${right}")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/atfile.txt.in"
"${CMAKE_CURRENT_BINARY_DIR}/atfile.txt")
file(READ "${CMAKE_CURRENT_BINARY_DIR}/atfile.txt" output)
message("-->${output}<--")

View File

@ -0,0 +1 @@
-->"<--

View File

@ -0,0 +1,9 @@
set(var "\"")
set(ref "@var@")
set(rref "\${var}")
string(CONFIGURE "${ref}" output ESCAPE_QUOTES)
message("-->${output}<--")
string(CONFIGURE "${rref}" output ESCAPE_QUOTES)
message("-->${output}<--")

View File

@ -0,0 +1 @@
-->\\n<--

View File

@ -0,0 +1,5 @@
set(var "n")
set(ref "\\@var@")
string(CONFIGURE "${ref}" output)
message("-->${output}<--")

View File

@ -0,0 +1 @@
-->@foo@<--

View File

@ -0,0 +1,6 @@
set("\${varname}" bar)
set(var foo)
set(ref "@\${var}@")
string(CONFIGURE "${ref}" output)
message("-->${output}<--")

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,20 @@
CMake Warning \(dev\) at CMakeLists.txt:3 \(include\):
Syntax Warning in cmake code at
.*/Tests/RunCMake/Syntax/ParenInENV.cmake:2:21
Argument not separated from preceding token by whitespace.
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Error at ParenInENV.cmake:2 \(message\):
Syntax error in cmake code at
.*/Tests/RunCMake/Syntax/ParenInENV.cmake:2
when parsing string
-->\$ENV{e
syntax error, unexpected \$end, expecting } \(9\)
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -0,0 +1,2 @@
set("ENV{e(x)}" value)
message(-->$ENV{e(x)}<--)

View File

@ -0,0 +1 @@
-->value<--

View File

@ -0,0 +1,2 @@
set("ENV{e(x)}" value)
message("-->$ENV{e(x)}<--")

View File

@ -52,3 +52,16 @@ run_cmake(UnterminatedString)
run_cmake(UnterminatedBracket0) run_cmake(UnterminatedBracket0)
run_cmake(UnterminatedBracket1) run_cmake(UnterminatedBracket1)
run_cmake(UnterminatedBracketComment) run_cmake(UnterminatedBracketComment)
# Variable expansion tests
run_cmake(ExpandInAt)
run_cmake(EscapedAt)
run_cmake(EscapeQuotes)
run_cmake(AtWithVariable)
run_cmake(AtWithVariableEmptyExpansion)
run_cmake(AtWithVariableAtOnly)
run_cmake(AtWithVariableEmptyExpansionAtOnly)
run_cmake(AtWithVariableFile)
run_cmake(AtWithVariableAtOnlyFile)
run_cmake(ParenInENV)
run_cmake(ParenInQuotedENV)

View File

@ -0,0 +1,4 @@
==>@var@<==
==>@empty@<==
==>${var}<==
==>${empty}<==