From 49d7e0c91dffe3cae50d174474f69716632eb866 Mon Sep 17 00:00:00 2001 From: "William R. Dieter" Date: Thu, 3 Dec 2020 18:49:57 -0500 Subject: [PATCH] Tests: Make GCOV test more robust to symbolic links in paths Symbolic links in the path to the cmake build directory caused some paths to have '..' directories in the path, which are equivalent, but not a string match for the expected path. As a result, some tests fail. Signed-off-by: William R. Dieter --- Tests/CTestCoverageCollectGCOV/test.cmake.in | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Tests/CTestCoverageCollectGCOV/test.cmake.in b/Tests/CTestCoverageCollectGCOV/test.cmake.in index 1818888755..a36f3743be 100644 --- a/Tests/CTestCoverageCollectGCOV/test.cmake.in +++ b/Tests/CTestCoverageCollectGCOV/test.cmake.in @@ -29,6 +29,20 @@ set(expected_out uncovered/uncovered2.cpp ) +# A symbolic link in the path can cause tar to put an equivalent, but not +# minimal file name to some files in the tar file. Convert paths to absolute +# then back to relative to get them in canonical form (or maybe this is a bug +# in how the tarball is generated?) +function(to_relative_paths real_paths paths) + foreach(file ${paths}) + file(REAL_PATH "${file}" real_path BASE_DIRECTORY "${CTEST_BINARY_DIRECTORY}") + file(RELATIVE_PATH relative_path "${CTEST_BINARY_DIRECTORY}" "${real_path}") + list(APPEND local_real_paths "${relative_path}") + message(DEBUG "${file} -> ${real_path} -> ${relative_path}") + endforeach() + set("${real_paths}" "${local_real_paths}" PARENT_SCOPE) +endfunction() + #------------------------------------------------------------------------------# # Test 1: with standard arguments #------------------------------------------------------------------------------# @@ -50,6 +64,7 @@ execute_process(COMMAND ) string(REPLACE "\n" ";" out "${out}") +to_relative_paths(out "${out}") list(SORT out) if("${out}" STREQUAL "${expected_out}") @@ -80,6 +95,7 @@ execute_process(COMMAND ) string(REPLACE "\n" ";" out "${out}") +to_relative_paths(out "${out}") list(SORT out) if("${out}" STREQUAL "${expected_out}") @@ -110,6 +126,7 @@ execute_process(COMMAND ) string(REPLACE "\n" ";" out "${out}") +to_relative_paths(out "${out}") list(SORT out) if("${out}" STREQUAL "${expected_out}") @@ -140,6 +157,7 @@ execute_process(COMMAND ) string(REPLACE "\n" ";" out "${out}") +to_relative_paths(out "${out}") list(SORT out) if("${out}" STREQUAL "${expected_out}") @@ -170,6 +188,7 @@ execute_process(COMMAND ) string(REPLACE "\n" ";" out "${out}") +to_relative_paths(out "${out}") list(SORT out) if("${out}" STREQUAL "${expected_out}")