<commit_before>## ---------------------------------------------------------------------
##
## Copyright (C) 2013 - 2016 by the deal.II authors
##
## This file is part of the deal.II library.
##
## The deal.II library is free software; you can use it, redistribute
## it, and/or modify it under the terms of the GNU Lesser General
## Public License as published by the Free Software Foundation; either
## version 2.1 of the License, or (at your option) any later version.
## The full text of the license can be found in the file LICENSE at
## the top level of the deal.II distribution.
##
## ---------------------------------------------------------------------

#
# A macro to set up testing and pick up all tests in the current
# subdirectory.
#
# If TEST_PICKUP_REGEX is set, only tests matching the regex will be
# processed.
#
# Furthermore, the macro sets up (if necessary) deal.II, perl, a diff tool
# and the following variables, that can be overwritten by environment or
# command line:
#
#     TEST_LIBRARIES
#     TEST_LIBRARIES_DEBUG
#     TEST_LIBRARIES_RELEASE
#       - specifying additional libraries (and targets) to link against.
#
#     TEST_TARGET or
#     TEST_TARGET_DEBUG and TEST_TARGET_RELEASE
#       - specifying a test target to be executed for a parameter run.
#
#     TEST_TIME_LIMIT
#       - specifying the maximal wall clock time in seconds a test is
#         allowed to run
#
# Either numdiff (if available), or diff are used for the comparison of
# test results. Their location can be specified with NUMDIFF_DIR and
# DIFF_DIR.
#
# Usage:
#     DEAL_II_PICKUP_TESTS()
#


#
# Two very small macros that are used below:
#

MACRO(SET_IF_EMPTY _variable)
  IF("${${_variable}}" STREQUAL "")
    SET(${_variable} ${ARGN})
  ENDIF()
ENDMACRO()

MACRO(ITEM_MATCHES _var _regex)
  SET(${_var})
  FOREACH (_item ${ARGN})
    IF("${_item}" MATCHES ${_regex})
      SET(${_var} TRUE)
      BREAK()
    ENDIF()
  ENDFOREACH()
ENDMACRO()


MACRO(DEAL_II_PICKUP_TESTS)

  IF(NOT DEAL_II_PROJECT_CONFIG_INCLUDED)
    MESSAGE(FATAL_ERROR
      "\nDEAL_II_PICKUP_TESTS can only be called in external (test sub-) "
      "projects after the inclusion of deal.IIConfig.cmake. It is not "
      "intended for internal use.\n\n"
      )
  ENDIF()

  #
  # Necessary external interpreters and programs:
  #

  FIND_PACKAGE(Perl REQUIRED)

  FIND_PROGRAM(DIFF_EXECUTABLE
    NAMES diff
    HINTS ${DIFF_DIR}
    PATH_SUFFIXES bin
    )

  FIND_PROGRAM(NUMDIFF_EXECUTABLE
    NAMES numdiff
    HINTS ${NUMDIFF_DIR}
    PATH_SUFFIXES bin
    )

  MARK_AS_ADVANCED(DIFF_EXECUTABLE NUMDIFF_EXECUTABLE)

  IF( NUMDIFF_EXECUTABLE MATCHES "-NOTFOUND" AND
      DIFF_EXECUTABLE MATCHES "-NOTFOUND" )
    MESSAGE(FATAL_ERROR
      "Could not find diff or numdiff. One of those are required for running the testsuite.\n"
      "Please specify DIFF_DIR or NUMDIFF_DIR to a location containing the binaries."
      )
  ENDIF()

  IF(DIFF_EXECUTABLE MATCHES "-NOTFOUND")
    SET(DIFF_EXECUTABLE ${NUMDIFF_EXECUTABLE})
  ENDIF()

  IF(NUMDIFF_EXECUTABLE MATCHES "-NOTFOUND")
    SET(NUMDIFF_EXECUTABLE ${DIFF_EXECUTABLE})
  ENDIF()

  #
  # Check that the diff programs can run and terminate successfully:
  #
  FOREACH(_diff_program ${NUMDIFF_EXECUTABLE} ${DIFF_EXECUTABLE})
    EXECUTE_PROCESS(COMMAND ${_diff_program} "-v"
      TIMEOUT 4 # seconds
      OUTPUT_QUIET
      ERROR_QUIET
      RESULT_VARIABLE _diff_program_status
      )

    IF(NOT "${_diff_program_status}" STREQUAL "0")
      MESSAGE(FATAL_ERROR
        "\nThe command \"${_diff_program} -v\" did not run correctly: it either "
        "failed to exit after a few seconds or returned a nonzero exit code. "
        "The test suite cannot be set up without this program, so please "
        "reinstall it and then run the test suite setup command again.\n")
    ENDIF()
  ENDFOREACH()

  #
  # Set time limit:
  #

  SET_IF_EMPTY(TEST_TIME_LIMIT "$ENV{TEST_TIME_LIMIT}")
  SET_IF_EMPTY(TEST_TIME_LIMIT 600)

  #
  # ... and finally pick up tests:
  #

  ENABLE_TESTING()

  SET_IF_EMPTY(TEST_PICKUP_REGEX "$ENV{TEST_PICKUP_REGEX}")
  GET_FILENAME_COMPONENT(_category ${CMAKE_CURRENT_SOURCE_DIR} NAME)

  SET(DEAL_II_SOURCE_DIR) # avoid a bogus warning

  FILE(GLOB _tests "*.output")<commit_msg>Add a simple numdiff relative tolerance test.<commit_after>## ---------------------------------------------------------------------
##
## Copyright (C) 2013 - 2016 by the deal.II authors
##
## This file is part of the deal.II library.
##
## The deal.II library is free software; you can use it, redistribute
## it, and/or modify it under the terms of the GNU Lesser General
## Public License as published by the Free Software Foundation; either
## version 2.1 of the License, or (at your option) any later version.
## The full text of the license can be found in the file LICENSE at
## the top level of the deal.II distribution.
##
## ---------------------------------------------------------------------

#
# A macro to set up testing and pick up all tests in the current
# subdirectory.
#
# If TEST_PICKUP_REGEX is set, only tests matching the regex will be
# processed.
#
# Furthermore, the macro sets up (if necessary) deal.II, perl, a diff tool
# and the following variables, that can be overwritten by environment or
# command line:
#
#     TEST_LIBRARIES
#     TEST_LIBRARIES_DEBUG
#     TEST_LIBRARIES_RELEASE
#       - specifying additional libraries (and targets) to link against.
#
#     TEST_TARGET or
#     TEST_TARGET_DEBUG and TEST_TARGET_RELEASE
#       - specifying a test target to be executed for a parameter run.
#
#     TEST_TIME_LIMIT
#       - specifying the maximal wall clock time in seconds a test is
#         allowed to run
#
# Either numdiff (if available), or diff are used for the comparison of
# test results. Their location can be specified with NUMDIFF_DIR and
# DIFF_DIR.
#
# Usage:
#     DEAL_II_PICKUP_TESTS()
#


#
# Two very small macros that are used below:
#

MACRO(SET_IF_EMPTY _variable)
  IF("${${_variable}}" STREQUAL "")
    SET(${_variable} ${ARGN})
  ENDIF()
ENDMACRO()

MACRO(ITEM_MATCHES _var _regex)
  SET(${_var})
  FOREACH (_item ${ARGN})
    IF("${_item}" MATCHES ${_regex})
      SET(${_var} TRUE)
      BREAK()
    ENDIF()
  ENDFOREACH()
ENDMACRO()


MACRO(DEAL_II_PICKUP_TESTS)

  IF(NOT DEAL_II_PROJECT_CONFIG_INCLUDED)
    MESSAGE(FATAL_ERROR
      "\nDEAL_II_PICKUP_TESTS can only be called in external (test sub-) "
      "projects after the inclusion of deal.IIConfig.cmake. It is not "
      "intended for internal use.\n\n"
      )
  ENDIF()

  #
  # Necessary external interpreters and programs:
  #

  FIND_PACKAGE(Perl REQUIRED)

  FIND_PROGRAM(DIFF_EXECUTABLE
    NAMES diff
    HINTS ${DIFF_DIR}
    PATH_SUFFIXES bin
    )

  FIND_PROGRAM(NUMDIFF_EXECUTABLE
    NAMES numdiff
    HINTS ${NUMDIFF_DIR}
    PATH_SUFFIXES bin
    )

  MARK_AS_ADVANCED(DIFF_EXECUTABLE NUMDIFF_EXECUTABLE)

  IF( NUMDIFF_EXECUTABLE MATCHES "-NOTFOUND" AND
      DIFF_EXECUTABLE MATCHES "-NOTFOUND" )
    MESSAGE(FATAL_ERROR
      "Could not find diff or numdiff. One of those are required for running the testsuite.\n"
      "Please specify DIFF_DIR or NUMDIFF_DIR to a location containing the binaries."
      )
  ENDIF()

  IF(DIFF_EXECUTABLE MATCHES "-NOTFOUND")
    SET(DIFF_EXECUTABLE ${NUMDIFF_EXECUTABLE})
  ENDIF()

  IF(NUMDIFF_EXECUTABLE MATCHES "-NOTFOUND")
    SET(NUMDIFF_EXECUTABLE ${DIFF_EXECUTABLE})
  ENDIF()

  #
  # Check that the diff programs can run and terminate successfully:
  #
  FOREACH(_diff_program ${NUMDIFF_EXECUTABLE} ${DIFF_EXECUTABLE})
    EXECUTE_PROCESS(COMMAND ${_diff_program} "-v"
      TIMEOUT 4 # seconds
      OUTPUT_QUIET
      ERROR_QUIET
      RESULT_VARIABLE _diff_program_status
      )

    IF(NOT "${_diff_program_status}" STREQUAL "0")
      MESSAGE(FATAL_ERROR
        "\nThe command \"${_diff_program} -v\" did not run correctly: it either "
        "failed to exit after a few seconds or returned a nonzero exit code. "
        "The test suite cannot be set up without this program, so please "
        "reinstall it and then run the test suite setup command again.\n")
    ENDIF()
  ENDFOREACH()

  #
  # Also check that numdiff is not a symlink to diff by running a relative
  # tolerance test. Note that we set NUMDIFF_EXECUTABLE to diff in case we were
  # not able to find it above, but here we check that the executable is really
  # named 'numdiff'.
  #
  STRING(FIND "${NUMDIFF_EXECUTABLE}" "numdiff" _found_numdiff_binary)
  IF(NOT "${_found_numdiff_binary}" STREQUAL "-1")
    SET(_first_test_file_name
      "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/numdiff-test-1.txt")
    SET(_second_test_file_name
      "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/numdiff-test-2.txt")
    FILE(WRITE "${_first_test_file_name}" "0.99999999998\n2.0\n1.0\n")
    FILE(WRITE "${_second_test_file_name}" "1.00000000001\n2.0\n1.0\n")

    EXECUTE_PROCESS(COMMAND ${NUMDIFF_EXECUTABLE}
      "-r" "1.0e-8" "--" "${_first_test_file_name}" "${_second_test_file_name}"
      TIMEOUT 4 # seconds
      OUTPUT_QUIET
      ERROR_QUIET
      RESULT_VARIABLE _numdiff_tolerance_test_status
      )

    #
    # Tidy up:
    #
    FILE(REMOVE ${_first_test_file_name})
    FILE(REMOVE ${_second_test_file_name})

    IF(NOT "${_numdiff_tolerance_test_status}" STREQUAL "0")
      MESSAGE(FATAL_ERROR
        "\nThe detected numdiff executable was not able to pass a simple "
        "relative tolerance test. This usually means that either numdiff "
        "was misconfigured or that it is a symbolic link to diff. "
        "The test suite needs numdiff to work correctly: please reinstall "
        "numdiff and run the test suite configuration again.\n")
    ENDIF()
  ENDIF()

  #
  # Set time limit:
  #

  SET_IF_EMPTY(TEST_TIME_LIMIT "$ENV{TEST_TIME_LIMIT}")
  SET_IF_EMPTY(TEST_TIME_LIMIT 600)

  #
  # ... and finally pick up tests:
  #

  ENABLE_TESTING()

  SET_IF_EMPTY(TEST_PICKUP_REGEX "$ENV{TEST_PICKUP_REGEX}")
  GET_FILENAME_COMPONENT(_category ${CMAKE_CURRENT_SOURCE_DIR} NAME)

  SET(DEAL_II_SOURCE_DIR) # avoid a bogus warning

  FILE(GLOB _tests "*.output")
{'fraction_non_alphanumeric': 0.11398401263199448, 'fraction_numerical': 0.006908121977696635, 'mean_word_length': 3.1094890510948905, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4033343', 'n_tokens_mistral': 3532, 'n_tokens_neox': 3312, 'n_words': 1012}