]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Tests examples: use a diff rule to update source files during test invocation
authorMatthias Maier <tamiko@43-1.org>
Sun, 2 Jul 2023 16:17:26 +0000 (11:17 -0500)
committerMatthias Maier <tamiko@43-1.org>
Mon, 3 Jul 2023 04:03:19 +0000 (23:03 -0500)
tests/examples/CMakeLists.txt
tests/examples/CMakeLists.txt.in [new file with mode: 0644]
tests/examples/update.sh [deleted file]

index 3440d0841698fa745568d25b309a5849162a0e11..a9fdd58a5c0b624a3deb5d2954e0e3b766f3d82e 100644 (file)
@@ -3,40 +3,41 @@ include(../scripts/setup_testsubproject.cmake)
 project(testsuite CXX)
 
 #
-# Make sure that we have been called with a proper deal.II source directory
-# layout:
+# Setting up example tests is a bit tricky because we need to patch the
+# current source file of the examples to make them suitable for the
+# testsuite (sanitize output, reduce run time).
 #
-set(DEAL_II_SOURCE_DIR "${CMAKE_SOURCE_DIR}/../..")
+# We thus create a set of "source" and "binary" sub directories in our
+# CMAKE_CURRENT_BINARY_DIR that we can manipulate at will. We then populate
+# the source directory with all (dynamically) patched step-*.cc files,
+# create symlinks to all output files, and put the CMakelists.txt.in file
+# in place.
+#
+# As a last step we call into the subdirectory and process all tests:
+#
+
+set(DEAL_II_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../..")
 if (EXISTS "${DEAL_II_SOURCE_DIR}/examples")
   #
   # Create CMake file structure in the current binary dir:
   #
+  set(_base_directory "${CMAKE_CURRENT_SOURCE_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}/example_test.h" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
+  configure_file(
+    "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt.in" "${_source_directory}/CMakeLists.txt"
+    COPYONLY
+    )
 
   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}"
-    )
-
+  # and now call into the second half of our setup in the writable "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/CMakeLists.txt.in b/tests/examples/CMakeLists.txt.in
new file mode 100644 (file)
index 0000000..5399bb3
--- /dev/null
@@ -0,0 +1,41 @@
+#
+# Parse all diff files...
+#
+
+file(GLOB _diff_files "${_base_directory}/*.diff")
+foreach(_diff_file ${_diff_files})
+  get_filename_component(_step "${_diff_file}" NAME_WLE)
+  set(_source_file "${DEAL_II_SOURCE_DIR}/examples/${_step}/${_step}.cc")
+  set(_output_file "${_source_directory}/${_step}.cc")
+
+  # ... and create a rule that updates all diff files if necessary during
+  # testsuite invocation:
+  add_custom_command(OUTPUT ${_output_file}
+    COMMAND patch ${_source_file} ${_diff_file} -o ${_output_file}
+    DEPENDS ${_source_file} ${_diff_file}
+    COMMENT "Patching ${_output_file}"
+    )
+
+  execute_process(
+    COMMAND patch ${_source_file} ${_diff_file} -o ${_output_file}
+    )
+
+  # Create symbolic links to the output files:
+  file(GLOB _output_files "${_base_directory}/${_step}*.output*")
+  foreach(_file ${_output_files})
+    get_filename_component(_destination "${_file}" NAME)
+    set(_destination "${_source_directory}/${_destination}")
+    file(CREATE_LINK ${_file} ${_destination} SYMBOLIC)
+  endforeach()
+endforeach()
+
+#
+# Create a top-level diff target:
+#
+
+add_custom_target(update_diffs
+  COMMAND "${_base_directory}/update_diffs.sh" "${DEAL_II_SOURCE_DIR}" "${_base_directory}"
+  WORKING_DIRECTORY "${_source_directory}"
+  )
+
+deal_ii_pickup_tests(examples)
diff --git a/tests/examples/update.sh b/tests/examples/update.sh
deleted file mode 100755 (executable)
index 64c79a0..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/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 ${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"
-  output_files="${CMAKE_CURRENT_SOURCE_DIR}/${filename}*.output*"
-
-  # Check if the corresponding .cc file exists
-  if [[ -f "${source_file}" ]]; then
-    # Apply the diff and save it to a new 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
-  fi
-done

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.