]> git.lyx.org Git - lyx.git/blob - src/tex2lyx/test/runtests.cmake
tex2lyx/Preamble.cpp: handle \lyxline
[lyx.git] / src / tex2lyx / test / runtests.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) 2013-2014 Kornel Benko <kornel@lyx.org>
5 #           (c) 2013-2014 Scott Kostyshak <skotysh@lyx.org>
6 #
7 # Script should be called like:
8 # COMMAND ${CMAKE_COMMAND} \
9 #     -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR} \
10 #     -DLYX_USERDIR_VER=${LYX_USERDIR_VER} \
11 #     -DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE} \
12 #     -DPY_SCRIPT=${TOP_SRC_DIR}/src/tex2lyx/test/runtests.py \
13 #     -DFIRST_PARAM=
14 #     -DTEX2LYX_EXE=$<TARGET_FILE:${_tex2lyx}> \
15 #     -DSCRIPT_DIR=${TOP_SRC_DIR}/lib/scripts \
16 #     -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR} \
17 #     -DTESTFILE=${fl} \
18 #     -P ${TOP_SRC_DIR}/src/tex2lyx/test/runtests.cmake
19
20 set(ENV{${LYX_USERDIR_VER}} ${LYX_TESTS_USERDIR})
21 message(STATUS "SCRIPT_DIR = ${SCRIPT_DIR}")
22
23 file(TIMESTAMP "${SCRIPT_DIR}/../configure.py" _config_time "%Y%j%H%M%S")
24 set(_configure_needed FALSE)
25 foreach(_f lyxrc.defaults lyxmodules.lst textclass.lst packages.lst)
26   if(NOT EXISTS "${LYX_TESTS_USERDIR}/${_f}")
27     message(STATUS "Configure needed, because \"${LYX_TESTS_USERDIR}/${_f}\" does not exist")
28     set(_configure_needed TRUE)
29     break()
30   endif()
31   file(TIMESTAMP "${LYX_TESTS_USERDIR}/${_f}" _ftime "%Y%j%H%M%S")
32   if(_config_time STRGREATER _ftime)
33     message(STATUS "Configure needed, because \"${LYX_TESTS_USERDIR}/${_f}\" too old")
34     set(_configure_needed TRUE)
35     break()
36   endif()
37 endforeach()
38
39 if(_configure_needed)
40   # Determine suffix from ${TEX2LYX_EXE}
41   if(TEX2LYX_EXE MATCHES ".*tex2lyx([0-9]\\.[0-9]).*")
42     set(_suffix ${CMAKE_MATCH_1})
43   else()
44     set(_suffix "")
45   endif()
46
47   if(_suffix STREQUAL "")
48     set(_with_ver "")
49   else()
50     set(_with_ver "--with-version-suffix=${_suffix}")
51   endif()
52
53   # Get binary directory of tex2lyx
54   string(REGEX REPLACE "(.*)tex2lyx${_suffix}.*" "\\1" _bindir "${TEX2LYX_EXE}")
55
56   message(STATUS "executing ${LYX_PYTHON_EXECUTABLE} -tt \"${SCRIPT_DIR}/../configure.py\" ${_with_ver} \"--binary-dir=${_bindir}\"")
57   execute_process(COMMAND ${LYX_PYTHON_EXECUTABLE} -tt "${SCRIPT_DIR}/../configure.py"
58     ${_with_ver} "--binary-dir=${_bindir}"
59     WORKING_DIRECTORY "${LYX_TESTS_USERDIR}"
60   )
61 endif()
62
63 execute_process(COMMAND ${LYX_PYTHON_EXECUTABLE} ${PY_SCRIPT} ${FIRST_PARAM}
64   ${TEX2LYX_EXE} ${SCRIPT_DIR} ${WORKDIR} ${TESTFILE}
65   RESULT_VARIABLE _err
66   OUTPUT_VARIABLE _out)
67
68 message(STATUS ${_out})
69 message(STATUS "Error output of ${PY_SCRIPT} = ${_err}")
70 string(COMPARE NOTEQUAL  ${_err} 0 _erg)
71
72 if(_erg)
73   message(FATAL_ERROR "${PY_SCRIPT} failed")
74 endif()
75
76