From e430586ec36e2bb1646191682f434e45fb871d26 Mon Sep 17 00:00:00 2001 From: Kornel Benko Date: Wed, 28 Oct 2015 17:59:28 +0100 Subject: [PATCH] Cmake tests: Get rid of use of command 'env', which is not available under Windows. --- src/tests/CMakeLists.txt | 4 +-- src/tex2lyx/test/CMakeLists.txt | 7 ++-- src/tex2lyx/test/env_custom_command.cmake | 40 +++++++++++++++++++++++ 3 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 src/tex2lyx/test/env_custom_command.cmake diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index bfbcdfd364..afcceb578c 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -38,11 +38,11 @@ foreach(bns ${layout_files} ${module_files}) if("${_checktype}" STREQUAL "module") file(WRITE "${LYX_TESTS_USERDIR}/layouts/test${bn}.layout" "#% Do not delete the line below; configure depends on this\n") file(APPEND "${LYX_TESTS_USERDIR}/layouts/test${bn}.layout" "# \\DeclareLaTeXClass{test${bn}}\n") - file(APPEND "${LYX_TESTS_USERDIR}/layouts/test${bn}.layout" "Format 55\n") file(APPEND "${LYX_TESTS_USERDIR}/layouts/test${bn}.layout" "Input ${bns}\n") add_test(NAME "check_layout/${bns}" - COMMAND env LYX_USERDIR_22x=${LYX_TESTS_USERDIR} $ "${LYX_TESTS_USERDIR}/layouts/test${bn}" "${CMAKE_CURRENT_BINARY_DIR}/${bn}.out${_checktype}") + COMMAND $ "${LYX_TESTS_USERDIR}/layouts/test${bn}" "${CMAKE_CURRENT_BINARY_DIR}/${bn}.out${_checktype}") + set_tests_properties("check_layout/${bns}" PROPERTIES ENVIRONMENT ${LYX_USERDIR_VER}=${LYX_TESTS_USERDIR}) else() add_test(NAME "check_layout/${bns}" COMMAND check_layout "${TOP_SRC_DIR}/lib/layouts/${bn}" "${CMAKE_CURRENT_BINARY_DIR}/${bn}.out${_checktype}") diff --git a/src/tex2lyx/test/CMakeLists.txt b/src/tex2lyx/test/CMakeLists.txt index c513d6e818..304e1623f3 100644 --- a/src/tex2lyx/test/CMakeLists.txt +++ b/src/tex2lyx/test/CMakeLists.txt @@ -64,8 +64,11 @@ add_dependencies(lyx_run_tests ${_tex2lyx} ${_lyx}) add_custom_command( OUTPUT LyxTestFiles COMMAND ${CMAKE_COMMAND} -E touch LyxTestFiles - COMMAND env LYX_USERDIR_VER=${LYX_USERDIR_VER} - ${LYX_PYTHON_EXECUTABLE} "${runtestsScript}" $ "${scriptDir}" "${CMAKE_CURRENT_SOURCE_DIR}" + COMMAND ${CMAKE_COMMAND} + -DENVIRON="${LYX_USERDIR_VER}=${LYX_TESTS_USERDIR}" + -DCOMMAND="${LYX_PYTHON_EXECUTABLE}" + -DPARAMS="${runtestsScript}'$'${scriptDir}'${CMAKE_CURRENT_SOURCE_DIR}" + -P ${TOP_SRC_DIR}/src/tex2lyx/test/env_custom_command.cmake WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" DEPENDS ${_tex2lyx} ${_lyx} ) diff --git a/src/tex2lyx/test/env_custom_command.cmake b/src/tex2lyx/test/env_custom_command.cmake new file mode 100644 index 0000000000..24acaae3b5 --- /dev/null +++ b/src/tex2lyx/test/env_custom_command.cmake @@ -0,0 +1,40 @@ +# This file is part of LyX, the document processor. +# Licence details can be found in the file COPYING. +# +# Copyright (c) 2015 Kornel Benko +# +# Environ and parameter strings are separated by "'" +# Script should be called like: +# add_custom_command( +# COMMAND ${CMAKE_COMMAND} +# -DENVIRON="${LYX_USERDIR_VER}=${LYX_TESTS_USERDIR}" \ +# -DCOMMAND="${LYX_PYTHON_EXECUTABLE}" \ +# -DPARAMS="${runtestsScript}'$'${scriptDir}'${CMAKE_CURRENT_SOURCE_DIR}" +# -P ${TOP_SRC_DIR}/src/tex2lyx/test/env_custom_command.cmake +# WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" +# DEPENDS ... +# ) + +string(REGEX MATCHALL "[^']+" ENVIRON_LIST "${ENVIRON}") +foreach(_env ${ENVIRON_LIST}) + if (_env MATCHES "^\([^=]+\)=\(.*\)$") + set(ENV{${CMAKE_MATCH_1}} ${CMAKE_MATCH_2}) + #message(STATUS "setting env ${CMAKE_MATCH_1}=${CMAKE_MATCH_2}") + else() + message(FATAL_ERROR "Wrong environment string \"${_env}\"") + endif() +endforeach() + +string(REGEX MATCHALL "[^']+" parameters "${PARAMS}") +execute_process(COMMAND "${COMMAND}" ${parameters} + RESULT_VARIABLE _err + OUTPUT_VARIABLE _out) + +message(STATUS ${_out}) +#message(STATUS "Error output of \"${COMMAND}\" " ${parameters} " = ${_err}") +string(COMPARE NOTEQUAL ${_err} 0 _erg) + +if(_erg) + message(FATAL_ERROR "\"${COMMAND}\" ${parameters} failed") +endif() + -- 2.39.2