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