2 # Copyright (c) 2014 Kornel Benko <kornel@lyx.org>
3 # Copyright (c) 2014 Scott Kostyshak <skotysh@lyx.org>
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
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.
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.
32 set(DVI_FORMATS "dvi" "dvi3")
33 set(PDF_FORMATS "pdf" "pdf2" "pdf3" "pdf4" "pdf5")
35 set(DVI_FORMATS "dvi")
36 set(PDF_FORMATS "pdf" "pdf2" "pdf3")
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")
41 macro(initLangVars varname)
42 foreach(_l ${potential_languages})
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})
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")
66 # Respect all other output formats
68 set(out_formats "xhtml" ${_format})
73 set(${varname} ${out_formats})
76 macro(findexpr found testname listname rsublabel)
79 foreach(_itrx ${${listname}})
80 if ("${_itrx}" MATCHES "^Sublabel:")
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")
88 list(APPEND tmpsublabel ${subl})
91 # remove doubles in sublabel
92 list(REMOVE_DUPLICATES tmpsublabel)
94 set(_itr "^${_itrx}$")
95 if (${testname} MATCHES "${_itr}")
102 if (NOT "${tmpsublabel}" STREQUAL "")
103 list(APPEND ${rsublabel} ${tmpsublabel})
106 set(${found} ${_found})
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)
116 macro(maketestname testname inverted listsuspicious listignored listunreliable listlabels)
117 string(REGEX MATCH "\\/[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${${testname}})
119 string(REGEX REPLACE "\\/" "" _v ${_v})
120 set(listsuspiciousx ${listsuspicious}_${_v})
121 set(listignoredx ${listignored}_${_v})
122 set(listunreliablex ${listunreliable}_${_v})
123 set(listsuspendedx suspendedTests_${_v})
125 set(listsuspiciousx ${listsuspicious})
126 set(listignoredx ${listignored})
127 set(listunreliablex ${listunreliable})
128 set(listsuspendedx suspendedTests)
130 set(sublabel "${${listlabels}}")
131 findexpr(mfound ${testname} ${listignoredx} sublabel)
134 findexpr(foundunreliable ${testname} ${listunreliablex} sublabel2)
136 set(sublabel "unreliable" ${sublabel} ${sublabel2})
137 list(REMOVE_ITEM sublabel "export" "inverted" "templates" "mathmacros" "manuals" "autotests")
139 string(REGEX MATCH "_(systemF|texF|pdf3|pdf2|pdf|dvi|lyx16|xhtml)$" _v ${${testname}})
140 # check if test _may_ be in listsuspicious
143 findexpr(mfound ${testname} ${listsuspiciousx} sublabel2)
149 findexpr(foundsuspended ${testname} ${listsuspendedx} sublabel3)
152 set(sublabel "suspended" ${sublabel} ${sublabel2} ${sublabel3})
153 list(REMOVE_ITEM sublabel "export" "inverted" )
155 set(sublabel "inverted" ${sublabel} ${sublabel2} ${sublabel3})
161 list(REMOVE_DUPLICATES sublabel)
162 if (NOT sublabel STREQUAL "")
163 join(sublabel "." tmpprefixx)
164 string(TOUPPER "${tmpprefixx}_" tmpprefix)
165 set(${testname} "${tmpprefix}${${testname}}")
166 set(${listlabels} ${sublabel})
169 # No testname because ignored
174 macro(loadTestList filename resList depth)
175 # Create list of strings from a file without comments
176 # ENCODING parameter is a new feature in cmake 3.1
177 initLangVars(${resList})
178 initLangVars("sublabel")
179 if (CMAKE_VERSION VERSION_GREATER "3.1")
180 file(STRINGS ${filename} tempList ENCODING "UTF-8")
182 file(STRINGS ${filename} tempList)
188 message(STATUS "Reading list ${filename}")
189 foreach(_l ${tempList})
191 string(REGEX REPLACE "[ \t]+$" "" _newl "${_l}")
192 string(REGEX REPLACE "[ \t]*#.*$" "" _newl "${_l}")
194 list(APPEND ${resList} "${_newl}")
195 if (_newl MATCHES "^Sublabel:")
196 string(REGEX REPLACE "^Sublabel:[ \t]*" "" _newlabels ${_newl})
197 string(REGEX MATCHALL "([0-9]*[a-zA-Z]+)" _labels ${_newlabels})
198 foreach(labname ${_labels})
199 if (NOT labname STREQUAL "RESET")
200 list(APPEND mylabels ${labname})
203 list(REMOVE_DUPLICATES mylabels)
204 set(sublabel ${_newl})
206 string(REGEX REPLACE "(\\/|\\||\\(|\\))" " " _vxx ${_newl})
207 string(REGEX MATCHALL " ([a-z][a-z](_[A-Z][A-Z])?) " _vx ${_vxx})
210 string(REGEX REPLACE " " "" _v ${_v})
211 #message(STATUS " ==> ${resList}_${_v}")
212 #message(STATUS "sublabel = ${sublabel}, sublabel_${_v} = ${sublabel_${_v}}")
213 if (NOT sublabel STREQUAL "${sublabel_${_v}}")
214 list(APPEND ${resList}_${_v} "${sublabel}")
215 set(sublabel_${_v} "${sublabel}")
216 #message(STATUS "Setting variable sublabel_${_v} with \"${sublabel}\"")
218 list(APPEND ${resList}_${_v} "${_newl}")
219 list(APPEND languages ${_v})
221 list(REMOVE_DUPLICATES languages)
222 #message(STATUS "languages = ${languages}")
227 foreach(_l1 ${mylabels})
228 if (_l1 MATCHES "^([0-9]+)([a-zA-Z]+)$")
229 set(_l ${CMAKE_MATCH_2})
230 set(depth1 ${CMAKE_MATCH_1})
235 list(FIND known_labels ${_l} _ff)
237 message(STATUS "Label \"${_l}\" already in use. Reused in ${filename}")
239 assignLabelDepth(${depth}${depth1} ${_l})
242 foreach(_lg ${languages})
243 # reset label for each used language string at end of file
244 #message(STATUS "Resetting variable sublabel_${_lg}, previously set to ${sublabel_${_lg}}")
245 set(sublabel_${_lg} "")
249 # This labels should not be used in .*Tests files
251 # Create depth info to each label
252 macro(assignLabelDepth depth)
253 foreach(_lab ${ARGN})
254 list(APPEND known_labels ${_lab})
255 set(depth_${_lab} ${depth})
259 assignLabelDepth(0 "export" "key" "layout" "load" "lyx2lyx" "module" "roundtrip" "url")
260 assignLabelDepth(1 "unreliable" "inverted")
261 assignLabelDepth(2 "suspended")
262 assignLabelDepth(3 "examples" "manuals" "mathmacros" "templates" "autotests")
264 loadTestList(suspiciousTests suspiciousTests 7)
265 loadTestList(ignoredTests ignoredTests 0)
266 loadTestList(suspendedTests suspendedTests 6)
267 loadTestList(unreliableTests unreliableTests 5)
269 # preparing to add e.g. development/mathmacros to the foreach() loop
270 foreach(libsubfolderx autotests/export lib/doc lib/examples lib/templates development/mathmacros)
271 set(testlabel "export")
272 if (libsubfolderx MATCHES "lib/doc")
273 list(APPEND testlabel "manuals")
274 elseif (libsubfolderx MATCHES "lib/examples")
275 list(APPEND testlabel "examples")
276 elseif (libsubfolderx MATCHES "lib/templates")
277 list(APPEND testlabel "templates")
278 elseif (libsubfolderx MATCHES "development/mathmacros")
279 list(APPEND testlabel "mathmacros")
280 elseif (libsubfolderx MATCHES "autotests/.+")
281 list(APPEND testlabel "autotests")
283 set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
284 string(REGEX REPLACE "^(lib|development|autotests)/" "" libsubfolder "${libsubfolderx}")
285 set(LIBSUB_SRC_DIR "${TOP_SRC_DIR}/${libsubfolderx}")
286 message(STATUS "Handling export dir ${LIBSUB_SRC_DIR}")
287 file(GLOB_RECURSE lyx_files RELATIVE "${LIBSUB_SRC_DIR}" "${LIBSUB_SRC_DIR}/*.lyx")
289 if (libsubfolderx MATCHES "development/mathmacros")
290 # This is a zipped file, removing from tests
291 list(REMOVE_ITEM lyx_files testcases_master_child.lyx)
293 # Now create 2 lists. One for files in a language dir, one without
295 set(nolang_lyx_files)
296 foreach(f ${lyx_files})
297 string(REGEX MATCHALL "^[a-z][a-z](_[A-Z][A-Z])?\\/" _v ${f})
299 list(APPEND lang_lyx_files ${f})
301 list(APPEND nolang_lyx_files ${f})
304 foreach(f ${nolang_lyx_files} ${lang_lyx_files})
306 string(REGEX REPLACE "\\.lyx$" "" f ${f})
307 set(TestName "export/${libsubfolder}/${f}_lyx16")
308 set(mytestlabel ${testlabel})
309 maketestname(TestName inverted suspiciousTests ignoredTests unreliableTests mytestlabel)
311 add_test(NAME ${TestName}
312 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
313 COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
314 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
315 -Dlyx=$<TARGET_FILE:${_lyx}>
316 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
317 -DLYX_USERDIR_VER=${LYX_USERDIR_VER}
321 -Dinverted=${inverted}
322 -DTOP_SRC_DIR=${TOP_SRC_DIR}
323 -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
324 -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
325 setmarkedtestlabel(${TestName} ${mytestlabel})
327 if(LYX_PYTHON_EXECUTABLE)
328 set(lyx2lyxtestlabel "lyx2lyx")
329 # For use of lyx2lyx we need the python executable
330 set(mytestlabel ${lyx2lyxtestlabel})
331 set(TestName "lyx2lyx/${libsubfolder}/${f}")
332 maketestname(TestName inverted suspiciousTests ignoredTests unreliableTests mytestlabel)
334 add_test(NAME ${TestName}
335 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
336 COMMAND ${CMAKE_COMMAND}
337 "-DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE}"
338 "-DLYX2LYX=${TOP_SRC_DIR}/lib/lyx2lyx/lyx2lyx"
339 "-DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}"
340 "-DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx"
341 -P "${TOP_SRC_DIR}/development/autotests/lyx2lyxtest.cmake")
342 setmarkedtestlabel(${TestName} ${mytestlabel})
345 set(loadtestlabel "load")
346 set(mytestlabel ${loadtestlabel})
347 set(TestName "check_load/${libsubfolder}/${f}")
348 maketestname(TestName inverted suspiciousTests ignoredTests unreliableTests mytestlabel)
350 add_test(NAME ${TestName}
351 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
352 COMMAND ${CMAKE_COMMAND} -DLYXFILE=${LIBSUB_SRC_DIR}/${f}.lyx
353 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
354 -Dlyx=$<TARGET_FILE:${_lyx}>
355 -DPARAMS_DIR=${TOP_SRC_DIR}/development/autotests
356 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
357 -P "${TOP_SRC_DIR}/development/autotests/check_load.cmake")
358 setmarkedtestlabel(${TestName} ${mytestlabel})
359 set_tests_properties(${TestName} PROPERTIES RUN_SERIAL ON)
361 getoutputformats("${LIBSUB_SRC_DIR}/${f}.lyx" formatlist)
362 foreach(format ${formatlist})
363 if(format MATCHES "dvi3|pdf4|pdf5")
364 set(fonttypes "texF" "systemF")
366 set(fonttypes "defaultF")
368 foreach(fonttype ${fonttypes})
369 if(fonttype MATCHES "defaultF")
370 set(TestName "export/${libsubfolder}/${f}_${format}")
372 set(TestName "export/${libsubfolder}/${f}_${format}_${fonttype}")
374 set(mytestlabel ${testlabel})
375 maketestname(TestName inverted suspiciousTests ignoredTests unreliableTests mytestlabel)
377 add_test(NAME ${TestName}
378 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}"
379 COMMAND ${CMAKE_COMMAND} -DLYX_ROOT=${LIBSUB_SRC_DIR}
380 -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR}
381 -Dlyx=$<TARGET_FILE:${_lyx}>
382 -DWORKDIR=${CMAKE_CURRENT_BINARY_DIR}/${LYX_HOME}
384 -Dfonttype=${fonttype}
385 -Dextension=${format}
387 -Dinverted=${inverted}
388 -DTOP_SRC_DIR=${TOP_SRC_DIR}
389 -DPERL_EXECUTABLE=${PERL_EXECUTABLE}
390 -P "${TOP_SRC_DIR}/development/autotests/export.cmake")
391 setmarkedtestlabel(${TestName} ${mytestlabel}) # check for suspended pdf/dvi exports