]> https://gitweb.dealii.org/ - dealii.git/commitdiff
CMake: add_test(): refactor, add comments, fix error message
authorMatthias Maier <tamiko@43-1.org>
Tue, 24 Jan 2023 02:07:28 +0000 (20:07 -0600)
committerMatthias Maier <tamiko@43-1.org>
Wed, 25 Jan 2023 23:26:29 +0000 (17:26 -0600)
cmake/macros/macro_deal_ii_add_test.cmake

index 90cff2e2189f4415657ff78a39bcfd5c932c5c4a..3cb92db2ada180b396345cad79c9dd1142578517 100644 (file)
@@ -348,15 +348,15 @@ function(deal_ii_add_test _category _test_name _comparison_file)
       # Override target and run command for parameter file variants:
       #
       if("${_source_file}" MATCHES "(prm|json)$")
-        if(NOT "${TEST_TARGET_${_build}}" STREQUAL "")
+        if(TARGET "${TEST_TARGET_${_build}}")
           set(_target ${TEST_TARGET_${_build}})
-        elseif(NOT "${TEST_TARGET}" STREQUAL "")
+        elseif(TARGET "${TEST_TARGET}")
           set(_target ${TEST_TARGET})
         else()
-          message(FATAL_ERROR "\n${_comparison_file}:\n"
-            "A parameter file \"${_test_name}.(prm|json)(|.in)\" has been "
-            "found, but neither \"\${TEST_TARGET}\", nor "
-            "\"\${TEST_TARGET_${_build}}\" have been defined.\n"
+          message(FATAL_ERROR
+            "The parameter file \"${_source_file}\" has been found, but neither "
+            "\"\${TEST_TARGET}\", nor \"\${TEST_TARGET_${_build}}\" have been set to "
+            "valid target name.\n"
             )
         endif()
         set(_target_short ${_target})
@@ -454,8 +454,6 @@ function(deal_ii_add_test _category _test_name _comparison_file)
           ${CMAKE_CURRENT_BINARY_DIR}/${_target_short}/interrupt_guard.cc
           )
 
-        add_dependencies(compile_test_executables ${_target})
-
         set_target_properties(${_target} PROPERTIES OUTPUT_NAME ${_target_short})
 
         deal_ii_setup_target(${_target} ${_build})
@@ -479,6 +477,7 @@ function(deal_ii_add_test _category _test_name _comparison_file)
           RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${_target_short}"
           )
 
+        add_dependencies(compile_test_executables ${_target})
       endif()
 
       #
@@ -500,6 +499,13 @@ function(deal_ii_add_test _category _test_name _comparison_file)
         )
 
       if(_run_only)
+        #
+        # Only compile and run the test executable. Do not run a diff
+        # stage. We use this feature for performance tests (where comparing
+        # output does not make sense), or for tests that signal success or
+        # failure with a return code (such as our quick tests).
+        #
+
         add_custom_target(${_test_target}
           COMMAND echo "${_test_full}: BUILD successful."
           COMMAND echo "${_test_full}: RUN successful."
@@ -509,6 +515,10 @@ function(deal_ii_add_test _category _test_name _comparison_file)
           )
 
       else()
+        #
+        # Add a diff rule and set up a test target that depends on a
+        # successful compilation, run and diff.
+        #
 
         file(GLOB _comparison_files ${_comparison_file} ${_comparison_file}.*)
 

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.