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)
163 MATH(EXPR lyx_ignored_count "${lyx_ignored_count}+1")
164 # No testname because ignored
168 findexpr(foundunreliable ${testname} ${listunreliablex} sublabel2)
170 set(sublabel "unreliable" ${sublabel} ${sublabel2})
171 list(REMOVE_ITEM sublabel "export" "inverted" "templates" "tabletemplates" "mathmacros" "manuals" "autotests")
173 string(REGEX MATCH "(^check_load|_(systemF|texF|pdf3|pdf2|pdf|dvi|lyx[0-9][0-9]|xhtml)$)" _v ${${testname}})
174 # check if test _may_ be in listinverted
176 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})
204 macro(loadTestList filename resList depth splitlangs)
205 # Create list of strings from a file without comments
206 # ENCODING parameter is a new feature in cmake 3.1
207 initLangVars(${resList})
208 initLangVars("sublabel")
209 if (CMAKE_VERSION VERSION_GREATER "3.1")
210 file(STRINGS ${filename} tempList ENCODING "UTF-8")
212 file(STRINGS ${filename} tempList)
218 message(STATUS "Reading list ${filename}")
219 foreach(_l ${tempList})
221 string(REGEX REPLACE "[ \t]+$" "" _newl "${_l}")
222 string(REGEX REPLACE "[ \t]*#.*$" "" _newl "${_l}")
224 list(APPEND ${resList} "${_newl}")
225 if (_newl MATCHES "^Sublabel:")
226 string(REGEX REPLACE "^Sublabel:[ \t]*" "" _newlabels ${_newl})
227 string(REGEX MATCHALL "([0-9]*${label_chars})" _labels ${_newlabels})
228 foreach(labname ${_labels})
229 if (NOT labname STREQUAL "RESET")
230 list(APPEND mylabels ${labname})
233 list(REMOVE_DUPLICATES mylabels)
234 set(sublabel ${_newl})
236 if (${splitlangs} MATCHES "ON")
237 string(REGEX REPLACE "(\\/|\\||\\(|\\))" " " _vxx ${_newl})
238 string(REGEX MATCHALL " ([a-z][a-z](_[A-Z][A-Z])?) " _vx ${_vxx})
244 string(REGEX REPLACE " " "" _v ${_v})
245 #message(STATUS " ==> ${resList}_${_v}")
246 #message(STATUS "sublabel = ${sublabel}, sublabel_${_v} = ${sublabel_${_v}}")
247 if (NOT sublabel STREQUAL "${sublabel_${_v}}")
248 list(APPEND ${resList}_${_v} "${sublabel}")
249 set(sublabel_${_v} "${sublabel}")
250 #message(STATUS "Setting variable sublabel_${_v} with \"${sublabel}\"")
252 list(APPEND ${resList}_${_v} "${_newl}")
253 list(APPEND languages ${_v})
255 list(REMOVE_DUPLICATES languages)
256 #message(STATUS "languages = ${languages}")
261 foreach(_l1 ${mylabels})
262 if (_l1 MATCHES "^([0-9]+)(${label_chars})$")
263 set(_l ${CMAKE_MATCH_2})
264 set(depth1 ${CMAKE_MATCH_1})
269 list(FIND known_labels ${_l} _ff)
271 message(STATUS "Label \"${_l}\" already in use. Reused in ${filename}")
273 assignLabelDepth(${depth}${depth1} ${_l})
276 foreach(_lg ${languages})
277 # reset label for each used language string at end of file
278 #message(STATUS "Resetting variable sublabel_${_lg}, previously set to ${sublabel_${_lg}}")
279 set(sublabel_${_lg} "")
283 # This labels should not be used in .*Tests files
285 # Create depth info to each label
286 macro(assignLabelDepth depth)
287 foreach(_lab ${ARGN})
288 list(APPEND known_labels ${_lab})
289 set(depth_${_lab} ${depth})
293 assignLabelDepth(0 "export" "key" "layout" "load" "lyx2lyx" "module" "roundtrip" "url")
294 assignLabelDepth(1 "unreliable" "inverted")
295 assignLabelDepth(2 "suspended")
296 assignLabelDepth(-1 "examples" "manuals" "mathmacros" "templates" "tabletemplates" "autotests")
298 loadTestList(invertedTests invertedTests 7 ON)
299 loadTestList(ignoredTests ignoredTests 0 ON)
300 loadTestList(suspendedTests suspendedTests 6 ON)
301 loadTestList(unreliableTests unreliableTests 5 ON)
302 loadTestList(ignoreLatexErrorsTests ignoreLatexErrorsTests 8 OFF)
304 foreach(libsubfolderx autotests/export lib/doc lib/examples lib/templates lib/tabletemplates autotests/mathmacros)
305 set(testlabel "export")
306 if (libsubfolderx MATCHES "lib/doc")
307 list(APPEND testlabel "manuals")
308 elseif (libsubfolderx MATCHES "lib/examples")
309 list(APPEND testlabel "examples")
310 elseif (libsubfolderx MATCHES "lib/templates")
311 list(APPEND testlabel "templates")
312 elseif (libsubfolderx MATCHES "lib/tabletemplates")
313 list(APPEND testlabel "tabletemplates")
314 elseif (libsubfolderx MATCHES "autotests/mathmacros")
315 list(APPEND testlabel "mathmacros")
316 elseif (libsubfolderx MATCHES "autotests/.+")
317 list(APPEND testlabel "autotests")
319 set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
320 string(REGEX REPLACE "^(lib|development|autotests)/" "" libsubfolder "${libsubfolderx}")
321 set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
322 message(STATUS "Handling export dir ${LIBSUB_SRC_DIR}")
323 file(GLOB_RECURSE lyx_files RELATIVE "${LIBSUB_SRC_DIR}" "${LIBSUB_SRC_DIR}/*.lyx")
325 # Now create 2 lists. One for files in a language dir, one without
327 set(nolang_lyx_files)
328 foreach(f ${lyx_files})
329 if (${f} MATCHES "#")
330 # Do nothing, probably wrong temporary file
332 string(REGEX MATCHALL "^[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${f})
334 list(APPEND lang_lyx_files ${f})
336 list(APPEND nolang_lyx_files ${f})
340 foreach(f ${nolang_lyx_files} ${lang_lyx_files})
342 string(REGEX REPLACE "\\.lyx$" "" f ${f})
343 foreach(_lyx_format_num 16 20 21 22 23)
344 set(TestName1 "export/${libsubfolder}/${f}_lyx${_lyx_format_num}")
345 string(REGEX REPLACE "[\\(\\)]" "_" TestName "${TestName1}")
346 set(mytestlabel ${testlabel} "lyx2lyx" "load")
347 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
349 add_test(NAME ${TestName}
350 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
351 COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
352 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
353 -Dlyx=$<TARGET_FILE:${_lyx}>
354 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
355 -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
356 -Dformat=lyx${_lyx_format_num}x
357 -Dextension=${_lyx_format_num}.lyx
358 -DLYX_FORMAT_NUM=${_lyx_format_num}
360 -Dinverted=${inverted}
361 -DTOP_SRC_DIR=${TOP_SRC_DIR}
362 -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
363 -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
364 setmarkedtestlabel(${TestName} ${mytestlabel})
367 if(LYX_PYTHON_EXECUTABLE)
368 set(lyx2lyxtestlabel "lyx2lyx")
369 # For use of lyx2lyx we need the python executable
370 set(mytestlabel ${lyx2lyxtestlabel})
371 set(TestName1 "lyx2lyx/${libsubfolder}/${f}")
372 string(REGEX REPLACE "[\\(\\)]" "_" TestName "${TestName1}")
373 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
375 add_test(NAME ${TestName}
376 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
377 COMMAND ${CMAKE_COMMAND}
378 "-DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE}"
379 "-DLYX2LYX=${TOP_SRC_DIR}/lib/lyx2lyx/lyx2lyx"
380 "-DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}"
381 "-DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx"
382 -P "${TOP_SRC_DIR}/development/autotests/lyx2lyxtest.cmake")
383 setmarkedtestlabel(${TestName} ${mytestlabel})
386 set(loadtestlabel "load")
387 set(mytestlabel ${loadtestlabel})
388 set(TestName1 "check_load/${libsubfolder}/${f}")
389 string(REGEX REPLACE "[\\(\\)]" "_" TestName "${TestName1}")
390 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
392 add_test(NAME ${TestName}
393 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
394 COMMAND ${CMAKE_COMMAND} -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
395 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
396 -Dlyx=$<TARGET_FILE:${_lyx}>
397 -DPARAMS_DIR=${TOP_SRC_DIR}/development/autotests
398 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
399 -Dinverted=${inverted}
400 -P "${TOP_SRC_DIR}/development/autotests/check_load.cmake")
401 setmarkedtestlabel(${TestName} ${mytestlabel})
402 #set_tests_properties(${TestName} PROPERTIES RUN_SERIAL ON)
404 set(default_output_format)
405 getoutputformats("${LIBSUB_SRC_DIR}/${f}.lyx" formatlist default_output_format)
406 foreach(format ${formatlist})
407 if(format MATCHES "dvi3|pdf4|pdf5")
408 set(fonttypes "texF" "systemF")
410 set(fonttypes "defaultF")
412 foreach(fonttype ${fonttypes})
413 if (format MATCHES "pdf2" AND f MATCHES "latex/unicodesymbols")
414 #message(STATUS "Test ${TestName} matches Unicode encodings")
415 # test_encodings does not include "default", since it should be covered
416 # by one of the supplied encodings
417 set(test_encodings "ascii" "utf8" "utf8x" "armscii8" "applemac"
418 "cp437" "cp437de" "cp850" "cp852"
419 "cp855" "cp862" "cp865"
420 "cp866" "cp1250" "cp1251" "cp1252"
421 "cp1255" "cp1256" "cp1257"
423 "iso8859-1" "iso8859-2" "iso8859-3"
424 "iso8859-4" "iso8859-5" "iso8859-6"
425 "iso8859-7" "iso8859-8" "iso8859-9"
426 "iso8859-13" "iso8859-15" "iso8859-16"
427 "pt154" "big5" "shift-jis"
428 "euc-cn" "gbk" "jis" "euc-kr"
429 "utf8-cjk" "euc-tw" "euc-jp"
430 "euc-jp-platex" "jis-platex"
431 "shift-jis-platex" "utf8-platex"
434 set(test_encodings "default")
436 foreach (_enc2 ${test_encodings})
437 if ("${_enc2}" STREQUAL "default")
440 set(_enc "_${_enc2}")
442 if(fonttype MATCHES "defaultF")
443 set(TestName1 "export/${libsubfolder}/${f}${_enc}_${format}")
445 set(TestName1 "export/${libsubfolder}/${f}${_enc}_${format}_${fonttype}")
447 if (format MATCHES "^${default_output_format}$")
448 set(extraLabels "defaultoutput")
453 findexpr(mfound TestName1 ignoreLatexErrorsTests missingLabels)
455 set(mytestlabel ${testlabel} "ignoring" ${missingLabels} ${extraLabels})
457 set(mytestlabel ${testlabel} ${extraLabels})
459 string(REGEX REPLACE "[\\(\\)]" "_" TestName "${TestName1}")
460 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
461 if (format MATCHES "docbook5")
462 set(f_extension "xml")
464 set(f_extension ${format})
467 add_test(NAME ${TestName}
468 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
469 COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
470 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
471 -Dlyx=$<TARGET_FILE:${_lyx}>
472 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
474 -Dfonttype=${fonttype}
475 -Dextension=${f_extension}
477 -Dinverted=${inverted}
478 -DTOP_SRC_DIR=${TOP_SRC_DIR}
479 "-DIgnoreErrorMessage=${missingLabels}"
480 -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
481 -DXMLLINT_EXECUTABLE=${XMLLINT_EXECUTABLE}
482 -DJAVA_EXECUTABLE=${jingjava}
484 -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
485 setmarkedtestlabel(${TestName} ${mytestlabel}) # check for suspended pdf/dvi exports