]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Tests examples: only use binary directory for temporary files
authorMatthias Maier <tamiko@43-1.org>
Sun, 2 Jul 2023 15:11:30 +0000 (10:11 -0500)
committerMatthias Maier <tamiko@43-1.org>
Mon, 3 Jul 2023 04:03:19 +0000 (23:03 -0500)
tests/examples/CMakeLists.txt
tests/examples/create_diffs.sh [deleted file]
tests/examples/update.sh
tests/examples/update_diffs.sh [new file with mode: 0755]

index 1ff57689661719f6ede52583b8354e6412304e87..3f5ef8ad90cdffda07f12897bd980d8511496970 100644 (file)
@@ -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 (executable)
index d752616..0000000
+++ /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
index 1211532171abbda7f7d8195095f2362ac5f8ff95..64c79a05d3e03a67a0d7ca1ebbd012f40eba2532 100755 (executable)
@@ -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 (executable)
index 0000000..3359cfd
--- /dev/null
@@ -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

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.