summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/File_Archive
diff options
context:
space:
mode:
authorAsit Dhal <dhal.asitk@gmail.com>2020-09-17 17:29:31 (GMT)
committerBrad King <brad.king@kitware.com>2020-09-21 17:08:11 (GMT)
commit195d14e7818244789638fffd2087b8b2d0952622 (patch)
tree7e46f8f1f6dfbb60dc73bb600e1190369bc00bc0 /Tests/RunCMake/File_Archive
parent4fc07cd369cd46fbd859f140eda971d00ac52704 (diff)
downloadCMake-195d14e7818244789638fffd2087b8b2d0952622.zip
CMake-195d14e7818244789638fffd2087b8b2d0952622.tar.gz
CMake-195d14e7818244789638fffd2087b8b2d0952622.tar.bz2
file(ARCHIVE_CREATE): Add option to control compression level
Fixes: #21125
Diffstat (limited to 'Tests/RunCMake/File_Archive')
-rw-r--r--Tests/RunCMake/File_Archive/RunCMakeTest.cmake8
-rw-r--r--Tests/RunCMake/File_Archive/argument-validation-compression-level-1-result.txt1
-rw-r--r--Tests/RunCMake/File_Archive/argument-validation-compression-level-1-stderr.txt5
-rw-r--r--Tests/RunCMake/File_Archive/argument-validation-compression-level-1.cmake8
-rw-r--r--Tests/RunCMake/File_Archive/argument-validation-compression-level-2-result.txt1
-rw-r--r--Tests/RunCMake/File_Archive/argument-validation-compression-level-2-stderr.txt5
-rw-r--r--Tests/RunCMake/File_Archive/argument-validation-compression-level-2.cmake8
-rw-r--r--Tests/RunCMake/File_Archive/compression-level.cmake85
-rw-r--r--Tests/RunCMake/File_Archive/gnutar-gz-compression-level.cmake10
-rw-r--r--Tests/RunCMake/File_Archive/pax-xz-compression-level.cmake10
-rw-r--r--Tests/RunCMake/File_Archive/pax-zstd-compression-level.cmake10
-rw-r--r--Tests/RunCMake/File_Archive/paxr-bz2-compression-level.cmake10
-rw-r--r--Tests/RunCMake/File_Archive/roundtrip.cmake17
-rw-r--r--Tests/RunCMake/File_Archive/unsupported-compression-level-result.txt1
-rw-r--r--Tests/RunCMake/File_Archive/unsupported-compression-level-stderr.txt5
-rw-r--r--Tests/RunCMake/File_Archive/unsupported-compression-level.cmake7
16 files changed, 191 insertions, 0 deletions
diff --git a/Tests/RunCMake/File_Archive/RunCMakeTest.cmake b/Tests/RunCMake/File_Archive/RunCMakeTest.cmake
index 2bd0cd8..3908f42 100644
--- a/Tests/RunCMake/File_Archive/RunCMakeTest.cmake
+++ b/Tests/RunCMake/File_Archive/RunCMakeTest.cmake
@@ -16,3 +16,11 @@ run_cmake(zip-filtered)
run_cmake(unsupported-format)
run_cmake(zip-with-bad-compression)
run_cmake(7zip-with-bad-compression)
+
+run_cmake(unsupported-compression-level)
+run_cmake(argument-validation-compression-level-1)
+run_cmake(argument-validation-compression-level-2)
+run_cmake(gnutar-gz-compression-level)
+run_cmake(pax-xz-compression-level)
+run_cmake(pax-zstd-compression-level)
+run_cmake(paxr-bz2-compression-level)
diff --git a/Tests/RunCMake/File_Archive/argument-validation-compression-level-1-result.txt b/Tests/RunCMake/File_Archive/argument-validation-compression-level-1-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/File_Archive/argument-validation-compression-level-1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/File_Archive/argument-validation-compression-level-1-stderr.txt b/Tests/RunCMake/File_Archive/argument-validation-compression-level-1-stderr.txt
new file mode 100644
index 0000000..d7bc79a
--- /dev/null
+++ b/Tests/RunCMake/File_Archive/argument-validation-compression-level-1-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at compression-level.cmake:39 \(file\):
+ file compression level 100 should be in range 0 to 9
+Call Stack \(most recent call first\):
+ argument-validation-compression-level-1.cmake:8 \(check_compression_level\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/File_Archive/argument-validation-compression-level-1.cmake b/Tests/RunCMake/File_Archive/argument-validation-compression-level-1.cmake
new file mode 100644
index 0000000..adedc34
--- /dev/null
+++ b/Tests/RunCMake/File_Archive/argument-validation-compression-level-1.cmake
@@ -0,0 +1,8 @@
+set(OUTPUT_NAME "test.tar.gz")
+
+set(ARCHIVE_FORMAT gnutar)
+set(COMPRESSION_TYPE GZip)
+
+include(${CMAKE_CURRENT_LIST_DIR}/compression-level.cmake)
+
+check_compression_level("100")
diff --git a/Tests/RunCMake/File_Archive/argument-validation-compression-level-2-result.txt b/Tests/RunCMake/File_Archive/argument-validation-compression-level-2-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/File_Archive/argument-validation-compression-level-2-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/File_Archive/argument-validation-compression-level-2-stderr.txt b/Tests/RunCMake/File_Archive/argument-validation-compression-level-2-stderr.txt
new file mode 100644
index 0000000..0f7bd9e
--- /dev/null
+++ b/Tests/RunCMake/File_Archive/argument-validation-compression-level-2-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at compression-level.cmake:39 \(file\):
+ file compression level high should be in range 0 to 9
+Call Stack \(most recent call first\):
+ argument-validation-compression-level-2.cmake:8 \(check_compression_level\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/File_Archive/argument-validation-compression-level-2.cmake b/Tests/RunCMake/File_Archive/argument-validation-compression-level-2.cmake
new file mode 100644
index 0000000..fa6d3fd
--- /dev/null
+++ b/Tests/RunCMake/File_Archive/argument-validation-compression-level-2.cmake
@@ -0,0 +1,8 @@
+set(OUTPUT_NAME "test.tar.gz")
+
+set(ARCHIVE_FORMAT gnutar)
+set(COMPRESSION_TYPE GZip)
+
+include(${CMAKE_CURRENT_LIST_DIR}/compression-level.cmake)
+
+check_compression_level("high")
diff --git a/Tests/RunCMake/File_Archive/compression-level.cmake b/Tests/RunCMake/File_Archive/compression-level.cmake
new file mode 100644
index 0000000..2f5141d
--- /dev/null
+++ b/Tests/RunCMake/File_Archive/compression-level.cmake
@@ -0,0 +1,85 @@
+foreach(parameter OUTPUT_NAME ARCHIVE_FORMAT)
+ if(NOT DEFINED ${parameter})
+ message(FATAL_ERROR "missing required parameter ${parameter}")
+ endif()
+endforeach()
+
+set(COMPRESS_DIR compress_dir)
+set(FULL_COMPRESS_DIR ${CMAKE_CURRENT_BINARY_DIR}/${COMPRESS_DIR})
+
+set(DECOMPRESS_DIR decompress_dir)
+set(FULL_DECOMPRESS_DIR ${CMAKE_CURRENT_BINARY_DIR}/${DECOMPRESS_DIR})
+
+set(FULL_OUTPUT_NAME ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_NAME})
+
+set(CHECK_FILES
+ "f1.txt"
+ "d1/f1.txt"
+ "d 2/f1.txt"
+ "d + 3/f1.txt"
+ "d_4/f1.txt"
+ "d-4/f1.txt"
+ "My Special Directory/f1.txt"
+)
+
+function(check_compression_level COMPRESSION_LEVEL)
+ foreach(file ${CHECK_FILES})
+ configure_file(${CMAKE_CURRENT_LIST_FILE} ${FULL_COMPRESS_DIR}/${file} COPYONLY)
+ endforeach()
+
+ if(UNIX)
+ execute_process(COMMAND ln -sf f1.txt ${FULL_COMPRESS_DIR}/d1/f2.txt)
+ list(APPEND CHECK_FILES "d1/f2.txt")
+ endif()
+
+ file(REMOVE ${FULL_OUTPUT_NAME})
+ file(REMOVE_RECURSE ${FULL_DECOMPRESS_DIR})
+ file(MAKE_DIRECTORY ${FULL_DECOMPRESS_DIR})
+
+ file(ARCHIVE_CREATE
+ OUTPUT ${FULL_OUTPUT_NAME}
+ FORMAT "${ARCHIVE_FORMAT}"
+ COMPRESSION "${COMPRESSION_TYPE}"
+ COMPRESSION_LEVEL ${COMPRESSION_LEVEL}
+ VERBOSE
+ PATHS ${COMPRESS_DIR})
+
+ file(ARCHIVE_EXTRACT
+ INPUT ${FULL_OUTPUT_NAME}
+ ${DECOMPRESSION_OPTIONS}
+ DESTINATION ${FULL_DECOMPRESS_DIR}
+ VERBOSE)
+
+ if(CUSTOM_CHECK_FILES)
+ set(CHECK_FILES ${CUSTOM_CHECK_FILES})
+ endif()
+
+ foreach(file ${CHECK_FILES})
+ set(input ${FULL_COMPRESS_DIR}/${file})
+ set(output ${FULL_DECOMPRESS_DIR}/${COMPRESS_DIR}/${file})
+
+ if(NOT EXISTS ${input})
+ message(SEND_ERROR "Cannot find input file ${output}")
+ endif()
+
+ if(NOT EXISTS ${output})
+ message(SEND_ERROR "Cannot find output file ${output}")
+ endif()
+
+ file(MD5 ${input} input_md5)
+ file(MD5 ${output} output_md5)
+
+ if(NOT input_md5 STREQUAL output_md5)
+ message(SEND_ERROR "Files \"${input}\" and \"${output}\" are different")
+ endif()
+ endforeach()
+
+ foreach(file ${NOT_EXISTING_FILES_CHECK})
+ set(output ${FULL_DECOMPRESS_DIR}/${COMPRESS_DIR}/${file})
+
+ if(EXISTS ${output})
+ message(SEND_ERROR "File ${output} exists but it shouldn't")
+ endif()
+ endforeach()
+
+endfunction()
diff --git a/Tests/RunCMake/File_Archive/gnutar-gz-compression-level.cmake b/Tests/RunCMake/File_Archive/gnutar-gz-compression-level.cmake
new file mode 100644
index 0000000..4106db5
--- /dev/null
+++ b/Tests/RunCMake/File_Archive/gnutar-gz-compression-level.cmake
@@ -0,0 +1,10 @@
+set(OUTPUT_NAME "test.tar.gz")
+
+set(ARCHIVE_FORMAT gnutar)
+set(COMPRESSION_TYPE GZip)
+
+include(${CMAKE_CURRENT_LIST_DIR}/compression-level.cmake)
+
+check_compression_level("1")
+check_compression_level("5")
+check_compression_level("9")
diff --git a/Tests/RunCMake/File_Archive/pax-xz-compression-level.cmake b/Tests/RunCMake/File_Archive/pax-xz-compression-level.cmake
new file mode 100644
index 0000000..d241adb
--- /dev/null
+++ b/Tests/RunCMake/File_Archive/pax-xz-compression-level.cmake
@@ -0,0 +1,10 @@
+set(OUTPUT_NAME "test.tar.xz")
+
+set(ARCHIVE_FORMAT pax)
+set(COMPRESSION_TYPE XZ)
+
+include(${CMAKE_CURRENT_LIST_DIR}/compression-level.cmake)
+
+check_compression_level("1")
+check_compression_level("5")
+check_compression_level("9")
diff --git a/Tests/RunCMake/File_Archive/pax-zstd-compression-level.cmake b/Tests/RunCMake/File_Archive/pax-zstd-compression-level.cmake
new file mode 100644
index 0000000..73fd84d
--- /dev/null
+++ b/Tests/RunCMake/File_Archive/pax-zstd-compression-level.cmake
@@ -0,0 +1,10 @@
+set(OUTPUT_NAME "test.tar.zstd")
+
+set(ARCHIVE_FORMAT pax)
+set(COMPRESSION_TYPE Zstd)
+
+include(${CMAKE_CURRENT_LIST_DIR}/compression-level.cmake)
+
+check_compression_level("1")
+check_compression_level("5")
+check_compression_level("9")
diff --git a/Tests/RunCMake/File_Archive/paxr-bz2-compression-level.cmake b/Tests/RunCMake/File_Archive/paxr-bz2-compression-level.cmake
new file mode 100644
index 0000000..05ea3fc
--- /dev/null
+++ b/Tests/RunCMake/File_Archive/paxr-bz2-compression-level.cmake
@@ -0,0 +1,10 @@
+set(OUTPUT_NAME "test.tar.bz2")
+
+set(ARCHIVE_FORMAT paxr)
+set(COMPRESSION_TYPE BZip2)
+
+include(${CMAKE_CURRENT_LIST_DIR}/compression-level.cmake)
+
+check_compression_level("1")
+check_compression_level("5")
+check_compression_level("9")
diff --git a/Tests/RunCMake/File_Archive/roundtrip.cmake b/Tests/RunCMake/File_Archive/roundtrip.cmake
index 0638367..4049256 100644
--- a/Tests/RunCMake/File_Archive/roundtrip.cmake
+++ b/Tests/RunCMake/File_Archive/roundtrip.cmake
@@ -90,3 +90,20 @@ function(check_magic EXPECTED)
"Actual [${ACTUAL}] does not match expected [${EXPECTED}]")
endif()
endfunction()
+
+
+function(check_compression_level COMPRESSION_LEVEL)
+ file(ARCHIVE_CREATE
+ OUTPUT "${FULL_OUTPUT_NAME}_compression_level"
+ FORMAT "${ARCHIVE_FORMAT}"
+ COMPRESSION_LEVEL ${COMPRESSION_LEVEL}
+ COMPRESSION "${COMPRESSION_TYPE}"
+ VERBOSE
+ PATHS ${COMPRESS_DIR})
+
+ file(ARCHIVE_EXTRACT
+ INPUT "${FULL_OUTPUT_NAME}_compression_level"
+ ${DECOMPRESSION_OPTIONS}
+ DESTINATION ${FULL_DECOMPRESS_DIR}
+ VERBOSE)
+endfunction()
diff --git a/Tests/RunCMake/File_Archive/unsupported-compression-level-result.txt b/Tests/RunCMake/File_Archive/unsupported-compression-level-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/File_Archive/unsupported-compression-level-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/File_Archive/unsupported-compression-level-stderr.txt b/Tests/RunCMake/File_Archive/unsupported-compression-level-stderr.txt
new file mode 100644
index 0000000..860b422
--- /dev/null
+++ b/Tests/RunCMake/File_Archive/unsupported-compression-level-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at compression-level.cmake:39 \(file\):
+ file compression level is not supported for compression "None"
+Call Stack \(most recent call first\):
+ unsupported-compression-level.cmake:7 \(check_compression_level\)
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/File_Archive/unsupported-compression-level.cmake b/Tests/RunCMake/File_Archive/unsupported-compression-level.cmake
new file mode 100644
index 0000000..ea06d1d
--- /dev/null
+++ b/Tests/RunCMake/File_Archive/unsupported-compression-level.cmake
@@ -0,0 +1,7 @@
+set(OUTPUT_NAME "test.7z")
+
+set(ARCHIVE_FORMAT 7zip)
+
+include(${CMAKE_CURRENT_LIST_DIR}/compression-level.cmake)
+
+check_compression_level("1")