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 if (_itrx MATCHES "^!\(.*\)$")
102 set(_itr "^${CMAKE_MATCH_1}$")
105 set(_itr "^${_itrx}$")
108 if (${testname} MATCHES "${_itr}")
109 set(_found ${_foundval})
115 if (NOT "${tmpsublabel}" STREQUAL "")
116 list(APPEND ${rsublabel} ${tmpsublabel})
119 set(${found} ${_found})
122 function(join rvalues glue routput)
123 set(locallist ${${rvalues}})
124 set(removelist "export" "lyx2lyx" "load")
125 foreach(_l ${locallist})
126 if (depth_${_l} LESS 0)
127 list(APPEND removelist ${_l})
130 list(REMOVE_ITEM locallist ${removelist})
131 string(REGEX REPLACE "([^\\]|^);" "\\1${glue}" out "${locallist}")
132 set(${routput} ${out} PARENT_SCOPE)
135 macro(maketestname testname inverted listinverted listignored listunreliable listlabels)
136 # initialize output variable
138 string(REGEX MATCH "\\/[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${${testname}})
140 string(REGEX REPLACE "\\/" "" _v ${_v})
141 set(listinvertedx ${listinverted}_${_v})
142 set(listignoredx ${listignored}_${_v})
143 set(listunreliablex ${listunreliable}_${_v})
144 set(listsuspendedx suspendedTests_${_v})
146 set(listinvertedx ${listinverted})
147 set(listignoredx ${listignored})
148 set(listunreliablex ${listunreliable})
149 set(listsuspendedx suspendedTests)
151 set(sublabel "${${listlabels}}")
152 findexpr(mfound ${testname} ${listignoredx} sublabel)
155 findexpr(foundunreliable ${testname} ${listunreliablex} sublabel2)
157 set(sublabel "unreliable" ${sublabel} ${sublabel2})
158 list(REMOVE_ITEM sublabel "export" "inverted" "templates" "mathmacros" "manuals" "autotests")
160 string(REGEX MATCH "(^check_load|_(systemF|texF|pdf3|pdf2|pdf|dvi|lyx[0-9][0-9]|xhtml)$)" _v ${${testname}})
161 # check if test _may_ be in listinverted
164 findexpr(mfound ${testname} ${listinvertedx} sublabel2)
170 findexpr(foundsuspended ${testname} ${listsuspendedx} sublabel3)
173 set(sublabel "suspended" ${sublabel} ${sublabel2} ${sublabel3})
174 list(REMOVE_ITEM sublabel "export" "inverted" )
176 set(sublabel "inverted" ${sublabel} ${sublabel2} ${sublabel3})
181 list(REMOVE_DUPLICATES sublabel)
182 if (NOT sublabel STREQUAL "")
183 join(sublabel "." tmpprefixx)
185 string(TOUPPER "${tmpprefixx}_" tmpprefix)
189 set(${testname} "${tmpprefix}${${testname}}")
190 set(${listlabels} ${sublabel})
193 # No testname because ignored
198 macro(loadTestList filename resList depth splitlangs)
199 # Create list of strings from a file without comments
200 # ENCODING parameter is a new feature in cmake 3.1
201 initLangVars(${resList})
202 initLangVars("sublabel")
203 if (CMAKE_VERSION VERSION_GREATER "3.1")
204 file(STRINGS ${filename} tempList ENCODING "UTF-8")
206 file(STRINGS ${filename} tempList)
212 message(STATUS "Reading list ${filename}")
213 foreach(_l ${tempList})
215 string(REGEX REPLACE "[ \t]+$" "" _newl "${_l}")
216 string(REGEX REPLACE "[ \t]*#.*$" "" _newl "${_l}")
218 list(APPEND ${resList} "${_newl}")
219 if (_newl MATCHES "^Sublabel:")
220 string(REGEX REPLACE "^Sublabel:[ \t]*" "" _newlabels ${_newl})
221 string(REGEX MATCHALL "([0-9]*${label_chars})" _labels ${_newlabels})
222 foreach(labname ${_labels})
223 if (NOT labname STREQUAL "RESET")
224 list(APPEND mylabels ${labname})
227 list(REMOVE_DUPLICATES mylabels)
228 set(sublabel ${_newl})
230 if (${splitlangs} MATCHES "ON")
231 string(REGEX REPLACE "(\\/|\\||\\(|\\))" " " _vxx ${_newl})
232 string(REGEX MATCHALL " ([a-z][a-z](_[A-Z][A-Z])?) " _vx ${_vxx})
238 string(REGEX REPLACE " " "" _v ${_v})
239 #message(STATUS " ==> ${resList}_${_v}")
240 #message(STATUS "sublabel = ${sublabel}, sublabel_${_v} = ${sublabel_${_v}}")
241 if (NOT sublabel STREQUAL "${sublabel_${_v}}")
242 list(APPEND ${resList}_${_v} "${sublabel}")
243 set(sublabel_${_v} "${sublabel}")
244 #message(STATUS "Setting variable sublabel_${_v} with \"${sublabel}\"")
246 list(APPEND ${resList}_${_v} "${_newl}")
247 list(APPEND languages ${_v})
249 list(REMOVE_DUPLICATES languages)
250 #message(STATUS "languages = ${languages}")
255 foreach(_l1 ${mylabels})
256 if (_l1 MATCHES "^([0-9]+)(${label_chars})$")
257 set(_l ${CMAKE_MATCH_2})
258 set(depth1 ${CMAKE_MATCH_1})
263 list(FIND known_labels ${_l} _ff)
265 message(STATUS "Label \"${_l}\" already in use. Reused in ${filename}")
267 assignLabelDepth(${depth}${depth1} ${_l})
270 foreach(_lg ${languages})
271 # reset label for each used language string at end of file
272 #message(STATUS "Resetting variable sublabel_${_lg}, previously set to ${sublabel_${_lg}}")
273 set(sublabel_${_lg} "")
277 # This labels should not be used in .*Tests files
279 # Create depth info to each label
280 macro(assignLabelDepth depth)
281 foreach(_lab ${ARGN})
282 list(APPEND known_labels ${_lab})
283 set(depth_${_lab} ${depth})
287 assignLabelDepth(0 "export" "key" "layout" "load" "lyx2lyx" "module" "roundtrip" "url")
288 assignLabelDepth(1 "unreliable" "inverted")
289 assignLabelDepth(2 "suspended")
290 assignLabelDepth(-1 "examples" "manuals" "mathmacros" "templates" "autotests")
292 loadTestList(invertedTests invertedTests 7 ON)
293 loadTestList(ignoredTests ignoredTests 0 ON)
294 loadTestList(suspendedTests suspendedTests 6 ON)
295 loadTestList(unreliableTests unreliableTests 5 ON)
296 loadTestList(ignoreLatexErrorsTests ignoreLatexErrorsTests 8 OFF)
298 foreach(libsubfolderx autotests/export lib/doc lib/examples lib/templates autotests/mathmacros)
299 set(testlabel "export")
300 if (libsubfolderx MATCHES "lib/doc")
301 list(APPEND testlabel "manuals")
302 elseif (libsubfolderx MATCHES "lib/examples")
303 list(APPEND testlabel "examples")
304 elseif (libsubfolderx MATCHES "lib/templates")
305 list(APPEND testlabel "templates")
306 elseif (libsubfolderx MATCHES "autotests/mathmacros")
307 list(APPEND testlabel "mathmacros")
308 elseif (libsubfolderx MATCHES "autotests/.+")
309 list(APPEND testlabel "autotests")
311 set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
312 string(REGEX REPLACE "^(lib|development|autotests)/" "" libsubfolder "${libsubfolderx}")
313 set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
314 message(STATUS "Handling export dir ${LIBSUB_SRC_DIR}")
315 file(GLOB_RECURSE lyx_files RELATIVE "${LIBSUB_SRC_DIR}" "${LIBSUB_SRC_DIR}/*.lyx")
317 # Now create 2 lists. One for files in a language dir, one without
319 set(nolang_lyx_files)
320 foreach(f ${lyx_files})
321 if (${f} MATCHES "#")
322 # Do nothing, probably wrong temporary file
324 string(REGEX MATCHALL "^[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${f})
326 list(APPEND lang_lyx_files ${f})
328 list(APPEND nolang_lyx_files ${f})
332 foreach(f ${nolang_lyx_files} ${lang_lyx_files})
334 string(REGEX REPLACE "\\.lyx$" "" f ${f})
335 foreach(_lyx_format_num 16 20 21 22 23)
336 set(TestName1 "export/${libsubfolder}/${f}_lyx${_lyx_format_num}")
337 string(REGEX REPLACE "[\\(\\)]" "_" TestName "${TestName1}")
338 set(mytestlabel ${testlabel} "lyx2lyx" "load")
339 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
341 add_test(NAME ${TestName}
342 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
343 COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
344 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
345 -Dlyx=$<TARGET_FILE:${_lyx}>
346 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
347 -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
348 -Dformat=lyx${_lyx_format_num}x
349 -Dextension=${_lyx_format_num}.lyx
350 -DLYX_FORMAT_NUM=${_lyx_format_num}
352 -Dinverted=${inverted}
353 -DTOP_SRC_DIR=${TOP_SRC_DIR}
354 -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
355 -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
356 setmarkedtestlabel(${TestName} ${mytestlabel})
359 if(LYX_PYTHON_EXECUTABLE)
360 set(lyx2lyxtestlabel "lyx2lyx")
361 # For use of lyx2lyx we need the python executable
362 set(mytestlabel ${lyx2lyxtestlabel})
363 set(TestName1 "lyx2lyx/${libsubfolder}/${f}")
364 string(REGEX REPLACE "[\\(\\)]" "_" TestName "${TestName1}")
365 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
367 add_test(NAME ${TestName}
368 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
369 COMMAND ${CMAKE_COMMAND}
370 "-DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE}"
371 "-DLYX2LYX=${TOP_SRC_DIR}/lib/lyx2lyx/lyx2lyx"
372 "-DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}"
373 "-DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx"
374 -P "${TOP_SRC_DIR}/development/autotests/lyx2lyxtest.cmake")
375 setmarkedtestlabel(${TestName} ${mytestlabel})
378 set(loadtestlabel "load")
379 set(mytestlabel ${loadtestlabel})
380 set(TestName1 "check_load/${libsubfolder}/${f}")
381 string(REGEX REPLACE "[\\(\\)]" "_" TestName "${TestName1}")
382 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
384 add_test(NAME ${TestName}
385 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
386 COMMAND ${CMAKE_COMMAND} -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
387 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
388 -Dlyx=$<TARGET_FILE:${_lyx}>
389 -DPARAMS_DIR=${TOP_SRC_DIR}/development/autotests
390 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
391 -Dinverted=${inverted}
392 -P "${TOP_SRC_DIR}/development/autotests/check_load.cmake")
393 setmarkedtestlabel(${TestName} ${mytestlabel})
394 #set_tests_properties(${TestName} PROPERTIES RUN_SERIAL ON)
396 set(default_output_format)
397 getoutputformats("${LIBSUB_SRC_DIR}/${f}.lyx" formatlist default_output_format)
398 foreach(format ${formatlist})
399 if(format MATCHES "dvi3|pdf4|pdf5")
400 set(fonttypes "texF" "systemF")
402 set(fonttypes "defaultF")
404 foreach(fonttype ${fonttypes})
405 if (format MATCHES "pdf2" AND f MATCHES "latex/unicodesymbols")
406 #message(STATUS "Test ${TestName} matches Unicode encodings")
407 # test_encodings does not include "default", since it should be covered
408 # by one of the supplied encodings
409 set(test_encodings "ascii" "utf8" "utf8x" "armscii8" "applemac"
410 "cp437" "cp437de" "cp850" "cp852"
411 "cp855" "cp862" "cp865"
412 "cp866" "cp1250" "cp1251" "cp1252"
413 "cp1255" "cp1256" "cp1257"
415 "iso8859-1" "iso8859-2" "iso8859-3"
416 "iso8859-4" "iso8859-5" "iso8859-6"
417 "iso8859-7" "iso8859-8" "iso8859-9"
418 "iso8859-13" "iso8859-15" "iso8859-16"
419 "pt154" "big5" "shift-jis"
420 "euc-cn" "gbk" "jis" "euc-kr"
421 "utf8-cjk" "euc-tw" "euc-jp"
422 "euc-jp-platex" "jis-platex"
423 "shift-jis-platex" "utf8-platex"
426 set(test_encodings "default")
428 foreach (_enc2 ${test_encodings})
429 if ("${_enc2}" STREQUAL "default")
432 set(_enc "_${_enc2}")
434 if(fonttype MATCHES "defaultF")
435 set(TestName1 "export/${libsubfolder}/${f}${_enc}_${format}")
437 set(TestName1 "export/${libsubfolder}/${f}${_enc}_${format}_${fonttype}")
439 if (format MATCHES "^${default_output_format}$")
440 set(extraLabels "defaultoutput")
445 findexpr(mfound TestName ignoreLatexErrorsTests missingLabels)
447 set(mytestlabel ${testlabel} "ignoring" ${missingLabels} ${extraLabels})
449 set(mytestlabel ${testlabel} ${extraLabels})
451 string(REGEX REPLACE "[\\(\\)]" "_" TestName "${TestName1}")
452 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
454 add_test(NAME ${TestName}
455 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
456 COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
457 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
458 -Dlyx=$<TARGET_FILE:${_lyx}>
459 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
461 -Dfonttype=${fonttype}
462 -Dextension=${format}
464 -Dinverted=${inverted}
465 -DTOP_SRC_DIR=${TOP_SRC_DIR}
466 "-DIgnoreErrorMessage=${missingLabels}"
467 -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
468 -DXMLLINT_EXECUTABLE=${XMLLINT_EXECUTABLE}
470 -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
471 setmarkedtestlabel(${TestName} ${mytestlabel}) # check for suspended pdf/dvi exports