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)
31 find_program(JAVA_EXECUTABLE java)
34 if (EXISTS "${TOP_SRC_DIR}/development/tools/jing.jar")
35 set(jingjava ${JAVA_EXECUTABLE})
40 set(DVI_FORMATS "dvi" "dvi3")
41 set(PDF_FORMATS "pdf" "pdf2" "pdf3" "pdf4" "pdf5")
43 set(DVI_FORMATS "dvi")
44 set(PDF_FORMATS "pdf" "pdf2" "pdf3")
47 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")
49 # Used to select labels from .*Tests files
50 set(label_chars "[a-zA-Z:_]+")
52 macro(initLangVars varname)
53 foreach(_l ${potential_languages})
58 macro(getoutputformats filepath varname format_set)
59 file(STRINGS "${filepath}" lines)
60 # What should we test, if default_output_format is not defined?
61 # For now we test everything ...
62 set(out_formats "xhtml" "docbook5" ${DVI_FORMATS} ${PDF_FORMATS})
63 foreach(_l IN LISTS lines)
64 if(_l MATCHES "^\\\\default_output_format +\([^ ]+\)")
65 set(_format ${CMAKE_MATCH_1})
66 if(_format STREQUAL "default")
67 set(out_formats "xhtml" "docbook5" ${DVI_FORMATS} ${PDF_FORMATS})
69 set(${format_set} ${_format})
70 if(_format STREQUAL "pdf2" AND "${filepath}" MATCHES "/doc/")
71 set(out_formats "xhtml" "docbook5" ${DVI_FORMATS} ${PDF_FORMATS})
72 elseif(_format MATCHES "pdf$")
73 set(out_formats "xhtml" "docbook5" ${PDF_FORMATS})
74 elseif(_format MATCHES "dvi$")
75 set(out_formats "xhtml" "docbook5" ${DVI_FORMATS})
76 elseif(_format MATCHES "docbook5")
77 set(out_formats "docbook5")
78 elseif(_format MATCHES "xhtml")
79 set(out_formats "xhtml")
81 # Respect all other output formats
83 set(out_formats "xhtml" ${_format})
89 set(${varname} ${out_formats})
92 macro(findexpr found testname listname rsublabel)
95 foreach(_itrx ${${listname}})
96 if ("${_itrx}" MATCHES "^Sublabel:")
98 string(REGEX REPLACE "^Sublabel:[ \t]*" "" _itrlabels ${_itrx})
99 string(REGEX MATCHALL ${label_chars} _labels ${_itrlabels})
100 foreach(subl ${_labels})
101 if (subl STREQUAL "RESET")
104 list(APPEND tmpsublabel ${subl})
107 # remove doubles in sublabel
108 list(REMOVE_DUPLICATES tmpsublabel)
110 if (_itrx MATCHES "^!\(.*\)$")
111 set(_itr "^${CMAKE_MATCH_1}$")
114 set(_itr "^${_itrx}$")
117 if (${testname} MATCHES "${_itr}")
118 set(_found ${_foundval})
124 if (NOT "${tmpsublabel}" STREQUAL "")
125 list(APPEND ${rsublabel} ${tmpsublabel})
128 set(${found} ${_found})
131 function(join rvalues glue routput)
132 set(locallist ${${rvalues}})
133 set(removelist "export" "lyx2lyx" "load")
134 foreach(_l ${locallist})
135 if (depth_${_l} LESS 0)
136 list(APPEND removelist ${_l})
139 list(REMOVE_ITEM locallist ${removelist})
140 string(REGEX REPLACE "([^\\]|^);" "\\1${glue}" out "${locallist}")
141 set(${routput} ${out} PARENT_SCOPE)
144 macro(maketestname testname inverted listinverted listignored listunreliable listlabels)
145 # initialize output variable
147 string(REGEX MATCH "\\/[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${${testname}})
149 string(REGEX REPLACE "\\/" "" _v ${_v})
150 set(listinvertedx ${listinverted}_${_v})
151 set(listignoredx ${listignored}_${_v})
152 set(listunreliablex ${listunreliable}_${_v})
153 set(listsuspendedx suspendedTests_${_v})
155 set(listinvertedx ${listinverted})
156 set(listignoredx ${listignored})
157 set(listunreliablex ${listunreliable})
158 set(listsuspendedx suspendedTests)
160 set(sublabel "${${listlabels}}")
161 findexpr(mfound ${testname} ${listignoredx} sublabel)
164 findexpr(foundunreliable ${testname} ${listunreliablex} sublabel2)
166 set(sublabel "unreliable" ${sublabel} ${sublabel2})
167 list(REMOVE_ITEM sublabel "export" "inverted" "templates" "tabletemplates" "mathmacros" "manuals" "autotests")
169 string(REGEX MATCH "(^check_load|_(systemF|texF|pdf3|pdf2|pdf|dvi|lyx[0-9][0-9]|xhtml)$)" _v ${${testname}})
170 # check if test _may_ be in listinverted
172 findexpr(mfound ${testname} ${listinvertedx} sublabel2)
175 findexpr(foundsuspended ${testname} ${listsuspendedx} sublabel3)
178 set(sublabel "suspended" ${sublabel} ${sublabel2} ${sublabel3})
179 list(REMOVE_ITEM sublabel "export" "inverted" )
181 set(sublabel "inverted" ${sublabel} ${sublabel2} ${sublabel3})
186 list(REMOVE_DUPLICATES sublabel)
187 if (NOT sublabel STREQUAL "")
188 join(sublabel "." tmpprefixx)
190 string(TOUPPER "${tmpprefixx}_" tmpprefix)
194 set(${testname} "${tmpprefix}${${testname}}")
195 set(${listlabels} ${sublabel})
198 # No testname because ignored
203 macro(loadTestList filename resList depth splitlangs)
204 # Create list of strings from a file without comments
205 # ENCODING parameter is a new feature in cmake 3.1
206 initLangVars(${resList})
207 initLangVars("sublabel")
208 if (CMAKE_VERSION VERSION_GREATER "3.1")
209 file(STRINGS ${filename} tempList ENCODING "UTF-8")
211 file(STRINGS ${filename} tempList)
217 message(STATUS "Reading list ${filename}")
218 foreach(_l ${tempList})
220 string(REGEX REPLACE "[ \t]+$" "" _newl "${_l}")
221 string(REGEX REPLACE "[ \t]*#.*$" "" _newl "${_l}")
223 list(APPEND ${resList} "${_newl}")
224 if (_newl MATCHES "^Sublabel:")
225 string(REGEX REPLACE "^Sublabel:[ \t]*" "" _newlabels ${_newl})
226 string(REGEX MATCHALL "([0-9]*${label_chars})" _labels ${_newlabels})
227 foreach(labname ${_labels})
228 if (NOT labname STREQUAL "RESET")
229 list(APPEND mylabels ${labname})
232 list(REMOVE_DUPLICATES mylabels)
233 set(sublabel ${_newl})
235 if (${splitlangs} MATCHES "ON")
236 string(REGEX REPLACE "(\\/|\\||\\(|\\))" " " _vxx ${_newl})
237 string(REGEX MATCHALL " ([a-z][a-z](_[A-Z][A-Z])?) " _vx ${_vxx})
243 string(REGEX REPLACE " " "" _v ${_v})
244 #message(STATUS " ==> ${resList}_${_v}")
245 #message(STATUS "sublabel = ${sublabel}, sublabel_${_v} = ${sublabel_${_v}}")
246 if (NOT sublabel STREQUAL "${sublabel_${_v}}")
247 list(APPEND ${resList}_${_v} "${sublabel}")
248 set(sublabel_${_v} "${sublabel}")
249 #message(STATUS "Setting variable sublabel_${_v} with \"${sublabel}\"")
251 list(APPEND ${resList}_${_v} "${_newl}")
252 list(APPEND languages ${_v})
254 list(REMOVE_DUPLICATES languages)
255 #message(STATUS "languages = ${languages}")
260 foreach(_l1 ${mylabels})
261 if (_l1 MATCHES "^([0-9]+)(${label_chars})$")
262 set(_l ${CMAKE_MATCH_2})
263 set(depth1 ${CMAKE_MATCH_1})
268 list(FIND known_labels ${_l} _ff)
270 message(STATUS "Label \"${_l}\" already in use. Reused in ${filename}")
272 assignLabelDepth(${depth}${depth1} ${_l})
275 foreach(_lg ${languages})
276 # reset label for each used language string at end of file
277 #message(STATUS "Resetting variable sublabel_${_lg}, previously set to ${sublabel_${_lg}}")
278 set(sublabel_${_lg} "")
282 # This labels should not be used in .*Tests files
284 # Create depth info to each label
285 macro(assignLabelDepth depth)
286 foreach(_lab ${ARGN})
287 list(APPEND known_labels ${_lab})
288 set(depth_${_lab} ${depth})
292 assignLabelDepth(0 "export" "key" "layout" "load" "lyx2lyx" "module" "roundtrip" "url")
293 assignLabelDepth(1 "unreliable" "inverted")
294 assignLabelDepth(2 "suspended")
295 assignLabelDepth(-1 "examples" "manuals" "mathmacros" "templates" "tabletemplates" "autotests")
297 loadTestList(invertedTests invertedTests 7 ON)
298 loadTestList(ignoredTests ignoredTests 0 ON)
299 loadTestList(suspendedTests suspendedTests 6 ON)
300 loadTestList(unreliableTests unreliableTests 5 ON)
301 loadTestList(ignoreLatexErrorsTests ignoreLatexErrorsTests 8 OFF)
303 foreach(libsubfolderx autotests/export lib/doc lib/examples lib/templates lib/tabletemplates autotests/mathmacros)
304 set(testlabel "export")
305 if (libsubfolderx MATCHES "lib/doc")
306 list(APPEND testlabel "manuals")
307 elseif (libsubfolderx MATCHES "lib/examples")
308 list(APPEND testlabel "examples")
309 elseif (libsubfolderx MATCHES "lib/templates")
310 list(APPEND testlabel "templates")
311 elseif (libsubfolderx MATCHES "lib/tabletemplates")
312 list(APPEND testlabel "tabletemplates")
313 elseif (libsubfolderx MATCHES "autotests/mathmacros")
314 list(APPEND testlabel "mathmacros")
315 elseif (libsubfolderx MATCHES "autotests/.+")
316 list(APPEND testlabel "autotests")
318 set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
319 string(REGEX REPLACE "^(lib|development|autotests)/" "" libsubfolder "${libsubfolderx}")
320 set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
321 message(STATUS "Handling export dir ${LIBSUB_SRC_DIR}")
322 file(GLOB_RECURSE lyx_files RELATIVE "${LIBSUB_SRC_DIR}" "${LIBSUB_SRC_DIR}/*.lyx")
324 # Now create 2 lists. One for files in a language dir, one without
326 set(nolang_lyx_files)
327 foreach(f ${lyx_files})
328 if (${f} MATCHES "#")
329 # Do nothing, probably wrong temporary file
331 string(REGEX MATCHALL "^[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${f})
333 list(APPEND lang_lyx_files ${f})
335 list(APPEND nolang_lyx_files ${f})
339 foreach(f ${nolang_lyx_files} ${lang_lyx_files})
341 string(REGEX REPLACE "\\.lyx$" "" f ${f})
342 foreach(_lyx_format_num 16 20 21 22 23)
343 set(TestName1 "export/${libsubfolder}/${f}_lyx${_lyx_format_num}")
344 string(REGEX REPLACE "[\\(\\)]" "_" TestName "${TestName1}")
345 set(mytestlabel ${testlabel} "lyx2lyx" "load")
346 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
348 add_test(NAME ${TestName}
349 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
350 COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
351 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
352 -Dlyx=$<TARGET_FILE:${_lyx}>
353 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
354 -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
355 -Dformat=lyx${_lyx_format_num}x
356 -Dextension=${_lyx_format_num}.lyx
357 -DLYX_FORMAT_NUM=${_lyx_format_num}
359 -Dinverted=${inverted}
360 -DTOP_SRC_DIR=${TOP_SRC_DIR}
361 -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
362 -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
363 setmarkedtestlabel(${TestName} ${mytestlabel})
366 if(LYX_PYTHON_EXECUTABLE)
367 set(lyx2lyxtestlabel "lyx2lyx")
368 # For use of lyx2lyx we need the python executable
369 set(mytestlabel ${lyx2lyxtestlabel})
370 set(TestName1 "lyx2lyx/${libsubfolder}/${f}")
371 string(REGEX REPLACE "[\\(\\)]" "_" TestName "${TestName1}")
372 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
374 add_test(NAME ${TestName}
375 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
376 COMMAND ${CMAKE_COMMAND}
377 "-DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE}"
378 "-DLYX2LYX=${TOP_SRC_DIR}/lib/lyx2lyx/lyx2lyx"
379 "-DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}"
380 "-DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx"
381 -P "${TOP_SRC_DIR}/development/autotests/lyx2lyxtest.cmake")
382 setmarkedtestlabel(${TestName} ${mytestlabel})
385 set(loadtestlabel "load")
386 set(mytestlabel ${loadtestlabel})
387 set(TestName1 "check_load/${libsubfolder}/${f}")
388 string(REGEX REPLACE "[\\(\\)]" "_" TestName "${TestName1}")
389 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
391 add_test(NAME ${TestName}
392 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
393 COMMAND ${CMAKE_COMMAND} -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
394 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
395 -Dlyx=$<TARGET_FILE:${_lyx}>
396 -DPARAMS_DIR=${TOP_SRC_DIR}/development/autotests
397 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
398 -Dinverted=${inverted}
399 -P "${TOP_SRC_DIR}/development/autotests/check_load.cmake")
400 setmarkedtestlabel(${TestName} ${mytestlabel})
401 #set_tests_properties(${TestName} PROPERTIES RUN_SERIAL ON)
403 set(default_output_format)
404 getoutputformats("${LIBSUB_SRC_DIR}/${f}.lyx" formatlist default_output_format)
405 foreach(format ${formatlist})
406 if(format MATCHES "dvi3|pdf4|pdf5")
407 set(fonttypes "texF" "systemF")
409 set(fonttypes "defaultF")
411 foreach(fonttype ${fonttypes})
412 if (format MATCHES "pdf2" AND f MATCHES "latex/unicodesymbols")
413 #message(STATUS "Test ${TestName} matches Unicode encodings")
414 # test_encodings does not include "default", since it should be covered
415 # by one of the supplied encodings
416 set(test_encodings "ascii" "utf8" "utf8x" "armscii8" "applemac"
417 "cp437" "cp437de" "cp850" "cp852"
418 "cp855" "cp862" "cp865"
419 "cp866" "cp1250" "cp1251" "cp1252"
420 "cp1255" "cp1256" "cp1257"
422 "iso8859-1" "iso8859-2" "iso8859-3"
423 "iso8859-4" "iso8859-5" "iso8859-6"
424 "iso8859-7" "iso8859-8" "iso8859-9"
425 "iso8859-13" "iso8859-15" "iso8859-16"
426 "pt154" "big5" "shift-jis"
427 "euc-cn" "gbk" "jis" "euc-kr"
428 "utf8-cjk" "euc-tw" "euc-jp"
429 "euc-jp-platex" "jis-platex"
430 "shift-jis-platex" "utf8-platex"
433 set(test_encodings "default")
435 foreach (_enc2 ${test_encodings})
436 if ("${_enc2}" STREQUAL "default")
439 set(_enc "_${_enc2}")
441 if(fonttype MATCHES "defaultF")
442 set(TestName1 "export/${libsubfolder}/${f}${_enc}_${format}")
444 set(TestName1 "export/${libsubfolder}/${f}${_enc}_${format}_${fonttype}")
446 if (format MATCHES "^${default_output_format}$")
447 set(extraLabels "defaultoutput")
452 findexpr(mfound TestName1 ignoreLatexErrorsTests missingLabels)
454 set(mytestlabel ${testlabel} "ignoring" ${missingLabels} ${extraLabels})
456 set(mytestlabel ${testlabel} ${extraLabels})
458 string(REGEX REPLACE "[\\(\\)]" "_" TestName "${TestName1}")
459 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
460 if (format MATCHES "docbook5")
461 set(f_extension "xml")
463 set(f_extension ${format})
466 add_test(NAME ${TestName}
467 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
468 COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
469 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
470 -Dlyx=$<TARGET_FILE:${_lyx}>
471 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
473 -Dfonttype=${fonttype}
474 -Dextension=${f_extension}
476 -Dinverted=${inverted}
477 -DTOP_SRC_DIR=${TOP_SRC_DIR}
478 "-DIgnoreErrorMessage=${missingLabels}"
479 -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
480 -DXMLLINT_EXECUTABLE=${XMLLINT_EXECUTABLE}
481 -DJAVA_EXECUTABLE=${jingjava}
483 -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
484 setmarkedtestlabel(${TestName} ${mytestlabel}) # check for suspended pdf/dvi exports