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