generated from krxecs/license-0bsd-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MunitAddTests.cmake
117 lines (99 loc) · 2.89 KB
/
MunitAddTests.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# SPDX-License-Identifier: CC0-1.0
set(tests)
include("${MUNIT_CMAKE_PATH}")
function(add_command NAME)
set(args "")
# use ARGV* instead of ARGN, because ARGN splits arrays into multiple arguments
math(EXPR number_of_args ${ARGC}-1)
foreach(i RANGE 1 ${number_of_args})
set(arg "${ARGV${i}}")
if(arg MATCHES "[^-./:a-zA-Z0-9_]")
# if argument contains any character other than alphanumeric characters
# along with '.', '/', ':' & '_'; use a bracket argument so that no
# unwanted expansion takes place.
set(args "${args} [==[${arg}]==]") # form a bracket_argument
else()
set(args "${args} ${arg}")
endif()
endforeach()
set(script "${script}${NAME}(${args})\n" PARENT_SCOPE)
endfunction()
function(add_command_unescaped NAME)
set(args "")
foreach(arg ${ARGN})
set(args "${args} ${arg}")
endforeach()
set(script "${script}${NAME}(${args})\n" PARENT_SCOPE)
endfunction()
if (NOT EXISTS "${TEST_EXECUTABLE}")
message(FATAL_ERROR
"Specified test executable '${TEST_EXECUTABLE}' not found."
)
endif ()
munit_get_test_list(
"${TEST_EXECUTABLE}"
LIST_OF_TESTS
WORKING_DIRECTORY "${_WORKING_DIRECTORY}"
ERRNO_VARIABLE LISTCMD_ERRNO
OUTPUT_VARIABLE LISTCMD_OUTPUT
CROSSCOMPILING_EMULATOR "${TEST_EXECUTOR}"
)
if (NOT ${LISTCMD_ERRNO} EQUAL 0)
message(FATAL_ERROR
"Error running test executable '${TEST_EXECUTABLE}':\n"
" Result: ${LISTCMD_ERRNO}\n"
" Output: ${LISTCMD_OUTPUT}\n"
)
endif ()
set(common_args)
if (TEST_ITERATIONS)
list(APPEND common_args "--iterations" "${TEST_ITERATIONS}")
endif ()
if (TEST_NO_FORK)
list(APPEND common_args "--no-fork")
endif ()
if (TEST_SHOW_STDERR)
list(APPEND common_args "--show-stderr")
endif ()
if (TEST_FATAL_FAILURES)
list(APPEND common_args "--fatal-failures")
endif ()
if (TEST_SINGLE)
list(APPEND common_args "--single")
endif ()
if (TEST_SEED)
list(APPEND common_args "--seed" "${TEST_SEED}")
endif ()
if (TEST_PARAMS)
list(LENGTH TEST_PARAMS PARAMS_SIZE)
math(EXPR PARAMS_SIZE_MODULO_2 "${PARAMS_SIZE} % 2")
foreach (i RANGE 1 "${PARAMS_SIZE}" 2)
list(POP_FRONT TEST_PARAMS KEY VAL)
list(APPEND common_args "--param" "${KEY}" "${VAL}")
endforeach ()
endif ()
if (TEST_LOG_VISIBLE)
list(APPEND common_args "--log-visible" "${TEST_LOG_VISIBLE}")
endif ()
if (TEST_LOG_FATAL)
list(APPEND common_args "--log-fatal" "${TEST_LOG_FATAL}")
endif ()
list(APPEND common_args ${TEST_EXTRA_ARGS})
foreach (line ${LISTCMD_OUTPUT})
set(test "${line}")
set(ctest_test "${TEST_PREFIX}${test}${TEST_SUFFIX}")
add_command(add_test "${ctest_test}"
${TEST_EXECUTOR}
"${TEST_EXECUTABLE}"
"${test}"
${common_args}
)
add_command(set_tests_properties
"${ctest_test}"
PROPERTIES
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
)
list(APPEND tests "${ctest_test}")
endforeach ()
add_command(set tests "${tests}")
file(WRITE "${CTEST_FILE}" "${script}")