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 set(_itr "^${_itrx}$")
102 if (${testname} MATCHES "${_itr}")
109 if (NOT "${tmpsublabel}" STREQUAL "")
110 list(APPEND ${rsublabel} ${tmpsublabel})
113 set(${found} ${_found})
116 function(join rvalues glue routput)
117 set(locallist ${${rvalues}})
118 set(removelist "export" "lyx2lyx" "load")
119 foreach(_l ${locallist})
120 if (depth_${_l} LESS 0)
121 list(APPEND removelist ${_l})
124 list(REMOVE_ITEM locallist ${removelist})
125 string(REGEX REPLACE "([^\\]|^);" "\\1${glue}" out "${locallist}")
126 set(${routput} ${out} PARENT_SCOPE)
129 macro(maketestname testname inverted listinverted listignored listunreliable listlabels)
130 # initialize output variable
132 string(REGEX MATCH "\\/[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${${testname}})
134 string(REGEX REPLACE "\\/" "" _v ${_v})
135 set(listinvertedx ${listinverted}_${_v})
136 set(listignoredx ${listignored}_${_v})
137 set(listunreliablex ${listunreliable}_${_v})
138 set(listsuspendedx suspendedTests_${_v})
140 set(listinvertedx ${listinverted})
141 set(listignoredx ${listignored})
142 set(listunreliablex ${listunreliable})
143 set(listsuspendedx suspendedTests)
145 set(sublabel "${${listlabels}}")
146 findexpr(mfound ${testname} ${listignoredx} sublabel)
149 findexpr(foundunreliable ${testname} ${listunreliablex} sublabel2)
151 set(sublabel "unreliable" ${sublabel} ${sublabel2})
152 list(REMOVE_ITEM sublabel "export" "inverted" "templates" "mathmacros" "manuals" "autotests")
154 string(REGEX MATCH "(^check_load|_(systemF|texF|pdf3|pdf2|pdf|dvi|lyx[0-9][0-9]|xhtml)$)" _v ${${testname}})
155 # check if test _may_ be in listinverted
158 findexpr(mfound ${testname} ${listinvertedx} sublabel2)
164 findexpr(foundsuspended ${testname} ${listsuspendedx} sublabel3)
167 set(sublabel "suspended" ${sublabel} ${sublabel2} ${sublabel3})
168 list(REMOVE_ITEM sublabel "export" "inverted" )
170 set(sublabel "inverted" ${sublabel} ${sublabel2} ${sublabel3})
175 list(REMOVE_DUPLICATES sublabel)
176 if (NOT sublabel STREQUAL "")
177 join(sublabel "." tmpprefixx)
179 string(TOUPPER "${tmpprefixx}_" tmpprefix)
183 set(${testname} "${tmpprefix}${${testname}}")
184 set(${listlabels} ${sublabel})
187 # No testname because ignored
192 macro(loadTestList filename resList depth splitlangs)
193 # Create list of strings from a file without comments
194 # ENCODING parameter is a new feature in cmake 3.1
195 initLangVars(${resList})
196 initLangVars("sublabel")
197 if (CMAKE_VERSION VERSION_GREATER "3.1")
198 file(STRINGS ${filename} tempList ENCODING "UTF-8")
200 file(STRINGS ${filename} tempList)
206 message(STATUS "Reading list ${filename}")
207 foreach(_l ${tempList})
209 string(REGEX REPLACE "[ \t]+$" "" _newl "${_l}")
210 string(REGEX REPLACE "[ \t]*#.*$" "" _newl "${_l}")
212 list(APPEND ${resList} "${_newl}")
213 if (_newl MATCHES "^Sublabel:")
214 string(REGEX REPLACE "^Sublabel:[ \t]*" "" _newlabels ${_newl})
215 string(REGEX MATCHALL "([0-9]*${label_chars})" _labels ${_newlabels})
216 foreach(labname ${_labels})
217 if (NOT labname STREQUAL "RESET")
218 list(APPEND mylabels ${labname})
221 list(REMOVE_DUPLICATES mylabels)
222 set(sublabel ${_newl})
224 if (${splitlangs} MATCHES "ON")
225 string(REGEX REPLACE "(\\/|\\||\\(|\\))" " " _vxx ${_newl})
226 string(REGEX MATCHALL " ([a-z][a-z](_[A-Z][A-Z])?) " _vx ${_vxx})
232 string(REGEX REPLACE " " "" _v ${_v})
233 #message(STATUS " ==> ${resList}_${_v}")
234 #message(STATUS "sublabel = ${sublabel}, sublabel_${_v} = ${sublabel_${_v}}")
235 if (NOT sublabel STREQUAL "${sublabel_${_v}}")
236 list(APPEND ${resList}_${_v} "${sublabel}")
237 set(sublabel_${_v} "${sublabel}")
238 #message(STATUS "Setting variable sublabel_${_v} with \"${sublabel}\"")
240 list(APPEND ${resList}_${_v} "${_newl}")
241 list(APPEND languages ${_v})
243 list(REMOVE_DUPLICATES languages)
244 #message(STATUS "languages = ${languages}")
249 foreach(_l1 ${mylabels})
250 if (_l1 MATCHES "^([0-9]+)(${label_chars})$")
251 set(_l ${CMAKE_MATCH_2})
252 set(depth1 ${CMAKE_MATCH_1})
257 list(FIND known_labels ${_l} _ff)
259 message(STATUS "Label \"${_l}\" already in use. Reused in ${filename}")
261 assignLabelDepth(${depth}${depth1} ${_l})
264 foreach(_lg ${languages})
265 # reset label for each used language string at end of file
266 #message(STATUS "Resetting variable sublabel_${_lg}, previously set to ${sublabel_${_lg}}")
267 set(sublabel_${_lg} "")
271 # This labels should not be used in .*Tests files
273 # Create depth info to each label
274 macro(assignLabelDepth depth)
275 foreach(_lab ${ARGN})
276 list(APPEND known_labels ${_lab})
277 set(depth_${_lab} ${depth})
281 assignLabelDepth(0 "export" "key" "layout" "load" "lyx2lyx" "module" "roundtrip" "url")
282 assignLabelDepth(1 "unreliable" "inverted")
283 assignLabelDepth(2 "suspended")
284 assignLabelDepth(-1 "examples" "manuals" "mathmacros" "templates" "autotests")
286 loadTestList(invertedTests invertedTests 7 ON)
287 loadTestList(ignoredTests ignoredTests 0 ON)
288 loadTestList(suspendedTests suspendedTests 6 ON)
289 loadTestList(unreliableTests unreliableTests 5 ON)
290 loadTestList(ignoreLatexErrorsTests ignoreLatexErrorsTests 8 OFF)
292 foreach(libsubfolderx autotests/export lib/doc lib/examples lib/templates autotests/mathmacros)
293 set(testlabel "export")
294 if (libsubfolderx MATCHES "lib/doc")
295 list(APPEND testlabel "manuals")
296 elseif (libsubfolderx MATCHES "lib/examples")
297 list(APPEND testlabel "examples")
298 elseif (libsubfolderx MATCHES "lib/templates")
299 list(APPEND testlabel "templates")
300 elseif (libsubfolderx MATCHES "autotests/mathmacros")
301 list(APPEND testlabel "mathmacros")
302 elseif (libsubfolderx MATCHES "autotests/.+")
303 list(APPEND testlabel "autotests")
305 set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
306 string(REGEX REPLACE "^(lib|development|autotests)/" "" libsubfolder "${libsubfolderx}")
307 set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
308 message(STATUS "Handling export dir ${LIBSUB_SRC_DIR}")
309 file(GLOB_RECURSE lyx_files RELATIVE "${LIBSUB_SRC_DIR}" "${LIBSUB_SRC_DIR}/*.lyx")
311 # Now create 2 lists. One for files in a language dir, one without
313 set(nolang_lyx_files)
314 foreach(f ${lyx_files})
315 if (${f} MATCHES "#")
316 # Do nothing, probably wrong temporary file
318 string(REGEX MATCHALL "^[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${f})
320 list(APPEND lang_lyx_files ${f})
322 list(APPEND nolang_lyx_files ${f})
326 foreach(f ${nolang_lyx_files} ${lang_lyx_files})
328 string(REGEX REPLACE "\\.lyx$" "" f ${f})
329 foreach(_lyx_format_num 16 21 22)
330 set(TestName "export/${libsubfolder}/${f}_lyx${_lyx_format_num}")
331 set(mytestlabel ${testlabel} "lyx2lyx" "load")
332 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
334 add_test(NAME ${TestName}
335 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
336 COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
337 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
338 -Dlyx=$<TARGET_FILE:${_lyx}>
339 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
340 -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
341 -Dformat=lyx${_lyx_format_num}x
342 -Dextension=${_lyx_format_num}.lyx
343 -DLYX_FORMAT_NUM=${_lyx_format_num}
345 -Dinverted=${inverted}
346 -DTOP_SRC_DIR=${TOP_SRC_DIR}
347 -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
348 -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
349 setmarkedtestlabel(${TestName} ${mytestlabel})
352 if(LYX_PYTHON_EXECUTABLE)
353 set(lyx2lyxtestlabel "lyx2lyx")
354 # For use of lyx2lyx we need the python executable
355 set(mytestlabel ${lyx2lyxtestlabel})
356 set(TestName "lyx2lyx/${libsubfolder}/${f}")
357 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
359 add_test(NAME ${TestName}
360 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
361 COMMAND ${CMAKE_COMMAND}
362 "-DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE}"
363 "-DLYX2LYX=${TOP_SRC_DIR}/lib/lyx2lyx/lyx2lyx"
364 "-DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}"
365 "-DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx"
366 -P "${TOP_SRC_DIR}/development/autotests/lyx2lyxtest.cmake")
367 setmarkedtestlabel(${TestName} ${mytestlabel})
370 set(loadtestlabel "load")
371 set(mytestlabel ${loadtestlabel})
372 set(TestName "check_load/${libsubfolder}/${f}")
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} -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
378 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
379 -Dlyx=$<TARGET_FILE:${_lyx}>
380 -DPARAMS_DIR=${TOP_SRC_DIR}/development/autotests
381 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
382 -Dinverted=${inverted}
383 -P "${TOP_SRC_DIR}/development/autotests/check_load.cmake")
384 setmarkedtestlabel(${TestName} ${mytestlabel})
385 #set_tests_properties(${TestName} PROPERTIES RUN_SERIAL ON)
387 set(default_output_format)
388 getoutputformats("${LIBSUB_SRC_DIR}/${f}.lyx" formatlist default_output_format)
389 foreach(format ${formatlist})
390 if(format MATCHES "dvi3|pdf4|pdf5")
391 set(fonttypes "texF" "systemF")
393 set(fonttypes "defaultF")
395 foreach(fonttype ${fonttypes})
396 if (format MATCHES "pdf2" AND f MATCHES "latex/unicodesymbols")
397 #message(STATUS "Test ${TestName} matches Unicode encodings")
398 # test_encodings does not include "default", since it should be covered
399 # by one of the supplied encodings
400 set(test_encodings "ascii" "utf8" "utf8x" "armscii8" "applemac"
401 "cp437" "cp437de" "cp850" "cp852"
402 "cp855" "cp862" "cp865"
403 "cp866" "cp1250" "cp1251" "cp1252"
404 "cp1255" "cp1256" "cp1257"
406 "iso8859-1" "iso8859-2" "iso8859-3"
407 "iso8859-4" "iso8859-5" "iso8859-6"
408 "iso8859-7" "iso8859-8" "iso8859-9"
409 "iso8859-13" "iso8859-15" "iso8859-16"
410 "pt154" "big5" "shift-jis"
411 "euc-cn" "gbk" "jis" "euc-kr"
412 "utf8-cjk" "euc-tw" "euc-jp"
413 "euc-jp-platex" "jis-platex"
414 "shift-jis-platex" "utf8-platex"
417 set(test_encodings "default")
419 foreach (_enc2 ${test_encodings})
420 if ("${_enc2}" STREQUAL "default")
423 set(_enc "_${_enc2}")
425 if(fonttype MATCHES "defaultF")
426 set(TestName "export/${libsubfolder}/${f}${_enc}_${format}")
428 set(TestName "export/${libsubfolder}/${f}${_enc}_${format}_${fonttype}")
430 if (format MATCHES "^${default_output_format}$")
431 set(extraLabels "defaultoutput")
436 findexpr(mfound TestName ignoreLatexErrorsTests missingLabels)
438 set(mytestlabel ${testlabel} "ignoring" ${missingLabels} ${extraLabels})
440 set(mytestlabel ${testlabel} ${extraLabels})
442 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
444 add_test(NAME ${TestName}
445 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
446 COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
447 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
448 -Dlyx=$<TARGET_FILE:${_lyx}>
449 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
451 -Dfonttype=${fonttype}
452 -Dextension=${format}
454 -Dinverted=${inverted}
455 -DTOP_SRC_DIR=${TOP_SRC_DIR}
456 "-DIgnoreErrorMessage=${missingLabels}"
457 -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
458 -DXMLLINT_EXECUTABLE=${XMLLINT_EXECUTABLE}
460 -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
461 setmarkedtestlabel(${TestName} ${mytestlabel}) # check for suspended pdf/dvi exports