]> git.lyx.org Git - features.git/blob - development/autotests/ExportTests.cmake
Cmake export tests: Removed unneded parameter
[features.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:[ \t]*\([a-z]+\)[ \t]*$")
71       set(sublabel "${CMAKE_MATCH_1}")
72       if (sublabel STREQUAL "RESET")
73         set(sublabel "")
74       endif()
75     else()
76       set(_itr "^${_itrx}$")
77       if (${testname} MATCHES "${_itr}")
78         set(_found 1)
79         break()
80       endif()
81     endif()
82   endforeach()
83   if (${_found})
84     if (NOT "${sublabel}" STREQUAL "")
85       set(${rsublabel} ${sublabel})
86     endif()
87   endif()
88   set(${found} ${_found})
89 endmacro()
90
91 macro(maketestname testname reverted listreverted listignored listunreliable listlabels)
92   set(sublabel "")
93   string(REGEX MATCH "\\/[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${${testname}})
94   if(_v)
95     string(REGEX REPLACE "\\/" "" _v ${_v})
96     set(listrevertedx ${listreverted}_${_v})
97     set(listignoredx ${listignored}_${_v})
98     set(listunreliablex ${listunreliable}_${_v})
99   else()
100     set(listrevertedx ${listreverted})
101     set(listignoredx ${listignored})
102     set(listunreliablex ${listunreliable})
103   endif()
104   findexpr(mfound ${testname} ${listignoredx} sublabel)
105   if (NOT mfound)
106     # check if they are unreliable
107     set(sublabel "")
108     findexpr(nsfound ${testname} ${listunreliablex} sublabel)
109     if (nsfound)
110       if (NOT "${sublabel}" STREQUAL "")
111         list(APPEND ${listlabels} ${sublabel})
112         string(TOUPPER "${sublabel}_" tmpprefix)
113       else()
114         set(tmpprefix "")
115       endif()
116       set(${testname} "UNRELIABLE.${tmpprefix}${${testname}}")
117     else ()
118       string(REGEX MATCH "_(systemF|texF|pdf3|pdf2|pdf|dvi|lyx16|xhtml)$" _v ${${testname}})
119       set(sublabel "")
120       # check if test _may_ be in listreverted
121       if (_v)
122         findexpr(mfound ${testname} ${listrevertedx} sublabel)
123       else()
124         set(mfound OFF)
125       endif()
126       if (NOT mfound)
127         set(${reverted} 0)
128       else()
129         set(${reverted} 1)
130         if (NOT sublabel STREQUAL "")
131           string(TOUPPER "${sublabel}_" tmpprefix)
132         else()
133           set(tmpprefix "ctest_")
134         endif()
135         set(${testname} "INVERTED_SEE-README.${tmpprefix}${${testname}}")
136         if (NOT sublabel STREQUAL "")
137           list(APPEND ${listlabels} ${sublabel})
138         endif()
139       endif()
140     endif()
141   else()
142     set(${testname} "")
143   endif()
144 endmacro()
145
146 # This labels should not be used in .*Tests files
147 set(known_labels "export" "key" "layout" "load" "lyx2lyx"
148   "examples" "manuals" "mathmacros" "reverted" "templates" "unreliable" "suspended" 
149   "module" "roundtrip" "url")
150
151 macro(loadTestList filename resList)
152   # Create list of strings from a file without comments
153   file(STRINGS ${filename} tempList ENCODING "UTF-8")
154   set(${resList})
155   set(sublabel)
156   set(mylabels "")
157   foreach(_l ${tempList})
158     set(_newl "${_l}")
159     string(REGEX REPLACE "[ \t]*#.*$" "" _newl "${_l}")
160     if(_newl)
161       string(REGEX REPLACE "(\\/|\\||\\(|\\))" "  " _vxx ${_newl})
162       string(REGEX MATCHALL " ([a-z][a-z](_[A-Z][A-Z])?) " _vx ${_vxx})
163       if (_newl MATCHES "^Sublabel:[ \t]*\([a-zA-Z]+\)")
164         set(labname ${CMAKE_MATCH_1})
165         if (NOT labname STREQUAL "RESET")
166           list(REMOVE_ITEM mylabels ${labname})
167           list(APPEND mylabels ${labname})
168         endif()
169         set(sublabel ${_newl})
170       endif()
171       if(_vx)
172         foreach(_v ${_vx})
173           string(REGEX REPLACE " " "" _v ${_v})
174           #message(STATUS " ==> ${resList}_${_v}")
175           if (NOT ${sublabel} STREQUAL "${sublabel}_${_v}")
176             list(APPEND ${resList}_${_v} "${sublabel}")
177             set(${sublabel}_${_v} "${sublabel}")
178           endif()
179           list(APPEND ${resList}_${_v} "${_newl}")
180         endforeach()
181         if(_newl MATCHES "\\(\\|")
182           #message(STATUS " ==> ${resList}")
183           list(APPEND ${resList} "${_newl}")
184         endif()
185       else()
186         #message(STATUS " ==> ${resList}")
187         list(APPEND ${resList} "${_newl}")
188       endif()
189     endif()
190   endforeach()
191   foreach(_l ${mylabels})
192     list(FIND known_labels ${_l} _ff)
193     if (_ff GREATER -1)
194       message(STATUS "Label \"${_l}\" already in use. Reused in ${filename}")
195     else()
196       list(APPEND known_labels ${_l})
197     endif()
198   endforeach()
199 endmacro()
200
201 loadTestList(revertedTests revertedTests)
202 loadTestList(ignoredTests ignoredTests)
203 loadTestList(suspendedTests suspendedTests)
204 loadTestList(unreliableTests unreliableTests)
205
206 macro(handlesuspended TestName reverted testlabel)
207   set(mylabel ${${testlabel}})
208   set(myreverted ${reverted})
209   set(sublabel)
210
211   # check for unreliable
212   if ("${TestName}" MATCHES "^UNRELIABLE")
213     list(REMOVE_ITEM mylabel "export" "reverted" "templates" "mathmacros" "manuals")
214     list(APPEND mylabel "unreliable")
215     set(myreverted 0)
216   elseif (${reverted})
217     # check suspension only for reverted tests
218     findexpr(tfound TestName suspendedTests sublabel)
219     if (tfound)
220       set(mylabel "suspended")
221       if (sublabel)
222         list(APPEND mylabel ${sublabel})
223       endif()
224       set(myreverted 0) # if test is to be suspended, remove the 'reverted' flag
225     endif()
226   endif()
227   setmarkedtestlabel(${TestName} ${myreverted} ${mylabel})
228 endmacro()
229
230 # preparing to add e.g. development/mathmacros to the foreach() loop
231 foreach(libsubfolderx lib/doc lib/examples lib/templates development/mathmacros autotests/export)
232   set(testlabel "export")
233   if (libsubfolderx MATCHES "lib/doc")
234     list(APPEND testlabel "manuals")
235   elseif (libsubfolderx MATCHES "lib/examples")
236     list(APPEND testlabel "examples")
237   elseif (libsubfolderx MATCHES "lib/templates")
238     list(APPEND testlabel "templates")
239   elseif (libsubfolderx MATCHES "development/mathmacros")
240     list(APPEND testlabel "mathmacros")
241   elseif (libsubfolderx MATCHES "autotests/.+")
242     list(APPEND testlabel "autotests")
243   endif()
244   set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
245   string(REGEX REPLACE "^(lib|development|autotests)/" "" libsubfolder "${libsubfolderx}")
246   set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
247   message(STATUS "Handling export dir ${LIBSUB_SRC_DIR}")
248   file(GLOB_RECURSE lyx_files RELATIVE "${LIBSUB_SRC_DIR}" "${LIBSUB_SRC_DIR}/*.lyx")
249   list(SORT lyx_files)
250   # Now create 2 lists. One for files in a language dir, one without
251   set(lang_lyx_files)
252   set(nolang_lyx_files)
253   foreach(f ${lyx_files})
254     string(REGEX MATCHALL "^[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${f})
255     if(_v)
256       list(APPEND lang_lyx_files ${f})
257     else()
258       list(APPEND nolang_lyx_files ${f})
259     endif()
260   endforeach()
261   foreach(f ${nolang_lyx_files} ${lang_lyx_files})
262     # Strip extension
263     string(REGEX REPLACE "\\.lyx$" "" f ${f})
264     set(TestName "export/${libsubfolder}/${f}_lyx16")
265     set(mytestlabel ${testlabel})
266     maketestname(TestName reverted revertedTests ignoredTests unreliableTests mytestlabel)
267     if(TestName)
268       add_test(NAME ${TestName}
269         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
270         COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
271         -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
272         -Dlyx=$<TARGET_FILE:${_lyx}>
273         -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
274         -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
275         -Dformat=lyx16x
276         -Dextension=16.lyx
277         -Dfile=${f}
278         -Dreverted=${reverted}
279         -DTOP_SRC_DIR=${TOP_SRC_DIR}
280         -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
281         -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
282       handlesuspended(${TestName} ${reverted} mytestlabel) # checking for suspended lyx16 exports
283     endif()
284     if(LYX_PYTHON_EXECUTABLE)
285       set(lyx2lyxtestlabel "lyx2lyx")
286       # For use of lyx2lyx we need the python executable
287       set(mytestlabel ${lyx2lyxtestlabel})
288       set(TestName "lyx2lyx/${libsubfolder}/${f}")
289       maketestname(TestName reverted revertedTests ignoredTests unreliableTests mytestlabel)
290       if(TestName)
291         add_test(NAME ${TestName}
292           WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
293           COMMAND ${CMAKE_COMMAND}
294           "-DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE}"
295           "-DLYX2LYX=${TOP_SRC_DIR}/lib/lyx2lyx/lyx2lyx"
296           "-DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}"
297           "-DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx"
298           -P "${TOP_SRC_DIR}/development/autotests/lyx2lyxtest.cmake")
299         handlesuspended(${TestName} ${reverted} mytestlabel)
300       endif()
301     endif()
302     set(loadtestlabel "load")
303     set(mytestlabel ${loadtestlabel})
304     set(TestName "check_load/${libsubfolder}/${f}")
305     maketestname(TestName reverted revertedTests ignoredTests unreliableTests mytestlabel)
306     if(TestName)
307       add_test(NAME ${TestName}
308         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
309         COMMAND ${CMAKE_COMMAND} -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
310         -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
311         -Dlyx=$<TARGET_FILE:${_lyx}>
312         -DPARAMS_DIR=${TOP_SRC_DIR}/development/autotests
313         -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
314         -P "${TOP_SRC_DIR}/development/autotests/check_load.cmake")
315       handlesuspended(${TestName} ${reverted} mytestlabel)
316       set_tests_properties(${TestName} PROPERTIES RUN_SERIAL ON)
317     endif()
318     getoutputformats("${LIBSUB_SRC_DIR}/${f}.lyx" formatlist)
319     foreach(format ${formatlist})
320       if(format MATCHES "dvi3|pdf4|pdf5")
321         set(fonttypes "texF" "systemF")
322       else()
323         set(fonttypes "defaultF")
324       endif()
325       foreach(fonttype ${fonttypes})
326         if(fonttype MATCHES "defaultF")
327           set(TestName "export/${libsubfolder}/${f}_${format}")
328         else()
329           set(TestName "export/${libsubfolder}/${f}_${format}_${fonttype}")
330         endif()
331         set(mytestlabel ${testlabel})
332         maketestname(TestName reverted revertedTests ignoredTests unreliableTests mytestlabel)
333         if(TestName)
334           add_test(NAME ${TestName}
335             WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
336             COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
337             -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
338             -Dlyx=$<TARGET_FILE:${_lyx}>
339             -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
340             -Dformat=${format}
341             -Dfonttype=${fonttype}
342             -Dextension=${format}
343             -Dfile=${f}
344             -Dreverted=${reverted}
345             -DTOP_SRC_DIR=${TOP_SRC_DIR}
346             -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
347             -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
348           handlesuspended(${TestName} ${reverted} mytestlabel) # check for suspended pdf/dvi exports
349         endif()
350       endforeach()
351     endforeach()
352   endforeach()
353 endforeach()