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
173 findexpr(mfound ${testname} ${listinvertedx} sublabel2)
179 findexpr(foundsuspended ${testname} ${listsuspendedx} sublabel3)
182 set(sublabel "suspended" ${sublabel} ${sublabel2} ${sublabel3})
183 list(REMOVE_ITEM sublabel "export" "inverted" )
185 set(sublabel "inverted" ${sublabel} ${sublabel2} ${sublabel3})
190 list(REMOVE_DUPLICATES sublabel)
191 if (NOT sublabel STREQUAL "")
192 join(sublabel "." tmpprefixx)
194 string(TOUPPER "${tmpprefixx}_" tmpprefix)
198 set(${testname} "${tmpprefix}${${testname}}")
199 set(${listlabels} ${sublabel})
202 # No testname because ignored
207 macro(loadTestList filename resList depth splitlangs)
208 # Create list of strings from a file without comments
209 # ENCODING parameter is a new feature in cmake 3.1
210 initLangVars(${resList})
211 initLangVars("sublabel")
212 if (CMAKE_VERSION VERSION_GREATER "3.1")
213 file(STRINGS ${filename} tempList ENCODING "UTF-8")
215 file(STRINGS ${filename} tempList)
221 message(STATUS "Reading list ${filename}")
222 foreach(_l ${tempList})
224 string(REGEX REPLACE "[ \t]+$" "" _newl "${_l}")
225 string(REGEX REPLACE "[ \t]*#.*$" "" _newl "${_l}")
227 list(APPEND ${resList} "${_newl}")
228 if (_newl MATCHES "^Sublabel:")
229 string(REGEX REPLACE "^Sublabel:[ \t]*" "" _newlabels ${_newl})
230 string(REGEX MATCHALL "([0-9]*${label_chars})" _labels ${_newlabels})
231 foreach(labname ${_labels})
232 if (NOT labname STREQUAL "RESET")
233 list(APPEND mylabels ${labname})
236 list(REMOVE_DUPLICATES mylabels)
237 set(sublabel ${_newl})
239 if (${splitlangs} MATCHES "ON")
240 string(REGEX REPLACE "(\\/|\\||\\(|\\))" " " _vxx ${_newl})
241 string(REGEX MATCHALL " ([a-z][a-z](_[A-Z][A-Z])?) " _vx ${_vxx})
247 string(REGEX REPLACE " " "" _v ${_v})
248 #message(STATUS " ==> ${resList}_${_v}")
249 #message(STATUS "sublabel = ${sublabel}, sublabel_${_v} = ${sublabel_${_v}}")
250 if (NOT sublabel STREQUAL "${sublabel_${_v}}")
251 list(APPEND ${resList}_${_v} "${sublabel}")
252 set(sublabel_${_v} "${sublabel}")
253 #message(STATUS "Setting variable sublabel_${_v} with \"${sublabel}\"")
255 list(APPEND ${resList}_${_v} "${_newl}")
256 list(APPEND languages ${_v})
258 list(REMOVE_DUPLICATES languages)
259 #message(STATUS "languages = ${languages}")
264 foreach(_l1 ${mylabels})
265 if (_l1 MATCHES "^([0-9]+)(${label_chars})$")
266 set(_l ${CMAKE_MATCH_2})
267 set(depth1 ${CMAKE_MATCH_1})
272 list(FIND known_labels ${_l} _ff)
274 message(STATUS "Label \"${_l}\" already in use. Reused in ${filename}")
276 assignLabelDepth(${depth}${depth1} ${_l})
279 foreach(_lg ${languages})
280 # reset label for each used language string at end of file
281 #message(STATUS "Resetting variable sublabel_${_lg}, previously set to ${sublabel_${_lg}}")
282 set(sublabel_${_lg} "")
286 # This labels should not be used in .*Tests files
288 # Create depth info to each label
289 macro(assignLabelDepth depth)
290 foreach(_lab ${ARGN})
291 list(APPEND known_labels ${_lab})
292 set(depth_${_lab} ${depth})
296 assignLabelDepth(0 "export" "key" "layout" "load" "lyx2lyx" "module" "roundtrip" "url")
297 assignLabelDepth(1 "unreliable" "inverted")
298 assignLabelDepth(2 "suspended")
299 assignLabelDepth(-1 "examples" "manuals" "mathmacros" "templates" "tabletemplates" "autotests")
301 loadTestList(invertedTests invertedTests 7 ON)
302 loadTestList(ignoredTests ignoredTests 0 ON)
303 loadTestList(suspendedTests suspendedTests 6 ON)
304 loadTestList(unreliableTests unreliableTests 5 ON)
305 loadTestList(ignoreLatexErrorsTests ignoreLatexErrorsTests 8 OFF)
307 foreach(libsubfolderx autotests/export lib/doc lib/examples lib/templates lib/tabletemplates autotests/mathmacros)
308 set(testlabel "export")
309 if (libsubfolderx MATCHES "lib/doc")
310 list(APPEND testlabel "manuals")
311 elseif (libsubfolderx MATCHES "lib/examples")
312 list(APPEND testlabel "examples")
313 elseif (libsubfolderx MATCHES "lib/templates")
314 list(APPEND testlabel "templates")
315 elseif (libsubfolderx MATCHES "lib/tabletemplates")
316 list(APPEND testlabel "tabletemplates")
317 elseif (libsubfolderx MATCHES "autotests/mathmacros")
318 list(APPEND testlabel "mathmacros")
319 elseif (libsubfolderx MATCHES "autotests/.+")
320 list(APPEND testlabel "autotests")
322 set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
323 string(REGEX REPLACE "^(lib|development|autotests)/" "" libsubfolder "${libsubfolderx}")
324 set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
325 message(STATUS "Handling export dir ${LIBSUB_SRC_DIR}")
326 file(GLOB_RECURSE lyx_files RELATIVE "${LIBSUB_SRC_DIR}" "${LIBSUB_SRC_DIR}/*.lyx")
328 # Now create 2 lists. One for files in a language dir, one without
330 set(nolang_lyx_files)
331 foreach(f ${lyx_files})
332 if (${f} MATCHES "#")
333 # Do nothing, probably wrong temporary file
335 string(REGEX MATCHALL "^[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${f})
337 list(APPEND lang_lyx_files ${f})
339 list(APPEND nolang_lyx_files ${f})
343 foreach(f ${nolang_lyx_files} ${lang_lyx_files})
345 string(REGEX REPLACE "\\.lyx$" "" f ${f})
346 foreach(_lyx_format_num 16 20 21 22 23)
347 set(TestName1 "export/${libsubfolder}/${f}_lyx${_lyx_format_num}")
348 string(REGEX REPLACE "[\\(\\)]" "_" TestName "${TestName1}")
349 set(mytestlabel ${testlabel} "lyx2lyx" "load")
350 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
352 add_test(NAME ${TestName}
353 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
354 COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
355 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
356 -Dlyx=$<TARGET_FILE:${_lyx}>
357 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
358 -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
359 -Dformat=lyx${_lyx_format_num}x
360 -Dextension=${_lyx_format_num}.lyx
361 -DLYX_FORMAT_NUM=${_lyx_format_num}
363 -Dinverted=${inverted}
364 -DTOP_SRC_DIR=${TOP_SRC_DIR}
365 -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
366 -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
367 setmarkedtestlabel(${TestName} ${mytestlabel})
370 if(LYX_PYTHON_EXECUTABLE)
371 set(lyx2lyxtestlabel "lyx2lyx")
372 # For use of lyx2lyx we need the python executable
373 set(mytestlabel ${lyx2lyxtestlabel})
374 set(TestName1 "lyx2lyx/${libsubfolder}/${f}")
375 string(REGEX REPLACE "[\\(\\)]" "_" TestName "${TestName1}")
376 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
378 add_test(NAME ${TestName}
379 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
380 COMMAND ${CMAKE_COMMAND}
381 "-DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE}"
382 "-DLYX2LYX=${TOP_SRC_DIR}/lib/lyx2lyx/lyx2lyx"
383 "-DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}"
384 "-DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx"
385 -P "${TOP_SRC_DIR}/development/autotests/lyx2lyxtest.cmake")
386 setmarkedtestlabel(${TestName} ${mytestlabel})
389 set(loadtestlabel "load")
390 set(mytestlabel ${loadtestlabel})
391 set(TestName1 "check_load/${libsubfolder}/${f}")
392 string(REGEX REPLACE "[\\(\\)]" "_" TestName "${TestName1}")
393 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
395 add_test(NAME ${TestName}
396 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
397 COMMAND ${CMAKE_COMMAND} -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
398 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
399 -Dlyx=$<TARGET_FILE:${_lyx}>
400 -DPARAMS_DIR=${TOP_SRC_DIR}/development/autotests
401 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
402 -Dinverted=${inverted}
403 -P "${TOP_SRC_DIR}/development/autotests/check_load.cmake")
404 setmarkedtestlabel(${TestName} ${mytestlabel})
405 #set_tests_properties(${TestName} PROPERTIES RUN_SERIAL ON)
407 set(default_output_format)
408 getoutputformats("${LIBSUB_SRC_DIR}/${f}.lyx" formatlist default_output_format)
409 foreach(format ${formatlist})
410 if(format MATCHES "dvi3|pdf4|pdf5")
411 set(fonttypes "texF" "systemF")
413 set(fonttypes "defaultF")
415 foreach(fonttype ${fonttypes})
416 if (format MATCHES "pdf2" AND f MATCHES "latex/unicodesymbols")
417 #message(STATUS "Test ${TestName} matches Unicode encodings")
418 # test_encodings does not include "default", since it should be covered
419 # by one of the supplied encodings
420 set(test_encodings "ascii" "utf8" "utf8x" "armscii8" "applemac"
421 "cp437" "cp437de" "cp850" "cp852"
422 "cp855" "cp862" "cp865"
423 "cp866" "cp1250" "cp1251" "cp1252"
424 "cp1255" "cp1256" "cp1257"
426 "iso8859-1" "iso8859-2" "iso8859-3"
427 "iso8859-4" "iso8859-5" "iso8859-6"
428 "iso8859-7" "iso8859-8" "iso8859-9"
429 "iso8859-13" "iso8859-15" "iso8859-16"
430 "pt154" "big5" "shift-jis"
431 "euc-cn" "gbk" "jis" "euc-kr"
432 "utf8-cjk" "euc-tw" "euc-jp"
433 "euc-jp-platex" "jis-platex"
434 "shift-jis-platex" "utf8-platex"
437 set(test_encodings "default")
439 foreach (_enc2 ${test_encodings})
440 if ("${_enc2}" STREQUAL "default")
443 set(_enc "_${_enc2}")
445 if(fonttype MATCHES "defaultF")
446 set(TestName1 "export/${libsubfolder}/${f}${_enc}_${format}")
448 set(TestName1 "export/${libsubfolder}/${f}${_enc}_${format}_${fonttype}")
450 if (format MATCHES "^${default_output_format}$")
451 set(extraLabels "defaultoutput")
456 findexpr(mfound TestName1 ignoreLatexErrorsTests missingLabels)
458 set(mytestlabel ${testlabel} "ignoring" ${missingLabels} ${extraLabels})
460 set(mytestlabel ${testlabel} ${extraLabels})
462 string(REGEX REPLACE "[\\(\\)]" "_" TestName "${TestName1}")
463 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
464 if (format MATCHES "docbook5")
465 set(f_extension "xml")
467 set(f_extension ${format})
470 add_test(NAME ${TestName}
471 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
472 COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
473 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
474 -Dlyx=$<TARGET_FILE:${_lyx}>
475 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
477 -Dfonttype=${fonttype}
478 -Dextension=${f_extension}
480 -Dinverted=${inverted}
481 -DTOP_SRC_DIR=${TOP_SRC_DIR}
482 "-DIgnoreErrorMessage=${missingLabels}"
483 -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
484 -DXMLLINT_EXECUTABLE=${XMLLINT_EXECUTABLE}
485 -DJAVA_EXECUTABLE=${jingjava}
487 -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
488 setmarkedtestlabel(${TestName} ${mytestlabel}) # check for suspended pdf/dvi exports