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)
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})
61 elseif(_format STREQUAL "pdf2" AND "${filepath}" MATCHES "/doc/")
62 set(out_formats "xhtml" ${DVI_FORMATS} ${PDF_FORMATS})
63 elseif(_format MATCHES "pdf$")
64 set(out_formats "xhtml" ${PDF_FORMATS})
65 elseif(_format MATCHES "dvi$")
66 set(out_formats "xhtml" ${DVI_FORMATS})
67 elseif(_format MATCHES "xhtml")
68 set(out_formats "xhtml")
70 # Respect all other output formats
72 set(out_formats "xhtml" ${_format})
77 set(${varname} ${out_formats})
80 macro(findexpr found testname listname rsublabel)
83 foreach(_itrx ${${listname}})
84 if ("${_itrx}" MATCHES "^Sublabel:")
86 string(REGEX REPLACE "^Sublabel:[ \t]*" "" _itrlabels ${_itrx})
87 string(REGEX MATCHALL ${label_chars} _labels ${_itrlabels})
88 foreach(subl ${_labels})
89 if (subl STREQUAL "RESET")
92 list(APPEND tmpsublabel ${subl})
95 # remove doubles in sublabel
96 list(REMOVE_DUPLICATES tmpsublabel)
98 set(_itr "^${_itrx}$")
99 if (${testname} MATCHES "${_itr}")
106 if (NOT "${tmpsublabel}" STREQUAL "")
107 list(APPEND ${rsublabel} ${tmpsublabel})
110 set(${found} ${_found})
113 function(join rvalues glue routput)
114 set(locallist ${${rvalues}})
115 set(removelist "export" "lyx2lyx" "load")
116 foreach(_l ${locallist})
117 if (depth_${_l} LESS 0)
118 list(APPEND removelist ${_l})
121 list(REMOVE_ITEM locallist ${removelist})
122 string(REGEX REPLACE "([^\\]|^);" "\\1${glue}" out "${locallist}")
123 set(${routput} ${out} PARENT_SCOPE)
126 macro(maketestname testname inverted listinverted listignored listunreliable listlabels)
127 # initialize output variable
129 string(REGEX MATCH "\\/[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${${testname}})
131 string(REGEX REPLACE "\\/" "" _v ${_v})
132 set(listinvertedx ${listinverted}_${_v})
133 set(listignoredx ${listignored}_${_v})
134 set(listunreliablex ${listunreliable}_${_v})
135 set(listsuspendedx suspendedTests_${_v})
137 set(listinvertedx ${listinverted})
138 set(listignoredx ${listignored})
139 set(listunreliablex ${listunreliable})
140 set(listsuspendedx suspendedTests)
142 set(sublabel "${${listlabels}}")
143 findexpr(mfound ${testname} ${listignoredx} sublabel)
146 findexpr(foundunreliable ${testname} ${listunreliablex} sublabel2)
148 set(sublabel "unreliable" ${sublabel} ${sublabel2})
149 list(REMOVE_ITEM sublabel "export" "inverted" "templates" "mathmacros" "manuals" "autotests")
151 string(REGEX MATCH "(^check_load|_(systemF|texF|pdf3|pdf2|pdf|dvi|lyx[0-9][0-9]|xhtml)$)" _v ${${testname}})
152 # check if test _may_ be in listinverted
155 findexpr(mfound ${testname} ${listinvertedx} sublabel2)
161 findexpr(foundsuspended ${testname} ${listsuspendedx} sublabel3)
164 set(sublabel "suspended" ${sublabel} ${sublabel2} ${sublabel3})
165 list(REMOVE_ITEM sublabel "export" "inverted" )
167 set(sublabel "inverted" ${sublabel} ${sublabel2} ${sublabel3})
172 list(REMOVE_DUPLICATES sublabel)
173 if (NOT sublabel STREQUAL "")
174 join(sublabel "." tmpprefixx)
176 string(TOUPPER "${tmpprefixx}_" tmpprefix)
180 set(${testname} "${tmpprefix}${${testname}}")
181 set(${listlabels} ${sublabel})
184 # No testname because ignored
189 macro(loadTestList filename resList depth splitlangs)
190 # Create list of strings from a file without comments
191 # ENCODING parameter is a new feature in cmake 3.1
192 initLangVars(${resList})
193 initLangVars("sublabel")
194 if (CMAKE_VERSION VERSION_GREATER "3.1")
195 file(STRINGS ${filename} tempList ENCODING "UTF-8")
197 file(STRINGS ${filename} tempList)
203 message(STATUS "Reading list ${filename}")
204 foreach(_l ${tempList})
206 string(REGEX REPLACE "[ \t]+$" "" _newl "${_l}")
207 string(REGEX REPLACE "[ \t]*#.*$" "" _newl "${_l}")
209 list(APPEND ${resList} "${_newl}")
210 if (_newl MATCHES "^Sublabel:")
211 string(REGEX REPLACE "^Sublabel:[ \t]*" "" _newlabels ${_newl})
212 string(REGEX MATCHALL "([0-9]*${label_chars})" _labels ${_newlabels})
213 foreach(labname ${_labels})
214 if (NOT labname STREQUAL "RESET")
215 list(APPEND mylabels ${labname})
218 list(REMOVE_DUPLICATES mylabels)
219 set(sublabel ${_newl})
222 string(REGEX REPLACE "(\\/|\\||\\(|\\))" " " _vxx ${_newl})
223 string(REGEX MATCHALL " ([a-z][a-z](_[A-Z][A-Z])?) " _vx ${_vxx})
229 string(REGEX REPLACE " " "" _v ${_v})
230 #message(STATUS " ==> ${resList}_${_v}")
231 #message(STATUS "sublabel = ${sublabel}, sublabel_${_v} = ${sublabel_${_v}}")
232 if (NOT sublabel STREQUAL "${sublabel_${_v}}")
233 list(APPEND ${resList}_${_v} "${sublabel}")
234 set(sublabel_${_v} "${sublabel}")
235 #message(STATUS "Setting variable sublabel_${_v} with \"${sublabel}\"")
237 list(APPEND ${resList}_${_v} "${_newl}")
238 list(APPEND languages ${_v})
240 list(REMOVE_DUPLICATES languages)
241 #message(STATUS "languages = ${languages}")
246 foreach(_l1 ${mylabels})
247 if (_l1 MATCHES "^([0-9]+)(${label_chars})$")
248 set(_l ${CMAKE_MATCH_2})
249 set(depth1 ${CMAKE_MATCH_1})
254 list(FIND known_labels ${_l} _ff)
256 message(STATUS "Label \"${_l}\" already in use. Reused in ${filename}")
258 assignLabelDepth(${depth}${depth1} ${_l})
261 foreach(_lg ${languages})
262 # reset label for each used language string at end of file
263 #message(STATUS "Resetting variable sublabel_${_lg}, previously set to ${sublabel_${_lg}}")
264 set(sublabel_${_lg} "")
268 # This labels should not be used in .*Tests files
270 # Create depth info to each label
271 macro(assignLabelDepth depth)
272 foreach(_lab ${ARGN})
273 list(APPEND known_labels ${_lab})
274 set(depth_${_lab} ${depth})
278 assignLabelDepth(0 "export" "key" "layout" "load" "lyx2lyx" "module" "roundtrip" "url")
279 assignLabelDepth(1 "unreliable" "inverted")
280 assignLabelDepth(2 "suspended")
281 assignLabelDepth(-1 "examples" "manuals" "mathmacros" "templates" "autotests")
283 loadTestList(invertedTests invertedTests 7 ON)
284 loadTestList(ignoredTests ignoredTests 0 ON)
285 loadTestList(suspendedTests suspendedTests 6 ON)
286 loadTestList(unreliableTests unreliableTests 5 ON)
287 loadTestList(ignoreLatexErrorsTests ignoreLatexErrorsTests 8 OFF)
289 foreach(libsubfolderx autotests/export lib/doc lib/examples lib/templates autotests/mathmacros)
290 set(testlabel "export")
291 if (libsubfolderx MATCHES "lib/doc")
292 list(APPEND testlabel "manuals")
293 elseif (libsubfolderx MATCHES "lib/examples")
294 list(APPEND testlabel "examples")
295 elseif (libsubfolderx MATCHES "lib/templates")
296 list(APPEND testlabel "templates")
297 elseif (libsubfolderx MATCHES "autotests/mathmacros")
298 list(APPEND testlabel "mathmacros")
299 elseif (libsubfolderx MATCHES "autotests/.+")
300 list(APPEND testlabel "autotests")
302 set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
303 string(REGEX REPLACE "^(lib|development|autotests)/" "" libsubfolder "${libsubfolderx}")
304 set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
305 message(STATUS "Handling export dir ${LIBSUB_SRC_DIR}")
306 file(GLOB_RECURSE lyx_files RELATIVE "${LIBSUB_SRC_DIR}" "${LIBSUB_SRC_DIR}/*.lyx")
308 # Now create 2 lists. One for files in a language dir, one without
310 set(nolang_lyx_files)
311 foreach(f ${lyx_files})
312 string(REGEX MATCHALL "^[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${f})
314 list(APPEND lang_lyx_files ${f})
316 list(APPEND nolang_lyx_files ${f})
319 foreach(f ${nolang_lyx_files} ${lang_lyx_files})
321 string(REGEX REPLACE "\\.lyx$" "" f ${f})
322 foreach(_lyx_format_num 16 21 22)
323 set(TestName "export/${libsubfolder}/${f}_lyx${_lyx_format_num}")
324 set(mytestlabel ${testlabel} "lyx2lyx" "load")
325 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
327 add_test(NAME ${TestName}
328 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
329 COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
330 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
331 -Dlyx=$<TARGET_FILE:${_lyx}>
332 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
333 -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
334 -Dformat=lyx${_lyx_format_num}x
335 -Dextension=${_lyx_format_num}.lyx
336 -DLYX_FORMAT_NUM=${_lyx_format_num}
338 -Dinverted=${inverted}
339 -DTOP_SRC_DIR=${TOP_SRC_DIR}
340 -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
341 -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
342 setmarkedtestlabel(${TestName} ${mytestlabel})
345 if(LYX_PYTHON_EXECUTABLE)
346 set(lyx2lyxtestlabel "lyx2lyx")
347 # For use of lyx2lyx we need the python executable
348 set(mytestlabel ${lyx2lyxtestlabel})
349 set(TestName "lyx2lyx/${libsubfolder}/${f}")
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}
355 "-DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE}"
356 "-DLYX2LYX=${TOP_SRC_DIR}/lib/lyx2lyx/lyx2lyx"
357 "-DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}"
358 "-DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx"
359 -P "${TOP_SRC_DIR}/development/autotests/lyx2lyxtest.cmake")
360 setmarkedtestlabel(${TestName} ${mytestlabel})
363 set(loadtestlabel "load")
364 set(mytestlabel ${loadtestlabel})
365 set(TestName "check_load/${libsubfolder}/${f}")
366 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
368 add_test(NAME ${TestName}
369 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
370 COMMAND ${CMAKE_COMMAND} -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
371 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
372 -Dlyx=$<TARGET_FILE:${_lyx}>
373 -DPARAMS_DIR=${TOP_SRC_DIR}/development/autotests
374 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
375 -Dinverted=${inverted}
376 -P "${TOP_SRC_DIR}/development/autotests/check_load.cmake")
377 setmarkedtestlabel(${TestName} ${mytestlabel})
378 #set_tests_properties(${TestName} PROPERTIES RUN_SERIAL ON)
380 getoutputformats("${LIBSUB_SRC_DIR}/${f}.lyx" formatlist)
381 foreach(format ${formatlist})
382 if(format MATCHES "dvi3|pdf4|pdf5")
383 set(fonttypes "texF" "systemF")
385 set(fonttypes "defaultF")
387 foreach(fonttype ${fonttypes})
388 if (format MATCHES "pdf2" AND f MATCHES "latex/unicodesymbols")
389 #message(STATUS "Test ${TestName} matches Unicode encodings")
390 # test_encodings does not include "default", since it should be covered
391 # by one of the supplied encodings
392 set(test_encodings "ascii" "utf8x" "armscii8" "applemac"
393 "cp437" "cp437de" "cp850" "cp852"
394 "cp855" "cp862" "cp865"
395 "cp866" "cp1250" "cp1251" "cp1252"
396 "cp1255" "cp1256" "cp1257"
398 "iso8859-1" "iso8859-2" "iso8859-3"
399 "iso8859-4" "iso8859-5" "iso8859-6"
400 "iso8859-7" "iso8859-8" "iso8859-9"
401 "iso8859-13" "iso8859-15" "iso8859-16"
402 "pt154" "big5" "shift-jis"
403 "euc-cn" "gbk" "jis" "euc-kr"
404 "utf8-cjk" "euc-tw" "euc-jp"
405 "euc-jp-platex" "jis-platex"
406 "shift-jis-platex" "utf8-platex"
409 set(test_encodings "default")
411 foreach (_enc2 ${test_encodings})
412 if ("${_enc2}" STREQUAL "default")
415 set(_enc "_${_enc2}")
417 if(fonttype MATCHES "defaultF")
418 set(TestName "export/${libsubfolder}/${f}${_enc}_${format}")
420 set(TestName "export/${libsubfolder}/${f}${_enc}_${format}_${fonttype}")
422 set(mytestlabel ${testlabel})
423 maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
426 findexpr(mfound TestName ignoreLatexErrorsTests missingLabels)
427 add_test(NAME ${TestName}
428 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
429 COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
430 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
431 -Dlyx=$<TARGET_FILE:${_lyx}>
432 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
434 -Dfonttype=${fonttype}
435 -Dextension=${format}
437 -Dinverted=${inverted}
438 -DTOP_SRC_DIR=${TOP_SRC_DIR}
439 "-DIgnoreErrorMessage=${missingLabels}"
440 -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
441 -DXMLLINT_EXECUTABLE=${XMLLINT_EXECUTABLE}
443 -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
444 setmarkedtestlabel(${TestName} ${mytestlabel}) # check for suspended pdf/dvi exports