From 6c971b5e936281cb3d9565332a07c116b183bbc6 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 23 Feb 2022 17:03:42 -0500 Subject: Tests: Generalize RunCMake.SymlinkTrees implementation Accept paths to the source and binary directories as arguments. Prepare to support more ways of passing the source and binary directories to `cmake`. --- Tests/RunCMake/SymlinkTrees/RunCMakeTest.cmake | 37 +++++++++++++++------- .../SymlinkTrees/common-separate-stdout.txt | 4 +++ .../SymlinkTrees/common_symlinks-stdout.txt | 4 --- 3 files changed, 30 insertions(+), 15 deletions(-) create mode 100644 Tests/RunCMake/SymlinkTrees/common-separate-stdout.txt delete mode 100644 Tests/RunCMake/SymlinkTrees/common_symlinks-stdout.txt diff --git a/Tests/RunCMake/SymlinkTrees/RunCMakeTest.cmake b/Tests/RunCMake/SymlinkTrees/RunCMakeTest.cmake index 3c3bc53..8c2ee04 100644 --- a/Tests/RunCMake/SymlinkTrees/RunCMakeTest.cmake +++ b/Tests/RunCMake/SymlinkTrees/RunCMakeTest.cmake @@ -1,19 +1,37 @@ include(RunCMake) +function(run_symlink_test_case) + file(REMOVE_RECURSE + "${RunCMake_TEST_BINARY_DIR}/CMakeCache.txt" + "${RunCMake_TEST_BINARY_DIR}/CMakeFiles" + ) + run_cmake_with_options(${ARGN}) +endfunction() + # This function assumes that ``${RunCMake_BINARY_DIR}/${name}/source`` and # ``${RunCMake_BINARY_DIR}/${name}/binary`` are set up properly prior to # calling it. -function (run_symlink_test name) +function (run_symlink_test case src bin) + string(REGEX REPLACE "-.*" "" name "${case}") set(RunCMake_TEST_NO_CLEAN TRUE) + set(RunCMake_TEST_SOURCE_DIR "${RunCMake_BINARY_DIR}/${name}/${src}") + set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/${name}/${bin}") configure_file( "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" - "${RunCMake_BINARY_DIR}/${name}/source/CMakeLists.txt" + "${RunCMake_TEST_SOURCE_DIR}/CMakeLists.txt" COPYONLY) - set(RunCMake_TEST_SOURCE_DIR "${RunCMake_BINARY_DIR}/${name}/source") - set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/${name}/binary") + + # We explicitly pass the source directory argument for each case. + set(RunCMake_TEST_NO_SOURCE_DIR 1) + + # Test running in binary directory. + set(RunCMake_TEST_COMMAND_WORKING_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") # Emulate a shell using this directory. - set(ENV{PWD} "${RunCMake_TEST_BINARY_DIR}") - run_cmake("${name}_symlinks") + set(ENV{PWD} "${RunCMake_TEST_COMMAND_WORKING_DIRECTORY}") + + # Pass absolute path to the source tree, plain. + set(RunCMake_TEST_VARIANT_DESCRIPTION " $abs/${name}/${src}") + run_symlink_test_case("${case}" "${RunCMake_TEST_SOURCE_DIR}") endfunction () # Create the following structure: @@ -21,12 +39,9 @@ endfunction () # .../common_real/source # .../common_real/binary # .../common -> common_real -# -# In this case, CMake should act as if .../common *is* .../common_real for all -# computations except ``REALPATH``. This supports the case where a system has -# a stable *symlink*, but not a stable target for that symlink. file(REMOVE_RECURSE "${RunCMake_BINARY_DIR}/common_real") file(REMOVE "${RunCMake_BINARY_DIR}/common") file(MAKE_DIRECTORY "${RunCMake_BINARY_DIR}/common_real/source") +file(MAKE_DIRECTORY "${RunCMake_BINARY_DIR}/common_real/binary") file(CREATE_LINK "common_real" "${RunCMake_BINARY_DIR}/common" SYMBOLIC) -run_symlink_test(common) +run_symlink_test(common-separate "source" "binary") diff --git a/Tests/RunCMake/SymlinkTrees/common-separate-stdout.txt b/Tests/RunCMake/SymlinkTrees/common-separate-stdout.txt new file mode 100644 index 0000000..bb04450 --- /dev/null +++ b/Tests/RunCMake/SymlinkTrees/common-separate-stdout.txt @@ -0,0 +1,4 @@ +-- source: '[^']*/Tests/RunCMake/SymlinkTrees/common/source' +-- binary: '[^']*/Tests/RunCMake/SymlinkTrees/common/binary' +-- real source: '[^']*/Tests/RunCMake/SymlinkTrees/common_real/source' +-- real binary: '[^']*/Tests/RunCMake/SymlinkTrees/common_real/binary' diff --git a/Tests/RunCMake/SymlinkTrees/common_symlinks-stdout.txt b/Tests/RunCMake/SymlinkTrees/common_symlinks-stdout.txt deleted file mode 100644 index bb04450..0000000 --- a/Tests/RunCMake/SymlinkTrees/common_symlinks-stdout.txt +++ /dev/null @@ -1,4 +0,0 @@ --- source: '[^']*/Tests/RunCMake/SymlinkTrees/common/source' --- binary: '[^']*/Tests/RunCMake/SymlinkTrees/common/binary' --- real source: '[^']*/Tests/RunCMake/SymlinkTrees/common_real/source' --- real binary: '[^']*/Tests/RunCMake/SymlinkTrees/common_real/binary' -- cgit v0.12