]> git.lyx.org Git - lyx.git/blob - development/autotests/ExportTests.cmake
ctests: revert a MultilingualCaptions XeTeX test
[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(found "xhtml" ${PDF_FORMATS})
51       elseif(_format MATCHES "dvi")
52         set(out_formats "xhtml" ${DVI_FORMATS})
53       else()
54         # Respect all other output formats
55         # like "eps3", "xhtml"
56         set(out_formats ${_format})
57       endif()
58       break()
59     endif()
60   endforeach()
61   set(${varname} ${out_formats})
62 endmacro()
63
64 macro(findexpr found testname listname)
65   set(_found 0)
66   foreach(_itrx ${${listname}})
67     set(_itr "^${_itrx}$")
68     if(${testname} MATCHES ${_itr})
69       set(_found 1)
70       break()
71     endif()
72   endforeach()
73   set(${found} ${_found})
74 endmacro()
75
76 macro(maketestname testname reverted listreverted listignored)
77   string(REGEX MATCH "\\/[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${${testname}})
78   if(_v)
79     string(REGEX REPLACE "\\/" "" _v ${_v})
80     set(listrevertedx ${listreverted}_${_v})
81     #message(STATUS "${listreverted} ==> ${listrevertedx}")
82     set(listignoredx ${listignored}_${_v})
83     #message(STATUS "${listignored} ==> ${listignoredx}")
84   else()
85     set(listrevertedx ${listreverted})
86     set(listignoredx ${listignored})
87   endif()
88   findexpr(mfound ${testname} ${listignoredx})
89   if (NOT mfound)
90     # check if test _may_ be in listreverted
91     string(REGEX MATCH "_(systemF|texF|pdf3|pdf2|pdf|dvi)$" _v ${${testname}})
92     if (_v)
93       findexpr(mfound ${testname} ${listrevertedx})
94     else()
95       set(mfound OFF)
96     endif()
97     if (NOT mfound)
98       set(${reverted} 0)
99     else()
100       set(${reverted} 1)
101       set(${testname} "INVERTED_SEE-README.ctest_${${testname}}")
102     endif()
103   else()
104     set(${testname} "")
105   endif()
106 endmacro()
107
108 macro(loadTestList filename resList)
109   # Create list of strings from a file without comments
110   file(STRINGS ${filename} tempList)
111   set(${resList})
112   foreach(_l ${tempList})
113     string(REGEX REPLACE "[ \t]*#.*" "" _newl "${_l}")
114     if(_newl)
115       #message(STATUS "Testing ${_newl}")
116       string(REGEX REPLACE "(\\/|\\||\\(|\\))" "  " _vxx ${_newl})
117       string(REGEX MATCHALL " ([a-z][a-z](_[A-Z][A-Z])?) " _vx ${_vxx})
118       if(_vx)
119         foreach(_v ${_vx})
120           string(REGEX REPLACE " " "" _v ${_v})
121           #message(STATUS " ==> ${resList}_${_v}")
122           list(APPEND ${resList}_${_v} "${_newl}")
123         endforeach()
124         if(_newl MATCHES "\\(\\|")
125           #message(STATUS " ==> ${resList}")
126           list(APPEND ${resList} "${_newl}")
127         endif()
128       else()
129         #message(STATUS " ==> ${resList}")
130         list(APPEND ${resList} "${_newl}")
131       endif()
132     endif()
133   endforeach()
134 endmacro()
135
136 loadTestList(revertedTests revertedTests)
137 loadTestList(ignoredTests ignoredTests)
138
139 foreach(libsubfolder doc examples templates)
140   set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/lib/${libsubfolder}")
141   file(GLOB_RECURSE lyx_files RELATIVE "${LIBSUB_SRC_DIR}" "${LIBSUB_SRC_DIR}/*.lyx")
142   list(SORT lyx_files)
143   # Now create 2 lists. One for files in a language dir, one without
144   set(lang_lyx_files)
145   set(nolang_lyx_files)
146   foreach(f ${lyx_files})
147     string(REGEX MATCHALL "^[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${f})
148     if(_v)
149       list(APPEND lang_lyx_files ${f})
150     else()
151       list(APPEND nolang_lyx_files ${f})
152     endif()
153   endforeach()
154   foreach(f ${nolang_lyx_files} ${lang_lyx_files})
155     # Strip extension
156     string(REGEX REPLACE "\\.lyx$" "" f ${f})
157     set(TestName "export/${libsubfolder}/${f}_lyx16")
158     maketestname(TestName reverted revertedTests ignoredTests)
159     if(TestName)
160       add_test(NAME ${TestName}
161         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
162         COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
163         -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
164         -Dlyx=$<TARGET_FILE:${_lyx}>
165         -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
166         -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
167         -Dformat=lyx16x
168         -Dextension=16.lyx
169         -Dfile=${f}
170         -Dreverted=${reverted}
171         -DTOP_SRC_DIR=${TOP_SRC_DIR}
172         -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
173         -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
174       setmarkedtestlabel(${TestName} ${reverted} "export")
175     endif()
176     if(LYX_PYTHON_EXECUTABLE)
177       # For use of lyx2lyx we need the python executable
178       set(TestName "lyx2lyx/${libsubfolder}/${f}")
179       maketestname(TestName reverted revertedTests ignoredTests)
180       if(TestName)
181         add_test(NAME ${TestName}
182           WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
183           COMMAND ${CMAKE_COMMAND}
184           "-DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE}"
185           "-DLYX2LYX=${TOP_SRC_DIR}/lib/lyx2lyx/lyx2lyx"
186           "-DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}"
187           "-DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx"
188           -P "${TOP_SRC_DIR}/development/autotests/lyx2lyxtest.cmake")
189         setmarkedtestlabel(${TestName} ${reverted} "lyx2lyx")
190       endif()
191     endif()
192     set(TestName "check_load/${libsubfolder}/${f}")
193     maketestname(TestName reverted revertedTests ignoredTests)
194     if(TestName)
195       add_test(NAME ${TestName}
196         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
197         COMMAND ${CMAKE_COMMAND} -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
198         -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
199         -Dlyx=$<TARGET_FILE:${_lyx}>
200         -DPARAMS_DIR=${TOP_SRC_DIR}/development/autotests
201         -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
202         -P "${TOP_SRC_DIR}/development/autotests/check_load.cmake")
203       setmarkedtestlabel(${TestName} ${reverted} "load")
204     endif()
205     getoutputformats("${LIBSUB_SRC_DIR}/${f}.lyx" formatlist)
206     foreach(format ${formatlist})
207       if(format MATCHES "dvi3|pdf4|pdf5")
208         set(fonttypes "texF" "systemF")
209       else()
210         set(fonttypes "defaultF")
211       endif()
212       foreach(fonttype ${fonttypes})
213         if(fonttype MATCHES "defaultF")
214           set(TestName "export/${libsubfolder}/${f}_${format}")
215         else()
216           set(TestName "export/${libsubfolder}/${f}_${format}_${fonttype}")
217         endif()
218         maketestname(TestName reverted revertedTests ignoredTests)
219         if(TestName)
220           add_test(NAME ${TestName}
221             WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
222             COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
223             -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
224             -Dlyx=$<TARGET_FILE:${_lyx}>
225             -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
226             -Dformat=${format}
227             -Dfonttype=${fonttype}
228             -Dextension=${format}
229             -Dfile=${f}
230             -Dreverted=${reverted}
231             -DTOP_SRC_DIR=${TOP_SRC_DIR}
232             -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
233             -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
234           setmarkedtestlabel(${TestName} ${reverted} "export")
235         endif()
236       endforeach()
237     endforeach()
238   endforeach()
239 endforeach()