]> git.lyx.org Git - lyx.git/blob - development/autotests/ExportTests.cmake
ec46ad0cc8d8cd68839ae00195786edb16b87329
[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
31 if(PERL_FOUND)
32   set(DVI_FORMATS "dvi" "dvi3")
33   set(PDF_FORMATS "pdf" "pdf2" "pdf3" "pdf4" "pdf5")
34 else()
35   set(DVI_FORMATS "dvi")
36   set(PDF_FORMATS "pdf" "pdf2" "pdf3")
37 endif()
38
39 macro(getoutputformats filepath varname)
40   file(STRINGS "${filepath}" lines)
41   # What should we test, if default_output_format is not defined?
42   # For now we test everything ...
43   set(out_formats "xhtml" ${DVI_FORMATS} ${PDF_FORMATS})
44   foreach(_l ${lines})
45     if(_l MATCHES "^\\\\default_output_format +\([^ ]+\)")
46       set(_format ${CMAKE_MATCH_1})
47       if(_format STREQUAL "default")
48         set(out_formats "xhtml" ${DVI_FORMATS} ${PDF_FORMATS})
49       elseif(_format MATCHES "pdf$")
50         set(out_formats "xhtml" ${PDF_FORMATS})
51       elseif(_format MATCHES "dvi$")
52         set(out_formats "xhtml" ${DVI_FORMATS})
53       elseif(_format MATCHES "xhtml")
54         set(out_formats "xhtml")
55       else()
56         # Respect all other output formats
57         # like "eps3"
58         set(out_formats "xhtml" ${_format})
59       endif()
60       break()
61     endif()
62   endforeach()
63   set(${varname} ${out_formats})
64 endmacro()
65
66 macro(findexpr found testname listname rsublabel)
67   set(_found 0)
68   set(tmpsublabel "")
69   foreach(_itrx ${${listname}})
70     if ("${_itrx}" MATCHES "^Sublabel:")
71       set(tmpsublabel "")
72       string(REGEX REPLACE "^Sublabel:[ \t]*" "" _itrlabels ${_itrx})
73       string(REGEX MATCHALL "([a-zA-Z]+)" _labels ${_itrlabels})
74       foreach(subl ${_labels})
75         if (subl STREQUAL "RESET")
76           set(tmpsublabel "")
77         else()
78           list(APPEND tmpsublabel ${subl})
79         endif()
80       endforeach()
81       # remove doubles in sublabel
82       list(REMOVE_DUPLICATES tmpsublabel)
83     else()
84       set(_itr "^${_itrx}$")
85       if (${testname} MATCHES "${_itr}")
86         set(_found 1)
87         break()
88       endif()
89     endif()
90   endforeach()
91   if (${_found})
92     if (NOT "${tmpsublabel}" STREQUAL "")
93       list(APPEND ${rsublabel} ${tmpsublabel})
94     endif()
95   endif()
96   set(${found} ${_found})
97 endmacro()
98
99 function(join rvalues glue routput)
100   string(REGEX REPLACE "([^\\]|^);" "\\1${glue}" out "${${rvalues}}")
101   set(${routput} ${out} PARENT_SCOPE)
102 endfunction()
103
104 macro(maketestname testname reverted listsuspicious listignored listunreliable listlabels)
105   set(sublabel "")
106   string(REGEX MATCH "\\/[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${${testname}})
107   if(_v)
108     string(REGEX REPLACE "\\/" "" _v ${_v})
109     set(listsuspiciousx ${listsuspicious}_${_v})
110     set(listignoredx ${listignored}_${_v})
111     set(listunreliablex ${listunreliable}_${_v})
112   else()
113     set(listsuspiciousx ${listsuspicious})
114     set(listignoredx ${listignored})
115     set(listunreliablex ${listunreliable})
116   endif()
117   findexpr(mfound ${testname} ${listignoredx} sublabel)
118   if (NOT mfound)
119     string(REGEX MATCH "_(systemF|texF|pdf3|pdf2|pdf|dvi|lyx16|xhtml)$" _v ${${testname}})
120     set(sublabel "")
121     # check if test _may_ be in listsuspicious
122     if (_v)
123       findexpr(mfound ${testname} ${listsuspiciousx} sublabel)
124     else()
125       set(mfound OFF)
126     endif()
127     if (NOT mfound)
128       set(${reverted} 0)
129     else()
130       # Now that the test is suspect,
131       # check if it is unreliable, and/or suspended
132       set(sublabel2 "")
133       findexpr(nsfound ${testname} ${listunreliablex} sublabel2)
134       findexpr(nsfound2 ${testname} suspendedTests sublabel2)
135       list(APPEND sublabel ${sublabel2})
136       if (nsfound)
137         set(sublabel "unreliable" ${sublabel})
138       endif()
139       if (nsfound2)
140         set(sublabel "suspended" ${sublabel})
141         message(STATUS "found suspended test ${${testname}}")
142       endif()
143       list(REMOVE_DUPLICATES sublabel)
144       if (nsfound OR nsfound2)
145         list(APPEND ${listlabels} ${sublabel})
146         set(${reverted} 0)
147       else()
148         set(sublabel "reverted" ${sublabel})
149         set(${reverted} 1)
150       endif()
151       join(sublabel "." tmpprefixx)
152       string(TOUPPER "${tmpprefixx}_" tmpprefix)
153       set(${testname} "${tmpprefix}${${testname}}")
154       string(TOUPPER "${sublabel}_" tmpprefix)
155       if (NOT sublabel STREQUAL "")
156         list(APPEND ${listlabels} ${sublabel})
157         list(FIND ${listlabels} "chemgreek" _i)
158       endif()
159     endif()
160   else()
161     set(${testname} "")
162   endif()
163 endmacro()
164
165 # This labels should not be used in .*Tests files
166 set(known_labels "export" "key" "layout" "load" "lyx2lyx"
167   "examples" "manuals" "mathmacros" "reverted" "templates" "unreliable" "suspended" 
168   "module" "roundtrip" "url")
169
170 macro(loadTestList filename resList)
171   # Create list of strings from a file without comments
172   # ENCODING parameter is a new feature in cmake 3.1
173   if (CMAKE_VERSION VERSION_GREATER "3.1")
174     file(STRINGS ${filename} tempList ENCODING "UTF-8")
175   else()
176     file(STRINGS ${filename} tempList)
177   endif()
178   set(${resList})
179   set(sublabel)
180   set(mylabels "")
181   set(languages "")
182   message(STATUS "Reading list ${filename}")
183   foreach(_l ${tempList})
184     set(_newl "${_l}")
185     string(REGEX REPLACE "[ \t]*#.*$" "" _newl "${_l}")
186     if(_newl)
187       list(APPEND ${resList} "${_newl}")
188       if (_newl MATCHES "^Sublabel:")
189         string(REGEX REPLACE "^Sublabel:[ \t]*" "" _newlabels ${_newl})
190         string(REGEX MATCHALL "([a-zA-Z]+)" _labels ${_newlabels})
191         foreach(labname ${_labels})
192           if (NOT labname STREQUAL "RESET")
193             list(APPEND mylabels ${labname})
194           endif()
195         endforeach()
196         list(REMOVE_DUPLICATES mylabels)
197         set(sublabel ${_newl})
198       else()
199         string(REGEX REPLACE "(\\/|\\||\\(|\\))" "  " _vxx ${_newl})
200         string(REGEX MATCHALL " ([a-z][a-z](_[A-Z][A-Z])?) " _vx ${_vxx})
201         if(_vx)
202           foreach(_v ${_vx})
203             string(REGEX REPLACE " " "" _v ${_v})
204             #message(STATUS " ==> ${resList}_${_v}")
205             #message(STATUS "sublabel = ${sublabel}, sublabel_${_v} = ${sublabel_${_v}}")
206             if (NOT sublabel STREQUAL "${sublabel_${_v}}")
207               list(APPEND ${resList}_${_v} "${sublabel}")
208               set(sublabel_${_v} "${sublabel}")
209               #message(STATUS "Setting variable sublabel_${_v} with \"${sublabel}\"")
210             endif()
211             list(APPEND ${resList}_${_v} "${_newl}")
212             list(APPEND languages ${_v})
213           endforeach()
214           list(REMOVE_DUPLICATES languages)
215           #message(STATUS "languages = ${languages}")
216         endif()
217       endif()
218     endif()
219   endforeach()
220   foreach(_l ${mylabels})
221     list(FIND known_labels ${_l} _ff)
222     if (_ff GREATER -1)
223       message(STATUS "Label \"${_l}\" already in use. Reused in ${filename}")
224     else()
225       list(APPEND known_labels ${_l})
226     endif()
227   endforeach()
228   foreach(_lg ${languages})
229     # reset label for each used language string at end of file
230     #message(STATUS "Resetting variable sublabel_${_lg}, previously set to ${sublabel_${_lg}}")
231     set(sublabel_${_lg} "")
232   endforeach()
233 endmacro()
234
235 loadTestList(suspiciousTests suspiciousTests)
236 loadTestList(ignoredTests ignoredTests)
237 loadTestList(suspendedTests suspendedTests)
238 loadTestList(unreliableTests unreliableTests)
239
240 macro(handlesuspended TestName reverted testlabel)
241   set(mylabel ${${testlabel}})
242   set(myreverted ${reverted})
243   set(sublabel)
244
245   # check for unreliable
246   if ("${TestName}" MATCHES "^UNRELIABLE")
247     list(REMOVE_ITEM mylabel "export" "reverted" "templates" "mathmacros" "manuals")
248     list(APPEND mylabel "unreliable")
249     set(myreverted 0)
250   elseif (${reverted})
251     # check suspension only for reverted tests
252     findexpr(tfound TestName suspendedTests sublabel)
253     if (tfound)
254       set(mylabel "suspended")
255       if (sublabel)
256         list(APPEND mylabel ${sublabel})
257       endif()
258       set(myreverted 0) # if test is to be suspended, remove the 'reverted' flag
259     endif()
260   endif()
261   setmarkedtestlabel(${TestName} ${myreverted} ${mylabel})
262 endmacro()
263
264 # preparing to add e.g. development/mathmacros to the foreach() loop
265 foreach(libsubfolderx lib/doc lib/examples lib/templates development/mathmacros autotests/export)
266   set(testlabel "export")
267   if (libsubfolderx MATCHES "lib/doc")
268     list(APPEND testlabel "manuals")
269   elseif (libsubfolderx MATCHES "lib/examples")
270     list(APPEND testlabel "examples")
271   elseif (libsubfolderx MATCHES "lib/templates")
272     list(APPEND testlabel "templates")
273   elseif (libsubfolderx MATCHES "development/mathmacros")
274     list(APPEND testlabel "mathmacros")
275   elseif (libsubfolderx MATCHES "autotests/.+")
276     list(APPEND testlabel "autotests")
277   endif()
278   set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
279   string(REGEX REPLACE "^(lib|development|autotests)/" "" libsubfolder "${libsubfolderx}")
280   set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
281   message(STATUS "Handling export dir ${LIBSUB_SRC_DIR}")
282   file(GLOB_RECURSE lyx_files RELATIVE "${LIBSUB_SRC_DIR}" "${LIBSUB_SRC_DIR}/*.lyx")
283   list(SORT lyx_files)
284   # Now create 2 lists. One for files in a language dir, one without
285   set(lang_lyx_files)
286   set(nolang_lyx_files)
287   foreach(f ${lyx_files})
288     string(REGEX MATCHALL "^[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${f})
289     if(_v)
290       list(APPEND lang_lyx_files ${f})
291     else()
292       list(APPEND nolang_lyx_files ${f})
293     endif()
294   endforeach()
295   foreach(f ${nolang_lyx_files} ${lang_lyx_files})
296     # Strip extension
297     string(REGEX REPLACE "\\.lyx$" "" f ${f})
298     set(TestName "export/${libsubfolder}/${f}_lyx16")
299     set(mytestlabel ${testlabel})
300     maketestname(TestName reverted suspiciousTests ignoredTests unreliableTests mytestlabel)
301     if(TestName)
302       add_test(NAME ${TestName}
303         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
304         COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
305         -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
306         -Dlyx=$<TARGET_FILE:${_lyx}>
307         -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
308         -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
309         -Dformat=lyx16x
310         -Dextension=16.lyx
311         -Dfile=${f}
312         -Dreverted=${reverted}
313         -DTOP_SRC_DIR=${TOP_SRC_DIR}
314         -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
315         -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
316       handlesuspended(${TestName} ${reverted} mytestlabel) # checking for suspended lyx16 exports
317     endif()
318     if(LYX_PYTHON_EXECUTABLE)
319       set(lyx2lyxtestlabel "lyx2lyx")
320       # For use of lyx2lyx we need the python executable
321       set(mytestlabel ${lyx2lyxtestlabel})
322       set(TestName "lyx2lyx/${libsubfolder}/${f}")
323       maketestname(TestName reverted suspiciousTests ignoredTests unreliableTests mytestlabel)
324       if(TestName)
325         add_test(NAME ${TestName}
326           WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
327           COMMAND ${CMAKE_COMMAND}
328           "-DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE}"
329           "-DLYX2LYX=${TOP_SRC_DIR}/lib/lyx2lyx/lyx2lyx"
330           "-DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}"
331           "-DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx"
332           -P "${TOP_SRC_DIR}/development/autotests/lyx2lyxtest.cmake")
333         handlesuspended(${TestName} ${reverted} mytestlabel)
334       endif()
335     endif()
336     set(loadtestlabel "load")
337     set(mytestlabel ${loadtestlabel})
338     set(TestName "check_load/${libsubfolder}/${f}")
339     maketestname(TestName reverted suspiciousTests ignoredTests unreliableTests mytestlabel)
340     if(TestName)
341       add_test(NAME ${TestName}
342         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
343         COMMAND ${CMAKE_COMMAND} -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
344         -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
345         -Dlyx=$<TARGET_FILE:${_lyx}>
346         -DPARAMS_DIR=${TOP_SRC_DIR}/development/autotests
347         -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
348         -P "${TOP_SRC_DIR}/development/autotests/check_load.cmake")
349       handlesuspended(${TestName} ${reverted} mytestlabel)
350       set_tests_properties(${TestName} PROPERTIES RUN_SERIAL ON)
351     endif()
352     getoutputformats("${LIBSUB_SRC_DIR}/${f}.lyx" formatlist)
353     foreach(format ${formatlist})
354       if(format MATCHES "dvi3|pdf4|pdf5")
355         set(fonttypes "texF" "systemF")
356       else()
357         set(fonttypes "defaultF")
358       endif()
359       foreach(fonttype ${fonttypes})
360         if(fonttype MATCHES "defaultF")
361           set(TestName "export/${libsubfolder}/${f}_${format}")
362         else()
363           set(TestName "export/${libsubfolder}/${f}_${format}_${fonttype}")
364         endif()
365         set(mytestlabel ${testlabel})
366         maketestname(TestName reverted suspiciousTests ignoredTests unreliableTests mytestlabel)
367         if(TestName)
368           add_test(NAME ${TestName}
369             WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
370             COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
371             -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
372             -Dlyx=$<TARGET_FILE:${_lyx}>
373             -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
374             -Dformat=${format}
375             -Dfonttype=${fonttype}
376             -Dextension=${format}
377             -Dfile=${f}
378             -Dreverted=${reverted}
379             -DTOP_SRC_DIR=${TOP_SRC_DIR}
380             -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
381             -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
382           handlesuspended(${TestName} ${reverted} mytestlabel) # check for suspended pdf/dvi exports
383         endif()
384       endforeach()
385     endforeach()
386   endforeach()
387 endforeach()