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