]> git.lyx.org Git - lyx.git/blob - development/autotests/ExportTests.cmake
findadv: almost all test cases, including \regex[{}, back to working with std::regex.
[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       set(_itr "^${_itrx}$")
102       if (${testname} MATCHES "${_itr}")
103         set(_found 1)
104         break()
105       endif()
106     endif()
107   endforeach()
108   if (${_found})
109     if (NOT "${tmpsublabel}" STREQUAL "")
110       list(APPEND ${rsublabel} ${tmpsublabel})
111     endif()
112   endif()
113   set(${found} ${_found})
114 endmacro()
115
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})
122     endif()
123   endforeach()
124   list(REMOVE_ITEM locallist ${removelist})
125   string(REGEX REPLACE "([^\\]|^);" "\\1${glue}" out "${locallist}")
126   set(${routput} ${out} PARENT_SCOPE)
127 endfunction()
128
129 macro(maketestname testname inverted listinverted listignored listunreliable listlabels)
130   # initialize output variable
131   set(${inverted} 0)
132   string(REGEX MATCH "\\/[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${${testname}})
133   if(_v)
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})
139   else()
140     set(listinvertedx ${listinverted})
141     set(listignoredx ${listignored})
142     set(listunreliablex ${listunreliable})
143     set(listsuspendedx suspendedTests)
144   endif()
145   set(sublabel "${${listlabels}}")
146   findexpr(mfound ${testname} ${listignoredx} sublabel)
147   if (NOT mfound)
148     set(sublabel2 "")
149     findexpr(foundunreliable ${testname} ${listunreliablex} sublabel2)
150     if (foundunreliable)
151       set(sublabel "unreliable" ${sublabel} ${sublabel2})
152       list(REMOVE_ITEM sublabel "export" "inverted" "templates" "mathmacros" "manuals" "autotests")
153     endif()
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
156     set(sublabel2 "")
157     if (_v)
158       findexpr(mfound ${testname} ${listinvertedx} sublabel2)
159     else()
160       set(mfound OFF)
161     endif()
162     if (mfound)
163       set(sublabel3 "")
164       findexpr(foundsuspended ${testname} ${listsuspendedx} sublabel3)
165       set(${inverted} 1)
166       if (foundsuspended)
167         set(sublabel "suspended" ${sublabel} ${sublabel2} ${sublabel3})
168         list(REMOVE_ITEM sublabel "export" "inverted" )
169       else()
170         set(sublabel "inverted" ${sublabel} ${sublabel2} ${sublabel3})
171       endif()
172     else()
173       set(${inverted} 0)
174     endif()
175     list(REMOVE_DUPLICATES sublabel)
176     if (NOT sublabel STREQUAL "")
177       join(sublabel "." tmpprefixx)
178       if (tmpprefixx)
179         string(TOUPPER "${tmpprefixx}_" tmpprefix)
180       else()
181         set(tmpprefix "")
182       endif()
183       set(${testname} "${tmpprefix}${${testname}}")
184       set(${listlabels} ${sublabel})
185     endif()
186   else()
187     # No testname because ignored
188     set(${testname} "")
189   endif()
190 endmacro()
191
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")
199   else()
200     file(STRINGS ${filename} tempList)
201   endif()
202   set(${resList})
203   set(sublabel)
204   set(mylabels "")
205   set(languages "")
206   message(STATUS "Reading list ${filename}")
207   foreach(_l ${tempList})
208     set(_newl "${_l}")
209     string(REGEX REPLACE "[ \t]+$" "" _newl "${_l}")
210     string(REGEX REPLACE "[ \t]*#.*$" "" _newl "${_l}")
211     if(_newl)
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})
219           endif()
220         endforeach()
221         list(REMOVE_DUPLICATES mylabels)
222         set(sublabel ${_newl})
223       else()
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})
227         else()
228           set(_vx OFF)
229         endif()
230         if(_vx)
231           foreach(_v ${_vx})
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}\"")
239             endif()
240             list(APPEND ${resList}_${_v} "${_newl}")
241             list(APPEND languages ${_v})
242           endforeach()
243           list(REMOVE_DUPLICATES languages)
244           #message(STATUS "languages = ${languages}")
245         endif()
246       endif()
247     endif()
248   endforeach()
249   foreach(_l1 ${mylabels})
250     if (_l1 MATCHES "^([0-9]+)(${label_chars})$")
251       set(_l ${CMAKE_MATCH_2})
252       set(depth1 ${CMAKE_MATCH_1})
253     else()
254       set(_l ${_l1})
255       set(depth1 "0")
256     endif()
257     list(FIND known_labels ${_l} _ff)
258     if (_ff GREATER -1)
259       message(STATUS "Label \"${_l}\" already in use. Reused in ${filename}")
260     else()
261       assignLabelDepth(${depth}${depth1} ${_l})
262     endif()
263   endforeach()
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} "")
268   endforeach()
269 endmacro()
270
271 # This labels should not be used in .*Tests files
272 set(known_labels "")
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})
278   endforeach()
279 endmacro()
280
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")
285
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)
291
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")
304   endif()
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")
310   list(SORT lyx_files)
311   # Now create 2 lists. One for files in a language dir, one without
312   set(lang_lyx_files)
313   set(nolang_lyx_files)
314   foreach(f ${lyx_files})
315     string(REGEX MATCHALL "^[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${f})
316     if(_v)
317       list(APPEND lang_lyx_files ${f})
318     else()
319       list(APPEND nolang_lyx_files ${f})
320     endif()
321   endforeach()
322   foreach(f ${nolang_lyx_files} ${lang_lyx_files})
323     # Strip extension
324     string(REGEX REPLACE "\\.lyx$" "" f ${f})
325     foreach(_lyx_format_num 16 21 22)
326       set(TestName "export/${libsubfolder}/${f}_lyx${_lyx_format_num}")
327       set(mytestlabel ${testlabel} "lyx2lyx" "load")
328       maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
329       if(TestName)
330         add_test(NAME ${TestName}
331           WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
332           COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
333           -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
334           -Dlyx=$<TARGET_FILE:${_lyx}>
335           -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
336           -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
337           -Dformat=lyx${_lyx_format_num}x
338           -Dextension=${_lyx_format_num}.lyx
339           -DLYX_FORMAT_NUM=${_lyx_format_num}
340           -Dfile=${f}
341           -Dinverted=${inverted}
342           -DTOP_SRC_DIR=${TOP_SRC_DIR}
343           -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
344           -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
345         setmarkedtestlabel(${TestName} ${mytestlabel})
346       endif()
347     endforeach()
348     if(LYX_PYTHON_EXECUTABLE)
349       set(lyx2lyxtestlabel "lyx2lyx")
350       # For use of lyx2lyx we need the python executable
351       set(mytestlabel ${lyx2lyxtestlabel})
352       set(TestName "lyx2lyx/${libsubfolder}/${f}")
353       maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
354       if(TestName)
355         add_test(NAME ${TestName}
356           WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
357           COMMAND ${CMAKE_COMMAND}
358           "-DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE}"
359           "-DLYX2LYX=${TOP_SRC_DIR}/lib/lyx2lyx/lyx2lyx"
360           "-DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}"
361           "-DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx"
362           -P "${TOP_SRC_DIR}/development/autotests/lyx2lyxtest.cmake")
363         setmarkedtestlabel(${TestName} ${mytestlabel})
364       endif()
365     endif()
366     set(loadtestlabel "load")
367     set(mytestlabel ${loadtestlabel})
368     set(TestName "check_load/${libsubfolder}/${f}")
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} -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
374         -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
375         -Dlyx=$<TARGET_FILE:${_lyx}>
376         -DPARAMS_DIR=${TOP_SRC_DIR}/development/autotests
377         -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
378         -Dinverted=${inverted}
379         -P "${TOP_SRC_DIR}/development/autotests/check_load.cmake")
380       setmarkedtestlabel(${TestName} ${mytestlabel})
381       #set_tests_properties(${TestName} PROPERTIES RUN_SERIAL ON)
382     endif()
383     set(default_output_format)
384     getoutputformats("${LIBSUB_SRC_DIR}/${f}.lyx" formatlist default_output_format)
385     foreach(format ${formatlist})
386       if(format MATCHES "dvi3|pdf4|pdf5")
387         set(fonttypes "texF" "systemF")
388       else()
389         set(fonttypes "defaultF")
390       endif()
391       foreach(fonttype ${fonttypes})
392         if (format MATCHES "pdf2" AND f MATCHES "latex/unicodesymbols")
393           #message(STATUS "Test ${TestName} matches Unicode encodings")
394           # test_encodings does not include "default", since it should be covered
395           # by one of the supplied encodings
396           set(test_encodings "ascii" "utf8" "utf8x" "armscii8" "applemac"
397             "cp437" "cp437de" "cp850" "cp852"
398             "cp855" "cp862" "cp865"
399             "cp866" "cp1250" "cp1251" "cp1252"
400             "cp1255" "cp1256" "cp1257"
401             "koi8-r" "koi8-u"
402             "iso8859-1" "iso8859-2" "iso8859-3"
403             "iso8859-4" "iso8859-5" "iso8859-6"
404             "iso8859-7" "iso8859-8" "iso8859-9"
405             "iso8859-13" "iso8859-15" "iso8859-16"
406             "pt154" "big5" "shift-jis"
407             "euc-cn" "gbk" "jis" "euc-kr"
408             "utf8-cjk" "euc-tw" "euc-jp"
409             "euc-jp-platex" "jis-platex"
410             "shift-jis-platex" "utf8-platex"
411             "tis620-0")
412         else()
413           set(test_encodings "default")
414         endif()
415         foreach (_enc2 ${test_encodings})
416           if ("${_enc2}" STREQUAL "default")
417             set(_enc "")
418           else()
419             set(_enc "_${_enc2}")
420           endif()
421           if(fonttype MATCHES "defaultF")
422             set(TestName "export/${libsubfolder}/${f}${_enc}_${format}")
423           else()
424             set(TestName "export/${libsubfolder}/${f}${_enc}_${format}_${fonttype}")
425           endif()
426           if (format MATCHES "^${default_output_format}$")
427             set(extraLabels "defaultoutput")
428           else()
429             set(extraLabels )
430           endif()
431           set(missingLabels )
432           findexpr(mfound TestName ignoreLatexErrorsTests missingLabels)
433           if (mfound)
434             set(mytestlabel ${testlabel} "ignoring" ${missingLabels} ${extraLabels})
435           else()
436             set(mytestlabel ${testlabel} ${extraLabels})
437           endif()
438           maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
439           if(TestName)
440             add_test(NAME ${TestName}
441               WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
442               COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
443               -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
444               -Dlyx=$<TARGET_FILE:${_lyx}>
445               -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
446               -Dformat=${format}
447               -Dfonttype=${fonttype}
448               -Dextension=${format}
449               -Dfile=${f}
450               -Dinverted=${inverted}
451               -DTOP_SRC_DIR=${TOP_SRC_DIR}
452               "-DIgnoreErrorMessage=${missingLabels}"
453               -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
454               -DXMLLINT_EXECUTABLE=${XMLLINT_EXECUTABLE}
455               -DENCODING=${_enc2}
456               -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
457             setmarkedtestlabel(${TestName} ${mytestlabel}) # check for suspended pdf/dvi exports
458           endif()
459         endforeach()
460       endforeach()
461     endforeach()
462   endforeach()
463 endforeach()