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 ${lyx} ${_LyXExtraParams} -userdir \"${LYX_TESTS_USERDIR}\" -E ${format} ${result_file_name} \"${LYX_SOURCE}\"")
221 file(REMOVE ${result_file_name})
223 COMMAND ${lyx} ${LyXExtraParams} -userdir "${LYX_TESTS_USERDIR}" -E ${format} ${result_file_name} "${LYX_SOURCE}"
224 RESULT_VARIABLE _err)
225 Summary(_err "Exporting \"${LYX_SOURCE}\" to format ${format}")
227 #check if result file created
228 if (NOT EXISTS "${result_file_name}")
229 message(STATUS "Expected result file \"${result_file_name}\" does not exist")
231 Summary(_err "Expected result file \"${result_file_name}\" does not exists")
233 message(STATUS "Expected result file \"${result_file_name}\" exists")
234 if (extension MATCHES "^x(ht)?ml$")
235 if (format MATCHES "xhtml")
236 set(xmllint_params --loaddtd --noout)
237 set(executable_ ${XMLLINT_EXECUTABLE})
240 set(executable_ ${PERL_EXECUTABLE} "${TOP_SRC_DIR}/development/autotests/filterXml4Sax.pl")
241 # Check with perl xml-parser
242 # needs XML::Parser module
243 message(STATUS "Calling ${PERL_EXECUTABLE} \"${TOP_SRC_DIR}/development/autotests/xmlParser.pl\" \"${result_file_name}\"")
245 COMMAND ${PERL_EXECUTABLE} "${TOP_SRC_DIR}/development/autotests/xmlParser.pl" "${result_file_name}"
246 OUTPUT_VARIABLE parserout
247 ERROR_VARIABLE parsererr
251 message(STATUS "${parsererr}")
253 Summary(_err "Checking \"${result_file_name}\" with xmlParser.pl")
255 if (XMLLINT_EXECUTABLE)
256 string(REPLACE ";" " " xmllint_params2 " ${xmllint_params}")
257 message(STATUS "Calling: " ${executable_} ${xmllint_params2} " ${WORKDIR}/${result_file_name}")
258 # check the created xhtml file
260 COMMAND ${executable_} ${xmllint_params} "${result_file_name}"
261 OUTPUT_VARIABLE xmlout
262 ERROR_VARIABLE xmlerr
263 RESULT_VARIABLE _err)
264 file(WRITE "${result_file_name}.sax_out" ${xmlout})
265 Summary(_err "Checking \"${result_file_name}\" with ${XMLLINT_EXECUTABLE}")
267 # check if parser output contains error messages
268 message(STATUS "Check the output: ${PERL_EXECUTABLE} ${TOP_SRC_DIR}/development/autotests/examineXmllintOutput.pl")
270 COMMAND ${PERL_EXECUTABLE} "${TOP_SRC_DIR}/development/autotests/examineXmllintOutput.pl" "${result_file_name}.sax_out"
271 OUTPUT_VARIABLE xmlout
272 RESULT_VARIABLE _err)
273 Summary(_err "Parse messages of ${XMLLINT_EXECUTABLE} for errors")
275 message(STATUS "Errors from xmllint: ${xmlerr}")
278 if (NOT "${xmlout}" STREQUAL "")
279 message(STATUS "${xmlout}")
281 Summary(_err "Non empty output of \"${XMLLINT_EXECUTABLE}\"")
285 if (NOT _err AND format MATCHES "docbook5" AND JAVA_EXECUTABLE)
287 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}\"")
289 COMMAND ${JAVA_EXECUTABLE} -jar "${TOP_SRC_DIR}/development/tools/jing.jar" "https://docbook.org/xml/5.2b09/rng/docbook.rng" "${WORKDIR}/${result_file_name}"
290 OUTPUT_VARIABLE jingout
291 RESULT_VARIABLE _err)
292 message(STATUS "_err = ${_err}, jingout = ${jingout}")
293 Summary(_err "Checking for empty output of ${JAVA_EXECUTABLE} -jar \"${TOP_SRC_DIR}/development/tools/jing.jar\"")
301 string(COMPARE EQUAL ${_err} 0 _erg)
303 string(COMPARE NOTEQUAL ${_err} 0 _erg)
306 if ($ENV{LYX_DEBUG_LATEX})
307 # Do not remove temporary files if one wants to examine them
308 # for example if setting the env-var LYX_DEBUG_LATEX
309 # This needs a remove all temp-dirs from time to time
311 # $ find autotests/out-home -name AbC_\* | xargs rm -rf
313 execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory "${TempDir}")
315 if(_TestResultMessage)
316 message(STATUS "Msg Summary:")
317 foreach(_l ${_TestResultMessage})
318 message(STATUS "\t${_l}")
322 message(STATUS "Exporting ${file}.lyx to ${format}")
323 message(FATAL_ERROR "Export failed")