]> git.lyx.org Git - features.git/blob - development/autotests/ExportTests.cmake
Cmake build: Initialize some variables before use.
[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 set(potential_languages "ca" "cs" "da" "de" "el" "es" "eu" "fa" "fr" "gl" "he" "hu" "id" "it" "ja" "ko" "nb" "nl" "pl" "pt" "ro" "ru" "sk" "sl" "sr" "sv" "uk" "zh_CN")
40
41 macro(initLangVars varname)
42   foreach(_l ${potential_languages})
43     set(${varname}_${_l})
44   endforeach()
45 endmacro()
46
47 macro(getoutputformats filepath varname)
48   file(STRINGS "${filepath}" lines)
49   # What should we test, if default_output_format is not defined?
50   # For now we test everything ...
51   set(out_formats "xhtml" ${DVI_FORMATS} ${PDF_FORMATS})
52   foreach(_l ${lines})
53     if(_l MATCHES "^\\\\default_output_format +\([^ ]+\)")
54       set(_format ${CMAKE_MATCH_1})
55       if(_format STREQUAL "default")
56         set(out_formats "xhtml" ${DVI_FORMATS} ${PDF_FORMATS})
57       elseif(_format MATCHES "pdf$")
58         set(out_formats "xhtml" ${PDF_FORMATS})
59       elseif(_format MATCHES "dvi$")
60         set(out_formats "xhtml" ${DVI_FORMATS})
61       elseif(_format MATCHES "xhtml")
62         set(out_formats "xhtml")
63       else()
64         # Respect all other output formats
65         # like "eps3"
66         set(out_formats "xhtml" ${_format})
67       endif()
68       break()
69     endif()
70   endforeach()
71   set(${varname} ${out_formats})
72 endmacro()
73
74 macro(findexpr found testname listname rsublabel)
75   set(_found 0)
76   set(tmpsublabel "")
77   foreach(_itrx ${${listname}})
78     if ("${_itrx}" MATCHES "^Sublabel:")
79       set(tmpsublabel "")
80       string(REGEX REPLACE "^Sublabel:[ \t]*" "" _itrlabels ${_itrx})
81       string(REGEX MATCHALL "[a-zA-Z]+" _labels ${_itrlabels})
82       foreach(subl ${_labels})
83         if (subl STREQUAL "RESET")
84           set(tmpsublabel "")
85         else()
86           list(APPEND tmpsublabel ${subl})
87         endif()
88       endforeach()
89       # remove doubles in sublabel
90       list(REMOVE_DUPLICATES tmpsublabel)
91     else()
92       set(_itr "^${_itrx}$")
93       if (${testname} MATCHES "${_itr}")
94         set(_found 1)
95         break()
96       endif()
97     endif()
98   endforeach()
99   if (${_found})
100     if (NOT "${tmpsublabel}" STREQUAL "")
101       list(APPEND ${rsublabel} ${tmpsublabel})
102     endif()
103   endif()
104   set(${found} ${_found})
105 endmacro()
106
107 function(join rvalues glue routput)
108   set(locallist ${${rvalues}})
109   list(REMOVE_ITEM locallist "export" "lyx2lyx" "load")
110   string(REGEX REPLACE "([^\\]|^);" "\\1${glue}" out "${locallist}")
111   set(${routput} ${out} PARENT_SCOPE)
112 endfunction()
113
114 macro(maketestname testname inverted listsuspicious listignored listunreliable listlabels)
115   string(REGEX MATCH "\\/[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${${testname}})
116   if(_v)
117     string(REGEX REPLACE "\\/" "" _v ${_v})
118     set(listsuspiciousx ${listsuspicious}_${_v})
119     set(listignoredx ${listignored}_${_v})
120     set(listunreliablex ${listunreliable}_${_v})
121     set(listsuspendedx suspendedTests_${_v})
122   else()
123     set(listsuspiciousx ${listsuspicious})
124     set(listignoredx ${listignored})
125     set(listunreliablex ${listunreliable})
126     set(listsuspendedx suspendedTests)
127   endif()
128   set(sublabel "${${listlabels}}")
129   findexpr(mfound ${testname} ${listignoredx} sublabel)
130   if (NOT mfound)
131     set(sublabel2 "")
132     findexpr(foundunreliable ${testname} ${listunreliablex} sublabel2)
133     if (foundunreliable)
134       set(sublabel "unreliable" ${sublabel} ${sublabel2})
135       list(REMOVE_ITEM sublabel "export" "inverted" "templates" "mathmacros" "manuals" "autotests")
136     else()
137       string(REGEX MATCH "_(systemF|texF|pdf3|pdf2|pdf|dvi|lyx16|xhtml)$" _v ${${testname}})
138       # check if test _may_ be in listsuspicious
139       set(sublabel2 "")
140       if (_v)
141         findexpr(mfound ${testname} ${listsuspiciousx} sublabel2)
142       else()
143         set(mfound OFF)
144       endif()
145       if (mfound)
146         set(sublabel3 "")
147         findexpr(foundsuspended ${testname} ${listsuspendedx} sublabel3)
148         set(${inverted} 1)
149         if (foundsuspended)
150           set(sublabel "suspended" ${sublabel} ${sublabel2} ${sublabel3})
151           list(REMOVE_ITEM sublabel "export" "inverted" )
152         else()
153           set(sublabel "inverted" ${sublabel} ${sublabel2} ${sublabel3})
154         endif()
155       else()
156         set(${inverted} 0)
157       endif()
158     endif()
159     list(REMOVE_DUPLICATES sublabel)
160     if (NOT sublabel STREQUAL "")
161       join(sublabel "." tmpprefixx)
162       string(TOUPPER "${tmpprefixx}_" tmpprefix)
163       set(${testname} "${tmpprefix}${${testname}}")
164       set(${listlabels} ${sublabel})
165     endif()
166   else()
167     # No testname because ignored
168     set(${testname} "")
169   endif()
170 endmacro()
171
172 macro(loadTestList filename resList depth)
173   # Create list of strings from a file without comments
174   # ENCODING parameter is a new feature in cmake 3.1
175   initLangVars(${resList})
176   initLangVars("sublabel")
177   if (CMAKE_VERSION VERSION_GREATER "3.1")
178     file(STRINGS ${filename} tempList ENCODING "UTF-8")
179   else()
180     file(STRINGS ${filename} tempList)
181   endif()
182   set(${resList})
183   set(sublabel)
184   set(mylabels "")
185   set(languages "")
186   message(STATUS "Reading list ${filename}")
187   foreach(_l ${tempList})
188     set(_newl "${_l}")
189     string(REGEX REPLACE "[ \t]+$" "" _newl "${_l}")
190     string(REGEX REPLACE "[ \t]*#.*$" "" _newl "${_l}")
191     if(_newl)
192       list(APPEND ${resList} "${_newl}")
193       if (_newl MATCHES "^Sublabel:")
194         string(REGEX REPLACE "^Sublabel:[ \t]*" "" _newlabels ${_newl})
195         string(REGEX MATCHALL "([0-9]*[a-zA-Z]+)" _labels ${_newlabels})
196         foreach(labname ${_labels})
197           if (NOT labname STREQUAL "RESET")
198             list(APPEND mylabels ${labname})
199           endif()
200         endforeach()
201         list(REMOVE_DUPLICATES mylabels)
202         set(sublabel ${_newl})
203       else()
204         string(REGEX REPLACE "(\\/|\\||\\(|\\))" "  " _vxx ${_newl})
205         string(REGEX MATCHALL " ([a-z][a-z](_[A-Z][A-Z])?) " _vx ${_vxx})
206         if(_vx)
207           foreach(_v ${_vx})
208             string(REGEX REPLACE " " "" _v ${_v})
209             #message(STATUS " ==> ${resList}_${_v}")
210             #message(STATUS "sublabel = ${sublabel}, sublabel_${_v} = ${sublabel_${_v}}")
211             if (NOT sublabel STREQUAL "${sublabel_${_v}}")
212               list(APPEND ${resList}_${_v} "${sublabel}")
213               set(sublabel_${_v} "${sublabel}")
214               #message(STATUS "Setting variable sublabel_${_v} with \"${sublabel}\"")
215             endif()
216             list(APPEND ${resList}_${_v} "${_newl}")
217             list(APPEND languages ${_v})
218           endforeach()
219           list(REMOVE_DUPLICATES languages)
220           #message(STATUS "languages = ${languages}")
221         endif()
222       endif()
223     endif()
224   endforeach()
225   foreach(_l1 ${mylabels})
226     if (_l1 MATCHES "^([0-9]+)([a-zA-Z]+)$")
227       set(_l ${CMAKE_MATCH_2})
228       set(depth1 ${CMAKE_MATCH_1})
229     else()
230       set(_l ${_l1})
231       set(depth1 "0")
232     endif()
233     list(FIND known_labels ${_l} _ff)
234     if (_ff GREATER -1)
235       message(STATUS "Label \"${_l}\" already in use. Reused in ${filename}")
236     else()
237       assignLabelDepth(${depth}${depth1} ${_l})
238     endif()
239   endforeach()
240   foreach(_lg ${languages})
241     # reset label for each used language string at end of file
242     #message(STATUS "Resetting variable sublabel_${_lg}, previously set to ${sublabel_${_lg}}")
243     set(sublabel_${_lg} "")
244   endforeach()
245 endmacro()
246
247 # This labels should not be used in .*Tests files
248 set(known_labels "")
249 # Create depth info to each label
250 macro(assignLabelDepth depth)
251   foreach(_lab ${ARGN})
252     list(APPEND known_labels ${_lab})
253     set(depth_${_lab} ${depth})
254   endforeach()
255 endmacro()
256
257 assignLabelDepth(0 "export" "key" "layout" "load" "lyx2lyx" "module" "roundtrip" "url")
258 assignLabelDepth(1 "unreliable" "inverted")
259 assignLabelDepth(2 "suspended")
260 assignLabelDepth(3 "examples" "manuals" "mathmacros" "templates" "autotests")
261
262 loadTestList(suspiciousTests suspiciousTests 7)
263 loadTestList(ignoredTests ignoredTests 0)
264 loadTestList(suspendedTests suspendedTests 6)
265 loadTestList(unreliableTests unreliableTests 5)
266
267 # preparing to add e.g. development/mathmacros to the foreach() loop
268 foreach(libsubfolderx autotests/export lib/doc lib/examples lib/templates development/mathmacros)
269   set(testlabel "export")
270   if (libsubfolderx MATCHES "lib/doc")
271     list(APPEND testlabel "manuals")
272   elseif (libsubfolderx MATCHES "lib/examples")
273     list(APPEND testlabel "examples")
274   elseif (libsubfolderx MATCHES "lib/templates")
275     list(APPEND testlabel "templates")
276   elseif (libsubfolderx MATCHES "development/mathmacros")
277     list(APPEND testlabel "mathmacros")
278   elseif (libsubfolderx MATCHES "autotests/.+")
279     list(APPEND testlabel "autotests")
280   endif()
281   set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
282   string(REGEX REPLACE "^(lib|development|autotests)/" "" libsubfolder "${libsubfolderx}")
283   set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
284   message(STATUS "Handling export dir ${LIBSUB_SRC_DIR}")
285   file(GLOB_RECURSE lyx_files RELATIVE "${LIBSUB_SRC_DIR}" "${LIBSUB_SRC_DIR}/*.lyx")
286   list(SORT lyx_files)
287   # Now create 2 lists. One for files in a language dir, one without
288   set(lang_lyx_files)
289   set(nolang_lyx_files)
290   foreach(f ${lyx_files})
291     string(REGEX MATCHALL "^[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${f})
292     if(_v)
293       list(APPEND lang_lyx_files ${f})
294     else()
295       list(APPEND nolang_lyx_files ${f})
296     endif()
297   endforeach()
298   foreach(f ${nolang_lyx_files} ${lang_lyx_files})
299     # Strip extension
300     string(REGEX REPLACE "\\.lyx$" "" f ${f})
301     set(TestName "export/${libsubfolder}/${f}_lyx16")
302     set(mytestlabel ${testlabel})
303     maketestname(TestName inverted suspiciousTests ignoredTests unreliableTests mytestlabel)
304     if(TestName)
305       add_test(NAME ${TestName}
306         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
307         COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
308         -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
309         -Dlyx=$<TARGET_FILE:${_lyx}>
310         -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
311         -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
312         -Dformat=lyx16x
313         -Dextension=16.lyx
314         -Dfile=${f}
315         -Dinverted=${inverted}
316         -DTOP_SRC_DIR=${TOP_SRC_DIR}
317         -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
318         -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
319       setmarkedtestlabel(${TestName} ${mytestlabel})
320     endif()
321     if(LYX_PYTHON_EXECUTABLE)
322       set(lyx2lyxtestlabel "lyx2lyx")
323       # For use of lyx2lyx we need the python executable
324       set(mytestlabel ${lyx2lyxtestlabel})
325       set(TestName "lyx2lyx/${libsubfolder}/${f}")
326       maketestname(TestName inverted suspiciousTests ignoredTests unreliableTests mytestlabel)
327       if(TestName)
328         add_test(NAME ${TestName}
329           WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
330           COMMAND ${CMAKE_COMMAND}
331           "-DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE}"
332           "-DLYX2LYX=${TOP_SRC_DIR}/lib/lyx2lyx/lyx2lyx"
333           "-DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}"
334           "-DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx"
335           -P "${TOP_SRC_DIR}/development/autotests/lyx2lyxtest.cmake")
336         setmarkedtestlabel(${TestName} ${mytestlabel})
337       endif()
338     endif()
339     set(loadtestlabel "load")
340     set(mytestlabel ${loadtestlabel})
341     set(TestName "check_load/${libsubfolder}/${f}")
342     maketestname(TestName inverted suspiciousTests ignoredTests unreliableTests mytestlabel)
343     if(TestName)
344       add_test(NAME ${TestName}
345         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
346         COMMAND ${CMAKE_COMMAND} -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
347         -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
348         -Dlyx=$<TARGET_FILE:${_lyx}>
349         -DPARAMS_DIR=${TOP_SRC_DIR}/development/autotests
350         -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
351         -P "${TOP_SRC_DIR}/development/autotests/check_load.cmake")
352       setmarkedtestlabel(${TestName} ${mytestlabel})
353       set_tests_properties(${TestName} PROPERTIES RUN_SERIAL ON)
354     endif()
355     getoutputformats("${LIBSUB_SRC_DIR}/${f}.lyx" formatlist)
356     foreach(format ${formatlist})
357       if(format MATCHES "dvi3|pdf4|pdf5")
358         set(fonttypes "texF" "systemF")
359       else()
360         set(fonttypes "defaultF")
361       endif()
362       foreach(fonttype ${fonttypes})
363         if(fonttype MATCHES "defaultF")
364           set(TestName "export/${libsubfolder}/${f}_${format}")
365         else()
366           set(TestName "export/${libsubfolder}/${f}_${format}_${fonttype}")
367         endif()
368         set(mytestlabel ${testlabel})
369         maketestname(TestName inverted suspiciousTests ignoredTests unreliableTests mytestlabel)
370         if(TestName)
371           add_test(NAME ${TestName}
372             WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
373             COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
374             -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
375             -Dlyx=$<TARGET_FILE:${_lyx}>
376             -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
377             -Dformat=${format}
378             -Dfonttype=${fonttype}
379             -Dextension=${format}
380             -Dfile=${f}
381             -Dinverted=${inverted}
382             -DTOP_SRC_DIR=${TOP_SRC_DIR}
383             -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
384             -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
385           setmarkedtestlabel(${TestName} ${mytestlabel}) # check for suspended pdf/dvi exports
386         endif()
387       endforeach()
388     endforeach()
389   endforeach()
390 endforeach()