]> git.lyx.org Git - lyx.git/blob - development/autotests/single-test.cmake
keytests: New script to replace 'pcregrep' in more complex cases.
[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 #       -DFRONTEND=Qt? \
27 #       -P ${AUTOTEST_ROOT}/single-test.cmake
28
29 set(KEYTEST "${AUTOTEST_ROOT}/keytest.py")
30
31 if(0)
32   # This thread works, but the sollution in keytest.py is faster
33   #-------------------------------------------------------------
34   # Try to wait some seconds until the previous lyx stopped
35   # but not more than 30 seconds
36   message(STATUS "Wait for maximal 30 seconds until the previous lyx finishes")
37   set(lcount 0)
38   set(pidstat 1)
39   while (NOT lcount GREATER 30)
40     MATH(EXPR lcount "${lcount} + 1")
41     execute_process(COMMAND pidof ${LYX} OUTPUT_VARIABLE LYX_PID RESULT_VARIABLE pidstat OUTPUT_VARIABLE pidres)
42     if (pidstat)
43       break()
44     endif()
45     execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 1)
46   endwhile()
47
48   if (lcount GREATER 1)
49     # We had to wait for some seconds
50     message(STATUS "There was still some lyx in way(${lcount})")
51   endif()
52   if (NOT pidstat)
53     # lyx still running, remove trailing '\n' from pid
54     string(REGEX REPLACE "\n" "" pidres ${pidres})
55     message(FATAL_ERROR "Old lyx with pid ${pidres} still running")
56   endif()
57 endif()
58
59 #check for plausible DISPLAY environment (needed bei keytests)
60 set(DISPLAY_VAR $ENV{DISPLAY})
61 if(NOT DISPLAY_VAR MATCHES "^[a-zA-Z\\.]*:[0-9]+\(\\.[0-9]+\)?$")
62   message(FATAL_ERROR "Invalid DISPLAY environment value (== '${DISPLAY_VAR}')")
63 endif()
64
65 set(LYX_EXE "${BINDIR}/${LYX}")
66
67 set(ENV{QT_FRONTEND} ${FRONTEND})
68
69 if(EXISTS "${LYX_TESTS_USERDIR}/session")
70   execute_process(COMMAND ${CMAKE_COMMAND} -E remove -f "${LYX_TESTS_USERDIR}/session")
71 endif()
72 # Environments needed by keytest.py
73 set(ENV{EXTRA_PATH} "${AUTOTEST_ROOT}")
74 set(ENV{PACKAGE} ${PACKAGE})
75 set(ENV{LOCALE_DIR} ${LOCALE_DIR})
76 set(ENV{LYX_LOCALEDIR} "${LOCALE_DIR}")
77 set(ENV{${LYX_USERDIR_VER}} "${LYX_TESTS_USERDIR}")
78 set(ENV{LYX_PID} ${pidres})
79 set(ENV{LYX_WINDOW_NAME} ${LYX_WINDOW_NAME})
80 set(ENV{LYX_EXE} ${LYX_EXE})
81 set(ENV{LYX} ${LYX})
82 set(ENV{XVKBD_EXE} ${XVKBD_EXE})
83 set(ENV{KEYTEST_INFILE} "${AUTOTEST_ROOT}/${KEYTEST_INFILE}")
84 set(ENV{KEYTEST_OUTFILE} "${WORKDIR}/${KEYTEST_OUTFILE}")
85 set(ENV{PO_BUILD_DIR} "${PO_BUILD_DIR}")
86 set(ENV{MAX_DROP} 0)
87 set(ENV{MAX_LOOPS} 1)
88 string(REGEX REPLACE "-in\\.(txt|sh)$" "" _jj ${KEYTEST_INFILE})
89 if(EXISTS "${WORKDIR}/../${_jj}.lyx.emergency")
90   execute_process(
91   COMMAND ${CMAKE_COMMAND} -E remove -f "${WORKDIR}/../${_jj}.lyx.emergency" )
92 endif()
93 file(GLOB _testfiles RELATIVE "${WORKDIR}" "test*.*" "#test*.*")
94 if(_testfiles)
95   # remove some leftover files from previous test
96   execute_process(
97   COMMAND ${CMAKE_COMMAND} -E remove -f ${_testfiles} )
98 endif()
99 if(EXISTS "${AUTOTEST_ROOT}/${_jj}.lyx")
100   configure_file("${AUTOTEST_ROOT}/${_jj}.lyx" "${WORKDIR}/../${_jj}.lyx" COPYONLY)
101 endif()
102
103 execute_process(
104   COMMAND python ${KEYTEST}
105   RESULT_VARIABLE KEYTEST_RES)
106 if(KEYTEST_RES)
107   message(FATAL_ERROR "KEYTEST failed: KEYTEST_RES=${KEYTEST_RES}")
108 endif()
109