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.
30 find_program(XMLLINT_EXECUTABLE xmllint)
33 set(DVI_FORMATS "dvi" "dvi3")
34 set(PDF_FORMATS "pdf" "pdf2" "pdf3" "pdf4" "pdf5")
36 set(DVI_FORMATS "dvi")
37 set(PDF_FORMATS "pdf" "pdf2" "pdf3")
40 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")
42 # Used to select labels from .*Tests files
43 set(label_chars "[a-zA-Z:_]+")
45 macro(initLangVars varname)
46 foreach(_l ${potential_languages})
51 macro(getoutputformats filepath varname format_set)
52 file(STRINGS "${filepath}" lines)
53 # What should we test, if default_output_format is not defined?
54 # For now we test everything ...
55 set(out_formats "xhtml" ${DVI_FORMATS} ${PDF_FORMATS})
57 if(_l MATCHES "^\\\\default_output_format +\([^ ]+\)")
58 set(_format ${CMAKE_MATCH_1})
59 if(_format STREQUAL "default")
60 set(out_formats "xhtml" ${DVI_FORMATS} ${PDF_FORMATS})
62 set(${format_set} ${_format})
63 if(_format STREQUAL "pdf2" AND "${filepath}" MATCHES "/doc/")
64 set(out_formats "xhtml" ${DVI_FORMATS} ${PDF_FORMATS})
65 elseif(_format MATCHES "pdf$")
66 set(out_formats "xhtml" ${PDF_FORMATS})
67 elseif(_format MATCHES "dvi$")
68 set(out_formats "xhtml" ${DVI_FORMATS})
69 elseif(_format MATCHES "xhtml")
70 set(out_formats "xhtml")
72 # Respect all other output formats
74 set(out_formats "xhtml" ${_format})
80 set(${varname} ${out_formats})
83 macro(findexpr found testname listname rsublabel)
86 foreach(_itrx ${${listname}})
87 if ("${_itrx}" MATCHES "^Sublabel:")
89 string(REGEX REPLACE "^Sublabel:[ \t]*" "" _itrlabels ${_itrx})
90 string(REGEX MATCHALL ${label_chars} _labels ${_itrlabels})
91 foreach(subl ${_labels})
92 if (subl STREQUAL "RESET")
95 list(APPEND tmpsublabel ${subl})
98 # remove doubles in sublabel
99 list(REMOVE_DUPLICATES tmpsublabel)
101 set(_itr "^${_itrx}$")
102 if (${testname} MATCHES "${_itr}")
109 if (NOT "${tmpsublabel}" STREQUAL "")
110 list(APPEND ${rsublabel} ${tmpsublabel})
113 set(${found} ${_found})
116 function(join rvalues glue routput)
117 set(locallist ${${rvalues}})
118 set(removelist "export" "lyx2lyx" "load")
119 foreach(_l ${locallist})
120 if (depth_${_l} LESS 0)
121 list(APPEND removelist ${_l})
124 list(REMOVE_ITEM locallist ${removelist})
125 string(REGEX REPLACE "([^\\]|^);" "\\1${glue}" out "${locallist}")
126 set(${routput} ${out} PARENT_SCOPE)
129 macro(maketestname testname inverted listinverted listignored listunreliable listlabels)
130 # initialize output variable
132 string(REGEX MATCH "\\/[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${${testname}})
134 string(REGEX REPLACE "\\/" "" _v ${_v})
135 set(listinvertedx ${listinverted}_${_v})
136 set(listignoredx ${listignored}_${_v})
137 set(listunreliablex ${listunreliable}_${_v})
138 set(listsuspendedx suspendedTests_${_v})
140 set(listinvertedx ${listinverted})
141 set(listignoredx ${listignored})
142 set(listunreliablex ${listunreliable})
143 set(listsuspendedx suspendedTests)
145 set(sublabel "${${listlabels}}")
146 findexpr(mfound ${testname} ${listignoredx} sublabel)
149 findexpr(foundunreliable ${testname} ${listunreliablex} sublabel2)
151 set(sublabel "unreliable" ${sublabel} ${sublabel2})
152 list(REMOVE_ITEM sublabel "export" "inverted" "templates" "mathmacros" "manuals" "autotests")
154 string(REGEX MATCH "(^check_load|_(systemF|texF|pdf3|pdf2|pdf|dvi|lyx[0-9][0-9]|xhtml)$)" _v ${${testname}})
155 # check if test _may_ be in listinverted
158 findexpr(mfound ${testname} ${listinvertedx} sublabel2)
164 findexpr(foundsuspended ${testname} ${listsuspendedx} sublabel3)
167 set(sublabel "suspended" ${sublabel} ${sublabel2} ${sublabel3})
168 list(REMOVE_ITEM sublabel "export" "inverted" )
170 set(sublabel "inverted" ${sublabel} ${sublabel2} ${sublabel3})
175 list(REMOVE_DUPLICATES sublabel)
176 if (NOT sublabel STREQUAL "")
177 join(sublabel "." tmpprefixx)
179 string(TOUPPER "${tmpprefixx}_" tmpprefix)
183 set(${testname} "${tmpprefix}${${testname}}")
184 set(${listlabels} ${sublabel})
187 # No testname because ignored
192 macro(loadTestList filename resList depth splitlangs)
193 # Create list of strings from a file without comments
194 # ENCODING parameter is a new feature in cmake 3.1
195 initLangVars(${resList})
196 initLangVars("sublabel")
197 if (CMAKE_VERSION VERSION_GREATER "3.1")
198 file(STRINGS ${filename} tempList ENCODING "UTF-8")
200 file(STRINGS ${filename} tempList)
206 message(STATUS "Reading list ${filename}")
207 foreach(_l ${tempList})
209 string(REGEX REPLACE "[ \t]+$" "" _newl "${_l}")
210 string(REGEX REPLACE "[ \t]*#.*$" "" _newl "${_l}")
212 list(APPEND ${resList} "${_newl}")
213 if (_newl MATCHES "^Sublabel:")
214 string(REGEX REPLACE "^Sublabel:[ \t]*" "" _newlabels ${_newl})
215 string(REGEX MATCHALL "([0-9]*${label_chars})" _labels ${_newlabels})
216 foreach(labname ${_labels})
217 if (NOT labname STREQUAL "RESET")
218 list(APPEND mylabels ${labname})
221 list(REMOVE_DUPLICATES mylabels)
222 set(sublabel ${_newl})
224 if (${splitlangs} MATCHES "ON")
225 string(REGEX REPLACE "(\\/|\\||\\(|\\))" " " _vxx ${_newl})
226 string(REGEX MATCHALL " ([a-z][a-z](_[A-Z][A-Z])?) " _vx ${_vxx})
232 string(REGEX REPLACE " " "" _v ${_v})
233 #message(STATUS " ==> ${resList}_${_v}")
234 #message(STATUS "sublabel = ${sublabel}, sublabel_${_v} = ${sublabel_${_v}}")
235 if (NOT sublabel STREQUAL "${sublabel_${_v}}")
236 list(APPEND ${resList}_${_v} "${sublabel}")
237 set(sublabel_${_v} "${sublabel}")
238 #message(STATUS "Setting variable sublabel_${_v} with \"${sublabel}\"")
240 list(APPEND ${resList}_${_v} "${_newl}")
241 list(APPEND languages ${_v})
243 list(REMOVE_DUPLICATES languages)
244 #message(STATUS "languages = ${languages}")
249 foreach(_l1 ${mylabels})
250 if (_l1 MATCHES "^([0-9]+)(${label_chars})$")
251 set(_l ${CMAKE_MATCH_2})
252 set(depth1 ${CMAKE_MATCH_1})
257 list(FIND known_labels ${_l} _ff)
259 message(STATUS "Label \"${_l}\" already in use. Reused in ${filename}")
261 assignLabelDepth(${depth}${depth1} ${_l})
264 foreach(_lg ${languages})
265 # reset label for each used language string at end of file
266 #message(STATUS "Resetting variable sublabel_${_lg}, previously set to ${sublabel_${_lg}}")
267 set(sublabel_${_lg} "")
271 # This labels should not be used in .*Tests files
273 # Create depth info to each label
274 macro(assignLabelDepth depth)
275 foreach(_lab ${ARGN})
276 list(APPEND known_labels ${_lab})
277 set(depth_${_lab} ${depth})
281 assignLabelDepth(0 "export" "key" "layout" "load" "lyx2lyx" "module" "roundtrip" "url")
282 assignLabelDepth(1 "unreliable" "inverted")
283 assignLabelDepth(2 "suspended")
284 assignLabelDepth(-1 "examples" "manuals" "mathmacros" "templates" "autotests")
286 loadTestList(invertedTests invertedTests 7 ON)
287 loadTestList(ignoredTests ignoredTests 0 ON)
288 loadTestList(suspendedTests suspendedTests 6 ON)
289 loadTestList(unreliableTests unreliableTests 5 ON)
290 loadTestList(ignoreLatexErrorsTests ignoreLatexErrorsTests 8 OFF)
292 foreach(libsubfolderx autotests/export lib/doc lib/examples lib/templates autotests/mathmacros)
293 set(testlabel "export")
294 if (libsubfolderx MATCHES "lib/doc")
295 list(APPEND testlabel "manuals")
296 elseif (libsubfolderx MATCHES "lib/examples")
297 list(APPEND testlabel "examples")
298 elseif (libsubfolderx MATCHES "lib/templates")
299 list(APPEND testlabel "templates")
300 elseif (libsubfolderx MATCHES "autotests/mathmacros")
301 list(APPEND testlabel "mathmacros")
302 elseif (libsubfolderx MATCHES "autotests/.+")
303 list(APPEND testlabel "autotests")
305 set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
306 string(REGEX REPLACE "^(lib|development|autotests)/" "" libsubfolder "${libsubfolderx}")
307 set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
308 message(STATUS "Handling export dir ${LIBSUB_SRC_DIR}")
309 file(GLOB_RECURSE lyx_files RELATIVE "${LIBSUB_SRC_DIR}" "${LIBSUB_SRC_DIR}/*.lyx")
311 # Now create 2 lists. One for files in a language dir, one without
313 set(nolang_lyx_files)
314 foreach(f ${lyx_files})
315 string(REGEX MATCHALL "^[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${f})
317 list(APPEND lang_lyx_files ${f})
319 list(APPEND nolang_lyx_files ${f})
322 foreach(f ${nolang_lyx_files} ${lang_lyx_files})
324 string(REGEX REPLACE "\\.lyx$" "" f ${f})
325 foreach(_lyx_format_num 16 21 22)
326 set(TestName "export/${libsubfolder}/${f}_lyx${_lyx_format_num}")
327 set(mytestlabel ${testlabel} "lyx2lyx" "load")
328 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
330 add_test(NAME ${TestName}
331 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
332 COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
333 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
334 -Dlyx=$<TARGET_FILE:${_lyx}>
335 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
336 -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
337 -Dformat=lyx${_lyx_format_num}x
338 -Dextension=${_lyx_format_num}.lyx
339 -DLYX_FORMAT_NUM=${_lyx_format_num}
341 -Dinverted=${inverted}
342 -DTOP_SRC_DIR=${TOP_SRC_DIR}
343 -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
344 -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
345 setmarkedtestlabel(${TestName} ${mytestlabel})
348 if(LYX_PYTHON_EXECUTABLE)
349 set(lyx2lyxtestlabel "lyx2lyx")
350 # For use of lyx2lyx we need the python executable
351 set(mytestlabel ${lyx2lyxtestlabel})
352 set(TestName "lyx2lyx/${libsubfolder}/${f}")
353 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
355 add_test(NAME ${TestName}
356 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
357 COMMAND ${CMAKE_COMMAND}
358 "-DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE}"
359 "-DLYX2LYX=${TOP_SRC_DIR}/lib/lyx2lyx/lyx2lyx"
360 "-DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}"
361 "-DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx"
362 -P "${TOP_SRC_DIR}/development/autotests/lyx2lyxtest.cmake")
363 setmarkedtestlabel(${TestName} ${mytestlabel})
366 set(loadtestlabel "load")
367 set(mytestlabel ${loadtestlabel})
368 set(TestName "check_load/${libsubfolder}/${f}")
369 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
371 add_test(NAME ${TestName}
372 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
373 COMMAND ${CMAKE_COMMAND} -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
374 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
375 -Dlyx=$<TARGET_FILE:${_lyx}>
376 -DPARAMS_DIR=${TOP_SRC_DIR}/development/autotests
377 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
378 -Dinverted=${inverted}
379 -P "${TOP_SRC_DIR}/development/autotests/check_load.cmake")
380 setmarkedtestlabel(${TestName} ${mytestlabel})
381 #set_tests_properties(${TestName} PROPERTIES RUN_SERIAL ON)
383 set(default_output_format)
384 getoutputformats("${LIBSUB_SRC_DIR}/${f}.lyx" formatlist default_output_format)
385 foreach(format ${formatlist})
386 if(format MATCHES "dvi3|pdf4|pdf5")
387 set(fonttypes "texF" "systemF")
389 set(fonttypes "defaultF")
391 foreach(fonttype ${fonttypes})
392 if (format MATCHES "pdf2" AND f MATCHES "latex/unicodesymbols")
393 #message(STATUS "Test ${TestName} matches Unicode encodings")
394 # test_encodings does not include "default", since it should be covered
395 # by one of the supplied encodings
396 set(test_encodings "ascii" "utf8" "utf8x" "armscii8" "applemac"
397 "cp437" "cp437de" "cp850" "cp852"
398 "cp855" "cp862" "cp865"
399 "cp866" "cp1250" "cp1251" "cp1252"
400 "cp1255" "cp1256" "cp1257"
402 "iso8859-1" "iso8859-2" "iso8859-3"
403 "iso8859-4" "iso8859-5" "iso8859-6"
404 "iso8859-7" "iso8859-8" "iso8859-9"
405 "iso8859-13" "iso8859-15" "iso8859-16"
406 "pt154" "big5" "shift-jis"
407 "euc-cn" "gbk" "jis" "euc-kr"
408 "utf8-cjk" "euc-tw" "euc-jp"
409 "euc-jp-platex" "jis-platex"
410 "shift-jis-platex" "utf8-platex"
413 set(test_encodings "default")
415 foreach (_enc2 ${test_encodings})
416 if ("${_enc2}" STREQUAL "default")
419 set(_enc "_${_enc2}")
421 if(fonttype MATCHES "defaultF")
422 set(TestName "export/${libsubfolder}/${f}${_enc}_${format}")
424 set(TestName "export/${libsubfolder}/${f}${_enc}_${format}_${fonttype}")
426 if (format MATCHES "^${default_output_format}$")
427 set(extraLabels "defaultoutput")
432 findexpr(mfound TestName ignoreLatexErrorsTests missingLabels)
434 set(mytestlabel ${testlabel} "ignoring" ${missingLabels} ${extraLabels})
436 set(mytestlabel ${testlabel} ${extraLabels})
438 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
440 add_test(NAME ${TestName}
441 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
442 COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
443 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
444 -Dlyx=$<TARGET_FILE:${_lyx}>
445 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
447 -Dfonttype=${fonttype}
448 -Dextension=${format}
450 -Dinverted=${inverted}
451 -DTOP_SRC_DIR=${TOP_SRC_DIR}
452 "-DIgnoreErrorMessage=${missingLabels}"
453 -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
454 -DXMLLINT_EXECUTABLE=${XMLLINT_EXECUTABLE}
456 -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
457 setmarkedtestlabel(${TestName} ${mytestlabel}) # check for suspended pdf/dvi exports