]> git.lyx.org Git - lyx.git/blob - development/autotests/ExportTests.cmake
Cmake export tests: Correct some mistakes in commit 4138ab7
[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(sublabel "")
69   foreach(_itrx ${${listname}})
70     if ("${_itrx}" MATCHES "^Sublabel:")
71       set(sublabel "")
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(sublabel "")
77         else()
78           list(APPEND sublabel ${subl})
79         endif()
80       endforeach()
81       # remove doubles in sublabel
82       list(REMOVE_DUPLICATES sublabel)
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 "${sublabel}" STREQUAL "")
93       set(${rsublabel} ${sublabel})
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 listreverted 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(listrevertedx ${listreverted}_${_v})
110     set(listignoredx ${listignored}_${_v})
111     set(listunreliablex ${listunreliable}_${_v})
112   else()
113     set(listrevertedx ${listreverted})
114     set(listignoredx ${listignored})
115     set(listunreliablex ${listunreliable})
116   endif()
117   findexpr(mfound ${testname} ${listignoredx} sublabel)
118   if (NOT mfound)
119     # check if they are unreliable
120     set(sublabel "")
121     findexpr(nsfound ${testname} ${listunreliablex} sublabel)
122     if (nsfound)
123       if (NOT "${sublabel}" STREQUAL "")
124         list(APPEND ${listlabels} ${sublabel})
125         join(sublabel "." tmpprefixx)
126         string(TOUPPER "${tmpprefixx}_" tmpprefix)
127       else()
128         set(tmpprefix "")
129       endif()
130       set(${testname} "UNRELIABLE.${tmpprefix}${${testname}}")
131     else ()
132       string(REGEX MATCH "_(systemF|texF|pdf3|pdf2|pdf|dvi|lyx16|xhtml)$" _v ${${testname}})
133       set(sublabel "")
134       # check if test _may_ be in listreverted
135       if (_v)
136         findexpr(mfound ${testname} ${listrevertedx} sublabel)
137       else()
138         set(mfound OFF)
139       endif()
140       if (NOT mfound)
141         set(${reverted} 0)
142       else()
143         set(${reverted} 1)
144         if (NOT sublabel STREQUAL "")
145           string(TOUPPER "${sublabel}_" tmpprefix)
146         else()
147           set(tmpprefix "ctest_")
148         endif()
149         set(${testname} "INVERTED_SEE-README.${tmpprefix}${${testname}}")
150         if (NOT sublabel STREQUAL "")
151           list(APPEND ${listlabels} ${sublabel})
152         endif()
153       endif()
154     endif()
155   else()
156     set(${testname} "")
157   endif()
158 endmacro()
159
160 # This labels should not be used in .*Tests files
161 set(known_labels "export" "key" "layout" "load" "lyx2lyx"
162   "examples" "manuals" "mathmacros" "reverted" "templates" "unreliable" "suspended" 
163   "module" "roundtrip" "url")
164
165 macro(loadTestList filename resList)
166   # Create list of strings from a file without comments
167   # ENCODING parameter is a new feature in cmake 3.1
168   if (CMAKE_VERSION VERSION_GREATER "3.1")
169     file(STRINGS ${filename} tempList ENCODING "UTF-8")
170   else()
171     file(STRINGS ${filename} tempList)
172   endif()
173   set(${resList})
174   set(sublabel)
175   set(mylabels "")
176   set(languages "")
177   message(STATUS "Reading list ${filename}")
178   foreach(_l ${tempList})
179     set(_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 "([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(_l ${mylabels})
216     list(FIND known_labels ${_l} _ff)
217     if (_ff GREATER -1)
218       message(STATUS "Label \"${_l}\" already in use. Reused in ${filename}")
219     else()
220       list(APPEND known_labels ${_l})
221     endif()
222   endforeach()
223   foreach(_lg ${languages})
224     # reset label for each used language string at end of file
225     #message(STATUS "Resetting variable sublabel_${_lg}, previously set to ${sublabel_${_lg}}")
226     set(sublabel_${_lg} "")
227   endforeach()
228 endmacro()
229
230 loadTestList(revertedTests revertedTests)
231 loadTestList(ignoredTests ignoredTests)
232 loadTestList(suspendedTests suspendedTests)
233 loadTestList(unreliableTests unreliableTests)
234
235 macro(handlesuspended TestName reverted testlabel)
236   set(mylabel ${${testlabel}})
237   set(myreverted ${reverted})
238   set(sublabel)
239
240   # check for unreliable
241   if ("${TestName}" MATCHES "^UNRELIABLE")
242     list(REMOVE_ITEM mylabel "export" "reverted" "templates" "mathmacros" "manuals")
243     list(APPEND mylabel "unreliable")
244     set(myreverted 0)
245   elseif (${reverted})
246     # check suspension only for reverted tests
247     findexpr(tfound TestName suspendedTests sublabel)
248     if (tfound)
249       set(mylabel "suspended")
250       if (sublabel)
251         list(APPEND mylabel ${sublabel})
252       endif()
253       set(myreverted 0) # if test is to be suspended, remove the 'reverted' flag
254     endif()
255   endif()
256   setmarkedtestlabel(${TestName} ${myreverted} ${mylabel})
257 endmacro()
258
259 # preparing to add e.g. development/mathmacros to the foreach() loop
260 foreach(libsubfolderx lib/doc lib/examples lib/templates development/mathmacros autotests/export)
261   set(testlabel "export")
262   if (libsubfolderx MATCHES "lib/doc")
263     list(APPEND testlabel "manuals")
264   elseif (libsubfolderx MATCHES "lib/examples")
265     list(APPEND testlabel "examples")
266   elseif (libsubfolderx MATCHES "lib/templates")
267     list(APPEND testlabel "templates")
268   elseif (libsubfolderx MATCHES "development/mathmacros")
269     list(APPEND testlabel "mathmacros")
270   elseif (libsubfolderx MATCHES "autotests/.+")
271     list(APPEND testlabel "autotests")
272   endif()
273   set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
274   string(REGEX REPLACE "^(lib|development|autotests)/" "" libsubfolder "${libsubfolderx}")
275   set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
276   message(STATUS "Handling export dir ${LIBSUB_SRC_DIR}")
277   file(GLOB_RECURSE lyx_files RELATIVE "${LIBSUB_SRC_DIR}" "${LIBSUB_SRC_DIR}/*.lyx")
278   list(SORT lyx_files)
279   # Now create 2 lists. One for files in a language dir, one without
280   set(lang_lyx_files)
281   set(nolang_lyx_files)
282   foreach(f ${lyx_files})
283     string(REGEX MATCHALL "^[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${f})
284     if(_v)
285       list(APPEND lang_lyx_files ${f})
286     else()
287       list(APPEND nolang_lyx_files ${f})
288     endif()
289   endforeach()
290   foreach(f ${nolang_lyx_files} ${lang_lyx_files})
291     # Strip extension
292     string(REGEX REPLACE "\\.lyx$" "" f ${f})
293     set(TestName "export/${libsubfolder}/${f}_lyx16")
294     set(mytestlabel ${testlabel})
295     maketestname(TestName reverted revertedTests ignoredTests unreliableTests mytestlabel)
296     if(TestName)
297       add_test(NAME ${TestName}
298         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
299         COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
300         -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
301         -Dlyx=$<TARGET_FILE:${_lyx}>
302         -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
303         -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
304         -Dformat=lyx16x
305         -Dextension=16.lyx
306         -Dfile=${f}
307         -Dreverted=${reverted}
308         -DTOP_SRC_DIR=${TOP_SRC_DIR}
309         -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
310         -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
311       handlesuspended(${TestName} ${reverted} mytestlabel) # checking for suspended lyx16 exports
312     endif()
313     if(LYX_PYTHON_EXECUTABLE)
314       set(lyx2lyxtestlabel "lyx2lyx")
315       # For use of lyx2lyx we need the python executable
316       set(mytestlabel ${lyx2lyxtestlabel})
317       set(TestName "lyx2lyx/${libsubfolder}/${f}")
318       maketestname(TestName reverted revertedTests ignoredTests unreliableTests mytestlabel)
319       if(TestName)
320         add_test(NAME ${TestName}
321           WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
322           COMMAND ${CMAKE_COMMAND}
323           "-DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE}"
324           "-DLYX2LYX=${TOP_SRC_DIR}/lib/lyx2lyx/lyx2lyx"
325           "-DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}"
326           "-DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx"
327           -P "${TOP_SRC_DIR}/development/autotests/lyx2lyxtest.cmake")
328         handlesuspended(${TestName} ${reverted} mytestlabel)
329       endif()
330     endif()
331     set(loadtestlabel "load")
332     set(mytestlabel ${loadtestlabel})
333     set(TestName "check_load/${libsubfolder}/${f}")
334     maketestname(TestName reverted revertedTests ignoredTests unreliableTests mytestlabel)
335     if(TestName)
336       add_test(NAME ${TestName}
337         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
338         COMMAND ${CMAKE_COMMAND} -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
339         -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
340         -Dlyx=$<TARGET_FILE:${_lyx}>
341         -DPARAMS_DIR=${TOP_SRC_DIR}/development/autotests
342         -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
343         -P "${TOP_SRC_DIR}/development/autotests/check_load.cmake")
344       handlesuspended(${TestName} ${reverted} mytestlabel)
345       set_tests_properties(${TestName} PROPERTIES RUN_SERIAL ON)
346     endif()
347     getoutputformats("${LIBSUB_SRC_DIR}/${f}.lyx" formatlist)
348     foreach(format ${formatlist})
349       if(format MATCHES "dvi3|pdf4|pdf5")
350         set(fonttypes "texF" "systemF")
351       else()
352         set(fonttypes "defaultF")
353       endif()
354       foreach(fonttype ${fonttypes})
355         if(fonttype MATCHES "defaultF")
356           set(TestName "export/${libsubfolder}/${f}_${format}")
357         else()
358           set(TestName "export/${libsubfolder}/${f}_${format}_${fonttype}")
359         endif()
360         set(mytestlabel ${testlabel})
361         maketestname(TestName reverted revertedTests ignoredTests unreliableTests mytestlabel)
362         if(TestName)
363           add_test(NAME ${TestName}
364             WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
365             COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
366             -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
367             -Dlyx=$<TARGET_FILE:${_lyx}>
368             -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
369             -Dformat=${format}
370             -Dfonttype=${fonttype}
371             -Dextension=${format}
372             -Dfile=${f}
373             -Dreverted=${reverted}
374             -DTOP_SRC_DIR=${TOP_SRC_DIR}
375             -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
376             -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
377           handlesuspended(${TestName} ${reverted} mytestlabel) # check for suspended pdf/dvi exports
378         endif()
379       endforeach()
380     endforeach()
381   endforeach()
382 endforeach()