cmCacheManager: Test and document newline truncation behavior

This commit is contained in:
Kyle Edwards
2018-01-10 10:43:42 -05:00
parent a9c483071e
commit c42b377c29
8 changed files with 43 additions and 0 deletions

View 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.

View File

@@ -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)

View File

@@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 3.5)
project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)

View 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()

View File

@@ -0,0 +1,2 @@
CMake Warning:
Value of NEWLINE_VARIABLE contained a newline; truncating

View File

@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.5)
project(CacheNewlineTest NONE)
set(NEWLINE_VARIABLE "a\nb" CACHE STRING "Offending entry")

View File

@@ -0,0 +1,3 @@
include(RunCMake)
run_cmake(CacheNewline)

View 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