summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/File_Generate
diff options
context:
space:
mode:
authorAsit Dhal <dhal.asitk@gmail.com>2020-12-22 12:29:34 (GMT)
committerAsit Dhal <dhal.asitk@gmail.com>2021-02-01 00:38:19 (GMT)
commit255df8622bc42c62bd8bc81d2ff2964ef8d6a803 (patch)
treee4540fb3853c457c190117a6a7542f807c0c1094 /Tests/RunCMake/File_Generate
parent93eef927779c14214d7730ccc6cbb94a04126af7 (diff)
downloadCMake-255df8622bc42c62bd8bc81d2ff2964ef8d6a803.zip
CMake-255df8622bc42c62bd8bc81d2ff2964ef8d6a803.tar.gz
CMake-255df8622bc42c62bd8bc81d2ff2964ef8d6a803.tar.bz2
file(GENERATE): Support new line style
Fixes: #19198
Diffstat (limited to 'Tests/RunCMake/File_Generate')
-rw-r--r--Tests/RunCMake/File_Generate/NewLineStyle-Default.cmake35
-rw-r--r--Tests/RunCMake/File_Generate/NewLineStyle-InvalidArg-result.txt1
-rw-r--r--Tests/RunCMake/File_Generate/NewLineStyle-InvalidArg-stderr.txt5
-rw-r--r--Tests/RunCMake/File_Generate/NewLineStyle-InvalidArg.cmake7
-rw-r--r--Tests/RunCMake/File_Generate/NewLineStyle-NoArg-result.txt1
-rw-r--r--Tests/RunCMake/File_Generate/NewLineStyle-NoArg-stderr.txt4
-rw-r--r--Tests/RunCMake/File_Generate/NewLineStyle-NoArg.cmake7
-rw-r--r--Tests/RunCMake/File_Generate/NewLineStyle-Unix.cmake33
-rw-r--r--Tests/RunCMake/File_Generate/NewLineStyle-Win32.cmake33
-rw-r--r--Tests/RunCMake/File_Generate/RunCMakeTest.cmake11
-rw-r--r--Tests/RunCMake/File_Generate/VerifyContent.cmake4
11 files changed, 141 insertions, 0 deletions
diff --git a/Tests/RunCMake/File_Generate/NewLineStyle-Default.cmake b/Tests/RunCMake/File_Generate/NewLineStyle-Default.cmake
new file mode 100644
index 0000000..9df8ffe
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/NewLineStyle-Default.cmake
@@ -0,0 +1,35 @@
+function(generate_from_file in out)
+ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/file_ip.txt "${in}")
+ file(GENERATE
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/$<LOWER_CASE:$<CONFIG>>/file_op.txt
+ INPUT ${CMAKE_CURRENT_BINARY_DIR}/file_ip.txt
+ )
+
+ add_custom_target(verifyContentFromFile ALL
+ COMMAND ${CMAKE_COMMAND}
+ -DgeneratedFile=${CMAKE_CURRENT_BINARY_DIR}/$<LOWER_CASE:$<CONFIG>>/file_op.txt
+ -DexpectedContent=${out}
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/VerifyContent.cmake"
+ )
+endfunction()
+
+function(generate_from_content in out)
+ file(GENERATE
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/$<LOWER_CASE:$<CONFIG>>/content_op.txt
+ CONTENT ${in}
+ )
+
+ add_custom_target(verifyContentFromContent ALL
+ COMMAND ${CMAKE_COMMAND}
+ -DgeneratedFile=${CMAKE_CURRENT_BINARY_DIR}/$<LOWER_CASE:$<CONFIG>>/content_op.txt
+ -DexpectedContent=${out}
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/VerifyContent.cmake"
+ )
+endfunction()
+
+if (WIN32)
+ generate_from_file("a" "610d0a") # 62->b, 0d0a->\r\n
+elseif(UNIX)
+ generate_from_file("a" "610a") # 62->b, 0a->\n
+endif()
+generate_from_content("a" "61")
diff --git a/Tests/RunCMake/File_Generate/NewLineStyle-InvalidArg-result.txt b/Tests/RunCMake/File_Generate/NewLineStyle-InvalidArg-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/NewLineStyle-InvalidArg-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/File_Generate/NewLineStyle-InvalidArg-stderr.txt b/Tests/RunCMake/File_Generate/NewLineStyle-InvalidArg-stderr.txt
new file mode 100644
index 0000000..44e32d0
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/NewLineStyle-InvalidArg-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at NewLineStyle-InvalidArg.cmake:[0-9]+ \(file\):
+ file GENERATE NEWLINE_STYLE sets an unknown style, only LF, CRLF, UNIX,
+ DOS, and WIN32 are supported
+Call Stack \(most recent call first\):
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/File_Generate/NewLineStyle-InvalidArg.cmake b/Tests/RunCMake/File_Generate/NewLineStyle-InvalidArg.cmake
new file mode 100644
index 0000000..578cf21
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/NewLineStyle-InvalidArg.cmake
@@ -0,0 +1,7 @@
+file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
+
+file(GENERATE
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
+ CONTENT "int main() { return 0; }\n"
+ NEWLINE_STYLE FOO
+ )
diff --git a/Tests/RunCMake/File_Generate/NewLineStyle-NoArg-result.txt b/Tests/RunCMake/File_Generate/NewLineStyle-NoArg-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/NewLineStyle-NoArg-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/File_Generate/NewLineStyle-NoArg-stderr.txt b/Tests/RunCMake/File_Generate/NewLineStyle-NoArg-stderr.txt
new file mode 100644
index 0000000..bc71f2f
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/NewLineStyle-NoArg-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at NewLineStyle-NoArg.cmake:[0-9]+ \(file\):
+ file Incorrect arguments to GENERATE subcommand.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/File_Generate/NewLineStyle-NoArg.cmake b/Tests/RunCMake/File_Generate/NewLineStyle-NoArg.cmake
new file mode 100644
index 0000000..9bd2ffa
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/NewLineStyle-NoArg.cmake
@@ -0,0 +1,7 @@
+file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
+
+file(GENERATE
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/main.cpp"
+ CONTENT "int main() { return 0; }\n"
+ NEWLINE_STYLE
+ )
diff --git a/Tests/RunCMake/File_Generate/NewLineStyle-Unix.cmake b/Tests/RunCMake/File_Generate/NewLineStyle-Unix.cmake
new file mode 100644
index 0000000..7c26217
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/NewLineStyle-Unix.cmake
@@ -0,0 +1,33 @@
+function(generate_from_file in out)
+ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/file_ip.txt "${in}")
+ file(GENERATE
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/$<LOWER_CASE:$<CONFIG>>/file_op.txt
+ INPUT ${CMAKE_CURRENT_BINARY_DIR}/file_ip.txt
+ NEWLINE_STYLE UNIX
+ )
+
+ add_custom_target(verifyContentFromFile ALL
+ COMMAND ${CMAKE_COMMAND}
+ -DgeneratedFile=${CMAKE_CURRENT_BINARY_DIR}/$<LOWER_CASE:$<CONFIG>>/file_op.txt
+ -DexpectedContent=${out}
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/VerifyContent.cmake"
+ )
+endfunction()
+
+function(generate_from_content in out)
+ file(GENERATE
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/$<LOWER_CASE:$<CONFIG>>/content_op.txt
+ CONTENT ${in}
+ NEWLINE_STYLE UNIX
+ )
+
+ add_custom_target(verifyContentFromContent ALL
+ COMMAND ${CMAKE_COMMAND}
+ -DgeneratedFile=${CMAKE_CURRENT_BINARY_DIR}/$<LOWER_CASE:$<CONFIG>>/content_op.txt
+ -DexpectedContent=${out}
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/VerifyContent.cmake"
+ )
+endfunction()
+
+generate_from_file("a" "610a") # 62->b, 0a->\n
+generate_from_content("a" "610a")
diff --git a/Tests/RunCMake/File_Generate/NewLineStyle-Win32.cmake b/Tests/RunCMake/File_Generate/NewLineStyle-Win32.cmake
new file mode 100644
index 0000000..394ef75
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/NewLineStyle-Win32.cmake
@@ -0,0 +1,33 @@
+function(generate_from_file in out)
+ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/file_ip.txt "${in}")
+ file(GENERATE
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/$<LOWER_CASE:$<CONFIG>>/file_op.txt
+ INPUT ${CMAKE_CURRENT_BINARY_DIR}/file_ip.txt
+ NEWLINE_STYLE WIN32
+ )
+
+ add_custom_target(verifyContentFromFile ALL
+ COMMAND ${CMAKE_COMMAND}
+ -DgeneratedFile=${CMAKE_CURRENT_BINARY_DIR}/$<LOWER_CASE:$<CONFIG>>/file_op.txt
+ -DexpectedContent=${out}
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/VerifyContent.cmake"
+ )
+endfunction()
+
+function(generate_from_content in out)
+ file(GENERATE
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/$<LOWER_CASE:$<CONFIG>>/content_op.txt
+ CONTENT ${in}
+ NEWLINE_STYLE WIN32
+ )
+
+ add_custom_target(verifyContentFromContent ALL
+ COMMAND ${CMAKE_COMMAND}
+ -DgeneratedFile=${CMAKE_CURRENT_BINARY_DIR}/$<LOWER_CASE:$<CONFIG>>/content_op.txt
+ -DexpectedContent=${out}
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/VerifyContent.cmake"
+ )
+endfunction()
+
+generate_from_file("a" "610d0a") # 62->b, 0d0a->\r\n
+generate_from_content("a" "610d0a")
diff --git a/Tests/RunCMake/File_Generate/RunCMakeTest.cmake b/Tests/RunCMake/File_Generate/RunCMakeTest.cmake
index 51491af..be3bf04 100644
--- a/Tests/RunCMake/File_Generate/RunCMakeTest.cmake
+++ b/Tests/RunCMake/File_Generate/RunCMakeTest.cmake
@@ -135,6 +135,11 @@ function(run_cmake_and_verify_after_build case)
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
set(RunCMake_TEST_NO_CLEAN 1)
+ if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
+ set(RunCMake_TEST_OPTIONS -DCMAKE_CONFIGURATION_TYPES=Debug)
+ else()
+ set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
+ endif()
run_cmake(${case})
run_cmake_command("${case}-build" ${CMAKE_COMMAND} --build .)
unset(RunCMake_TEST_NO_CLEAN)
@@ -144,3 +149,9 @@ endfunction()
run_cmake_and_verify_after_build(NoSourcePermissions)
run_cmake_and_verify_after_build(UseSourcePermissions)
run_cmake_and_verify_after_build(CustomFilePermissions)
+
+run_cmake(NewLineStyle-NoArg)
+run_cmake(NewLineStyle-InvalidArg)
+run_cmake_and_verify_after_build(NewLineStyle-Default)
+run_cmake_and_verify_after_build(NewLineStyle-Unix)
+run_cmake_and_verify_after_build(NewLineStyle-Win32)
diff --git a/Tests/RunCMake/File_Generate/VerifyContent.cmake b/Tests/RunCMake/File_Generate/VerifyContent.cmake
new file mode 100644
index 0000000..8563708
--- /dev/null
+++ b/Tests/RunCMake/File_Generate/VerifyContent.cmake
@@ -0,0 +1,4 @@
+file(READ ${generatedFile} actualContent HEX)
+if(NOT "${actualContent}" STREQUAL "${expectedContent}")
+ message(SEND_ERROR "Content mismatch actual: \"${actualContent}\" expected: \"${expectedContent}\"")
+endif()