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" "epub" ${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" "epub" ${DVI_FORMATS} ${PDF_FORMATS})
69 set(${format_set} ${_format})
70 if(_format STREQUAL "pdf2" AND "${filepath}" MATCHES "/doc/")
71 set(out_formats "xhtml" "docbook5" "epub" ${DVI_FORMATS} ${PDF_FORMATS})
72 elseif(_format MATCHES "pdf$")
73 set(out_formats "xhtml" "docbook5" "epub" ${PDF_FORMATS})
74 elseif(_format MATCHES "dvi$")
75 set(out_formats "xhtml" "docbook5" "epub" ${DVI_FORMATS})
76 elseif(_format MATCHES "docbook5")
77 set(out_formats "docbook5")
78 elseif(_format MATCHES "xhtml")
79 set(out_formats "xhtml")
80 elseif(_format MATCHES "epub")
81 set(out_formats "epub")
83 # Respect all other output formats
85 set(out_formats "xhtml" ${_format})
91 set(${varname} ${out_formats})
94 macro(findexpr found testname listname rsublabel)
97 foreach(_itrx ${${listname}})
98 if ("${_itrx}" MATCHES "^Sublabel:")
100 string(REGEX REPLACE "^Sublabel:[ \t]*" "" _itrlabels ${_itrx})
101 string(REGEX MATCHALL ${label_chars} _labels ${_itrlabels})
102 foreach(subl ${_labels})
103 if (subl STREQUAL "RESET")
106 list(APPEND tmpsublabel ${subl})
109 # remove doubles in sublabel
110 list(REMOVE_DUPLICATES tmpsublabel)
112 if (_itrx MATCHES "^!\(.*\)$")
113 set(_itr "^${CMAKE_MATCH_1}$")
116 set(_itr "^${_itrx}$")
119 if (${testname} MATCHES "${_itr}")
120 set(_found ${_foundval})
126 if (NOT "${tmpsublabel}" STREQUAL "")
127 list(APPEND ${rsublabel} ${tmpsublabel})
130 set(${found} ${_found})
133 function(join rvalues glue routput)
134 set(locallist ${${rvalues}})
135 set(removelist "export" "lyx2lyx" "load")
136 foreach(_l ${locallist})
137 if (depth_${_l} LESS 0)
138 list(APPEND removelist ${_l})
141 list(REMOVE_ITEM locallist ${removelist})
142 string(REGEX REPLACE "([^\\]|^);" "\\1${glue}" out "${locallist}")
143 set(${routput} ${out} PARENT_SCOPE)
146 macro(maketestname testname inverted listinverted listignored listunreliable listlabels)
147 # initialize output variable
149 string(REGEX MATCH "\\/[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${${testname}})
151 string(REGEX REPLACE "\\/" "" _v ${_v})
152 set(listinvertedx ${listinverted}_${_v})
153 set(listignoredx ${listignored}_${_v})
154 set(listunreliablex ${listunreliable}_${_v})
155 set(listsuspendedx suspendedTests_${_v})
157 set(listinvertedx ${listinverted})
158 set(listignoredx ${listignored})
159 set(listunreliablex ${listunreliable})
160 set(listsuspendedx suspendedTests)
162 set(sublabel "${${listlabels}}")
163 findexpr(mfound ${testname} ${listignoredx} sublabel)
165 MATH(EXPR lyx_ignored_count "${lyx_ignored_count}+1")
166 # No testname because ignored
170 findexpr(foundunreliable ${testname} ${listunreliablex} sublabel2)
172 set(sublabel "unreliable" ${sublabel} ${sublabel2})
173 list(REMOVE_ITEM sublabel "export" "inverted" "templates" "tabletemplates" "mathmacros" "manuals" "autotests")
175 string(REGEX MATCH "(^check_load|_(systemF|texF|pdf3|pdf2|pdf|dvi|lyx[0-9][0-9]|xhtml)$)" _v ${${testname}})
176 # check if test _may_ be in listinverted
178 findexpr(mfound ${testname} ${listinvertedx} sublabel2)
181 findexpr(foundsuspended ${testname} ${listsuspendedx} sublabel3)
184 set(sublabel "suspended" ${sublabel} ${sublabel2} ${sublabel3})
185 list(REMOVE_ITEM sublabel "export" "inverted" )
187 set(sublabel "inverted" ${sublabel} ${sublabel2} ${sublabel3})
192 list(REMOVE_DUPLICATES sublabel)
193 if (NOT sublabel STREQUAL "")
194 join(sublabel "." tmpprefixx)
196 string(TOUPPER "${tmpprefixx}_" tmpprefix)
200 set(${testname} "${tmpprefix}${${testname}}")
201 set(${listlabels} ${sublabel})
206 macro(loadTestList filename resList depth splitlangs)
207 # Create list of strings from a file without comments
208 # ENCODING parameter is a new feature in cmake 3.1
209 initLangVars(${resList})
210 initLangVars("sublabel")
211 if (CMAKE_VERSION VERSION_GREATER "3.1")
212 file(STRINGS ${filename} tempList ENCODING "UTF-8")
214 file(STRINGS ${filename} tempList)
220 message(STATUS "Reading list ${filename}")
221 foreach(_l ${tempList})
223 string(REGEX REPLACE "[ \t]+$" "" _newl "${_l}")
224 string(REGEX REPLACE "[ \t]*#.*$" "" _newl "${_l}")
226 list(APPEND ${resList} "${_newl}")
227 if (_newl MATCHES "^Sublabel:")
228 string(REGEX REPLACE "^Sublabel:[ \t]*" "" _newlabels ${_newl})
229 string(REGEX MATCHALL "([0-9]*${label_chars})" _labels ${_newlabels})
230 foreach(labname ${_labels})
231 if (NOT labname STREQUAL "RESET")
232 list(APPEND mylabels ${labname})
235 list(REMOVE_DUPLICATES mylabels)
236 set(sublabel ${_newl})
238 if (${splitlangs} MATCHES "ON")
239 string(REGEX REPLACE "(\\/|\\||\\(|\\))" " " _vxx ${_newl})
240 string(REGEX MATCHALL " ([a-z][a-z](_[A-Z][A-Z])?) " _vx ${_vxx})
246 string(REGEX REPLACE " " "" _v ${_v})
247 #message(STATUS " ==> ${resList}_${_v}")
248 #message(STATUS "sublabel = ${sublabel}, sublabel_${_v} = ${sublabel_${_v}}")
249 if (NOT sublabel STREQUAL "${sublabel_${_v}}")
250 list(APPEND ${resList}_${_v} "${sublabel}")
251 set(sublabel_${_v} "${sublabel}")
252 #message(STATUS "Setting variable sublabel_${_v} with \"${sublabel}\"")
254 list(APPEND ${resList}_${_v} "${_newl}")
255 list(APPEND languages ${_v})
257 list(REMOVE_DUPLICATES languages)
258 #message(STATUS "languages = ${languages}")
263 foreach(_l1 ${mylabels})
264 if (_l1 MATCHES "^([0-9]+)(${label_chars})$")
265 set(_l ${CMAKE_MATCH_2})
266 set(depth1 ${CMAKE_MATCH_1})
271 list(FIND known_labels ${_l} _ff)
273 message(STATUS "Label \"${_l}\" already in use. Reused in ${filename}")
275 assignLabelDepth(${depth}${depth1} ${_l})
278 foreach(_lg ${languages})
279 # reset label for each used language string at end of file
280 #message(STATUS "Resetting variable sublabel_${_lg}, previously set to ${sublabel_${_lg}}")
281 set(sublabel_${_lg} "")
285 # This labels should not be used in .*Tests files
287 # Create depth info to each label
288 macro(assignLabelDepth depth)
289 foreach(_lab ${ARGN})
290 list(APPEND known_labels ${_lab})
291 set(depth_${_lab} ${depth})
295 assignLabelDepth(0 "export" "key" "layout" "load" "lyx2lyx" "module" "roundtrip" "url")
296 assignLabelDepth(1 "unreliable" "inverted")
297 assignLabelDepth(2 "suspended")
298 assignLabelDepth(-1 "examples" "manuals" "mathmacros" "templates" "tabletemplates" "autotests")
300 loadTestList(invertedTests invertedTests 7 ON)
301 loadTestList(ignoredTests ignoredTests 0 ON)
302 loadTestList(suspendedTests suspendedTests 6 ON)
303 loadTestList(unreliableTests unreliableTests 5 ON)
304 loadTestList(ignoreLatexErrorsTests ignoreLatexErrorsTests 8 OFF)
306 foreach(libsubfolderx autotests/export lib/doc lib/examples lib/templates lib/tabletemplates autotests/mathmacros)
307 set(testlabel "export")
308 if (libsubfolderx MATCHES "lib/doc")
309 list(APPEND testlabel "manuals")
310 elseif (libsubfolderx MATCHES "lib/examples")
311 list(APPEND testlabel "examples")
312 elseif (libsubfolderx MATCHES "lib/templates")
313 list(APPEND testlabel "templates")
314 elseif (libsubfolderx MATCHES "lib/tabletemplates")
315 list(APPEND testlabel "tabletemplates")
316 elseif (libsubfolderx MATCHES "autotests/mathmacros")
317 list(APPEND testlabel "mathmacros")
318 elseif (libsubfolderx MATCHES "autotests/.+")
319 list(APPEND testlabel "autotests")
321 set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
322 string(REGEX REPLACE "^(lib|development|autotests)/" "" libsubfolder "${libsubfolderx}")
323 set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
324 message(STATUS "Handling export dir ${LIBSUB_SRC_DIR}")
325 file(GLOB_RECURSE lyx_files RELATIVE "${LIBSUB_SRC_DIR}" "${LIBSUB_SRC_DIR}/*.lyx")
327 # Now create 2 lists. One for files in a language dir, one without
329 set(nolang_lyx_files)
330 foreach(f ${lyx_files})
331 if (${f} MATCHES "#")
332 # Do nothing, probably wrong temporary file
334 string(REGEX MATCHALL "^[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${f})
336 list(APPEND lang_lyx_files ${f})
338 list(APPEND nolang_lyx_files ${f})
342 foreach(f ${nolang_lyx_files} ${lang_lyx_files})
344 string(REGEX REPLACE "\\.lyx$" "" f ${f})
345 foreach(_lyx_format_num 16 20 21 22 23)
346 set(TestName1 "export/${libsubfolder}/${f}_lyx${_lyx_format_num}")
347 string(REGEX REPLACE "[\\(\\)]" "_" TestName "${TestName1}")
348 set(mytestlabel ${testlabel} "lyx2lyx" "load")
349 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
351 add_test(NAME ${TestName}
352 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
353 COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
354 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
355 -Dlyx=$<TARGET_FILE:${_lyx}>
356 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
357 -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
358 -Dformat=lyx${_lyx_format_num}x
359 -Dextension=${_lyx_format_num}.lyx
360 -DLYX_FORMAT_NUM=${_lyx_format_num}
362 -Dinverted=${inverted}
363 -DTOP_SRC_DIR=${TOP_SRC_DIR}
364 -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
365 -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
366 setmarkedtestlabel(${TestName} ${mytestlabel})
369 if(LYX_PYTHON_EXECUTABLE)
370 set(lyx2lyxtestlabel "lyx2lyx")
371 # For use of lyx2lyx we need the python executable
372 set(mytestlabel ${lyx2lyxtestlabel})
373 set(TestName1 "lyx2lyx/${libsubfolder}/${f}")
374 string(REGEX REPLACE "[\\(\\)]" "_" TestName "${TestName1}")
375 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
377 add_test(NAME ${TestName}
378 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
379 COMMAND ${CMAKE_COMMAND}
380 "-DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE}"
381 "-DLYX2LYX=${TOP_SRC_DIR}/lib/lyx2lyx/lyx2lyx"
382 "-DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}"
383 "-DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx"
384 -P "${TOP_SRC_DIR}/development/autotests/lyx2lyxtest.cmake")
385 setmarkedtestlabel(${TestName} ${mytestlabel})
388 set(loadtestlabel "load")
389 set(mytestlabel ${loadtestlabel})
390 set(TestName1 "check_load/${libsubfolder}/${f}")
391 string(REGEX REPLACE "[\\(\\)]" "_" TestName "${TestName1}")
392 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
394 add_test(NAME ${TestName}
395 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
396 COMMAND ${CMAKE_COMMAND} -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
397 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
398 -Dlyx=$<TARGET_FILE:${_lyx}>
399 -DPARAMS_DIR=${TOP_SRC_DIR}/development/autotests
400 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
401 -Dinverted=${inverted}
402 -P "${TOP_SRC_DIR}/development/autotests/check_load.cmake")
403 setmarkedtestlabel(${TestName} ${mytestlabel})
404 #set_tests_properties(${TestName} PROPERTIES RUN_SERIAL ON)
406 set(default_output_format)
407 getoutputformats("${LIBSUB_SRC_DIR}/${f}.lyx" formatlist default_output_format)
408 foreach(format ${formatlist})
409 if(format MATCHES "dvi3|pdf4|pdf5")
410 set(fonttypes "texF" "systemF")
412 set(fonttypes "defaultF")
414 foreach(fonttype ${fonttypes})
415 if (format MATCHES "pdf2" AND f MATCHES "latex/unicodesymbols")
416 #message(STATUS "Test ${TestName} matches Unicode encodings")
417 # test_encodings does not include "default", since it should be covered
418 # by one of the supplied encodings
419 set(test_encodings "ascii" "utf8" "utf8x" "armscii8" "applemac"
420 "cp437" "cp437de" "cp850" "cp852"
421 "cp855" "cp862" "cp865"
422 "cp866" "cp1250" "cp1251" "cp1252"
423 "cp1255" "cp1256" "cp1257"
425 "iso8859-1" "iso8859-2" "iso8859-3"
426 "iso8859-4" "iso8859-5" "iso8859-6"
427 "iso8859-7" "iso8859-8" "iso8859-9"
428 "iso8859-13" "iso8859-15" "iso8859-16"
429 "pt154" "big5" "shift-jis"
430 "euc-cn" "gbk" "jis" "euc-kr"
431 "utf8-cjk" "euc-tw" "euc-jp"
432 "euc-jp-platex" "jis-platex"
433 "shift-jis-platex" "utf8-platex"
436 set(test_encodings "default")
438 foreach (_enc2 ${test_encodings})
439 if ("${_enc2}" STREQUAL "default")
442 set(_enc "_${_enc2}")
444 if(fonttype MATCHES "defaultF")
445 set(TestName1 "export/${libsubfolder}/${f}${_enc}_${format}")
447 set(TestName1 "export/${libsubfolder}/${f}${_enc}_${format}_${fonttype}")
449 if (format MATCHES "^${default_output_format}$")
450 set(extraLabels "defaultoutput")
455 findexpr(mfound TestName1 ignoreLatexErrorsTests missingLabels)
457 set(mytestlabel ${testlabel} "ignoring" ${missingLabels} ${extraLabels})
459 set(mytestlabel ${testlabel} ${extraLabels})
461 string(REGEX REPLACE "[\\(\\)]" "_" TestName "${TestName1}")
462 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
463 if (format MATCHES "docbook5")
464 set(f_extension "xml")
466 set(f_extension ${format})
469 add_test(NAME ${TestName}
470 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
471 COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
472 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
473 -Dlyx=$<TARGET_FILE:${_lyx}>
474 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
476 -Dfonttype=${fonttype}
477 -Dextension=${f_extension}
479 -Dinverted=${inverted}
480 -DTOP_SRC_DIR=${TOP_SRC_DIR}
481 "-DIgnoreErrorMessage=${missingLabels}"
482 -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
483 -DXMLLINT_EXECUTABLE=${XMLLINT_EXECUTABLE}
484 -DJAVA_EXECUTABLE=${jingjava}
486 -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
487 setmarkedtestlabel(${TestName} ${mytestlabel}) # check for suspended pdf/dvi exports