blob: 042248725f52cafca5068efd204a916935e43d0f (
plain)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
project(tests C)
include_directories(
${CMAKE_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/include
)
set(CMOCKA_TESTS
test_alloc
test_group_setup_assert
test_group_setup_fail
test_fixtures
test_group_fixtures
test_assert_macros
test_assert_macros_fail
test_exception_handler
test_basics
test_skip
test_setup_fail
test_ordering
test_ordering_fail
test_returns
test_returns_fail)
foreach(_CMOCKA_TEST ${CMOCKA_TESTS})
add_cmocka_test(${_CMOCKA_TEST} ${_CMOCKA_TEST}.c ${CMOCKA_STATIC_LIBRARY})
endforeach()
### Special Cases
if (${CMAKE_C_COMPILER_ID} MATCHES "(GNU|Clang)")
set_source_files_properties(test_cmockery.c PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations")
endif()
add_cmocka_test(test_cmockery test_cmockery.c ${CMOCKA_STATIC_LIBRARY})
### Exceptions
# test_skip
set_tests_properties(
test_skip
PROPERTIES
PASS_REGULAR_EXPRESSION
"\\[ SKIPPED \\] test_check_skip"
)
# test_assert_macros_fail
set_tests_properties(
test_assert_macros_fail
PROPERTIES
PASS_REGULAR_EXPRESSION
"\\[ FAILED \\] 1 test"
)
# test_ordering ensure proper failures
set_tests_properties(
test_ordering_fail
PROPERTIES
PASS_REGULAR_EXPRESSION
"\\[ FAILED \\] 7 test"
)
# test_returns_fail ensure proper failures
set_tests_properties(
test_returns_fail
PROPERTIES
PASS_REGULAR_EXPRESSION
"\\[ FAILED \\] 3 test"
)
# test_exception_handler
if (WIN32)
set_tests_properties(
test_exception_handler
PROPERTIES
PASS_REGULAR_EXPRESSION
"EXCEPTION_ACCESS_VIOLATION occurred at")
else()
set_tests_properties(
test_exception_handler
PROPERTIES
PASS_REGULAR_EXPRESSION
"Test failed with exception: (Segmentation fault|Segmentation Fault|11)"
)
endif (WIN32)
set_tests_properties(
test_setup_fail
PROPERTIES
WILL_FAIL
1
)
set_tests_properties(
test_group_setup_assert
PROPERTIES
WILL_FAIL
1
)
set_tests_properties(
test_group_setup_fail
PROPERTIES
WILL_FAIL
1
)
add_test (test_setup_fail_1_failed test_setup_fail)
set_tests_properties(
test_setup_fail_1_failed
PROPERTIES
PASS_REGULAR_EXPRESSION
"\\[ ERROR \\] int_test_ignored"
)
add_test (test_setup_fail_1_passed test_setup_fail)
set_tests_properties(
test_setup_fail_1_passed
PROPERTIES
PASS_REGULAR_EXPRESSION
"\\[ PASSED \\] 1 test\\(s\\)."
)
add_test (test_setup_fail_match_failed test_setup_fail)
set_tests_properties(
test_setup_fail_match_failed
PROPERTIES
PASS_REGULAR_EXPRESSION
"\\[ ERROR \\] int_test_ignored"
)
add_test (test_setup_fail_match_passed test_setup_fail)
set_tests_properties(
test_setup_fail_match_passed
PROPERTIES
PASS_REGULAR_EXPRESSION
"\\[ OK \\] int_test_success"
)
### Output formats
# test output of success, failure, skip, fixture failure
set(OUTPUT_TESTS
test_basics
test_assert_macros_fail
test_skip
test_setup_fail)
set(TEST_OUTPUT_FMTS
tap
subunit
xml)
set(test_basics_tap_out
"^\t1\\.\\.2[ \n\r]+\tok 1 - null_test_success[ \n\r]+\tok 2 - int_test_success[ \n\r]+ok - tests")
set(test_assert_macros_fail_tap_out
"^\t1\\.\\.1[ \n\r]+\tnot ok 1 - test_assert_return_code_fail[ \n\r]+\t#[^\n\r]+[\n\r]\t#[^\n\r]+[\n\r]not ok - tests")
set(test_skip_tap_out
"not ok 1 # SKIP")
set(test_setup_fail_tap_out
"not ok 1 - int_test_ignored Could not run the test - check test fixtures")
set(test_basics_subunit_out
"^test: null_test_success[ \n\r]+success: null_test_success")
set(test_assert_macros_fail_subunit_out
"failure: test_assert_return_code_fail \\[")
set(test_skip_subunit_out
"^test: test_check_skip[ \n\r]+skip: test_check_skip")
set(test_setup_fail_subunit_out
"error: int_test_ignored \\[ Could not run the test - check test fixtures \\]")
set(test_basics_xml_out
"<testsuite name=\"tests\" time=\"[0-9.]+\" tests=\"2\" failures=\"0\" errors=\"0\" skipped=\"0\" >[ \n\r]+<testcase name=\"null_test_success\" time=\"[0-9.]+\" >.*</testcase>")
set(test_assert_macros_fail_xml_out
"<testcase name=\"test_assert_return_code_fail\" time=\"[0-9.]+\" >[ \n\r]+<failure>")
set(test_skip_xml_out
"<testcase name=\"test_check_skip\" time=\"[0-9.]+\" >[ \n\r]+<skipped/>")
set(test_setup_fail_xml_out
"<testcase name=\"int_test_ignored\" time=\"[0-9.]+\" >[ \n\r]+<failure><!\\[CDATA\\[Test setup failed\\]\\]></failure>")
foreach(_TEST_OUTPUT_FMT ${TEST_OUTPUT_FMTS})
foreach(_OUTPUT_TEST ${OUTPUT_TESTS})
set(TEST_NAME ${_OUTPUT_TEST}_${_TEST_OUTPUT_FMT})
add_test(${TEST_NAME} ${_OUTPUT_TEST})
set_property(
TEST
${TEST_NAME}
PROPERTY
ENVIRONMENT CMOCKA_MESSAGE_OUTPUT=${_TEST_OUTPUT_FMT}
)
set_tests_properties(
${TEST_NAME}
PROPERTIES
PASS_REGULAR_EXPRESSION
${${TEST_NAME}_out}
)
endforeach()
endforeach()
|