]> git.lyx.org Git - lyx.git/blob - development/autotests/ExportTests.cmake
ctests: uninvert solved problems and make samples robust
[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)
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       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")
69       else()
70         # Respect all other output formats
71         # like "eps3"
72         set(out_formats "xhtml" ${_format})
73       endif()
74       break()
75     endif()
76   endforeach()
77   set(${varname} ${out_formats})
78 endmacro()
79
80 macro(findexpr found testname listname rsublabel)
81   set(_found 0)
82   set(tmpsublabel "")
83   foreach(_itrx ${${listname}})
84     if ("${_itrx}" MATCHES "^Sublabel:")
85       set(tmpsublabel "")
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")
90           set(tmpsublabel "")
91         else()
92           list(APPEND tmpsublabel ${subl})
93         endif()
94       endforeach()
95       # remove doubles in sublabel
96       list(REMOVE_DUPLICATES tmpsublabel)
97     else()
98       set(_itr "^${_itrx}$")
99       if (${testname} MATCHES "${_itr}")
100         set(_found 1)
101         break()
102       endif()
103     endif()
104   endforeach()
105   if (${_found})
106     if (NOT "${tmpsublabel}" STREQUAL "")
107       list(APPEND ${rsublabel} ${tmpsublabel})
108     endif()
109   endif()
110   set(${found} ${_found})
111 endmacro()
112
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})
119     endif()
120   endforeach()
121   list(REMOVE_ITEM locallist ${removelist})
122   string(REGEX REPLACE "([^\\]|^);" "\\1${glue}" out "${locallist}")
123   set(${routput} ${out} PARENT_SCOPE)
124 endfunction()
125
126 macro(maketestname testname inverted listinverted listignored listunreliable listlabels)
127   # initialize output variable
128   set(${inverted} 0)
129   string(REGEX MATCH "\\/[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${${testname}})
130   if(_v)
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})
136   else()
137     set(listinvertedx ${listinverted})
138     set(listignoredx ${listignored})
139     set(listunreliablex ${listunreliable})
140     set(listsuspendedx suspendedTests)
141   endif()
142   set(sublabel "${${listlabels}}")
143   findexpr(mfound ${testname} ${listignoredx} sublabel)
144   if (NOT mfound)
145     set(sublabel2 "")
146     findexpr(foundunreliable ${testname} ${listunreliablex} sublabel2)
147     if (foundunreliable)
148       set(sublabel "unreliable" ${sublabel} ${sublabel2})
149       list(REMOVE_ITEM sublabel "export" "inverted" "templates" "mathmacros" "manuals" "autotests")
150     else()
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
153       set(sublabel2 "")
154       if (_v)
155         findexpr(mfound ${testname} ${listinvertedx} sublabel2)
156       else()
157         set(mfound OFF)
158       endif()
159       if (mfound)
160         set(sublabel3 "")
161         findexpr(foundsuspended ${testname} ${listsuspendedx} sublabel3)
162         set(${inverted} 1)
163         if (foundsuspended)
164           set(sublabel "suspended" ${sublabel} ${sublabel2} ${sublabel3})
165           list(REMOVE_ITEM sublabel "export" "inverted" )
166         else()
167           set(sublabel "inverted" ${sublabel} ${sublabel2} ${sublabel3})
168         endif()
169       else()
170         set(${inverted} 0)
171       endif()
172     endif()
173     list(REMOVE_DUPLICATES sublabel)
174     if (NOT sublabel STREQUAL "")
175       join(sublabel "." tmpprefixx)
176       if (tmpprefixx)
177         string(TOUPPER "${tmpprefixx}_" tmpprefix)
178       else()
179         set(tmpprefix "")
180       endif()
181       set(${testname} "${tmpprefix}${${testname}}")
182       set(${listlabels} ${sublabel})
183     endif()
184   else()
185     # No testname because ignored
186     set(${testname} "")
187   endif()
188 endmacro()
189
190 macro(loadTestList filename resList depth)
191   # Create list of strings from a file without comments
192   # ENCODING parameter is a new feature in cmake 3.1
193   initLangVars(${resList})
194   initLangVars("sublabel")
195   if (CMAKE_VERSION VERSION_GREATER "3.1")
196     file(STRINGS ${filename} tempList ENCODING "UTF-8")
197   else()
198     file(STRINGS ${filename} tempList)
199   endif()
200   set(${resList})
201   set(sublabel)
202   set(mylabels "")
203   set(languages "")
204   message(STATUS "Reading list ${filename}")
205   foreach(_l ${tempList})
206     set(_newl "${_l}")
207     string(REGEX REPLACE "[ \t]+$" "" _newl "${_l}")
208     string(REGEX REPLACE "[ \t]*#.*$" "" _newl "${_l}")
209     if(_newl)
210       list(APPEND ${resList} "${_newl}")
211       if (_newl MATCHES "^Sublabel:")
212         string(REGEX REPLACE "^Sublabel:[ \t]*" "" _newlabels ${_newl})
213         string(REGEX MATCHALL "([0-9]*${label_chars})" _labels ${_newlabels})
214         foreach(labname ${_labels})
215           if (NOT labname STREQUAL "RESET")
216             list(APPEND mylabels ${labname})
217           endif()
218         endforeach()
219         list(REMOVE_DUPLICATES mylabels)
220         set(sublabel ${_newl})
221       else()
222         string(REGEX REPLACE "(\\/|\\||\\(|\\))" "  " _vxx ${_newl})
223         string(REGEX MATCHALL " ([a-z][a-z](_[A-Z][A-Z])?) " _vx ${_vxx})
224         if(_vx)
225           foreach(_v ${_vx})
226             string(REGEX REPLACE " " "" _v ${_v})
227             #message(STATUS " ==> ${resList}_${_v}")
228             #message(STATUS "sublabel = ${sublabel}, sublabel_${_v} = ${sublabel_${_v}}")
229             if (NOT sublabel STREQUAL "${sublabel_${_v}}")
230               list(APPEND ${resList}_${_v} "${sublabel}")
231               set(sublabel_${_v} "${sublabel}")
232               #message(STATUS "Setting variable sublabel_${_v} with \"${sublabel}\"")
233             endif()
234             list(APPEND ${resList}_${_v} "${_newl}")
235             list(APPEND languages ${_v})
236           endforeach()
237           list(REMOVE_DUPLICATES languages)
238           #message(STATUS "languages = ${languages}")
239         endif()
240       endif()
241     endif()
242   endforeach()
243   foreach(_l1 ${mylabels})
244     if (_l1 MATCHES "^([0-9]+)(${label_chars})$")
245       set(_l ${CMAKE_MATCH_2})
246       set(depth1 ${CMAKE_MATCH_1})
247     else()
248       set(_l ${_l1})
249       set(depth1 "0")
250     endif()
251     list(FIND known_labels ${_l} _ff)
252     if (_ff GREATER -1)
253       message(STATUS "Label \"${_l}\" already in use. Reused in ${filename}")
254     else()
255       assignLabelDepth(${depth}${depth1} ${_l})
256     endif()
257   endforeach()
258   foreach(_lg ${languages})
259     # reset label for each used language string at end of file
260     #message(STATUS "Resetting variable sublabel_${_lg}, previously set to ${sublabel_${_lg}}")
261     set(sublabel_${_lg} "")
262   endforeach()
263 endmacro()
264
265 # This labels should not be used in .*Tests files
266 set(known_labels "")
267 # Create depth info to each label
268 macro(assignLabelDepth depth)
269   foreach(_lab ${ARGN})
270     list(APPEND known_labels ${_lab})
271     set(depth_${_lab} ${depth})
272   endforeach()
273 endmacro()
274
275 assignLabelDepth(0 "export" "key" "layout" "load" "lyx2lyx" "module" "roundtrip" "url")
276 assignLabelDepth(1 "unreliable" "inverted")
277 assignLabelDepth(2 "suspended")
278 assignLabelDepth(-1 "examples" "manuals" "mathmacros" "templates" "autotests")
279
280 loadTestList(invertedTests invertedTests 7)
281 loadTestList(ignoredTests ignoredTests 0)
282 loadTestList(suspendedTests suspendedTests 6)
283 loadTestList(unreliableTests unreliableTests 5)
284
285 foreach(libsubfolderx autotests/export lib/doc lib/examples lib/templates autotests/mathmacros)
286   set(testlabel "export")
287   if (libsubfolderx MATCHES "lib/doc")
288     list(APPEND testlabel "manuals")
289   elseif (libsubfolderx MATCHES "lib/examples")
290     list(APPEND testlabel "examples")
291   elseif (libsubfolderx MATCHES "lib/templates")
292     list(APPEND testlabel "templates")
293   elseif (libsubfolderx MATCHES "autotests/mathmacros")
294     list(APPEND testlabel "mathmacros")
295   elseif (libsubfolderx MATCHES "autotests/.+")
296     list(APPEND testlabel "autotests")
297   endif()
298   set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
299   string(REGEX REPLACE "^(lib|development|autotests)/" "" libsubfolder "${libsubfolderx}")
300   set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
301   message(STATUS "Handling export dir ${LIBSUB_SRC_DIR}")
302   file(GLOB_RECURSE lyx_files RELATIVE "${LIBSUB_SRC_DIR}" "${LIBSUB_SRC_DIR}/*.lyx")
303   list(SORT lyx_files)
304   # Now create 2 lists. One for files in a language dir, one without
305   set(lang_lyx_files)
306   set(nolang_lyx_files)
307   foreach(f ${lyx_files})
308     string(REGEX MATCHALL "^[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${f})
309     if(_v)
310       list(APPEND lang_lyx_files ${f})
311     else()
312       list(APPEND nolang_lyx_files ${f})
313     endif()
314   endforeach()
315   foreach(f ${nolang_lyx_files} ${lang_lyx_files})
316     # Strip extension
317     string(REGEX REPLACE "\\.lyx$" "" f ${f})
318     foreach(_lyx_format_num 16 21 22)
319       set(TestName "export/${libsubfolder}/${f}_lyx${_lyx_format_num}")
320       set(mytestlabel ${testlabel} "lyx2lyx" "load")
321       maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
322       if(TestName)
323         add_test(NAME ${TestName}
324           WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
325           COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
326           -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
327           -Dlyx=$<TARGET_FILE:${_lyx}>
328           -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
329           -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
330           -Dformat=lyx${_lyx_format_num}x
331           -Dextension=${_lyx_format_num}.lyx
332           -DLYX_FORMAT_NUM=${_lyx_format_num}
333           -Dfile=${f}
334           -Dinverted=${inverted}
335           -DTOP_SRC_DIR=${TOP_SRC_DIR}
336           -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
337           -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
338         setmarkedtestlabel(${TestName} ${mytestlabel})
339       endif()
340     endforeach()
341     if(LYX_PYTHON_EXECUTABLE)
342       set(lyx2lyxtestlabel "lyx2lyx")
343       # For use of lyx2lyx we need the python executable
344       set(mytestlabel ${lyx2lyxtestlabel})
345       set(TestName "lyx2lyx/${libsubfolder}/${f}")
346       maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
347       if(TestName)
348         add_test(NAME ${TestName}
349           WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
350           COMMAND ${CMAKE_COMMAND}
351           "-DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE}"
352           "-DLYX2LYX=${TOP_SRC_DIR}/lib/lyx2lyx/lyx2lyx"
353           "-DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}"
354           "-DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx"
355           -P "${TOP_SRC_DIR}/development/autotests/lyx2lyxtest.cmake")
356         setmarkedtestlabel(${TestName} ${mytestlabel})
357       endif()
358     endif()
359     set(loadtestlabel "load")
360     set(mytestlabel ${loadtestlabel})
361     set(TestName "check_load/${libsubfolder}/${f}")
362     maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
363     if(TestName)
364       add_test(NAME ${TestName}
365         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
366         COMMAND ${CMAKE_COMMAND} -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
367         -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
368         -Dlyx=$<TARGET_FILE:${_lyx}>
369         -DPARAMS_DIR=${TOP_SRC_DIR}/development/autotests
370         -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
371         -Dinverted=${inverted}
372         -P "${TOP_SRC_DIR}/development/autotests/check_load.cmake")
373       setmarkedtestlabel(${TestName} ${mytestlabel})
374       #set_tests_properties(${TestName} PROPERTIES RUN_SERIAL ON)
375     endif()
376     getoutputformats("${LIBSUB_SRC_DIR}/${f}.lyx" formatlist)
377     foreach(format ${formatlist})
378       if(format MATCHES "dvi3|pdf4|pdf5")
379         set(fonttypes "texF" "systemF")
380       else()
381         set(fonttypes "defaultF")
382       endif()
383       foreach(fonttype ${fonttypes})
384         if(fonttype MATCHES "defaultF")
385           set(TestName "export/${libsubfolder}/${f}_${format}")
386         else()
387           set(TestName "export/${libsubfolder}/${f}_${format}_${fonttype}")
388         endif()
389         set(mytestlabel ${testlabel})
390         maketestname(TestName inverted invertedTests ignoredTests unreliableTests mytestlabel)
391         if(TestName)
392           add_test(NAME ${TestName}
393             WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
394             COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
395             -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
396             -Dlyx=$<TARGET_FILE:${_lyx}>
397             -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
398             -Dformat=${format}
399             -Dfonttype=${fonttype}
400             -Dextension=${format}
401             -Dfile=${f}
402             -Dinverted=${inverted}
403             -DTOP_SRC_DIR=${TOP_SRC_DIR}
404             -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
405             -DXMLLINT_EXECUTABLE=${XMLLINT_EXECUTABLE}
406             -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
407           setmarkedtestlabel(${TestName} ${mytestlabel}) # check for suspended pdf/dvi exports
408         endif()
409       endforeach()
410     endforeach()
411   endforeach()
412 endforeach()