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