Debian Codegraph @

tests/PNAddTest.cmake

raw
1 #
2 # Licensed to the Apache Software Foundation (ASF) under one
3 # or more contributor license agreements. See the NOTICE file
4 # distributed with this work for additional information
5 # regarding copyright ownership. The ASF licenses this file
6 # to you under the Apache License, Version 2.0 (the
7 # "License"); you may not use this file except in compliance
8 # with the License. You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing,
13 # software distributed under the License is distributed on an
14 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 # KIND, either express or implied. See the License for the
16 # specific language governing permissions and limitations
17 # under the License.
18 #
19
20 # Helper function to define execution environment for ctest test targets
21
22 include(CMakeParseArguments)
23 include(CTest)
24
25 function(pn_add_test)
26 set(options EXECUTABLE INTERPRETED UNWRAPPED IGNORE_ENVIRONMENT)
27 set(oneValueArgs NAME COMMAND WORKING_DIRECTORY)
28 set(multiValueArgs PREPEND_ENVIRONMENT APPEND_ENVIRONMENT)
29
30 # Semicolon is CMake list separator and path separator on Windows; cmake_parse_arguments flattens nested lists!
31 # Replace \; to /////, call cmake_parse_arguments, then replace back where it matters; ///// is unlikely to appear
32 STRING(REPLACE \\\; ///// escaped_ARGN "${ARGN}")
33 cmake_parse_arguments(pn_add_test "${options}" "${oneValueArgs}" "${multiValueArgs}" "${escaped_ARGN}")
34
35 set(escaped_environment ${pn_add_test_PREPEND_ENVIRONMENT} ${TEST_ENV} ${pn_add_test_APPEND_ENVIRONMENT})
36 STRING(REPLACE ///// \\\; environment "${escaped_environment}")
37
38 if (pn_add_test_IGNORE_ENVIRONMENT)
39 set (ignore_environment "--ignore_environment")
40 else(pn_add_test_IGNORE_ENVIRONMENT)
41 set (ignore_environment "")
42 endif(pn_add_test_IGNORE_ENVIRONMENT)
43
44 if (pn_add_test_UNWRAPPED)
45 set (wrapper "")
46 elseif(pn_add_test_INTERPRETED)
47 set (wrapper "${TEST_WRAP_PREFIX_CMD}")
48 elseif(pn_add_test_EXECUTABLE)
49 set (wrapper "${TEST_EXE_PREFIX_CMD}")
50 else()
51 message(FATAL_ERROR "pn_add_test requires one of EXECUTABLE INTERPRETED UNWRAPPED")
52 endif()
53
54 add_test (
55 NAME "${pn_add_test_NAME}"
56 COMMAND ${PN_ENV_SCRIPT} ${ignore_environment} -- ${environment} ${wrapper} ${pn_add_test_COMMAND} ${pn_add_test_UNPARSED_ARGUMENTS}
57 WORKING_DIRECTORY "${pn_add_test_WORKING_DIRECTORY}"
58 )
59
60 # TODO jdanek 2020-01-17: this could be used instead of env.py, it looks CMake 2.8.12 compatible
61 #set_tests_properties("${pn_add_test_NAME}" PROPERTIES ENVIRONMENT "${environment}")
62 endfunction(pn_add_test)