]> git.lyx.org Git - lyx.git/blob - development/autotests/ExportTests.cmake
Cmake export tests: Allow deeper label nesting.
[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   set(locallist ${${rvalues}})
101   list(REMOVE_ITEM locallist "export" "lyx2lyx" "load")
102   string(REGEX REPLACE "([^\\]|^);" "\\1${glue}" out "${locallist}")
103   set(${routput} ${out} PARENT_SCOPE)
104 endfunction()
105
106 macro(maketestname testname inverted listsuspicious listignored listunreliable listlabels)
107   string(REGEX MATCH "\\/[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${${testname}})
108   if(_v)
109     string(REGEX REPLACE "\\/" "" _v ${_v})
110     set(listsuspiciousx ${listsuspicious}_${_v})
111     set(listignoredx ${listignored}_${_v})
112     set(listunreliablex ${listunreliable}_${_v})
113     set(listsuspendedx suspendedTests_${_v})
114   else()
115     set(listsuspiciousx ${listsuspicious})
116     set(listignoredx ${listignored})
117     set(listunreliablex ${listunreliable})
118     set(listsuspendedx suspendedTests)
119   endif()
120   set(sublabel "${${listlabels}}")
121   findexpr(mfound ${testname} ${listignoredx} sublabel)
122   if (NOT mfound)
123     set(sublabel2 "")
124     findexpr(foundunreliable ${testname} ${listunreliablex} sublabel2)
125     if (foundunreliable)
126       set(sublabel "unreliable" ${sublabel} ${sublabel2})
127       list(REMOVE_ITEM sublabel "export" "inverted" "templates" "mathmacros" "manuals" "autotests")
128     else()
129       string(REGEX MATCH "_(systemF|texF|pdf3|pdf2|pdf|dvi|lyx16|xhtml)$" _v ${${testname}})
130       # check if test _may_ be in listsuspicious
131       set(sublabel2 "")
132       if (_v)
133         findexpr(mfound ${testname} ${listsuspiciousx} sublabel2)
134       else()
135         set(mfound OFF)
136       endif()
137       if (mfound)
138         set(sublabel3 "")
139         findexpr(foundsuspended ${testname} ${listsuspendedx} sublabel3)
140         set(${inverted} 1)
141         if (foundsuspended)
142           set(sublabel "suspended" ${sublabel} ${sublabel2} ${sublabel3})
143           list(REMOVE_ITEM sublabel "export" "inverted" )
144         else()
145           set(sublabel "inverted" ${sublabel} ${sublabel2} ${sublabel3})
146         endif()
147       else()
148         set(${inverted} 0)
149       endif()
150     endif()
151     list(REMOVE_DUPLICATES sublabel)
152     if (NOT sublabel STREQUAL "")
153       join(sublabel "." tmpprefixx)
154       string(TOUPPER "${tmpprefixx}_" tmpprefix)
155       set(${testname} "${tmpprefix}${${testname}}")
156       set(${listlabels} ${sublabel})
157     endif()
158   else()
159     # No testname because ignored
160     set(${testname} "")
161   endif()
162 endmacro()
163
164 macro(loadTestList filename resList depth)
165   # Create list of strings from a file without comments
166   # ENCODING parameter is a new feature in cmake 3.1
167   if (CMAKE_VERSION VERSION_GREATER "3.1")
168     file(STRINGS ${filename} tempList ENCODING "UTF-8")
169   else()
170     file(STRINGS ${filename} tempList)
171   endif()
172   set(${resList})
173   set(sublabel)
174   set(mylabels "")
175   set(languages "")
176   message(STATUS "Reading list ${filename}")
177   foreach(_l ${tempList})
178     set(_newl "${_l}")
179     string(REGEX REPLACE "[ \t]+$" "" _newl "${_l}")
180     string(REGEX REPLACE "[ \t]*#.*$" "" _newl "${_l}")
181     if(_newl)
182       list(APPEND ${resList} "${_newl}")
183       if (_newl MATCHES "^Sublabel:")
184         string(REGEX REPLACE "^Sublabel:[ \t]*" "" _newlabels ${_newl})
185         string(REGEX MATCHALL "([0-9]*[a-zA-Z]+)" _labels ${_newlabels})
186         foreach(labname ${_labels})
187           if (NOT labname STREQUAL "RESET")
188             list(APPEND mylabels ${labname})
189           endif()
190         endforeach()
191         list(REMOVE_DUPLICATES mylabels)
192         set(sublabel ${_newl})
193       else()
194         string(REGEX REPLACE "(\\/|\\||\\(|\\))" "  " _vxx ${_newl})
195         string(REGEX MATCHALL " ([a-z][a-z](_[A-Z][A-Z])?) " _vx ${_vxx})
196         if(_vx)
197           foreach(_v ${_vx})
198             string(REGEX REPLACE " " "" _v ${_v})
199             #message(STATUS " ==> ${resList}_${_v}")
200             #message(STATUS "sublabel = ${sublabel}, sublabel_${_v} = ${sublabel_${_v}}")
201             if (NOT sublabel STREQUAL "${sublabel_${_v}}")
202               list(APPEND ${resList}_${_v} "${sublabel}")
203               set(sublabel_${_v} "${sublabel}")
204               #message(STATUS "Setting variable sublabel_${_v} with \"${sublabel}\"")
205             endif()
206             list(APPEND ${resList}_${_v} "${_newl}")
207             list(APPEND languages ${_v})
208           endforeach()
209           list(REMOVE_DUPLICATES languages)
210           #message(STATUS "languages = ${languages}")
211         endif()
212       endif()
213     endif()
214   endforeach()
215   foreach(_l1 ${mylabels})
216     if (_l1 MATCHES "^([0-9]+)([a-zA-Z]+)$")
217       set(_l ${CMAKE_MATCH_2})
218       set(depth1 ${CMAKE_MATCH_1})
219     else()
220       set(_l ${_l1})
221       set(depth1 "0")
222     endif()
223     list(FIND known_labels ${_l} _ff)
224     if (_ff GREATER -1)
225       message(STATUS "Label \"${_l}\" already in use. Reused in ${filename}")
226     else()
227       assignLabelDepth(${depth}${depth1} ${_l})
228     endif()
229   endforeach()
230   foreach(_lg ${languages})
231     # reset label for each used language string at end of file
232     #message(STATUS "Resetting variable sublabel_${_lg}, previously set to ${sublabel_${_lg}}")
233     set(sublabel_${_lg} "")
234   endforeach()
235 endmacro()
236
237 # This labels should not be used in .*Tests files
238 set(known_labels "")
239 # Create depth info to each label
240 macro(assignLabelDepth depth)
241   foreach(_lab ${ARGN})
242     list(APPEND known_labels ${_lab})
243     set(depth_${_lab} ${depth})
244   endforeach()
245 endmacro()
246
247 assignLabelDepth(0 "export" "key" "layout" "load" "lyx2lyx" "module" "roundtrip" "url")
248 assignLabelDepth(1 "unreliable" "inverted")
249 assignLabelDepth(2 "suspended")
250 assignLabelDepth(3 "examples" "manuals" "mathmacros" "templates" "autotests")
251
252 loadTestList(suspiciousTests suspiciousTests 7)
253 loadTestList(ignoredTests ignoredTests 0)
254 loadTestList(suspendedTests suspendedTests 6)
255 loadTestList(unreliableTests unreliableTests 5)
256
257 # preparing to add e.g. development/mathmacros to the foreach() loop
258 foreach(libsubfolderx autotests/export lib/doc lib/examples lib/templates development/mathmacros)
259   set(testlabel "export")
260   if (libsubfolderx MATCHES "lib/doc")
261     list(APPEND testlabel "manuals")
262   elseif (libsubfolderx MATCHES "lib/examples")
263     list(APPEND testlabel "examples")
264   elseif (libsubfolderx MATCHES "lib/templates")
265     list(APPEND testlabel "templates")
266   elseif (libsubfolderx MATCHES "development/mathmacros")
267     list(APPEND testlabel "mathmacros")
268   elseif (libsubfolderx MATCHES "autotests/.+")
269     list(APPEND testlabel "autotests")
270   endif()
271   set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
272   string(REGEX REPLACE "^(lib|development|autotests)/" "" libsubfolder "${libsubfolderx}")
273   set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
274   message(STATUS "Handling export dir ${LIBSUB_SRC_DIR}")
275   file(GLOB_RECURSE lyx_files RELATIVE "${LIBSUB_SRC_DIR}" "${LIBSUB_SRC_DIR}/*.lyx")
276   list(SORT lyx_files)
277   # Now create 2 lists. One for files in a language dir, one without
278   set(lang_lyx_files)
279   set(nolang_lyx_files)
280   foreach(f ${lyx_files})
281     string(REGEX MATCHALL "^[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${f})
282     if(_v)
283       list(APPEND lang_lyx_files ${f})
284     else()
285       list(APPEND nolang_lyx_files ${f})
286     endif()
287   endforeach()
288   foreach(f ${nolang_lyx_files} ${lang_lyx_files})
289     # Strip extension
290     string(REGEX REPLACE "\\.lyx$" "" f ${f})
291     set(TestName "export/${libsubfolder}/${f}_lyx16")
292     set(mytestlabel ${testlabel})
293     maketestname(TestName inverted suspiciousTests ignoredTests unreliableTests mytestlabel)
294     if(TestName)
295       add_test(NAME ${TestName}
296         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
297         COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
298         -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
299         -Dlyx=$<TARGET_FILE:${_lyx}>
300         -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
301         -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
302         -Dformat=lyx16x
303         -Dextension=16.lyx
304         -Dfile=${f}
305         -Dinverted=${inverted}
306         -DTOP_SRC_DIR=${TOP_SRC_DIR}
307         -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
308         -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
309       setmarkedtestlabel(${TestName} ${mytestlabel})
310     endif()
311     if(LYX_PYTHON_EXECUTABLE)
312       set(lyx2lyxtestlabel "lyx2lyx")
313       # For use of lyx2lyx we need the python executable
314       set(mytestlabel ${lyx2lyxtestlabel})
315       set(TestName "lyx2lyx/${libsubfolder}/${f}")
316       maketestname(TestName inverted suspiciousTests ignoredTests unreliableTests mytestlabel)
317       if(TestName)
318         add_test(NAME ${TestName}
319           WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
320           COMMAND ${CMAKE_COMMAND}
321           "-DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE}"
322           "-DLYX2LYX=${TOP_SRC_DIR}/lib/lyx2lyx/lyx2lyx"
323           "-DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}"
324           "-DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx"
325           -P "${TOP_SRC_DIR}/development/autotests/lyx2lyxtest.cmake")
326         setmarkedtestlabel(${TestName} ${mytestlabel})
327       endif()
328     endif()
329     set(loadtestlabel "load")
330     set(mytestlabel ${loadtestlabel})
331     set(TestName "check_load/${libsubfolder}/${f}")
332     maketestname(TestName inverted suspiciousTests ignoredTests unreliableTests mytestlabel)
333     if(TestName)
334       add_test(NAME ${TestName}
335         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
336         COMMAND ${CMAKE_COMMAND} -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
337         -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
338         -Dlyx=$<TARGET_FILE:${_lyx}>
339         -DPARAMS_DIR=${TOP_SRC_DIR}/development/autotests
340         -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
341         -P "${TOP_SRC_DIR}/development/autotests/check_load.cmake")
342       setmarkedtestlabel(${TestName} ${mytestlabel})
343       set_tests_properties(${TestName} PROPERTIES RUN_SERIAL ON)
344     endif()
345     getoutputformats("${LIBSUB_SRC_DIR}/${f}.lyx" formatlist)
346     foreach(format ${formatlist})
347       if(format MATCHES "dvi3|pdf4|pdf5")
348         set(fonttypes "texF" "systemF")
349       else()
350         set(fonttypes "defaultF")
351       endif()
352       foreach(fonttype ${fonttypes})
353         if(fonttype MATCHES "defaultF")
354           set(TestName "export/${libsubfolder}/${f}_${format}")
355         else()
356           set(TestName "export/${libsubfolder}/${f}_${format}_${fonttype}")
357         endif()
358         set(mytestlabel ${testlabel})
359         maketestname(TestName inverted suspiciousTests ignoredTests unreliableTests mytestlabel)
360         if(TestName)
361           add_test(NAME ${TestName}
362             WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
363             COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
364             -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
365             -Dlyx=$<TARGET_FILE:${_lyx}>
366             -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
367             -Dformat=${format}
368             -Dfonttype=${fonttype}
369             -Dextension=${format}
370             -Dfile=${f}
371             -Dinverted=${inverted}
372             -DTOP_SRC_DIR=${TOP_SRC_DIR}
373             -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
374             -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
375           setmarkedtestlabel(${TestName} ${mytestlabel}) # check for suspended pdf/dvi exports
376         endif()
377       endforeach()
378     endforeach()
379   endforeach()
380 endforeach()