]> git.lyx.org Git - lyx.git/blob - development/autotests/single-test.cmake
Merge remote-tracking branch 'features/scroll-reloaded'
[lyx.git] / development / autotests / single-test.cmake
1 # This script invokes the keytest.py script with the simple set-up needed
2 # to re-run deterministic regression tests that one would like to have.
3 #
4 # AUTOTEST_ROOT   = ${LYX_ROOT}/development/autotests
5 # KEYTEST_INFILE  = xxx-in.txt
6 # KEYTEST_OUTFILE = xxx-out.txt
7 # BINDIR          = ${BUILD_DIR}/bin
8 # WORKDIR         = ${BUILD_DIR}/autotests/out-home
9 # LYX_USERDIR_VER = ${LYX_USERDIR_VER}
10 # LOCALE_DIR      = ${BUILD_DIR}/autotests/locale
11 # PO_BUILD_DIR    = ${BUILD_DIR}/po
12 # PACKAGE         = lyx2.1
13 #
14 # Script should be called like:
15 # cmake -DAUTOTEST_ROOT=xxxx \
16 #       -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
17 #       -DKEYTEST_INFILE=xxxx \
18 #       -DKEYTEST_OUTFILE=xxx \
19 #       -DBINDIR=xxx \
20 #       -DLYX=xxx \
21 #       -DWORKDIR=xxx \
22 #       -DLYX_USERDIR_VER=${LYX_USERDIR_VER} \
23 #       -DLOCALE_DIR=xxx \
24 #       -DPO_BUILD_DIR=xxx \
25 #       -DPACKAGE=xxx \
26 #       -P ${AUTOTEST_ROOT}/single-test.cmake
27
28 set(KEYTEST "${AUTOTEST_ROOT}/keytest.py")
29
30 execute_process(COMMAND pidof ${LYX} OUTPUT_VARIABLE LYX_PID RESULT_VARIABLE pidstat OUTPUT_VARIABLE pidres)
31 message(STATUS "pidres = ${pidres}")
32 if (NOT pidstat)
33   # lyx already running, remove trailing '\n' from pid
34   string(REGEX REPLACE "\n" "" pidres ${pidres})
35   execute_process(COMMAND wmctrl -l -p OUTPUT_VARIABLE _wmco)
36   string(REGEX REPLACE "[\n]+" ";" _wmc ${_wmco})
37   foreach(_w ${_wmc})
38     string(REGEX MATCH "${pidres}" _wr ${_w})
39     if (${_wr} MATCHES ${pidres})
40       # this entry contains the pid, go search for X11-window-id
41       string(REGEX REPLACE " .*" "" _wr ${_w})
42       set(LYX_WINDOW_NAME ${_wr})
43       message(STATUS "Set LYX_WINDOW_NAME to ${_wr}")
44     endif()
45   endforeach()
46 else()
47   set(pidres "")
48   set(LYX_WINDOW_NAME "")
49 endif()
50
51 #check for plausible DISPLAY environment (needed bei keytests)
52 set(DISPLAY_VAR $ENV{DISPLAY})
53 if(NOT DISPLAY_VAR MATCHES "^[a-zA-Z\\.]*:[0-9]+\(\\.[0-9]+\)?$")
54   message(FATAL_ERROR "Invalid DISPLAY environment value (== '${DISPLAY_VAR}')")
55 endif()
56
57 set(LYX_EXE "${BINDIR}/${LYX}")
58 set(use_hacked $ENV{XVKBD_HACKED})
59 if(NOT use_hacked)
60   if(use_hacked STREQUAL "")
61     # ENV{XVKBD_HACKED} probably not set, so the default should be
62     # to use the hacked
63     set(use_hacked "1")
64   else()
65     set(use_hacked "0")
66   endif()
67 else()
68   set(use_hacked "1")
69 endif()
70
71 set(ENV{XVKBD_HACKED} ${use_hacked})
72 if(use_hacked)
73   set(XVKBD_EXE "${BINDIR}/xvkbd")
74 else()
75   set(XVKBD_EXE "/usr/bin/xvkbd")
76 endif()
77
78 if(EXISTS "${LYX_TESTS_USERDIR}/session")
79   execute_process(COMMAND ${CMAKE_COMMAND} -E remove -f "${LYX_TESTS_USERDIR}/session")
80 endif()
81 # Environments needed by keytest.py
82 set(ENV{PACKAGE} ${PACKAGE})
83 set(ENV{LOCALE_DIR} ${LOCALE_DIR})
84 set(ENV{LYX_LOCALEDIR} "${LOCALE_DIR}")
85 set(ENV{${LYX_USERDIR_VER}} "${LYX_TESTS_USERDIR}")
86 set(ENV{LYX_PID} ${pidres})
87 set(ENV{LYX_WINDOW_NAME} ${LYX_WINDOW_NAME})
88 set(ENV{LYX_EXE} ${LYX_EXE})
89 set(ENV{LYX} ${LYX})
90 set(ENV{XVKBD_EXE} ${XVKBD_EXE})
91 set(ENV{KEYTEST_INFILE} "${AUTOTEST_ROOT}/${KEYTEST_INFILE}")
92 set(ENV{KEYTEST_OUTFILE} "${WORKDIR}/${KEYTEST_OUTFILE}")
93 set(ENV{PO_BUILD_DIR} "${PO_BUILD_DIR}")
94 set(ENV{MAX_DROP} 0)
95 set(ENV{MAX_LOOPS} 1)
96 string(REGEX REPLACE "-in\\.(txt|sh)$" "" _jj ${KEYTEST_INFILE})
97 if(EXISTS "${WORKDIR}/../${_jj}.lyx.emergency")
98   execute_process(
99   COMMAND ${CMAKE_COMMAND} -E remove -f "${WORKDIR}/../${_jj}.lyx.emergency" )
100 endif()
101 file(GLOB _testfiles RELATIVE "${WORKDIR}" "test*.*" "#test*.*")
102 if(_testfiles)
103   # remove some leftover files from previous test
104   execute_process(
105   COMMAND ${CMAKE_COMMAND} -E remove -f ${_testfiles} )
106 endif()
107 if(EXISTS "${AUTOTEST_ROOT}/${_jj}.lyx")
108   configure_file("${AUTOTEST_ROOT}/${_jj}.lyx" "${WORKDIR}/../${_jj}.lyx" COPYONLY)
109 endif()
110 execute_process(
111   COMMAND python ${KEYTEST}
112   RESULT_VARIABLE KEYTEST_RES)
113 if(KEYTEST_RES)
114   message(FATAL_ERROR "KEYTEST failed: KEYTEST_RES=${KEYTEST_RES}")
115 endif()
116