From: Matthias Maier Date: Sun, 2 Jul 2023 15:11:30 +0000 (-0500) Subject: Tests examples: only use binary directory for temporary files X-Git-Tag: relicensing~766^2~6 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=22fecf1ba025ac2a3cee874e2e2870c78bb8748f;p=dealii.git Tests examples: only use binary directory for temporary files --- diff --git a/tests/examples/CMakeLists.txt b/tests/examples/CMakeLists.txt index 1ff5768966..3f5ef8ad90 100644 --- a/tests/examples/CMakeLists.txt +++ b/tests/examples/CMakeLists.txt @@ -2,10 +2,41 @@ cmake_minimum_required(VERSION 3.13.4) include(../scripts/setup_testsubproject.cmake) project(testsuite CXX) -# create tests from diffs: -execute_process( - COMMAND "./update.sh" - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -) +# +# Make sure that we have been called with a proper deal.II source directory +# layout: +# +set(DEAL_II_SOURCE_DIR "${CMAKE_SOURCE_DIR}/../..") +if (EXISTS "${DEAL_II_SOURCE_DIR}/examples") + # + # Create CMake file structure in the current binary dir: + # + set(_source_directory "${CMAKE_CURRENT_BINARY_DIR}/source") + set(_binary_directory "${CMAKE_CURRENT_BINARY_DIR}/binary") + message(STATUS "Temporary source directory: ${_source_directory}") + message(STATUS "Temporary binary directory: ${_binary_directory}") + file(MAKE_DIRECTORY "${_source_directory}") + file(WRITE "${_source_directory}/CMakeLists.txt" "deal_ii_pickup_tests(examples)") + file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/../tests.h" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") -deal_ii_pickup_tests() + enable_testing() + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/CTestFile.cmake" "subdirs(binary)") + + # + # Create tests from diffs: + # + execute_process( + COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/update.sh" "${DEAL_II_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" + WORKING_DIRECTORY "${_source_directory}" + ) + + add_subdirectory(${_source_directory} ${_binary_directory}) + + # + # Create a top-level diff target: + # + add_custom_target(update_diffs + COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/update_diffs.sh" "${DEAL_II_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" + WORKING_DIRECTORY "${_source_directory}" + ) +endif() diff --git a/tests/examples/create_diffs.sh b/tests/examples/create_diffs.sh deleted file mode 100755 index d752616c9f..0000000000 --- a/tests/examples/create_diffs.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -# create .diff files from current .cc files - -# Find all *.diff files in the current directory -diff_files=$(find . -maxdepth 1 -type f -name "*.diff") - -for file in $diff_files; do - # Extract the filename without the extension - filename=$(basename "$file" .diff) - src="../../examples/$filename/$filename.cc" - - # Check if the corresponding .cc file exists - if [[ -f "$src" ]]; then - echo "creating $file from $src and $filename.cc" - diff "$src" "$filename.cc" > "$file" - else - echo "No matching .cc file found for $file" - exit 1 - fi -done diff --git a/tests/examples/update.sh b/tests/examples/update.sh index 1211532171..64c79a05d3 100755 --- a/tests/examples/update.sh +++ b/tests/examples/update.sh @@ -1,19 +1,30 @@ #!/bin/bash +set -eu +DEAL_II_SOURCE_DIR="${1}" +shift +CMAKE_CURRENT_SOURCE_DIR="${1}" +shift + +# # use .diff files to create .cc files +# # Find all *.diff files in the current directory -diff_files=$(find . -maxdepth 1 -type f -name "*.diff") +diff_files="$(find ${CMAKE_CURRENT_SOURCE_DIR} -maxdepth 1 -type f -name "*.diff")" -for file in $diff_files; do +for file in ${diff_files}; do # Extract the filename without the extension - filename=$(basename "$file" .diff) - src="../../examples/$filename/$filename.cc" + filename="$(basename "${file}" ".diff")" + source_file="${DEAL_II_SOURCE_DIR}/examples/${filename}/${filename}.cc" + output_files="${CMAKE_CURRENT_SOURCE_DIR}/${filename}*.output*" # Check if the corresponding .cc file exists - if [[ -f "$src" ]]; then + if [[ -f "${source_file}" ]]; then # Apply the diff and save it to a new file - patch "$src" -o "$filename.cc" < "$file" + patch "${source_file}" -o "${filename}.cc" < "${file}" + echo "copying file(s) ${output_files}" + cp ${output_files} . else echo "No matching .cc file found for ${file}" exit 1 diff --git a/tests/examples/update_diffs.sh b/tests/examples/update_diffs.sh new file mode 100755 index 0000000000..3359cfd590 --- /dev/null +++ b/tests/examples/update_diffs.sh @@ -0,0 +1,31 @@ +#!/bin/bash +set -u + +DEAL_II_SOURCE_DIR="${1}" +shift +CMAKE_CURRENT_SOURCE_DIR="${1}" +shift + +# +# update .diff files from current .cc files +# + +# Find all *.diff files in the current directory +diff_files="$(find ${CMAKE_CURRENT_SOURCE_DIR} -maxdepth 1 -type f -name "*.diff")" + +for file in ${diff_files}; do + # Extract the filename without the extension + filename="$(basename "${file}" ".diff")" + source_file="${DEAL_II_SOURCE_DIR}/examples/${filename}/${filename}.cc" + modified_file="${filename}.cc" + + # Check if the corresponding .cc file exists + if [[ -f "${source_file}" && -f "${modified_file}" ]]; then + echo diff "${source_file}" "${modified_file}" "${file}" + diff -Nur "${source_file}" "${modified_file}" > "${file}" + echo success + else + echo "No matching .cc files found for ${file}" + exit 1 + fi +done