Tests: Consolidate, refactor and extend -E tar tests

This commit is contained in:
Nils Gladitz 2015-04-07 19:40:33 +02:00 committed by Brad King
parent fd04d87323
commit 6c4781baa9
41 changed files with 198 additions and 88 deletions

View File

@ -218,7 +218,6 @@ if(BUILD_TESTING)
ADD_TEST_MACRO(FindModulesExecuteAll FindModulesExecuteAll) ADD_TEST_MACRO(FindModulesExecuteAll FindModulesExecuteAll)
ADD_TEST_MACRO(StringFileTest StringFileTest) ADD_TEST_MACRO(StringFileTest StringFileTest)
ADD_TEST_MACRO(TryCompile TryCompile) ADD_TEST_MACRO(TryCompile TryCompile)
ADD_TEST_MACRO(TarTest TarTest)
ADD_TEST_MACRO(SystemInformation SystemInformation) ADD_TEST_MACRO(SystemInformation SystemInformation)
ADD_TEST_MACRO(MathTest MathTest) ADD_TEST_MACRO(MathTest MathTest)
ADD_TEST_MACRO(CompileFeatures CompileFeatures) ADD_TEST_MACRO(CompileFeatures CompileFeatures)

View File

@ -200,6 +200,7 @@ add_RunCMake_test(target_link_libraries)
add_RunCMake_test(target_compile_features) add_RunCMake_test(target_compile_features)
add_RunCMake_test(CheckModules) add_RunCMake_test(CheckModules)
add_RunCMake_test(CommandLine) add_RunCMake_test(CommandLine)
add_RunCMake_test(CommandLineTar)
add_RunCMake_test(install) add_RunCMake_test(install)
add_RunCMake_test(CPackInstallProperties) add_RunCMake_test(CPackInstallProperties)

View File

@ -1,17 +1,5 @@
include(RunCMake) include(RunCMake)
run_cmake_command(E_tar-bad-opt1 ${CMAKE_COMMAND} -E tar cvf bad.tar --bad)
run_cmake_command(E_tar-bad-mtime1 ${CMAKE_COMMAND} -E tar cvf bad.tar --mtime=bad .)
run_cmake_command(E_tar-bad-from1 ${CMAKE_COMMAND} -E tar cvf bad.tar --files-from=bad)
run_cmake_command(E_tar-bad-from2 ${CMAKE_COMMAND} -E tar cvf bad.tar --files-from=.)
run_cmake_command(E_tar-bad-from3 ${CMAKE_COMMAND} -E tar cvf bad.tar --files-from=${CMAKE_CURRENT_LIST_DIR}/E_tar-bad-from3.txt)
run_cmake_command(E_tar-bad-from4 ${CMAKE_COMMAND} -E tar cvf bad.tar --files-from=${CMAKE_CURRENT_LIST_DIR}/E_tar-bad-from4.txt)
run_cmake_command(E_tar-bad-from5 ${CMAKE_COMMAND} -E tar cvf bad.tar --files-from=${CMAKE_CURRENT_LIST_DIR}/E_tar-bad-from5.txt)
run_cmake_command(E_tar-end-opt1 ${CMAKE_COMMAND} -E tar cvf bad.tar -- --bad)
run_cmake_command(E_tar-end-opt2 ${CMAKE_COMMAND} -E tar cvf bad.tar --)
run_cmake_command(E_tar-mtime ${CMAKE_COMMAND} -E tar cvf bad.tar "--mtime=1970-01-01 00:00:00 UTC")
run_cmake_command(E_tar-bad-format ${CMAKE_COMMAND} -E tar cvf bad.tar "--format=bad-format")
run_cmake_command(build-no-cache run_cmake_command(build-no-cache
${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}) ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR})
run_cmake_command(build-no-generator run_cmake_command(build-no-generator

View File

@ -0,0 +1 @@
CMake Error: Can not use compression flags with format: 7zip

View File

@ -0,0 +1,10 @@
set(OUTPUT_NAME "test.7z")
set(COMPRESSION_FLAGS cvf)
set(COMPRESSION_OPTIONS --format=7zip)
set(DECOMPRESSION_FLAGS xvf)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
check_magic("377abcaf271c" LIMIT 6 HEX)

View File

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

View File

@ -0,0 +1,28 @@
include(RunCMake)
function(external_command_test NAME)
run_cmake_command(${NAME} ${CMAKE_COMMAND} -E ${ARGN})
endfunction()
external_command_test(bad-opt1 tar cvf bad.tar --bad)
external_command_test(bad-mtime1 tar cvf bad.tar --mtime=bad .)
external_command_test(bad-from1 tar cvf bad.tar --files-from=bad)
external_command_test(bad-from2 tar cvf bad.tar --files-from=.)
external_command_test(bad-from3 tar cvf bad.tar --files-from=${CMAKE_CURRENT_LIST_DIR}/bad-from3.txt)
external_command_test(bad-from4 tar cvf bad.tar --files-from=${CMAKE_CURRENT_LIST_DIR}/bad-from4.txt)
external_command_test(bad-from5 tar cvf bad.tar --files-from=${CMAKE_CURRENT_LIST_DIR}/bad-from5.txt)
external_command_test(end-opt1 tar cvf bad.tar -- --bad)
external_command_test(end-opt2 tar cvf bad.tar --)
external_command_test(mtime tar cvf bad.tar "--mtime=1970-01-01 00:00:00 UTC")
external_command_test(bad-format tar cvf bad.tar "--format=bad-format")
external_command_test(zip-bz2 tar cvjf bad.tar "--format=zip")
external_command_test(7zip-gz tar cvzf bad.tar "--format=7zip")
run_cmake(7zip)
run_cmake(gnutar)
run_cmake(gnutar-gz)
run_cmake(pax)
run_cmake(pax-xz)
run_cmake(paxr)
run_cmake(paxr-bz2)
run_cmake(zip)

View File

@ -1,2 +1,2 @@
^CMake Error: -E tar --files-from='.*/Tests/RunCMake/CommandLine/E_tar-bad-from3.txt' file invalid line: ^CMake Error: -E tar --files-from='.*/Tests/RunCMake/CommandLineTar/bad-from3.txt' file invalid line:
-add-file=option-typo$ -add-file=option-typo$

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,10 @@
set(OUTPUT_NAME "test.tar.gz")
set(COMPRESSION_FLAGS cvzf)
set(COMPRESSION_OPTIONS --format=gnutar)
set(DECOMPRESSION_FLAGS xvzf)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
check_magic("1f8b" LIMIT 2 HEX)

View File

@ -0,0 +1,10 @@
set(OUTPUT_NAME "test.tar")
set(COMPRESSION_FLAGS cvf)
set(COMPRESSION_OPTIONS --format=gnutar)
set(DECOMPRESSION_FLAGS xvf)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
check_magic("7573746172202000" OFFSET 257 LIMIT 8 HEX)

View File

@ -0,0 +1,10 @@
set(OUTPUT_NAME "test.tar.xz")
set(COMPRESSION_FLAGS cvJf)
set(COMPRESSION_OPTIONS --format=pax)
set(DECOMPRESSION_FLAGS xvJf)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
check_magic("fd377a585a00" LIMIT 6 HEX)

View File

@ -0,0 +1,10 @@
set(OUTPUT_NAME "test.tar")
set(COMPRESSION_FLAGS cvf)
set(COMPRESSION_OPTIONS --format=pax)
set(DECOMPRESSION_FLAGS xvf)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
check_magic("7573746172003030" OFFSET 257 LIMIT 8 HEX)

View File

@ -0,0 +1,10 @@
set(OUTPUT_NAME "test.tar.bz2")
set(COMPRESSION_FLAGS cvjf)
set(COMPRESSION_OPTIONS --format=paxr)
set(DECOMPRESSION_FLAGS xvjf)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
check_magic("425a68" LIMIT 3 HEX)

View File

@ -0,0 +1,10 @@
set(OUTPUT_NAME "test.tar")
set(COMPRESSION_FLAGS cvf)
set(COMPRESSION_OPTIONS --format=paxr)
set(DECOMPRESSION_FLAGS xvf)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
check_magic("7573746172003030" OFFSET 257 LIMIT 8 HEX)

View File

@ -0,0 +1,81 @@
foreach(parameter OUTPUT_NAME COMPRESSION_FLAGS DECOMPRESSION_FLAGS)
if(NOT DEFINED ${parameter})
message(FATAL_ERROR "missing required parameter ${parameter}")
endif()
endforeach()
function(run_tar WORKING_DIRECTORY)
execute_process(COMMAND ${CMAKE_COMMAND} -E tar ${ARGN}
WORKING_DIRECTORY ${WORKING_DIRECTORY}
RESULT_VARIABLE result
)
if(NOT result STREQUAL "0")
message(FATAL_ERROR "tar failed with arguments [${ARGN}] result [${result}]")
endif()
endfunction()
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"
)
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})
run_tar(${CMAKE_CURRENT_BINARY_DIR} ${COMPRESSION_FLAGS} ${FULL_OUTPUT_NAME} ${COMPRESSION_OPTIONS} ${COMPRESS_DIR})
run_tar(${FULL_DECOMPRESS_DIR} ${DECOMPRESSION_FLAGS} ${FULL_OUTPUT_NAME} ${DECOMPRESSION_OPTIONS})
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()
function(check_magic EXPECTED)
file(READ ${FULL_OUTPUT_NAME} ACTUAL
${ARGN}
)
if(NOT ACTUAL STREQUAL EXPECTED)
message(FATAL_ERROR
"Actual [${ACTUAL}] does not match expected [${EXPECTED}]")
endif()
endfunction()

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1 @@
CMake Error: Can not use compression flags with format: zip

View File

@ -0,0 +1,10 @@
set(OUTPUT_NAME "test.zip")
set(COMPRESSION_FLAGS cvf)
set(COMPRESSION_OPTIONS --format=zip)
set(DECOMPRESSION_FLAGS xvf)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
check_magic("504b0304" LIMIT 4 HEX)

View File

@ -1,69 +0,0 @@
cmake_minimum_required (VERSION 2.6)
project(TarTest)
# this is macro that we will be running
macro(EXEC_TAR_COMMAND DIR ARGS)
exec_program("${CMAKE_COMMAND}" "${DIR}" ARGS "-E tar ${ARGS}" RETURN_VALUE RET)
if(${RET})
message(FATAL_ERROR "CMake tar command failed with arguments \"${ARGS}\"")
endif()
endmacro()
# Create a directory structure
set(CHECK_FILES)
macro(COPY F1 F2)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${F1}" "${CMAKE_CURRENT_BINARY_DIR}/tar_dir/${F2}" COPYONLY)
set(CHECK_FILES ${CHECK_FILES} "${F2}")
endmacro()
COPY("CMakeLists.txt" "f1.txt")
COPY("CMakeLists.txt" "d1/f1.txt")
COPY("CMakeLists.txt" "d 2/f1.txt")
COPY("CMakeLists.txt" "d + 3/f1.txt")
COPY("CMakeLists.txt" "d_4/f1.txt")
COPY("CMakeLists.txt" "d-4/f1.txt")
COPY("CMakeLists.txt" "My Special Directory/f1.txt")
if(UNIX)
exec_program("ln" ARGS "-sf f1.txt \"${CMAKE_CURRENT_BINARY_DIR}/tar_dir/d1/f2.txt\"")
set(CHECK_FILES ${CHECK_FILES} "d1/f2.txt")
endif()
# cleanup first in case there are files left from previous runs
# if the umask is odd on the machine it might create files that
# are not automatically over written. These tests are run
# each time the configure step is run.
file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/test_tar.tar")
file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/test_tgz.tgz")
file(REMOVE_RECURSE "${CMAKE_CURRENT_BINARY_DIR}/test_output_tar")
file(REMOVE_RECURSE "${CMAKE_CURRENT_BINARY_DIR}/test_output_tgz")
make_directory("${CMAKE_CURRENT_BINARY_DIR}/test_output_tar")
make_directory("${CMAKE_CURRENT_BINARY_DIR}/test_output_tgz")
# Run tests
EXEC_TAR_COMMAND("${CMAKE_CURRENT_BINARY_DIR}" "cvf \"${CMAKE_CURRENT_BINARY_DIR}/test_tar.tar\" tar_dir")
EXEC_TAR_COMMAND("${CMAKE_CURRENT_BINARY_DIR}" "cvfz \"${CMAKE_CURRENT_BINARY_DIR}/test_tgz.tgz\" tar_dir")
EXEC_TAR_COMMAND("${CMAKE_CURRENT_BINARY_DIR}/test_output_tar" "xvf \"${CMAKE_CURRENT_BINARY_DIR}/test_tar.tar\"")
EXEC_TAR_COMMAND("${CMAKE_CURRENT_BINARY_DIR}/test_output_tgz" "xvfz \"${CMAKE_CURRENT_BINARY_DIR}/test_tgz.tgz\"")
macro(CHECK_DIR_STRUCTURE DIR)
foreach(file ${CHECK_FILES})
set(sfile "${DIR}/${file}")
set(rfile "${CMAKE_CURRENT_BINARY_DIR}/tar_dir/${file}")
if(NOT EXISTS "${sfile}")
message(SEND_ERROR "Cannot find file ${sfile}")
else()
exec_program("${CMAKE_COMMAND}" ARGS "-E compare_files \"${sfile}\" \"${rfile}\"" RETURN_VALUE ret)
if(${ret})
message(SEND_ERROR "Files \"${sfile}\" \"${rfile}\" are different")
endif()
endif()
endforeach()
endmacro()
CHECK_DIR_STRUCTURE("${CMAKE_CURRENT_BINARY_DIR}/test_output_tar/tar_dir")
add_executable(TarTest TestTarExec.cxx)

View File

@ -1,5 +0,0 @@
int main()
{
return 0;
}