]> git.lyx.org Git - lyx.git/blob - development/autotests/ExportTests.cmake
ctests: ignore Japanese dvi3 systemF tests
[lyx.git] / development / autotests / ExportTests.cmake
1 #
2 #  Copyright (c) 2014 Kornel Benko <kornel@lyx.org>
3 #  Copyright (c) 2014 Scott Kostyshak <skotysh@lyx.org>
4 #
5 #  Redistribution and use in source and binary forms, with or without
6 #  modification, are permitted provided that the following conditions
7 #  are met:
8 #
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.
16 #
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.
27 #
28
29 find_package(Perl)
30 find_program(XMLLINT_EXECUTABLE xmllint)
31
32 if(PERL_FOUND)
33   set(DVI_FORMATS "dvi" "dvi3")
34   set(PDF_FORMATS "pdf" "pdf2" "pdf3" "pdf4" "pdf5")
35 else()
36   set(DVI_FORMATS "dvi")
37   set(PDF_FORMATS "pdf" "pdf2" "pdf3")
38 endif()
39
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")
41
42 # Used to select labels from .*Tests files
43 set(label_chars "[a-zA-Z:_]+")
44
45 macro(initLangVars varname)
46   foreach(_l ${potential_languages})
47     set(${varname}_${_l})
48   endforeach()
49 endmacro()
50
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" "docbook5" ${DVI_FORMATS} ${PDF_FORMATS})
56   foreach(_l IN LISTS lines)
57     if(_l MATCHES "^\\\\default_output_format +\([^ ]+\)")
58       set(_format ${CMAKE_MATCH_1})
59       if(_format STREQUAL "default")
60         set(out_formats "xhtml" "docbook5" ${DVI_FORMATS} ${PDF_FORMATS})
61       else()
62         set(${format_set} ${_format})
63         if(_format STREQUAL "pdf2" AND "${filepath}" MATCHES "/doc/")
64           set(out_formats "xhtml" "docbook5" ${DVI_FORMATS} ${PDF_FORMATS})
65         elseif(_format MATCHES "pdf$")
66           set(out_formats "xhtml" "docbook5" ${PDF_FORMATS})
67         elseif(_format MATCHES "dvi$")
68           set(out_formats "xhtml" "docbook5" ${DVI_FORMATS})
69         elseif(_format MATCHES "docbook5")
70           set(out_formats "docbook5")
71         elseif(_format MATCHES "xhtml")
72           set(out_formats "xhtml")
73         else()
74           # Respect all other output formats
75           # like "eps3"
76           set(out_formats "xhtml" ${_format})
77         endif()
78       endif()
79       break()
80     endif()
81   endforeach()
82   set(${varname} ${out_formats})
83 endmacro()
84
85 macro(findexpr found testname listname rsublabel)
86   set(_found 0)
87   set(tmpsublabel "")
88   foreach(_itrx ${${listname}})
89     if ("${_itrx}" MATCHES "^Sublabel:")
90       set(tmpsublabel "")
91       string(REGEX REPLACE "^Sublabel:[ \t]*" "" _itrlabels ${_itrx})
92       string(REGEX MATCHALL ${label_chars} _labels ${_itrlabels})
93       foreach(subl ${_labels})
94         if (subl STREQUAL "RESET")
95           set(tmpsublabel "")
96         else()
97           list(APPEND tmpsublabel ${subl})
98         endif()
99       endforeach()
100       # remove doubles in sublabel
101       list(REMOVE_DUPLICATES tmpsublabel)
102     else()
103       if (_itrx MATCHES "^!\(.*\)$")
104         set(_itr "^${CMAKE_MATCH_1}$")
105         set(_foundval 0)
106       else()
107         set(_itr "^${_itrx}$")
108         set(_foundval 1)
109       endif()
110       if (${testname} MATCHES "${_itr}")
111         set(_found ${_foundval})
112         break()
113       endif()
114     endif()
115   endforeach()
116   if (${_found})
117     if (NOT "${tmpsublabel}" STREQUAL "")
118       list(APPEND ${rsublabel} ${tmpsublabel})
119     endif()
120   endif()
121   set(${found} ${_found})
122 endmacro()
123
124 function(join rvalues glue routput)
125   set(locallist ${${rvalues}})
126   set(removelist "export" "lyx2lyx" "load")
127   foreach(_l ${locallist})
128     if (depth_${_l} LESS 0)
129       list(APPEND removelist ${_l})
130     endif()
131   endforeach()
132   list(REMOVE_ITEM locallist ${removelist})
133   string(REGEX REPLACE "([^\\]|^);" "\\1${glue}" out "${locallist}")
134   set(${routput} ${out} PARENT_SCOPE)
135 endfunction()
136
137 macro(maketestname testname inverted listinverted listignored listunreliable listlabels)
138   # initialize output variable
139   set(${inverted} 0)
140   string(REGEX MATCH "\\/[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${${testname}})
141   if(_v)
142     string(REGEX REPLACE "\\/" "" _v ${_v})
143     set(listinvertedx ${listinverted}_${_v})
144     set(listignoredx ${listignored}_${_v})
145     set(listunreliablex ${listunreliable}_${_v})
146     set(listsuspendedx suspendedTests_${_v})
147   else()
148     set(listinvertedx ${listinverted})
149     set(listignoredx ${listignored})
150     set(listunreliablex ${listunreliable})
151     set(listsuspendedx suspendedTests)
152   endif()
153   set(sublabel "${${listlabels}}")
154   findexpr(mfound ${testname} ${listignoredx} sublabel)
155   if (NOT mfound)
156     set(sublabel2 "")
157     findexpr(foundunreliable ${testname} ${listunreliablex} sublabel2)
158     if (foundunreliable)
159       set(sublabel "unreliable" ${sublabel} ${sublabel2})
160       list(REMOVE_ITEM sublabel "export" "inverted" "templates" "tabletemplates" "mathmacros" "manuals" "autotests")
161     endif()
162     string(REGEX MATCH "(^check_load|_(systemF|texF|pdf3|pdf2|pdf|dvi|lyx[0-9][0-9]|xhtml)$)" _v ${${testname}})
163     # check if test _may_ be in listinverted
164     set(sublabel2 "")
165     if (_v)
166       findexpr(mfound ${testname} ${listinvertedx} sublabel2)
167     else()
168       set(mfound OFF)
169     endif()
170     if (mfound)
171       set(sublabel3 "")
172       findexpr(foundsuspended ${testname} ${listsuspendedx} sublabel3)
173       set(${inverted} 1)
174       if (foundsuspended)
175         set(sublabel "suspended" ${sublabel} ${sublabel2} ${sublabel3})
176         list(REMOVE_ITEM sublabel "export" "inverted" )
177       else()
178         set(sublabel "inverted" ${sublabel} ${sublabel2} ${sublabel3})
179       endif()
180     else()
181       set(${inverted} 0)
182     endif()
183     list(REMOVE_DUPLICATES sublabel)
184     if (NOT sublabel STREQUAL "")
185       join(sublabel "." tmpprefixx)
186       if (tmpprefixx)
187         string(TOUPPER "${tmpprefixx}_" tmpprefix)
188       else()
189         set(tmpprefix "")
190       endif()
191       set(${testname} "${tmpprefix}${${testname}}")
192       set(${listlabels} ${sublabel})
193     endif()
194   else()
195     # No testname because ignored
196     set(${testname} "")
197   endif()
198 endmacro()
199
200 macro(loadTestList filename resList depth splitlangs)
201   # Create list of strings from a file without comments
202   # ENCODING parameter is a new feature in cmake 3.1
203   initLangVars(${resList})
204   initLangVars("sublabel")
205   if (CMAKE_VERSION VERSION_GREATER "3.1")
206     file(STRINGS ${filename} tempList ENCODING "UTF-8")
207   else()
208     file(STRINGS ${filename} tempList)
209   endif()
210   set(${resList})
211   set(sublabel)
212   set(mylabels "")
213   set(languages "")
214   message(STATUS "Reading list ${filename}")
215   foreach(_l ${tempList})
216     set(_newl "${_l}")
217     string(REGEX REPLACE "[ \t]+$" "" _newl "${_l}")
218     string(REGEX REPLACE "[ \t]*#.*$" "" _newl "${_l}")
219     if(_newl)
220       list(APPEND ${resList} "${_newl}")
221       if (_newl MATCHES "^Sublabel:")
222         string(REGEX REPLACE "^Sublabel:[ \t]*" "" _newlabels ${_newl})
223         string(REGEX MATCHALL "([0-9]*${label_chars})" _labels ${_newlabels})
224         foreach(labname ${_labels})
225           if (NOT labname STREQUAL "RESET")
226             list(APPEND mylabels ${labname})
227           endif()
228         endforeach()
229         list(REMOVE_DUPLICATES mylabels)
230         set(sublabel ${_newl})
231       else()
232         if (${splitlangs} MATCHES "ON")
233           string(REGEX REPLACE "(\\/|\\||\\(|\\))" "  " _vxx ${_newl})
234           string(REGEX MATCHALL " ([a-z][a-z](_[A-Z][A-Z])?) " _vx ${_vxx})
235         else()
236           set(_vx OFF)
237         endif()
238         if(_vx)
239           foreach(_v ${_vx})
240             string(REGEX REPLACE " " "" _v ${_v})
241             #message(STATUS " ==> ${resList}_${_v}")
242             #message(STATUS "sublabel = ${sublabel}, sublabel_${_v} = ${sublabel_${_v}}")
243             if (NOT sublabel STREQUAL "${sublabel_${_v}}")
244               list(APPEND ${resList}_${_v} "${sublabel}")
245               set(sublabel_${_v} "${sublabel}")
246               #message(STATUS "Setting variable sublabel_${_v} with \"${sublabel}\"")
247             endif()
248             list(APPEND ${resList}_${_v} "${_newl}")
249             list(APPEND languages ${_v})
250           endforeach()
251           list(REMOVE_DUPLICATES languages)
252           #message(STATUS "languages = ${languages}")
253         endif()
254       endif()
255     endif()
256   endforeach()
257   foreach(_l1 ${mylabels})
258     if (_l1 MATCHES "^([0-9]+)(${label_chars})$")
259       set(_l ${CMAKE_MATCH_2})
260       set(depth1 ${CMAKE_MATCH_1})
261     else()
262       set(_l ${_l1})
263       set(depth1 "0")
264     endif()
265     list(FIND known_labels ${_l} _ff)
266     if (_ff GREATER -1)
267       message(STATUS "Label \"${_l}\" already in use. Reused in ${filename}")
268     else()
269       assignLabelDepth(${depth}${depth1} ${_l})
270     endif()
271   endforeach()
272   foreach(_lg ${languages})
273     # reset label for each used language string at end of file
274     #message(STATUS "Resetting variable sublabel_${_lg}, previously set to ${sublabel_${_lg}}")
275     set(sublabel_${_lg} "")
276   endforeach()
277 endmacro()
278
279 # This labels should not be used in .*Tests files
280 set(known_labels "")
281 # Create depth info to each label
282 macro(assignLabelDepth depth)
283   foreach(_lab ${ARGN})
284     list(APPEND known_labels ${_lab})
285     set(depth_${_lab} ${depth})
286   endforeach()
287 endmacro()
288
289 assignLabelDepth(0 "export" "key" "layout" "load" "lyx2lyx" "module" "roundtrip" "url")
290 assignLabelDepth(1 "unreliable" "inverted")
291 assignLabelDepth(2 "suspended")
292 assignLabelDepth(-1 "examples" "manuals" "mathmacros" "templates" "tabletemplates" "autotests")
293
294 loadTestList(invertedTests invertedTests 7 ON)
295 loadTestList(ignoredTests ignoredTests 0 ON)
296 loadTestList(suspendedTests suspendedTests 6 ON)
297 loadTestList(unreliableTests unreliableTests 5 ON)
298 loadTestList(ignoreLatexErrorsTests ignoreLatexErrorsTests 8 OFF)
299
300 foreach(libsubfolderx autotests/export lib/doc lib/examples lib/templates lib/tabletemplates autotests/mathmacros)
301   set(testlabel "export")
302   if (libsubfolderx MATCHES "lib/doc")
303     list(APPEND testlabel "manuals")
304   elseif (libsubfolderx MATCHES "lib/examples")
305     list(APPEND testlabel "examples")
306   elseif (libsubfolderx MATCHES "lib/templates")
307     list(APPEND testlabel "templates")
308   elseif (libsubfolderx MATCHES "lib/tabletemplates")
309     list(APPEND testlabel "tabletemplates")
310   elseif (libsubfolderx MATCHES "autotests/mathmacros")
311     list(APPEND testlabel "mathmacros")
312   elseif (libsubfolderx MATCHES "autotests/.+")
313     list(APPEND testlabel "autotests")
314   endif()
315   set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
316   string(REGEX REPLACE "^(lib|development|autotests)/" "" libsubfolder "${libsubfolderx}")
317   set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
318   message(STATUS "Handling export dir ${LIBSUB_SRC_DIR}")
319   file(GLOB_RECURSE lyx_files RELATIVE "${LIBSUB_SRC_DIR}" "${LIBSUB_SRC_DIR}/*.lyx")
320   list(SORT lyx_files)
321   # Now create 2 lists. One for files in a language dir, one without
322   set(lang_lyx_files)
323   set(nolang_lyx_files)
324   foreach(f ${lyx_files})
325     if (${f} MATCHES "#")
326       # Do nothing, probably wrong temporary file
327     else()
328       string(REGEX MATCHALL "^[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${f})
329       if(_v)
330         list(APPEND lang_lyx_files ${f})
331       else()
332         list(APPEND nolang_lyx_files ${f})
333       endif()
334     endif()
335   endforeach()
336   foreach(f ${nolang_lyx_files} ${lang_lyx_files})
337     # Strip extension
338     string(REGEX REPLACE "\\.lyx$" "" f ${f})
339     foreach(_lyx_format_num 16 20 21 22 23)
340       set(TestName1 "export/${libsubfolder}/${f}_lyx${_lyx_format_num}")
341       string(REGEX REPLACE "[\\(\\)]" "_" TestName "${TestName1}")
342       set(mytestlabel ${testlabel} "lyx2lyx" "load")
343       maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
344       if(TestName)
345         add_test(NAME ${TestName}
346           WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
347           COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
348           -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
349           -Dlyx=$<TARGET_FILE:${_lyx}>
350           -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
351           -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
352           -Dformat=lyx${_lyx_format_num}x
353           -Dextension=${_lyx_format_num}.lyx
354           -DLYX_FORMAT_NUM=${_lyx_format_num}
355           -Dfile=${f}
356           -Dinverted=${inverted}
357           -DTOP_SRC_DIR=${TOP_SRC_DIR}
358           -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
359           -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
360         setmarkedtestlabel(${TestName} ${mytestlabel})
361       endif()
362     endforeach()
363     if(LYX_PYTHON_EXECUTABLE)
364       set(lyx2lyxtestlabel "lyx2lyx")
365       # For use of lyx2lyx we need the python executable
366       set(mytestlabel ${lyx2lyxtestlabel})
367       set(TestName1 "lyx2lyx/${libsubfolder}/${f}")
368       string(REGEX REPLACE "[\\(\\)]" "_" TestName "${TestName1}")
369       maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
370       if(TestName)
371         add_test(NAME ${TestName}
372           WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
373           COMMAND ${CMAKE_COMMAND}
374           "-DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE}"
375           "-DLYX2LYX=${TOP_SRC_DIR}/lib/lyx2lyx/lyx2lyx"
376           "-DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}"
377           "-DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx"
378           -P "${TOP_SRC_DIR}/development/autotests/lyx2lyxtest.cmake")
379         setmarkedtestlabel(${TestName} ${mytestlabel})
380       endif()
381     endif()
382     set(loadtestlabel "load")
383     set(mytestlabel ${loadtestlabel})
384     set(TestName1 "check_load/${libsubfolder}/${f}")
385     string(REGEX REPLACE "[\\(\\)]" "_" TestName "${TestName1}")
386     maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
387     if(TestName)
388       add_test(NAME ${TestName}
389         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
390         COMMAND ${CMAKE_COMMAND} -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
391         -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
392         -Dlyx=$<TARGET_FILE:${_lyx}>
393         -DPARAMS_DIR=${TOP_SRC_DIR}/development/autotests
394         -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
395         -Dinverted=${inverted}
396         -P "${TOP_SRC_DIR}/development/autotests/check_load.cmake")
397       setmarkedtestlabel(${TestName} ${mytestlabel})
398       #set_tests_properties(${TestName} PROPERTIES RUN_SERIAL ON)
399     endif()
400     set(default_output_format)
401     getoutputformats("${LIBSUB_SRC_DIR}/${f}.lyx" formatlist default_output_format)
402     foreach(format ${formatlist})
403       if(format MATCHES "dvi3|pdf4|pdf5")
404         set(fonttypes "texF" "systemF")
405       else()
406         set(fonttypes "defaultF")
407       endif()
408       foreach(fonttype ${fonttypes})
409         if (format MATCHES "pdf2" AND f MATCHES "latex/unicodesymbols")
410           #message(STATUS "Test ${TestName} matches Unicode encodings")
411           # test_encodings does not include "default", since it should be covered
412           # by one of the supplied encodings
413           set(test_encodings "ascii" "utf8" "utf8x" "armscii8" "applemac"
414             "cp437" "cp437de" "cp850" "cp852"
415             "cp855" "cp862" "cp865"
416             "cp866" "cp1250" "cp1251" "cp1252"
417             "cp1255" "cp1256" "cp1257"
418             "koi8-r" "koi8-u"
419             "iso8859-1" "iso8859-2" "iso8859-3"
420             "iso8859-4" "iso8859-5" "iso8859-6"
421             "iso8859-7" "iso8859-8" "iso8859-9"
422             "iso8859-13" "iso8859-15" "iso8859-16"
423             "pt154" "big5" "shift-jis"
424             "euc-cn" "gbk" "jis" "euc-kr"
425             "utf8-cjk" "euc-tw" "euc-jp"
426             "euc-jp-platex" "jis-platex"
427             "shift-jis-platex" "utf8-platex"
428             "tis620-0")
429         else()
430           set(test_encodings "default")
431         endif()
432         foreach (_enc2 ${test_encodings})
433           if ("${_enc2}" STREQUAL "default")
434             set(_enc "")
435           else()
436             set(_enc "_${_enc2}")
437           endif()
438           if(fonttype MATCHES "defaultF")
439             set(TestName1 "export/${libsubfolder}/${f}${_enc}_${format}")
440           else()
441             set(TestName1 "export/${libsubfolder}/${f}${_enc}_${format}_${fonttype}")
442           endif()
443           if (format MATCHES "^${default_output_format}$")
444             set(extraLabels "defaultoutput")
445           else()
446             set(extraLabels )
447           endif()
448           set(missingLabels )
449           findexpr(mfound TestName1 ignoreLatexErrorsTests missingLabels)
450           if (mfound)
451             set(mytestlabel ${testlabel} "ignoring" ${missingLabels} ${extraLabels})
452           else()
453             set(mytestlabel ${testlabel} ${extraLabels})
454           endif()
455           string(REGEX REPLACE "[\\(\\)]" "_" TestName "${TestName1}")
456           maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
457           if (format MATCHES "docbook5")
458             set(f_extension "xml")
459           else()
460             set(f_extension ${format})
461           endif()
462           if(TestName)
463             add_test(NAME ${TestName}
464               WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
465               COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
466               -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
467               -Dlyx=$<TARGET_FILE:${_lyx}>
468               -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
469               -Dformat=${format}
470               -Dfonttype=${fonttype}
471               -Dextension=${f_extension}
472               -Dfile=${f}
473               -Dinverted=${inverted}
474               -DTOP_SRC_DIR=${TOP_SRC_DIR}
475               "-DIgnoreErrorMessage=${missingLabels}"
476               -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
477               -DXMLLINT_EXECUTABLE=${XMLLINT_EXECUTABLE}
478               -DENCODING=${_enc2}
479               -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
480             setmarkedtestlabel(${TestName} ${mytestlabel}) # check for suspended pdf/dvi exports
481           endif()
482         endforeach()
483       endforeach()
484     endforeach()
485   endforeach()
486 endforeach()