mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-06 05:40:54 -06:00
cmCacheManager: Test and document newline truncation behavior
This commit is contained in:
7
Help/release/dev/cache-newline.rst
Normal file
7
Help/release/dev/cache-newline.rst
Normal file
@@ -0,0 +1,7 @@
|
||||
cache-newline
|
||||
-------------
|
||||
|
||||
* Variables containing newlines in their values now get truncated before the
|
||||
newline when they are written to the cache file. In addition, a warning
|
||||
comment is written to the cache file, and a warning message is displayed to
|
||||
the user on the console.
|
||||
@@ -339,6 +339,7 @@ add_RunCMake_test(CPackInstallProperties)
|
||||
add_RunCMake_test(ExternalProject)
|
||||
add_RunCMake_test(FetchContent)
|
||||
add_RunCMake_test(CTestCommandLine)
|
||||
add_RunCMake_test(CacheNewline)
|
||||
# Only run this test on unix platforms that support
|
||||
# symbolic links
|
||||
if(UNIX)
|
||||
|
||||
3
Tests/RunCMake/CacheNewline/CMakeLists.txt
Normal file
3
Tests/RunCMake/CacheNewline/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
project(${RunCMake_TEST} NONE)
|
||||
include(${RunCMake_TEST}.cmake)
|
||||
16
Tests/RunCMake/CacheNewline/CacheNewline-check.cmake
Normal file
16
Tests/RunCMake/CacheNewline/CacheNewline-check.cmake
Normal file
@@ -0,0 +1,16 @@
|
||||
set(CACHE_EXPECTED_FILE "${RunCMake_TEST_SOURCE_DIR}/cache-regex.txt")
|
||||
set(CACHE_ACTUAL_FILE "${RunCMake_BINARY_DIR}/CacheNewline-build/CMakeCache.txt")
|
||||
|
||||
file(READ ${CACHE_EXPECTED_FILE} CACHE_EXPECTED)
|
||||
string(REGEX REPLACE "\r\n" "\n" CACHE_EXPECTED "${CACHE_EXPECTED}")
|
||||
string(REGEX REPLACE "\n+$" "" CACHE_EXPECTED "${CACHE_EXPECTED}")
|
||||
file(READ ${CACHE_ACTUAL_FILE} CACHE_ACTUAL)
|
||||
string(REGEX REPLACE "\r\n" "\n" CACHE_ACTUAL "${CACHE_ACTUAL}")
|
||||
string(REGEX REPLACE "\n+$" "" CACHE_ACTUAL "${CACHE_ACTUAL}")
|
||||
|
||||
if(NOT "${CACHE_ACTUAL}" MATCHES "${CACHE_EXPECTED}")
|
||||
set(RunCMake_TEST_FAILED "${CACHE_ACTUAL_FILE} does not match ${CACHE_EXPECTED_FILE}:
|
||||
|
||||
CMakeCache.txt contents = [\n${CACHE_ACTUAL}\n]
|
||||
Expected = [\n${CACHE_EXPECTED}\n]")
|
||||
endif()
|
||||
2
Tests/RunCMake/CacheNewline/CacheNewline-stderr.txt
Normal file
2
Tests/RunCMake/CacheNewline/CacheNewline-stderr.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
CMake Warning:
|
||||
Value of NEWLINE_VARIABLE contained a newline; truncating
|
||||
5
Tests/RunCMake/CacheNewline/CacheNewline.cmake
Normal file
5
Tests/RunCMake/CacheNewline/CacheNewline.cmake
Normal file
@@ -0,0 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
project(CacheNewlineTest NONE)
|
||||
|
||||
set(NEWLINE_VARIABLE "a\nb" CACHE STRING "Offending entry")
|
||||
3
Tests/RunCMake/CacheNewline/RunCMakeTest.cmake
Normal file
3
Tests/RunCMake/CacheNewline/RunCMakeTest.cmake
Normal file
@@ -0,0 +1,3 @@
|
||||
include(RunCMake)
|
||||
|
||||
run_cmake(CacheNewline)
|
||||
6
Tests/RunCMake/CacheNewline/cache-regex.txt
Normal file
6
Tests/RunCMake/CacheNewline/cache-regex.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
//Offending entry
|
||||
NEWLINE_VARIABLE:STRING=a
|
||||
# WARNING: Value of NEWLINE_VARIABLE contained a newline and was
|
||||
# truncated\. Original value:
|
||||
# a
|
||||
# \\nb
|
||||
Reference in New Issue
Block a user