CMake/Modules/MatlabTestsRedirect.cmake

106 lines
3.4 KiB
CMake
Raw Normal View History

Simplify CMake per-source license notices Per-source copyright/license notice headers that spell out copyright holder names and years are hard to maintain and often out-of-date or plain wrong. Precise contributor information is already maintained automatically by the version control tool. Ultimately it is the receiver of a file who is responsible for determining its licensing status, and per-source notices are merely a convenience. Therefore it is simpler and more accurate for each source to have a generic notice of the license name and references to more detailed information on copyright holders and full license terms. Our `Copyright.txt` file now contains a list of Contributors whose names appeared source-level copyright notices. It also references version control history for more precise information. Therefore we no longer need to spell out the list of Contributors in each source file notice. Replace CMake per-source copyright/license notice headers with a short description of the license and links to `Copyright.txt` and online information available from "https://cmake.org/licensing". The online URL also handles cases of modules being copied out of our source into other projects, so we can drop our notices about replacing links with full license text. Run the `Utilities/Scripts/filter-notices.bash` script to perform the majority of the replacements mechanically. Manually fix up shebang lines and trailing newlines in a few files. Manually update the notices in a few files that the script does not handle.
2016-09-27 22:01:08 +03:00
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
# This is an undocumented internal helper for the FindMatlab
# module ``matlab_add_unit_test`` command.
# Usage: cmake
# -Dtest_timeout=180
# -Doutput_directory=
# -Dadditional_paths=""
# -Dno_unittest_framework=""
# -DMatlab_PROGRAM=matlab_exe_location
# -DMatlab_ADDITIONNAL_STARTUP_OPTIONS=""
# -Dtest_name=name_of_the_test
# -Dcustom_Matlab_test_command=""
# -Dcmd_to_run_before_test=""
# -Dunittest_file_to_run
# -P FindMatlab_TestsRedirect.cmake
set(Matlab_UNIT_TESTS_CMD -nosplash -nodesktop -nodisplay ${Matlab_ADDITIONNAL_STARTUP_OPTIONS})
if(WIN32)
set(Matlab_UNIT_TESTS_CMD ${Matlab_UNIT_TESTS_CMD} -wait)
endif()
if(NOT test_timeout)
set(test_timeout 180)
endif()
# If timeout is -1, then do not put a timeout on the execute_process
if(test_timeout EQUAL -1)
set(test_timeout "")
else()
set(test_timeout TIMEOUT ${test_timeout})
endif()
if(NOT cmd_to_run_before_test)
set(cmd_to_run_before_test)
endif()
get_filename_component(unittest_file_directory "${unittest_file_to_run}" DIRECTORY)
get_filename_component(unittest_file_to_run_name "${unittest_file_to_run}" NAME_WE)
set(concat_string '${unittest_file_directory}')
foreach(s IN LISTS additional_paths)
if(NOT "${s}" STREQUAL "")
string(APPEND concat_string ", '${s}'")
endif()
endforeach()
if(custom_Matlab_test_command)
set(unittest_to_run "${custom_Matlab_test_command}")
else()
set(unittest_to_run "runtests('${unittest_file_to_run_name}'), exit(max([ans(1,:).Failed]))")
endif()
if(no_unittest_framework)
set(unittest_to_run "try, ${unittest_file_to_run_name}, catch err, disp('An exception has been thrown during the execution'), disp(err), disp(err.stack), exit(1), end, exit(0)")
endif()
set(Matlab_SCRIPT_TO_RUN
"addpath(${concat_string}); ${cmd_to_run_before_test}; ${unittest_to_run}"
)
# if the working directory is not specified then default
# to the output_directory because the log file will go there
# if the working_directory is specified it will override the
# output_directory
if(NOT working_directory)
set(working_directory "${output_directory}")
endif()
string(REPLACE "/" "_" log_file_name "${test_name}.log")
set(Matlab_LOG_FILE "${working_directory}/${log_file_name}")
set(devnull)
if(UNIX)
set(devnull INPUT_FILE /dev/null)
elseif(WIN32)
set(devnull INPUT_FILE NUL)
endif()
execute_process(
# Do not use a full path to log file. Depend on the fact that the log file
# is always going to go in the working_directory. This is because matlab
# on unix is a shell script that does not handle spaces in the logfile path.
COMMAND "${Matlab_PROGRAM}" ${Matlab_UNIT_TESTS_CMD} -logfile "${log_file_name}" -r "${Matlab_SCRIPT_TO_RUN}"
RESULT_VARIABLE res
${test_timeout}
OUTPUT_QUIET # we do not want the output twice
WORKING_DIRECTORY "${working_directory}"
${devnull}
)
if(NOT EXISTS ${Matlab_LOG_FILE})
message( FATAL_ERROR "[MATLAB] ERROR: cannot find the log file ${Matlab_LOG_FILE}")
endif()
# print the output in any case.
file(READ ${Matlab_LOG_FILE} matlab_log_content)
message("Matlab test ${name_of_the_test} output:\n${matlab_log_content}") # if we put FATAL_ERROR here, the file is indented.
if(NOT (res EQUAL 0))
message( FATAL_ERROR "[MATLAB] TEST FAILED Matlab returned ${res}" )
endif()