1 # This file is part of LyX, the document processor.
2 # Licence details can be found in the file COPYING.
4 # Copyright (c) 2012 Kornel Benko kornel@lyx.org
7 # LYX_ROOT = ${TOP_SRC_DIR}/lib/{doc,examples,templates,tabletemplates}
8 # LYX_USERDIR_VER = Name of environment variable for the user directory
10 # format = lyx16x|lyx20x|lyx21x|lyx22x|xhtml|docbook5
11 # extension = 16.lyx|20.lyx|21.lyx|22.lyx|xhtml|xml
14 # Script should be called like:
15 # cmake -DLYX_ROOT=xxx \
16 # -DLYX_TESTS_USERDIR=${LYX_TESTS_USERDIR} \
17 # -DWORKDIR=${BUILD_DIR}/autotests/out-home \
18 # -DLYX_USERDIR_VER=${LYX_USERDIR_VER} \
23 # -DLYX_FORMAT_NUM=${_lyx_format_num} \
26 # -DTOP_SRC_DIR=${TOP_SRC_DIR} \
27 # -DIgnoreErrorMessage=(ON/OFF) \
28 # -DPERL_EXECUTABLE=${PERL_EXECUTABLE} \
29 # -DXMLLINT_EXECUTABLE=${XMLLINT_EXECUTABLE} \
30 # -DJAVA_EXECUTABLE=${JAVA_EXECUTABLE} \
32 # -P "${TOP_SRC_DIR}/development/autotests/export.cmake"
35 set(_TestResultMessage "")
36 message(STATUS "IgnoreErrorMessage = \"${IgnoreErrorMessage}\"")
37 set(Perl_Script "${TOP_SRC_DIR}/development/autotests/useSystemFonts.pl")
38 set(Structure_Script "${TOP_SRC_DIR}/development/autotests/beginEndStructureCheck.pl")
39 set(LanguageFile "${TOP_SRC_DIR}/lib/languages")
40 set(GetTempDir "${TOP_SRC_DIR}/development/autotests/getTempDir.pl")
42 execute_process(COMMAND ${PERL_EXECUTABLE} "${GetTempDir}" "${WORKDIR}" OUTPUT_VARIABLE TempDir)
43 message(STATUS "using fonttype = ${_ft}")
45 set(ENCODING "default")
47 if(ENCODING STREQUAL "default")
50 set(_enc "_${ENCODING}")
53 # move the the last directory part of LYX_ROOT to filename
54 # to make the destination unique for otherwise identical
56 get_filename_component(updir_ "${LYX_ROOT}" DIRECTORY)
57 get_filename_component(updir2_ "${LYX_ROOT}" NAME)
58 set(file "${updir2_}/${file}")
59 set(LYX_ROOT "${updir_}")
61 if(format MATCHES "dvi|pdf")
62 message(STATUS "LYX_TESTS_USERDIR = ${LYX_TESTS_USERDIR}")
63 message(STATUS "Converting with perl ${Perl_Script}")
64 set(LYX_SOURCE "${TempDir}/${file}_${format}_${_ft}${_enc}.lyx")
65 message(STATUS "Using source \"${LYX_ROOT}/${file}.lyx\"")
66 message(STATUS "Using dest \"${LYX_SOURCE}\"")
67 if(NOT "${ENCODING}" STREQUAL "default")
68 # message(STATUS "ENCODING = ${ENCODING}")
70 message(STATUS "Executing ${PERL_EXECUTABLE} \"${Perl_Script}\" \"${LYX_ROOT}/${file}.lyx\" \"${LYX_SOURCE}\" ${format} ${_ft} ${ENCODING} ${LanguageFile}")
71 execute_process(COMMAND ${PERL_EXECUTABLE} "${Perl_Script}" "${LYX_ROOT}/${file}.lyx" "${LYX_SOURCE}" ${format} ${_ft} ${ENCODING} ${LanguageFile}
73 string(COMPARE EQUAL ${_err} 0 _erg)
75 message(FATAL_ERROR "Export failed while converting")
77 # We only need "_${ENCODING}" for unicode tests (because multiple encodings
78 # are tested with the same format), but doesn't hurt to include for all.
79 set(result_file_name ${file}_${_ft}_${ENCODING}.${extension})
81 message(STATUS "Converting with perl ${Perl_Script}")
82 set(LYX_SOURCE "${TempDir}/${file}.lyx")
83 message(STATUS "Using source \"${LYX_ROOT}/${file}.lyx\"")
84 message(STATUS "Using dest \"${LYX_SOURCE}\"")
85 execute_process(COMMAND ${PERL_EXECUTABLE} "${Perl_Script}" "${LYX_ROOT}/${file}.lyx" "${LYX_SOURCE}" ${format} "dontChange" "default" ${LanguageFile}
87 string(COMPARE EQUAL ${_err} 0 _erg)
89 message(FATAL_ERROR "Export failed while converting")
91 if(extension MATCHES "\\.lyx$")
92 # Font-type not relevant for lyx16/lyx2[0123] exports
93 set(result_file_base "${TempDir}/${file}")
95 set(result_file_name ${file}.${extension})
99 function(get_md5sum msource mresult mreserr)
101 COMMAND ${CMAKE_COMMAND} -E md5sum ${${msource}}
102 OUTPUT_VARIABLE msource_md5sum_x
103 RESULT_VARIABLE mres_err)
105 string(REGEX REPLACE " .*" "" msource_md5sum ${msource_md5sum_x})
106 set(${mresult} ${msource_md5sum} PARENT_SCOPE)
107 message(STATUS "MD5SUM of \"${${msource}}\" is ${msource_md5sum}")
109 set(${mresult} "xx" PARENT_SCOPE)
110 message(STATUS "Error getting MD5SUM of \"${${msource}}\"")
112 set(${mreserr} ${mres_err} PARENT_SCOPE)
115 macro(Summary _err _msg)
117 list(APPEND _TestResultMessage "Error: ${_msg}")
119 list(APPEND _TestResultMessage "OK: ${_msg}")
123 set(ENV{${LYX_USERDIR_VER}} "${LYX_TESTS_USERDIR}")
124 set(ENV{LANG} "en_US.UTF-8") # to get all error-messages in english
125 set(ENV{LANGUAGE} "US:en")
126 #set(ENV{LC_ALL} "C")
127 if (extension MATCHES "\\.lyx$")
128 include(${TOP_SRC_DIR}/development/autotests/CheckLoadErrors.cmake)
129 get_md5sum(LYX_SOURCE source_md5sum _err)
130 foreach(_lv RANGE 1 20)
131 set(used_tex_file "${result_file_base}.tex")
132 set(result_file_base "${result_file_base}.${LYX_FORMAT_NUM}")
133 set(result_file_name "${result_file_base}.lyx")
134 file(REMOVE "${result_file_name}" "${result_file_name}.emergency" )
135 message(STATUS "Executing ${lyx} -userdir \"${LYX_TESTS_USERDIR}\" -E ${format} ${result_file_name} \"${LYX_SOURCE}\"")
136 message(STATUS "This implicitly checks load of ${LYX_SOURCE}")
138 COMMAND ${lyx} -userdir "${LYX_TESTS_USERDIR}" -E ${format} ${result_file_name} "${LYX_SOURCE}"
140 ERROR_VARIABLE lyxerr)
141 Summary(_err "Converting \"${LYX_SOURCE}\" to format ${format}")
145 if(NOT EXISTS "${result_file_name}")
147 Summary(_err "Expected result file \"${result_file_name}\" does not exist")
150 message(STATUS "Expected result file \"${result_file_name}\" exists")
152 COMMAND ${PERL_EXECUTABLE} ${Structure_Script} "${result_file_name}"
153 RESULT_VARIABLE _err)
154 Summary(_err "Structure of the intermediate file \"${result_file_name}\"")
158 checkLoadErrors(lyxerr "${TOP_SRC_DIR}/development/autotests" _err)
159 Summary(_err "Examination of error/warning messages of the conversion of \"${LYX_SOURCE}\" to format ${format}")
163 message(STATUS "Create the corresponding .tex file \"${used_tex_file}\"")
165 COMMAND ${lyx} -userdir "${LYX_TESTS_USERDIR}" -E pdflatex ${used_tex_file} "${LYX_SOURCE}"
166 RESULT_VARIABLE _errx)
169 get_md5sum(result_file_name result_md5sum _err)
170 Summary(_err "Getting md5sum of \"${result_file_name}\"")
172 # Somehow the created file is not readable?
175 # Check if result file identical to source file
176 if(result_md5sum STREQUAL ${source_md5sum})
177 if (format MATCHES "lyx(1[0-9]|2[01])x")
178 # Do not compile, missing \origin statement prevents inclusion of
179 # files with relative path
180 message(STATUS "Not exporting due to missing \\origin statement")
182 elseif(format MATCHES "lyx22x" AND file MATCHES "Minted")
183 message(STATUS "Not exporting due to missing minted support")
186 message(STATUS "Source(${LYX_SOURCE}) and dest(${result_file_name}) are equal")
187 message(STATUS "Now try to export the lyx2lyx created file")
188 message(STATUS "Executing ${lyx} -userdir \"${LYX_TESTS_USERDIR}\" -E default \"${result_file_name}.default\" \"${result_file_name}\"")
190 COMMAND ${lyx} -userdir "${LYX_TESTS_USERDIR}" -E default "${result_file_name}.default" "${result_file_name}"
192 ERROR_VARIABLE lyxerr)
193 Summary(_err "Test-compilation of \"${result_file_name}\" to format default")
196 list(APPEND _TestResultMessage "Warning: \"${LYX_SOURCE}\" and \"${result_file_name}\" differ")
197 message(STATUS "Source(${LYX_SOURCE}) and dest(${result_file_name}) are still different")
200 message(STATUS "Possible endless loop encountered")
201 Summary(_err "Test-Loop exceeded the count of 10, Possible endless loop")
205 set(source_md5sum ${result_md5sum})
206 set(LYX_SOURCE ${result_file_name})
209 if ($ENV{LYX_DEBUG_LATEX})
210 set(LyXExtraParams -dbg latex)
212 set(LyXExtraParams -dbg info)
214 if(IgnoreErrorMessage)
215 foreach (_em ${IgnoreErrorMessage})
216 list(APPEND LyXExtraParams --ignore-error-message ${_em})
219 string(REGEX REPLACE ";" " " _LyXExtraParams "${LyXExtraParams}")
220 message(STATUS "Executing in working dir ${TempDir}")
221 message(STATUS "Executing ${lyx} ${_LyXExtraParams} -userdir \"${LYX_TESTS_USERDIR}\" -E ${format} ${result_file_name} \"${LYX_SOURCE}\"")
222 file(REMOVE "${TempDir}/${result_file_name}")
224 COMMAND ${lyx} ${LyXExtraParams} -userdir "${LYX_TESTS_USERDIR}" -E ${format} ${result_file_name} "${LYX_SOURCE}"
225 WORKING_DIRECTORY "${TempDir}"
226 RESULT_VARIABLE _err)
227 Summary(_err "Exporting \"${LYX_SOURCE}\" to format ${format}")
229 #check if result file created
230 if (NOT EXISTS "${TempDir}/${result_file_name}")
231 message(STATUS "Expected result file \"${TempDir}/${result_file_name}\" does not exist")
233 Summary(_err "Expected result file \"${TempDir}/${result_file_name}\" does not exists")
235 message(STATUS "Expected result file \"${TempDir}/${result_file_name}\" exists")
236 if (extension MATCHES "^x(ht)?ml$")
237 if (format MATCHES "xhtml")
238 set(xmllint_params --loaddtd --noout)
239 set(executable_ ${XMLLINT_EXECUTABLE})
242 set(executable_ ${PERL_EXECUTABLE} "${TOP_SRC_DIR}/development/autotests/filterXml4Sax.pl")
243 # Check with perl xml-parser
244 # needs XML::Parser module
245 message(STATUS "Calling ${PERL_EXECUTABLE} \"${TOP_SRC_DIR}/development/autotests/xmlParser.pl\" \"${result_file_name}\"")
247 COMMAND ${PERL_EXECUTABLE} "${TOP_SRC_DIR}/development/autotests/xmlParser.pl" "${result_file_name}"
248 WORKING_DIRECTORY "${TempDir}"
249 OUTPUT_VARIABLE parserout
250 ERROR_VARIABLE parsererr
254 message(STATUS "${parsererr}")
256 Summary(_err "Checking \"${TempDir}/${result_file_name}\" with xmlParser.pl")
258 if (XMLLINT_EXECUTABLE)
259 string(REPLACE ";" " " xmllint_params2 " ${xmllint_params}")
260 message(STATUS "Calling: " ${executable_} ${xmllint_params2} " ${WORKDIR}/${result_file_name}")
261 # check the created xhtml file
263 COMMAND ${executable_} ${xmllint_params} "${result_file_name}"
264 WORKING_DIRECTORY "${TempDir}"
265 OUTPUT_VARIABLE xmlout
266 ERROR_VARIABLE xmlerr
267 RESULT_VARIABLE _err)
268 file(WRITE "${TempDir}/${result_file_name}.sax_out" ${xmlout})
269 Summary(_err "Checking \"${TempDir}/${result_file_name}\" with ${XMLLINT_EXECUTABLE}")
271 # check if parser output contains error messages
272 message(STATUS "Check the output: ${PERL_EXECUTABLE} ${TOP_SRC_DIR}/development/autotests/examineXmllintOutput.pl")
274 COMMAND ${PERL_EXECUTABLE} "${TOP_SRC_DIR}/development/autotests/examineXmllintOutput.pl" "${result_file_name}.sax_out"
275 WORKING_DIRECTORY "${TempDir}"
276 OUTPUT_VARIABLE xmlout
277 RESULT_VARIABLE _err)
278 Summary(_err "Parse messages of ${XMLLINT_EXECUTABLE} for errors")
280 message(STATUS "Errors from xmllint: ${xmlerr}")
283 if (NOT "${xmlout}" STREQUAL "")
284 message(STATUS "${xmlout}")
286 Summary(_err "Non empty output of \"${XMLLINT_EXECUTABLE}\"")
290 if (NOT _err AND format MATCHES "docbook5" AND JAVA_EXECUTABLE)
292 message(STATUS "Calling: ${JAVA_EXECUTABLE} -jar \"${TOP_SRC_DIR}/development/tools/jing.jar\" https://docbook.org/xml/5.2b09/rng/docbook.rng \"${WORKDIR}/${result_file_name}\"")
294 COMMAND ${JAVA_EXECUTABLE} -jar "${TOP_SRC_DIR}/development/tools/jing.jar" "https://docbook.org/xml/5.2b09/rng/docbook.rng" "${result_file_name}"
295 WORKING_DIRECTORY "${TempDir}"
296 OUTPUT_VARIABLE jingout
297 RESULT_VARIABLE _err)
298 message(STATUS "_err = ${_err}, jingout = ${jingout}")
299 Summary(_err "Checking for empty output of ${JAVA_EXECUTABLE} -jar \"${TOP_SRC_DIR}/development/tools/jing.jar\"")
307 string(COMPARE EQUAL ${_err} 0 _erg)
309 string(COMPARE NOTEQUAL ${_err} 0 _erg)
312 if ($ENV{LYX_DEBUG_LATEX})
313 # Do not remove temporary files if one wants to examine them
314 # for example if setting the env-var LYX_DEBUG_LATEX
315 # This needs a remove all temp-dirs from time to time
317 # $ find autotests/out-home -name AbC_\* | xargs rm -rf
319 execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory "${TempDir}")
321 if(_TestResultMessage)
322 message(STATUS "Msg Summary:")
323 foreach(_l ${_TestResultMessage})
324 message(STATUS "\t${_l}")
328 message(STATUS "Exporting ${file}.lyx to ${format}")
329 message(FATAL_ERROR "Export failed")