]> git.lyx.org Git - features.git/blob - development/autotests/CMakeLists.txt
Cmake tests: Allow for comments in control files
[features.git] / development / autotests / CMakeLists.txt
1 # This file is part of LyX, the document processor.
2 # Licence details can be found in the file COPYING.
3 #
4 # Copyright (c) 2012 Kornel Benko kornel@lyx.org
5 #
6
7 set(LYX_HOME "out-home")
8 set(LYX_USERDIR "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}/.lyx")
9 set(LOCALE_DIR "${CMAKE_CURRENT_BINARY_DIR}/locale")
10 file(MAKE_DIRECTORY "${LYX_USERDIR}" "${LOCALE_DIR}")
11
12 if(Q_WS_X11)
13   set(Missing)
14   set(XVFBDLIBS)
15   # Make sure, the needed programs are in PATH
16   find_program(PCREGREP_EXE "pcregrep")
17   if (NOT PCREGREP_EXE)
18     list(APPEND Missing "pcregrep")
19   endif()
20   find_program(WMCTRL_EXE "wmctrl")
21   if(NOT WMCTRL_EXE)
22     list(APPEND Missing "wmctrl")
23   endif()
24   # This is needed to build xvkbd
25   # Programs pcregrep wmctrl and xvkbd are used in subsequent scripts
26   # while testing
27
28   # Check for needed libraries for xvkbd
29   # do not add autotests, if any of them is lacking
30
31   find_package(X11)
32   if(NOT X11_FOUND)
33     list(APPEND Missing "X11")
34   endif()
35   find_package(PkgConfig)
36   if(PKG_CONFIG_FOUND)
37     foreach(_lb "xaw7" "xmu" "xtst")
38       pkg_check_modules(${_lb}LIB ${_lb})
39       if(${_lb}LIB_LIBRARIES)
40         list(APPEND XVFBDLIBS ${${_lb}LIB_LIBRARIES})
41       else()
42         list(APPEND Missing ${_lb})
43       endif()
44     endforeach()
45   else()
46     foreach(_lb "Xaw7" "Xmu")
47       find_library(${_lb}LIB ${_lb})
48       if(${_lb}LIB)
49         list(APPEND XVFBDLIBS ${${_lb}LIB})
50       else()
51         list(APPEND Missing ${_lb})
52       endif()
53     endforeach()
54     foreach(_lb Xt XTest X11)
55       if(X11_${_lb}_LIB)
56         list(APPEND XVFBDLIBS ${X11_${_lb}_LIB})
57       else()
58         list(APPEND Missing ${_lb})
59       endif()
60     endforeach()
61   endif()
62   if (XVFBDLIBS)
63     list(REMOVE_DUPLICATES XVFBDLIBS)
64   endif()
65
66   if(Missing)
67     message(STATUS "Missing Libraries or programs to create xvkbd: ${Missing}")
68     message(STATUS "cmake build is therefore omitting keytests")
69   endif()
70
71   if(NOT Missing)
72     project(keytest)
73
74     add_subdirectory(xvkbd)
75
76     set(KEYTEST "${CMAKE_CURRENT_SOURCE_DIR}/keytest.py")
77     file(GLOB TESTST RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*-in.txt")
78     file(GLOB TESTSS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*-in.sh")
79     list(REMOVE_ITEM TESTST hello-world-in.txt first-time-in.txt)
80     list(SORT TESTST)
81     file(MAKE_DIRECTORY "${LYX_USERDIR}" "${LOCALE_DIR}")
82
83     foreach(_tf first-time-in.txt hello-world-in.txt ${TESTST})
84       string(REGEX REPLACE "-in\\.(txt|sh)" "" _t ${_tf})
85       add_test(NAME keytest/${_t}
86         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
87         COMMAND ${CMAKE_COMMAND}
88         -DAUTOTEST_ROOT=${TOP_SRC_DIR}/development/autotests
89         -DPO_BUILD_DIR=${TOP_BINARY_DIR}/po
90         -DKEYTEST_INFILE=${_tf}
91         -DBINDIR=$<TARGET_FILE_DIR:${_lyx}>
92         -DLYX=${_lyx}
93         -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
94         -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
95         -DKEYTEST_OUTFILE=${_t}-out.txt
96         -DPACKAGE=${PACKAGE}
97         -DLOCALE_DIR=${LOCALE_DIR}
98         -P ${TOP_SRC_DIR}/development/autotests/single-test.cmake)
99     endforeach()
100   endif()
101 endif()
102
103 macro(getoutputformats filepath varname)
104   file(STRINGS "${filepath}" lines)
105   set(out_formats "xhtml" "pdf" "pdf2" "pdf5")
106   set(${varname} ${out_formats})
107   foreach(_l ${lines})
108     if(_l MATCHES "^\\\\default_output_format +\([^ ]+\)")
109       if(CMAKE_MATCH_1 STREQUAL "default")
110         set(found ${out_formats})
111       elseif(CMAKE_MATCH_1 STREQUAL "xhtml")
112         set(found "xhtml")
113       else()
114         set(found "xhtml" ${CMAKE_MATCH_1})
115       endif()
116       set(${varname} ${found})
117       break()
118     endif()
119   endforeach()
120 endmacro()
121
122 macro(getreverted testname reverted listreverted)
123   list(FIND ${listreverted} ${${testname}} _idx)
124   if (${_idx} LESS 0)
125     set(${reverted} 0)
126   else()
127     set(${reverted} 1)
128     set(${testname} "INVERTED_SEE-README.ctest_${${testname}}")
129   endif()
130 endmacro()
131
132 macro(loadTestList filename resList)
133   # Create list of strings from a file without comments
134   file(STRINGS ${filename} tempList)
135   set(${resList})
136   foreach(_l ${tempList})
137     string(REGEX REPLACE "[ \t]*#.*" "" _newl "${_l}")
138     if(_newl)
139       list(APPEND ${resList} "${_newl}")
140     endif()
141   endforeach()
142 endmacro()
143
144 loadTestList(revertedTests revertedTests)
145 loadTestList(ignoredTests ignoredTests)
146
147 foreach(libsubfolder doc examples templates)
148   set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/lib/${libsubfolder}")
149   file(GLOB_RECURSE lyx_files RELATIVE "${LIBSUB_SRC_DIR}" "${LIBSUB_SRC_DIR}/*.lyx")
150   list(SORT lyx_files)
151   # Now create 2 lists. One for files in a language dir, one without
152   set(lang_lyx_files)
153   set(nolang_lyx_files)
154   foreach(f ${lyx_files})
155     string(REGEX MATCHALL "^[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${f})
156     if(_v)
157       list(APPEND lang_lyx_files ${f})
158     else()
159       list(APPEND nolang_lyx_files ${f})
160     endif()
161   endforeach()
162   foreach(f ${nolang_lyx_files} ${lang_lyx_files})
163     # Strip extension
164     string(REGEX REPLACE "\\.lyx$" "" f ${f})
165     set(TestName "export/${libsubfolder}/${f}_lyx16")
166     getreverted(TestName reverted revertedTests)
167     add_test(NAME ${TestName}
168       WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
169       COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
170           -Dlyx=$<TARGET_FILE:${_lyx}>
171           -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
172           -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
173           -Dformat=lyx16x
174           -Dextension=16.lyx
175           -Dfile=${f}
176           -Dreverted=${reverted}
177           -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
178     set(TestName "lyx2lyx/${libsubfolder}/${f}")
179     getreverted(TestName reverted revertedTests)
180     add_test(NAME ${TestName}
181       WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
182       COMMAND ${CMAKE_COMMAND} -DLYX2LYX=${TOP_SRC_DIR}/lib/lyx2lyx/lyx2lyx
183         -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
184         -P "${TOP_SRC_DIR}/development/autotests/lyx2lyxtest.cmake")
185     set(TestName "check_load/${libsubfolder}/${f}")
186     getreverted(TestName reverted revertedTests)
187     add_test(NAME ${TestName}
188       WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
189       COMMAND ${CMAKE_COMMAND} -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
190         -Dlyx=$<TARGET_FILE:${_lyx}>
191         -DPARAMS_DIR=${TOP_SRC_DIR}/development/autotests
192         -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
193         -P "${TOP_SRC_DIR}/development/autotests/check_load.cmake")
194     getoutputformats("${LIBSUB_SRC_DIR}/${f}.lyx" formatlist)
195     foreach(format ${formatlist})
196       set(TestName "export/${libsubfolder}/${f}_${format}")
197       list(FIND ignoredTests ${TestName} _idx)
198       if (${_idx} LESS 0)
199         getreverted(TestName reverted revertedTests)
200         add_test(NAME ${TestName}
201           WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
202           COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
203             -Dlyx=$<TARGET_FILE:${_lyx}>
204             -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
205             -Dformat=${format}
206             -Dextension=${format}
207             -Dfile=${f}
208             -Dreverted=${reverted}
209             -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
210       endif()
211     endforeach()
212   endforeach()
213 endforeach()
214