From 35a96bde514a8897f6f0fcc41c5833bf63df2e2a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 18:29:01 +0200 Subject: Adding upstream version 1.0.2. Signed-off-by: Daniel Baumann --- testfiles/cli_tests/CMakeLists.txt | 441 +++++++++++++++++++++++++++++++++++++ 1 file changed, 441 insertions(+) create mode 100644 testfiles/cli_tests/CMakeLists.txt (limited to 'testfiles/cli_tests/CMakeLists.txt') diff --git a/testfiles/cli_tests/CMakeLists.txt b/testfiles/cli_tests/CMakeLists.txt new file mode 100644 index 0000000..032cd95 --- /dev/null +++ b/testfiles/cli_tests/CMakeLists.txt @@ -0,0 +1,441 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + + +# Helper function to add a CLI test +# +# Run an Inkscape command line and check for pass/fail condition (by default only exit status is checked) +# +# Command line options: +# INPUT_FILENAME - name of input file (optional) +# OUTPUT_FILENAME - name of output file (optional) +# PARAMETERS - additional command line parameters to pass to Inkscape +# +# Pass/fail criteria: +# PASS_FOR_OUTPUT - pass if output matches the given value, otherwise fail +# see https://cmake.org/cmake/help/latest/prop_test/PASS_REGULAR_EXPRESSION.html for details +# FAIL_FOR_OUTPUT - fail if output matches the given value +# see https://cmake.org/cmake/help/latest/prop_test/FAIL_REGULAR_EXPRESSION.html for details +# REFERENCE_FILENAME - compare OUTPUT_FILENAME with this pre-rendered reference file +# both files are converted to PNG and compared with ImageMagick's 'compare' +# EXPECTED_FILES - verify the command produced the expected files (i.e. they exist on disk) +# TEST_SCRIPT - additional script to run after performing all checks and before cleaning up +# +# Other options: +# ENVIRONMENT - Additional environment variables to set while running the test +function(add_cli_test name) + # parse arguments + set(oneValueArgs INPUT_FILENAME OUTPUT_FILENAME PASS_FOR_OUTPUT FAIL_FOR_OUTPUT REFERENCE_FILENAME) + set(multiValueArgs PARAMETERS EXPECTED_FILES TEST_SCRIPT ENVIRONMENT) + cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + set(testname cli_${name}) + + if(DEFINED ARG_OUTPUT_FILENAME) + set(ARG_PARAMETERS ${ARG_PARAMETERS} "--export-filename=${ARG_OUTPUT_FILENAME}") + endif() + if(DEFINED ARG_INPUT_FILENAME) + set(ARG_INPUT_FILENAME "${CMAKE_CURRENT_SOURCE_DIR}/testcases/${ARG_INPUT_FILENAME}") + set(ARG_PARAMETERS ${ARG_PARAMETERS} ${ARG_INPUT_FILENAME}) + endif() + + set(CMAKE_CTEST_ENV "${INKSCAPE_TEST_PROFILE_DIR_ENV}/${testname};${CMAKE_CTEST_ENV}") + if(DEFINED ARG_ENVIRONMENT) + if(ARG_ENVIRONMENT STREQUAL "unset") + unset(CMAKE_CTEST_ENV) + else() + # variables might already be set, however the last value wins + list(APPEND CMAKE_CTEST_ENV ${ARG_ENVIRONMENT}) + endif() + endif() + + # add test for main command line + add_test(NAME ${testname} COMMAND inkscape ${ARG_PARAMETERS}) + set_tests_properties(${testname} PROPERTIES ENVIRONMENT "${CMAKE_CTEST_ENV}") + if(DEFINED ARG_PASS_FOR_OUTPUT) + set_tests_properties(${testname} PROPERTIES PASS_REGULAR_EXPRESSION ${ARG_PASS_FOR_OUTPUT}) + endif() + if(DEFINED ARG_FAIL_FOR_OUTPUT) + set_tests_properties(${testname} PROPERTIES FAIL_REGULAR_EXPRESSION ${ARG_FAIL_FOR_OUTPUT}) + endif() + + # add test to check output files + if(DEFINED ARG_REFERENCE_FILENAME OR DEFINED ARG_EXPECTED_FILES OR DEFINED ARG_TEST_SCRIPT) + if(DEFINED ARG_REFERENCE_FILENAME) + file(TO_NATIVE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/testcases/${ARG_REFERENCE_FILENAME}" ARG_REFERENCE_FILENAME) + endif() + if(DEFINED ARG_EXPECTED_FILES) + string(REPLACE ";" " " ARG_EXPECTED_FILES "${ARG_EXPECTED_FILES}") + endif() + if(DEFINED ARG_TEST_SCRIPT) + set(ARG_TEST_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/${ARG_TEST_SCRIPT}") + endif() + + add_test(NAME ${testname}_check_output + COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/check_output.sh + "${ARG_OUTPUT_FILENAME}" "${ARG_REFERENCE_FILENAME}" "${ARG_EXPECTED_FILES}" "${ARG_TEST_SCRIPT}") + set_tests_properties(${testname}_check_output PROPERTIES + ENVIRONMENT "${CMAKE_CTEST_ENV}" DEPENDS ${testname} SKIP_RETURN_CODE 42) + endif() +endfunction(add_cli_test) + + + +##### Tests follow below ##### + + + +############################################################################################# +### Command line options (basic tests for all program options as listed in --help output) ### +############################################################################################# + +# --help + +# --version (check if we can run inkscape and the revision is known) +add_cli_test(version PARAMETERS --version) +add_cli_test(version_known PARAMETERS --version FAIL_FOR_OUTPUT unknown) + +# --system-data-directory / --user-data-directory (unset environment variables to override our override) +# TODO: Can we make these tests more specific without making too many assumptions? +add_cli_test(system-data-directory PARAMETERS --system-data-directory ENVIRONMENT unset PASS_FOR_OUTPUT "inkscape\n$") +add_cli_test(user-data-directory PARAMETERS --user-data-directory ENVIRONMENT unset PASS_FOR_OUTPUT "inkscape\n$") + +# --pipe + +# --pdf-page=PAGE + +# --pdf-poppler +add_cli_test(pdf-poppler-mesh-import + PARAMETERS --pdf-poppler + INPUT_FILENAME pdf-mesh.pdf + OUTPUT_FILENAME pdf-mesh_poppler.svg + TEST_SCRIPT match_regex.sh pdf-mesh_poppler.svg "