]> git.lyx.org Git - lyx.git/blob - development/autotests/ExportTests.cmake
ctests: invert ko splash lyx22x and lyx23x 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" ${DVI_FORMATS} ${PDF_FORMATS})
56   foreach(_l ${lines})
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       else()
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")
71         else()
72           # Respect all other output formats
73           # like "eps3"
74           set(out_formats "xhtml" ${_format})
75         endif()
76       endif()
77       break()
78     endif()
79   endforeach()
80   set(${varname} ${out_formats})
81 endmacro()
82
83 macro(findexpr found testname listname rsublabel)
84   set(_found 0)
85   set(tmpsublabel "")
86   foreach(_itrx ${${listname}})
87     if ("${_itrx}" MATCHES "^Sublabel:")
88       set(tmpsublabel "")
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")
93           set(tmpsublabel "")
94         else()
95           list(APPEND tmpsublabel ${subl})
96         endif()
97       endforeach()
98       # remove doubles in sublabel
99       list(REMOVE_DUPLICATES tmpsublabel)
100     else()
101       if (_itrx MATCHES "^!\(.*\)$")
102         set(_itr "^${CMAKE_MATCH_1}$")
103         set(_foundval 0)
104       else()
105         set(_itr "^${_itrx}$")
106         set(_foundval 1)
107       endif()
108       if (${testname} MATCHES "${_itr}")
109         set(_found ${_foundval})
110         break()
111       endif()
112     endif()
113   endforeach()
114   if (${_found})
115     if (NOT "${tmpsublabel}" STREQUAL "")
116       list(APPEND ${rsublabel} ${tmpsublabel})
117     endif()
118   endif()
119   set(${found} ${_found})
120 endmacro()
121
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})
128     endif()
129   endforeach()
130   list(REMOVE_ITEM locallist ${removelist})
131   string(REGEX REPLACE "([^\\]|^);" "\\1${glue}" out "${locallist}")
132   set(${routput} ${out} PARENT_SCOPE)
133 endfunction()
134
135 macro(maketestname testname inverted listinverted listignored listunreliable listlabels)
136   # initialize output variable
137   set(${inverted} 0)
138   string(REGEX MATCH "\\/[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${${testname}})
139   if(_v)
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})
145   else()
146     set(listinvertedx ${listinverted})
147     set(listignoredx ${listignored})
148     set(listunreliablex ${listunreliable})
149     set(listsuspendedx suspendedTests)
150   endif()
151   set(sublabel "${${listlabels}}")
152   findexpr(mfound ${testname} ${listignoredx} sublabel)
153   if (NOT mfound)
154     set(sublabel2 "")
155     findexpr(foundunreliable ${testname} ${listunreliablex} sublabel2)
156     if (foundunreliable)
157       set(sublabel "unreliable" ${sublabel} ${sublabel2})
158       list(REMOVE_ITEM sublabel "export" "inverted" "templates" "mathmacros" "manuals" "autotests")
159     endif()
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
162     set(sublabel2 "")
163     if (_v)
164       findexpr(mfound ${testname} ${listinvertedx} sublabel2)
165     else()
166       set(mfound OFF)
167     endif()
168     if (mfound)
169       set(sublabel3 "")
170       findexpr(foundsuspended ${testname} ${listsuspendedx} sublabel3)
171       set(${inverted} 1)
172       if (foundsuspended)
173         set(sublabel "suspended" ${sublabel} ${sublabel2} ${sublabel3})
174         list(REMOVE_ITEM sublabel "export" "inverted" )
175       else()
176         set(sublabel "inverted" ${sublabel} ${sublabel2} ${sublabel3})
177       endif()
178     else()
179       set(${inverted} 0)
180     endif()
181     list(REMOVE_DUPLICATES sublabel)
182     if (NOT sublabel STREQUAL "")
183       join(sublabel "." tmpprefixx)
184       if (tmpprefixx)
185         string(TOUPPER "${tmpprefixx}_" tmpprefix)
186       else()
187         set(tmpprefix "")
188       endif()
189       set(${testname} "${tmpprefix}${${testname}}")
190       set(${listlabels} ${sublabel})
191     endif()
192   else()
193     # No testname because ignored
194     set(${testname} "")
195   endif()
196 endmacro()
197
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")
205   else()
206     file(STRINGS ${filename} tempList)
207   endif()
208   set(${resList})
209   set(sublabel)
210   set(mylabels "")
211   set(languages "")
212   message(STATUS "Reading list ${filename}")
213   foreach(_l ${tempList})
214     set(_newl "${_l}")
215     string(REGEX REPLACE "[ \t]+$" "" _newl "${_l}")
216     string(REGEX REPLACE "[ \t]*#.*$" "" _newl "${_l}")
217     if(_newl)
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})
225           endif()
226         endforeach()
227         list(REMOVE_DUPLICATES mylabels)
228         set(sublabel ${_newl})
229       else()
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})
233         else()
234           set(_vx OFF)
235         endif()
236         if(_vx)
237           foreach(_v ${_vx})
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}\"")
245             endif()
246             list(APPEND ${resList}_${_v} "${_newl}")
247             list(APPEND languages ${_v})
248           endforeach()
249           list(REMOVE_DUPLICATES languages)
250           #message(STATUS "languages = ${languages}")
251         endif()
252       endif()
253     endif()
254   endforeach()
255   foreach(_l1 ${mylabels})
256     if (_l1 MATCHES "^([0-9]+)(${label_chars})$")
257       set(_l ${CMAKE_MATCH_2})
258       set(depth1 ${CMAKE_MATCH_1})
259     else()
260       set(_l ${_l1})
261       set(depth1 "0")
262     endif()
263     list(FIND known_labels ${_l} _ff)
264     if (_ff GREATER -1)
265       message(STATUS "Label \"${_l}\" already in use. Reused in ${filename}")
266     else()
267       assignLabelDepth(${depth}${depth1} ${_l})
268     endif()
269   endforeach()
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} "")
274   endforeach()
275 endmacro()
276
277 # This labels should not be used in .*Tests files
278 set(known_labels "")
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})
284   endforeach()
285 endmacro()
286
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")
291
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)
297
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")
310   endif()
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")
316   list(SORT lyx_files)
317   # Now create 2 lists. One for files in a language dir, one without
318   set(lang_lyx_files)
319   set(nolang_lyx_files)
320   foreach(f ${lyx_files})
321     if (${f} MATCHES "#")
322       # Do nothing, probably wrong temporary file
323     else()
324       string(REGEX MATCHALL "^[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${f})
325       if(_v)
326         list(APPEND lang_lyx_files ${f})
327       else()
328         list(APPEND nolang_lyx_files ${f})
329       endif()
330     endif()
331   endforeach()
332   foreach(f ${nolang_lyx_files} ${lang_lyx_files})
333     # Strip extension
334     string(REGEX REPLACE "\\.lyx$" "" f ${f})
335     foreach(_lyx_format_num 16 21 22 23)
336       set(TestName "export/${libsubfolder}/${f}_lyx${_lyx_format_num}")
337       set(mytestlabel ${testlabel} "lyx2lyx" "load")
338       maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
339       if(TestName)
340         add_test(NAME ${TestName}
341           WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
342           COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
343           -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
344           -Dlyx=$<TARGET_FILE:${_lyx}>
345           -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
346           -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
347           -Dformat=lyx${_lyx_format_num}x
348           -Dextension=${_lyx_format_num}.lyx
349           -DLYX_FORMAT_NUM=${_lyx_format_num}
350           -Dfile=${f}
351           -Dinverted=${inverted}
352           -DTOP_SRC_DIR=${TOP_SRC_DIR}
353           -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
354           -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
355         setmarkedtestlabel(${TestName} ${mytestlabel})
356       endif()
357     endforeach()
358     if(LYX_PYTHON_EXECUTABLE)
359       set(lyx2lyxtestlabel "lyx2lyx")
360       # For use of lyx2lyx we need the python executable
361       set(mytestlabel ${lyx2lyxtestlabel})
362       set(TestName "lyx2lyx/${libsubfolder}/${f}")
363       maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
364       if(TestName)
365         add_test(NAME ${TestName}
366           WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
367           COMMAND ${CMAKE_COMMAND}
368           "-DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE}"
369           "-DLYX2LYX=${TOP_SRC_DIR}/lib/lyx2lyx/lyx2lyx"
370           "-DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}"
371           "-DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx"
372           -P "${TOP_SRC_DIR}/development/autotests/lyx2lyxtest.cmake")
373         setmarkedtestlabel(${TestName} ${mytestlabel})
374       endif()
375     endif()
376     set(loadtestlabel "load")
377     set(mytestlabel ${loadtestlabel})
378     set(TestName "check_load/${libsubfolder}/${f}")
379     maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
380     if(TestName)
381       add_test(NAME ${TestName}
382         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
383         COMMAND ${CMAKE_COMMAND} -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
384         -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
385         -Dlyx=$<TARGET_FILE:${_lyx}>
386         -DPARAMS_DIR=${TOP_SRC_DIR}/development/autotests
387         -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
388         -Dinverted=${inverted}
389         -P "${TOP_SRC_DIR}/development/autotests/check_load.cmake")
390       setmarkedtestlabel(${TestName} ${mytestlabel})
391       #set_tests_properties(${TestName} PROPERTIES RUN_SERIAL ON)
392     endif()
393     set(default_output_format)
394     getoutputformats("${LIBSUB_SRC_DIR}/${f}.lyx" formatlist default_output_format)
395     foreach(format ${formatlist})
396       if(format MATCHES "dvi3|pdf4|pdf5")
397         set(fonttypes "texF" "systemF")
398       else()
399         set(fonttypes "defaultF")
400       endif()
401       foreach(fonttype ${fonttypes})
402         if (format MATCHES "pdf2" AND f MATCHES "latex/unicodesymbols")
403           #message(STATUS "Test ${TestName} matches Unicode encodings")
404           # test_encodings does not include "default", since it should be covered
405           # by one of the supplied encodings
406           set(test_encodings "ascii" "utf8" "utf8x" "armscii8" "applemac"
407             "cp437" "cp437de" "cp850" "cp852"
408             "cp855" "cp862" "cp865"
409             "cp866" "cp1250" "cp1251" "cp1252"
410             "cp1255" "cp1256" "cp1257"
411             "koi8-r" "koi8-u"
412             "iso8859-1" "iso8859-2" "iso8859-3"
413             "iso8859-4" "iso8859-5" "iso8859-6"
414             "iso8859-7" "iso8859-8" "iso8859-9"
415             "iso8859-13" "iso8859-15" "iso8859-16"
416             "pt154" "big5" "shift-jis"
417             "euc-cn" "gbk" "jis" "euc-kr"
418             "utf8-cjk" "euc-tw" "euc-jp"
419             "euc-jp-platex" "jis-platex"
420             "shift-jis-platex" "utf8-platex"
421             "tis620-0")
422         else()
423           set(test_encodings "default")
424         endif()
425         foreach (_enc2 ${test_encodings})
426           if ("${_enc2}" STREQUAL "default")
427             set(_enc "")
428           else()
429             set(_enc "_${_enc2}")
430           endif()
431           if(fonttype MATCHES "defaultF")
432             set(TestName "export/${libsubfolder}/${f}${_enc}_${format}")
433           else()
434             set(TestName "export/${libsubfolder}/${f}${_enc}_${format}_${fonttype}")
435           endif()
436           if (format MATCHES "^${default_output_format}$")
437             set(extraLabels "defaultoutput")
438           else()
439             set(extraLabels )
440           endif()
441           set(missingLabels )
442           findexpr(mfound TestName ignoreLatexErrorsTests missingLabels)
443           if (mfound)
444             set(mytestlabel ${testlabel} "ignoring" ${missingLabels} ${extraLabels})
445           else()
446             set(mytestlabel ${testlabel} ${extraLabels})
447           endif()
448           maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
449           if(TestName)
450             add_test(NAME ${TestName}
451               WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
452               COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
453               -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
454               -Dlyx=$<TARGET_FILE:${_lyx}>
455               -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
456               -Dformat=${format}
457               -Dfonttype=${fonttype}
458               -Dextension=${format}
459               -Dfile=${f}
460               -Dinverted=${inverted}
461               -DTOP_SRC_DIR=${TOP_SRC_DIR}
462               "-DIgnoreErrorMessage=${missingLabels}"
463               -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
464               -DXMLLINT_EXECUTABLE=${XMLLINT_EXECUTABLE}
465               -DENCODING=${_enc2}
466               -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
467             setmarkedtestlabel(${TestName} ${mytestlabel}) # check for suspended pdf/dvi exports
468           endif()
469         endforeach()
470       endforeach()
471     endforeach()
472   endforeach()
473 endforeach()