2 # Copyright (c) 2014 Kornel Benko <kornel@lyx.org>
3 # Copyright (c) 2014 Scott Kostyshak <skotysh@lyx.org>
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # 3. The name of the author may not be used to endorse or promote products
15 # derived from this software without specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 set(DVI_FORMATS "dvi" "dvi3")
33 set(PDF_FORMATS "pdf" "pdf2" "pdf3" "pdf4" "pdf5")
35 set(DVI_FORMATS "dvi")
36 set(PDF_FORMATS "pdf" "pdf2" "pdf3")
39 macro(getoutputformats filepath varname)
40 file(STRINGS "${filepath}" lines)
41 # What should we test, if default_output_format is not defined?
42 # For now we test everything ...
43 set(out_formats "xhtml" ${DVI_FORMATS} ${PDF_FORMATS})
45 if(_l MATCHES "^\\\\default_output_format +\([^ ]+\)")
46 set(_format ${CMAKE_MATCH_1})
47 if(_format STREQUAL "default")
48 set(out_formats "xhtml" ${DVI_FORMATS} ${PDF_FORMATS})
49 elseif(_format MATCHES "pdf$")
50 set(out_formats "xhtml" ${PDF_FORMATS})
51 elseif(_format MATCHES "dvi$")
52 set(out_formats "xhtml" ${DVI_FORMATS})
53 elseif(_format MATCHES "xhtml")
54 set(out_formats "xhtml")
56 # Respect all other output formats
58 set(out_formats "xhtml" ${_format})
63 set(${varname} ${out_formats})
66 macro(findexpr found testname listname rsublabel)
69 foreach(_itrx ${${listname}})
70 if ("${_itrx}" MATCHES "^Sublabel:")
72 string(REGEX REPLACE "^Sublabel:[ \t]*" "" _itrlabels ${_itrx})
73 string(REGEX MATCHALL "([a-zA-Z]+)" _labels ${_itrlabels})
74 foreach(subl ${_labels})
75 if (subl STREQUAL "RESET")
78 list(APPEND tmpsublabel ${subl})
81 # remove doubles in sublabel
82 list(REMOVE_DUPLICATES tmpsublabel)
84 set(_itr "^${_itrx}$")
85 if (${testname} MATCHES "${_itr}")
92 if (NOT "${tmpsublabel}" STREQUAL "")
93 list(APPEND ${rsublabel} ${tmpsublabel})
96 set(${found} ${_found})
99 function(join rvalues glue routput)
100 set(locallist ${${rvalues}})
101 list(REMOVE_ITEM locallist "export" "lyx2lyx" "load")
102 string(REGEX REPLACE "([^\\]|^);" "\\1${glue}" out "${locallist}")
103 set(${routput} ${out} PARENT_SCOPE)
106 macro(maketestname testname reverted listsuspicious listignored listunreliable listlabels)
107 string(REGEX MATCH "\\/[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${${testname}})
109 string(REGEX REPLACE "\\/" "" _v ${_v})
110 set(listsuspiciousx ${listsuspicious}_${_v})
111 set(listignoredx ${listignored}_${_v})
112 set(listunreliablex ${listunreliable}_${_v})
113 set(listsuspendedx suspendedTests_${v})
115 set(listsuspiciousx ${listsuspicious})
116 set(listignoredx ${listignored})
117 set(listunreliablex ${listunreliable})
118 set(listsuspendedx suspendedTests)
120 set(sublabel "${${listlabels}}")
121 findexpr(mfound ${testname} ${listignoredx} sublabel)
124 findexpr(foundunreliable ${testname} ${listunreliablex} sublabel2)
126 set(sublabel "unreliable" ${sublabel} ${sublabel2})
127 list(REMOVE_ITEM sublabel "export" "reverted" "templates" "mathmacros" "manuals" "autotests")
129 string(REGEX MATCH "_(systemF|texF|pdf3|pdf2|pdf|dvi|lyx16|xhtml)$" _v ${${testname}})
130 # check if test _may_ be in listsuspicious
133 findexpr(mfound ${testname} ${listsuspiciousx} sublabel2)
139 findexpr(foundsuspended ${testname} ${listsuspendedx} sublabel3)
142 set(sublabel "suspended" ${sublabel} ${sublabel2} ${sublabel3})
143 list(REMOVE_ITEM sublabel "export" "reverted" )
145 set(sublabel "reverted" ${sublabel} ${sublabel2} ${sublabel3})
151 list(REMOVE_DUPLICATES sublabel)
152 if (NOT sublabel STREQUAL "")
153 join(sublabel "." tmpprefixx)
154 string(TOUPPER "${tmpprefixx}_" tmpprefix)
155 set(${testname} "${tmpprefix}${${testname}}")
156 set(${listlabels} ${sublabel})
159 # No testname because ignored
164 # This labels should not be used in .*Tests files
165 set(known_labels "export" "key" "layout" "load" "lyx2lyx"
166 "examples" "manuals" "mathmacros" "reverted" "templates" "unreliable" "suspended"
167 "module" "roundtrip" "url")
169 macro(loadTestList filename resList)
170 # Create list of strings from a file without comments
171 # ENCODING parameter is a new feature in cmake 3.1
172 if (CMAKE_VERSION VERSION_GREATER "3.1")
173 file(STRINGS ${filename} tempList ENCODING "UTF-8")
175 file(STRINGS ${filename} tempList)
181 message(STATUS "Reading list ${filename}")
182 foreach(_l ${tempList})
184 string(REGEX REPLACE "[ \t]+$" "" _newl "${_l}")
185 string(REGEX REPLACE "[ \t]*#.*$" "" _newl "${_l}")
187 list(APPEND ${resList} "${_newl}")
188 if (_newl MATCHES "^Sublabel:")
189 string(REGEX REPLACE "^Sublabel:[ \t]*" "" _newlabels ${_newl})
190 string(REGEX MATCHALL "([a-zA-Z]+)" _labels ${_newlabels})
191 foreach(labname ${_labels})
192 if (NOT labname STREQUAL "RESET")
193 list(APPEND mylabels ${labname})
196 list(REMOVE_DUPLICATES mylabels)
197 set(sublabel ${_newl})
199 string(REGEX REPLACE "(\\/|\\||\\(|\\))" " " _vxx ${_newl})
200 string(REGEX MATCHALL " ([a-z][a-z](_[A-Z][A-Z])?) " _vx ${_vxx})
203 string(REGEX REPLACE " " "" _v ${_v})
204 #message(STATUS " ==> ${resList}_${_v}")
205 #message(STATUS "sublabel = ${sublabel}, sublabel_${_v} = ${sublabel_${_v}}")
206 if (NOT sublabel STREQUAL "${sublabel_${_v}}")
207 list(APPEND ${resList}_${_v} "${sublabel}")
208 set(sublabel_${_v} "${sublabel}")
209 #message(STATUS "Setting variable sublabel_${_v} with \"${sublabel}\"")
211 list(APPEND ${resList}_${_v} "${_newl}")
212 list(APPEND languages ${_v})
214 list(REMOVE_DUPLICATES languages)
215 #message(STATUS "languages = ${languages}")
220 foreach(_l ${mylabels})
221 list(FIND known_labels ${_l} _ff)
223 message(STATUS "Label \"${_l}\" already in use. Reused in ${filename}")
225 list(APPEND known_labels ${_l})
228 foreach(_lg ${languages})
229 # reset label for each used language string at end of file
230 #message(STATUS "Resetting variable sublabel_${_lg}, previously set to ${sublabel_${_lg}}")
231 set(sublabel_${_lg} "")
235 loadTestList(suspiciousTests suspiciousTests)
236 loadTestList(ignoredTests ignoredTests)
237 loadTestList(suspendedTests suspendedTests)
238 loadTestList(unreliableTests unreliableTests)
240 # preparing to add e.g. development/mathmacros to the foreach() loop
241 foreach(libsubfolderx autotests/export lib/doc lib/examples lib/templates development/mathmacros)
242 set(testlabel "export")
243 if (libsubfolderx MATCHES "lib/doc")
244 list(APPEND testlabel "manuals")
245 elseif (libsubfolderx MATCHES "lib/examples")
246 list(APPEND testlabel "examples")
247 elseif (libsubfolderx MATCHES "lib/templates")
248 list(APPEND testlabel "templates")
249 elseif (libsubfolderx MATCHES "development/mathmacros")
250 list(APPEND testlabel "mathmacros")
251 elseif (libsubfolderx MATCHES "autotests/.+")
252 list(APPEND testlabel "autotests")
254 set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
255 string(REGEX REPLACE "^(lib|development|autotests)/" "" libsubfolder "${libsubfolderx}")
256 set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
257 message(STATUS "Handling export dir ${LIBSUB_SRC_DIR}")
258 file(GLOB_RECURSE lyx_files RELATIVE "${LIBSUB_SRC_DIR}" "${LIBSUB_SRC_DIR}/*.lyx")
260 # Now create 2 lists. One for files in a language dir, one without
262 set(nolang_lyx_files)
263 foreach(f ${lyx_files})
264 string(REGEX MATCHALL "^[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${f})
266 list(APPEND lang_lyx_files ${f})
268 list(APPEND nolang_lyx_files ${f})
271 foreach(f ${nolang_lyx_files} ${lang_lyx_files})
273 string(REGEX REPLACE "\\.lyx$" "" f ${f})
274 set(TestName "export/${libsubfolder}/${f}_lyx16")
275 set(mytestlabel ${testlabel})
276 maketestname(TestName reverted suspiciousTests ignoredTests unreliableTests mytestlabel)
278 add_test(NAME ${TestName}
279 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
280 COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
281 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
282 -Dlyx=$<TARGET_FILE:${_lyx}>
283 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
284 -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
288 -Dreverted=${reverted}
289 -DTOP_SRC_DIR=${TOP_SRC_DIR}
290 -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
291 -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
292 setmarkedtestlabel(${TestName} ${reverted} ${mytestlabel})
294 if(LYX_PYTHON_EXECUTABLE)
295 set(lyx2lyxtestlabel "lyx2lyx")
296 # For use of lyx2lyx we need the python executable
297 set(mytestlabel ${lyx2lyxtestlabel})
298 set(TestName "lyx2lyx/${libsubfolder}/${f}")
299 maketestname(TestName reverted suspiciousTests ignoredTests unreliableTests mytestlabel)
301 add_test(NAME ${TestName}
302 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
303 COMMAND ${CMAKE_COMMAND}
304 "-DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE}"
305 "-DLYX2LYX=${TOP_SRC_DIR}/lib/lyx2lyx/lyx2lyx"
306 "-DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}"
307 "-DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx"
308 -P "${TOP_SRC_DIR}/development/autotests/lyx2lyxtest.cmake")
309 setmarkedtestlabel(${TestName} ${reverted} ${mytestlabel})
312 set(loadtestlabel "load")
313 set(mytestlabel ${loadtestlabel})
314 set(TestName "check_load/${libsubfolder}/${f}")
315 maketestname(TestName reverted suspiciousTests ignoredTests unreliableTests mytestlabel)
317 add_test(NAME ${TestName}
318 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
319 COMMAND ${CMAKE_COMMAND} -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
320 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
321 -Dlyx=$<TARGET_FILE:${_lyx}>
322 -DPARAMS_DIR=${TOP_SRC_DIR}/development/autotests
323 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
324 -P "${TOP_SRC_DIR}/development/autotests/check_load.cmake")
325 setmarkedtestlabel(${TestName} ${reverted} ${mytestlabel})
326 set_tests_properties(${TestName} PROPERTIES RUN_SERIAL ON)
328 getoutputformats("${LIBSUB_SRC_DIR}/${f}.lyx" formatlist)
329 foreach(format ${formatlist})
330 if(format MATCHES "dvi3|pdf4|pdf5")
331 set(fonttypes "texF" "systemF")
333 set(fonttypes "defaultF")
335 foreach(fonttype ${fonttypes})
336 if(fonttype MATCHES "defaultF")
337 set(TestName "export/${libsubfolder}/${f}_${format}")
339 set(TestName "export/${libsubfolder}/${f}_${format}_${fonttype}")
341 set(mytestlabel ${testlabel})
342 maketestname(TestName reverted suspiciousTests ignoredTests unreliableTests mytestlabel)
344 add_test(NAME ${TestName}
345 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
346 COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
347 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
348 -Dlyx=$<TARGET_FILE:${_lyx}>
349 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
351 -Dfonttype=${fonttype}
352 -Dextension=${format}
354 -Dreverted=${reverted}
355 -DTOP_SRC_DIR=${TOP_SRC_DIR}
356 -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
357 -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
358 setmarkedtestlabel(${TestName} ${reverted} ${mytestlabel}) # check for suspended pdf/dvi exports