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 set(potential_languages "ca" "cs" "da" "de" "el" "es" "eu" "fa" "fr" "gl" "he" "hu" "id" "it" "ja" "ko" "nb" "nl" "pl" "pt" "ro" "ru" "sk" "sl" "sr" "sv" "uk" "zh_CN")
41 # Used to select labels from .*Tests files
42 set(label_chars "[a-zA-Z:_]+")
44 macro(initLangVars varname)
45 foreach(_l ${potential_languages})
50 macro(getoutputformats filepath varname)
51 file(STRINGS "${filepath}" lines)
52 # What should we test, if default_output_format is not defined?
53 # For now we test everything ...
54 set(out_formats "xhtml" ${DVI_FORMATS} ${PDF_FORMATS})
56 if(_l MATCHES "^\\\\default_output_format +\([^ ]+\)")
57 set(_format ${CMAKE_MATCH_1})
58 if(_format STREQUAL "default")
59 set(out_formats "xhtml" ${DVI_FORMATS} ${PDF_FORMATS})
60 elseif(_format STREQUAL "pdf2" AND "${filepath}" MATCHES "/doc/")
61 set(out_formats "xhtml" ${DVI_FORMATS} ${PDF_FORMATS})
62 elseif(_format MATCHES "pdf$")
63 set(out_formats "xhtml" ${PDF_FORMATS})
64 elseif(_format MATCHES "dvi$")
65 set(out_formats "xhtml" ${DVI_FORMATS})
66 elseif(_format MATCHES "xhtml")
67 set(out_formats "xhtml")
69 # Respect all other output formats
71 set(out_formats "xhtml" ${_format})
76 set(${varname} ${out_formats})
79 macro(findexpr found testname listname rsublabel)
82 foreach(_itrx ${${listname}})
83 if ("${_itrx}" MATCHES "^Sublabel:")
85 string(REGEX REPLACE "^Sublabel:[ \t]*" "" _itrlabels ${_itrx})
86 string(REGEX MATCHALL ${label_chars} _labels ${_itrlabels})
87 foreach(subl ${_labels})
88 if (subl STREQUAL "RESET")
91 list(APPEND tmpsublabel ${subl})
94 # remove doubles in sublabel
95 list(REMOVE_DUPLICATES tmpsublabel)
97 set(_itr "^${_itrx}$")
98 if (${testname} MATCHES "${_itr}")
105 if (NOT "${tmpsublabel}" STREQUAL "")
106 list(APPEND ${rsublabel} ${tmpsublabel})
109 set(${found} ${_found})
112 function(join rvalues glue routput)
113 set(locallist ${${rvalues}})
114 set(removelist "export" "lyx2lyx" "load")
115 foreach(_l ${locallist})
116 if (depth_${_l} LESS 0)
117 list(APPEND removelist ${_l})
120 list(REMOVE_ITEM locallist ${removelist})
121 string(REGEX REPLACE "([^\\]|^);" "\\1${glue}" out "${locallist}")
122 set(${routput} ${out} PARENT_SCOPE)
125 macro(maketestname testname inverted listsuspicious listignored listunreliable listlabels)
126 # initialize output variable
128 string(REGEX MATCH "\\/[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${${testname}})
130 string(REGEX REPLACE "\\/" "" _v ${_v})
131 set(listsuspiciousx ${listsuspicious}_${_v})
132 set(listignoredx ${listignored}_${_v})
133 set(listunreliablex ${listunreliable}_${_v})
134 set(listsuspendedx suspendedTests_${_v})
136 set(listsuspiciousx ${listsuspicious})
137 set(listignoredx ${listignored})
138 set(listunreliablex ${listunreliable})
139 set(listsuspendedx suspendedTests)
141 set(sublabel "${${listlabels}}")
142 findexpr(mfound ${testname} ${listignoredx} sublabel)
145 findexpr(foundunreliable ${testname} ${listunreliablex} sublabel2)
147 set(sublabel "unreliable" ${sublabel} ${sublabel2})
148 list(REMOVE_ITEM sublabel "export" "inverted" "templates" "mathmacros" "manuals" "autotests")
150 string(REGEX MATCH "(^check_load|_(systemF|texF|pdf3|pdf2|pdf|dvi|lyx[0-9][0-9]|xhtml)$)" _v ${${testname}})
151 # check if test _may_ be in listsuspicious
154 findexpr(mfound ${testname} ${listsuspiciousx} sublabel2)
160 findexpr(foundsuspended ${testname} ${listsuspendedx} sublabel3)
163 set(sublabel "suspended" ${sublabel} ${sublabel2} ${sublabel3})
164 list(REMOVE_ITEM sublabel "export" "inverted" )
166 set(sublabel "inverted" ${sublabel} ${sublabel2} ${sublabel3})
172 list(REMOVE_DUPLICATES sublabel)
173 if (NOT sublabel STREQUAL "")
174 join(sublabel "." tmpprefixx)
176 string(TOUPPER "${tmpprefixx}_" tmpprefix)
180 set(${testname} "${tmpprefix}${${testname}}")
181 set(${listlabels} ${sublabel})
184 # No testname because ignored
189 macro(loadTestList filename resList depth)
190 # Create list of strings from a file without comments
191 # ENCODING parameter is a new feature in cmake 3.1
192 initLangVars(${resList})
193 initLangVars("sublabel")
194 if (CMAKE_VERSION VERSION_GREATER "3.1")
195 file(STRINGS ${filename} tempList ENCODING "UTF-8")
197 file(STRINGS ${filename} tempList)
203 message(STATUS "Reading list ${filename}")
204 foreach(_l ${tempList})
206 string(REGEX REPLACE "[ \t]+$" "" _newl "${_l}")
207 string(REGEX REPLACE "[ \t]*#.*$" "" _newl "${_l}")
209 list(APPEND ${resList} "${_newl}")
210 if (_newl MATCHES "^Sublabel:")
211 string(REGEX REPLACE "^Sublabel:[ \t]*" "" _newlabels ${_newl})
212 string(REGEX MATCHALL "([0-9]*${label_chars})" _labels ${_newlabels})
213 foreach(labname ${_labels})
214 if (NOT labname STREQUAL "RESET")
215 list(APPEND mylabels ${labname})
218 list(REMOVE_DUPLICATES mylabels)
219 set(sublabel ${_newl})
221 string(REGEX REPLACE "(\\/|\\||\\(|\\))" " " _vxx ${_newl})
222 string(REGEX MATCHALL " ([a-z][a-z](_[A-Z][A-Z])?) " _vx ${_vxx})
225 string(REGEX REPLACE " " "" _v ${_v})
226 #message(STATUS " ==> ${resList}_${_v}")
227 #message(STATUS "sublabel = ${sublabel}, sublabel_${_v} = ${sublabel_${_v}}")
228 if (NOT sublabel STREQUAL "${sublabel_${_v}}")
229 list(APPEND ${resList}_${_v} "${sublabel}")
230 set(sublabel_${_v} "${sublabel}")
231 #message(STATUS "Setting variable sublabel_${_v} with \"${sublabel}\"")
233 list(APPEND ${resList}_${_v} "${_newl}")
234 list(APPEND languages ${_v})
236 list(REMOVE_DUPLICATES languages)
237 #message(STATUS "languages = ${languages}")
242 foreach(_l1 ${mylabels})
243 if (_l1 MATCHES "^([0-9]+)(${label_chars})$")
244 set(_l ${CMAKE_MATCH_2})
245 set(depth1 ${CMAKE_MATCH_1})
250 list(FIND known_labels ${_l} _ff)
252 message(STATUS "Label \"${_l}\" already in use. Reused in ${filename}")
254 assignLabelDepth(${depth}${depth1} ${_l})
257 foreach(_lg ${languages})
258 # reset label for each used language string at end of file
259 #message(STATUS "Resetting variable sublabel_${_lg}, previously set to ${sublabel_${_lg}}")
260 set(sublabel_${_lg} "")
264 # This labels should not be used in .*Tests files
266 # Create depth info to each label
267 macro(assignLabelDepth depth)
268 foreach(_lab ${ARGN})
269 list(APPEND known_labels ${_lab})
270 set(depth_${_lab} ${depth})
274 assignLabelDepth(0 "export" "key" "layout" "load" "lyx2lyx" "module" "roundtrip" "url")
275 assignLabelDepth(1 "unreliable" "inverted")
276 assignLabelDepth(2 "suspended")
277 assignLabelDepth(-1 "examples" "manuals" "mathmacros" "templates" "autotests")
279 loadTestList(suspiciousTests suspiciousTests 7)
280 loadTestList(ignoredTests ignoredTests 0)
281 loadTestList(suspendedTests suspendedTests 6)
282 loadTestList(unreliableTests unreliableTests 5)
284 foreach(libsubfolderx autotests/export lib/doc lib/examples lib/templates autotests/mathmacros)
285 set(testlabel "export")
286 if (libsubfolderx MATCHES "lib/doc")
287 list(APPEND testlabel "manuals")
288 elseif (libsubfolderx MATCHES "lib/examples")
289 list(APPEND testlabel "examples")
290 elseif (libsubfolderx MATCHES "lib/templates")
291 list(APPEND testlabel "templates")
292 elseif (libsubfolderx MATCHES "autotests/mathmacros")
293 list(APPEND testlabel "mathmacros")
294 elseif (libsubfolderx MATCHES "autotests/.+")
295 list(APPEND testlabel "autotests")
297 set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
298 string(REGEX REPLACE "^(lib|development|autotests)/" "" libsubfolder "${libsubfolderx}")
299 set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
300 message(STATUS "Handling export dir ${LIBSUB_SRC_DIR}")
301 file(GLOB_RECURSE lyx_files RELATIVE "${LIBSUB_SRC_DIR}" "${LIBSUB_SRC_DIR}/*.lyx")
303 # Now create 2 lists. One for files in a language dir, one without
305 set(nolang_lyx_files)
306 foreach(f ${lyx_files})
307 string(REGEX MATCHALL "^[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${f})
309 list(APPEND lang_lyx_files ${f})
311 list(APPEND nolang_lyx_files ${f})
314 foreach(f ${nolang_lyx_files} ${lang_lyx_files})
316 string(REGEX REPLACE "\\.lyx$" "" f ${f})
317 foreach(_lyx_format_num 16 21)
318 set(TestName "export/${libsubfolder}/${f}_lyx${_lyx_format_num}")
319 set(mytestlabel ${testlabel} "lyx2lyx" "load")
320 maketestname(TestName inverted suspiciousTests ignoredTests unreliableTests mytestlabel)
322 add_test(NAME ${TestName}
323 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
324 COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
325 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
326 -Dlyx=$<TARGET_FILE:${_lyx}>
327 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
328 -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
329 -Dformat=lyx${_lyx_format_num}x
330 -Dextension=${_lyx_format_num}.lyx
331 -DLYX_FORMAT_NUM=${_lyx_format_num}
333 -Dinverted=${inverted}
334 -DTOP_SRC_DIR=${TOP_SRC_DIR}
335 -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
336 -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
337 setmarkedtestlabel(${TestName} ${mytestlabel})
340 if(LYX_PYTHON_EXECUTABLE)
341 set(lyx2lyxtestlabel "lyx2lyx")
342 # For use of lyx2lyx we need the python executable
343 set(mytestlabel ${lyx2lyxtestlabel})
344 set(TestName "lyx2lyx/${libsubfolder}/${f}")
345 maketestname(TestName inverted suspiciousTests ignoredTests unreliableTests mytestlabel)
347 add_test(NAME ${TestName}
348 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
349 COMMAND ${CMAKE_COMMAND}
350 "-DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE}"
351 "-DLYX2LYX=${TOP_SRC_DIR}/lib/lyx2lyx/lyx2lyx"
352 "-DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}"
353 "-DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx"
354 -P "${TOP_SRC_DIR}/development/autotests/lyx2lyxtest.cmake")
355 setmarkedtestlabel(${TestName} ${mytestlabel})
358 set(loadtestlabel "load")
359 set(mytestlabel ${loadtestlabel})
360 set(TestName "check_load/${libsubfolder}/${f}")
361 maketestname(TestName inverted suspiciousTests ignoredTests unreliableTests mytestlabel)
363 add_test(NAME ${TestName}
364 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
365 COMMAND ${CMAKE_COMMAND} -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
366 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
367 -Dlyx=$<TARGET_FILE:${_lyx}>
368 -DPARAMS_DIR=${TOP_SRC_DIR}/development/autotests
369 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
370 -Dinverted=${inverted}
371 -P "${TOP_SRC_DIR}/development/autotests/check_load.cmake")
372 setmarkedtestlabel(${TestName} ${mytestlabel})
373 #set_tests_properties(${TestName} PROPERTIES RUN_SERIAL ON)
375 getoutputformats("${LIBSUB_SRC_DIR}/${f}.lyx" formatlist)
376 foreach(format ${formatlist})
377 if(format MATCHES "dvi3|pdf4|pdf5")
378 set(fonttypes "texF" "systemF")
380 set(fonttypes "defaultF")
382 foreach(fonttype ${fonttypes})
383 if(fonttype MATCHES "defaultF")
384 set(TestName "export/${libsubfolder}/${f}_${format}")
386 set(TestName "export/${libsubfolder}/${f}_${format}_${fonttype}")
388 set(mytestlabel ${testlabel})
389 maketestname(TestName inverted suspiciousTests ignoredTests unreliableTests mytestlabel)
391 add_test(NAME ${TestName}
392 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
393 COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
394 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
395 -Dlyx=$<TARGET_FILE:${_lyx}>
396 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
398 -Dfonttype=${fonttype}
399 -Dextension=${format}
401 -Dinverted=${inverted}
402 -DTOP_SRC_DIR=${TOP_SRC_DIR}
403 -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
404 -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
405 setmarkedtestlabel(${TestName} ${mytestlabel}) # check for suspended pdf/dvi exports