]> git.lyx.org Git - lyx.git/blob - src/tex2lyx/test/env_custom_command.cmake
ctests: invert Math.lyx tests failing from mhchem
[lyx.git] / src / tex2lyx / test / env_custom_command.cmake
1 # This file is part of LyX, the document processor.
2 # Licence details can be found in the file COPYING.
3 #
4 # Copyright (c) 2015 Kornel Benko <kornel@lyx.org>
5 #
6 # Environ and parameter strings are separated by "'"
7 # Script should be called like:
8 #   add_custom_command(
9 #     COMMAND ${CMAKE_COMMAND}
10 #     -DENVIRON="${LYX_USERDIR_VER}=${LYX_TESTS_USERDIR}" \
11 #     -DCOMMAND="${LYX_PYTHON_EXECUTABLE}" \
12 #     -DPARAMS="${runtestsScript}'$<TARGET_FILE:${_tex2lyx}>'${scriptDir}'${CMAKE_CURRENT_SOURCE_DIR}"
13 #     -P ${TOP_SRC_DIR}/src/tex2lyx/test/env_custom_command.cmake
14 #     WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
15 #     DEPENDS ...
16 #     )
17
18 string(REGEX MATCHALL "[^']+" ENVIRON_LIST "${ENVIRON}")
19 foreach(_env ${ENVIRON_LIST})
20   if (_env MATCHES "^\([^=]+\)=\(.*\)$")
21     set(ENV{${CMAKE_MATCH_1}} ${CMAKE_MATCH_2})
22     #message(STATUS "setting env ${CMAKE_MATCH_1}=${CMAKE_MATCH_2}")
23   else()
24     message(FATAL_ERROR "Wrong environment string \"${_env}\"")
25   endif()
26 endforeach()
27
28 string(REGEX MATCHALL "[^']+" parameters "${PARAMS}")
29 execute_process(COMMAND "${COMMAND}" ${parameters}
30   RESULT_VARIABLE _err
31   OUTPUT_VARIABLE _out)
32
33 message(STATUS ${_out})
34 #message(STATUS "Error output of \"${COMMAND}\" " ${parameters} " = ${_err}")
35 string(COMPARE NOTEQUAL  ${_err} 0 _erg)
36
37 if(_erg)
38   message(FATAL_ERROR "\"${COMMAND}\" ${parameters} failed")
39 endif()
40