]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/kyua/integration/cmd_report_junit_test.sh
contrib/kyua: Merge vendor import
[FreeBSD/FreeBSD.git] / contrib / kyua / integration / cmd_report_junit_test.sh
1 # Copyright 2014 The Kyua Authors.
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
7 #
8 # * Redistributions of source code must retain the above copyright
9 #   notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above copyright
11 #   notice, this list of conditions and the following disclaimer in the
12 #   documentation and/or other materials provided with the distribution.
13 # * Neither the name of Google Inc. nor the names of its contributors
14 #   may be used to endorse or promote products derived from this software
15 #   without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29
30 # Executes a mock test suite to generate data in the database.
31 #
32 # \param mock_env The value to store in a MOCK variable in the environment.
33 #     Use this to be able to differentiate executions by inspecting the
34 #     context of the output.
35 # \param dbfile_name File to which to write the path to the generated database
36 #     file.
37 run_tests() {
38     local mock_env="${1}"; shift
39     local dbfile_name="${1}"; shift
40
41     cat >Kyuafile <<EOF
42 syntax(2)
43 test_suite("integration")
44 atf_test_program{name="simple_all_pass"}
45 EOF
46
47     utils_cp_helper simple_all_pass .
48     atf_check -s exit:0 -o save:stdout -e empty env MOCK="${mock_env}" kyua test
49     grep '^Results saved to ' stdout | cut -d ' ' -f 4 >"${dbfile_name}"
50     rm stdout
51
52     # Ensure the results of 'report-junit' come from the database.
53     rm Kyuafile simple_all_pass
54 }
55
56
57 # Removes the contents of a properties tag from stdout.
58 strip_properties='awk "
59 BEGIN { skip = 0; }
60
61 /<\/properties>/ {
62     print \"</properties>\";
63     skip = 0;
64     next;
65 }
66
67 /<properties>/ {
68     print \"<properties>\";
69     print \"CONTENTS STRIPPED BY TEST\";
70     skip = 1;
71     next;
72 }
73
74 { if (!skip) print; }"'
75
76
77 utils_test_case default_behavior__ok
78 default_behavior__ok_body() {
79     utils_install_times_wrapper
80
81     run_tests "mock1
82 this should not be seen
83 mock1 new line" unused_dbfile_name
84
85     cat >expout <<EOF
86 <?xml version="1.0" encoding="iso-8859-1"?>
87 <testsuite>
88 <properties>
89 CONTENTS STRIPPED BY TEST
90 </properties>
91 <testcase classname="simple_all_pass" name="pass" time="S.UUU">
92 <system-out>This is the stdout of pass
93 </system-out>
94 <system-err>Test case metadata
95 ------------------
96
97 allowed_architectures is empty
98 allowed_platforms is empty
99 description is empty
100 has_cleanup = false
101 is_exclusive = false
102 required_configs is empty
103 required_disk_space = 0
104 required_files is empty
105 required_memory = 0
106 required_programs is empty
107 required_user is empty
108 timeout = 300
109
110 Timing information
111 ------------------
112
113 Start time: YYYY-MM-DDTHH:MM:SS.ssssssZ
114 End time:   YYYY-MM-DDTHH:MM:SS.ssssssZ
115 Duration:   S.UUUs
116
117 Original stderr
118 ---------------
119
120 This is the stderr of pass
121 </system-err>
122 </testcase>
123 <testcase classname="simple_all_pass" name="skip" time="S.UUU">
124 <skipped/>
125 <system-out>This is the stdout of skip
126 </system-out>
127 <system-err>Skipped result details
128 ----------------------
129
130 The reason for skipping is this
131
132 Test case metadata
133 ------------------
134
135 allowed_architectures is empty
136 allowed_platforms is empty
137 description is empty
138 has_cleanup = false
139 is_exclusive = false
140 required_configs is empty
141 required_disk_space = 0
142 required_files is empty
143 required_memory = 0
144 required_programs is empty
145 required_user is empty
146 timeout = 300
147
148 Timing information
149 ------------------
150
151 Start time: YYYY-MM-DDTHH:MM:SS.ssssssZ
152 End time:   YYYY-MM-DDTHH:MM:SS.ssssssZ
153 Duration:   S.UUUs
154
155 Original stderr
156 ---------------
157
158 This is the stderr of skip
159 </system-err>
160 </testcase>
161 </testsuite>
162 EOF
163     atf_check -s exit:0 -o file:expout -e empty -x "kyua report-junit" \
164         "| ${strip_properties}"
165 }
166
167
168 utils_test_case default_behavior__no_store
169 default_behavior__no_store_body() {
170     echo 'kyua: E: No previous results file found for test suite' \
171         "$(utils_test_suite_id)." >experr
172     atf_check -s exit:2 -o empty -e file:experr kyua report-junit
173 }
174
175
176 utils_test_case results_file__explicit
177 results_file__explicit_body() {
178     run_tests "mock1" dbfile_name1
179     run_tests "mock2" dbfile_name2
180
181     atf_check -s exit:0 -o match:"MOCK.*mock1" -o not-match:"MOCK.*mock2" \
182         -e empty kyua report-junit --results-file="$(cat dbfile_name1)"
183     atf_check -s exit:0 -o not-match:"MOCK.*mock1" -o match:"MOCK.*mock2" \
184         -e empty kyua report-junit --results-file="$(cat dbfile_name2)"
185 }
186
187
188 utils_test_case results_file__not_found
189 results_file__not_found_body() {
190     atf_check -s exit:2 -o empty -e match:"kyua: E: No previous results.*foo" \
191         kyua report-junit --results-file=foo
192 }
193
194
195 utils_test_case output__explicit
196 output__explicit_body() {
197     run_tests unused_mock unused_dbfile_name
198
199     cat >report <<EOF
200 <?xml version="1.0" encoding="iso-8859-1"?>
201 <testsuite>
202 <properties>
203 CONTENTS STRIPPED BY TEST
204 </properties>
205 <testcase classname="simple_all_pass" name="pass" time="S.UUU">
206 <system-out>This is the stdout of pass
207 </system-out>
208 <system-err>Test case metadata
209 ------------------
210
211 allowed_architectures is empty
212 allowed_platforms is empty
213 description is empty
214 has_cleanup = false
215 is_exclusive = false
216 required_configs is empty
217 required_disk_space = 0
218 required_files is empty
219 required_memory = 0
220 required_programs is empty
221 required_user is empty
222 timeout = 300
223
224 Timing information
225 ------------------
226
227 Start time: YYYY-MM-DDTHH:MM:SS.ssssssZ
228 End time:   YYYY-MM-DDTHH:MM:SS.ssssssZ
229 Duration:   S.UUUs
230
231 Original stderr
232 ---------------
233
234 This is the stderr of pass
235 </system-err>
236 </testcase>
237 <testcase classname="simple_all_pass" name="skip" time="S.UUU">
238 <skipped/>
239 <system-out>This is the stdout of skip
240 </system-out>
241 <system-err>Skipped result details
242 ----------------------
243
244 The reason for skipping is this
245
246 Test case metadata
247 ------------------
248
249 allowed_architectures is empty
250 allowed_platforms is empty
251 description is empty
252 has_cleanup = false
253 is_exclusive = false
254 required_configs is empty
255 required_disk_space = 0
256 required_files is empty
257 required_memory = 0
258 required_programs is empty
259 required_user is empty
260 timeout = 300
261
262 Timing information
263 ------------------
264
265 Start time: YYYY-MM-DDTHH:MM:SS.ssssssZ
266 End time:   YYYY-MM-DDTHH:MM:SS.ssssssZ
267 Duration:   S.UUUs
268
269 Original stderr
270 ---------------
271
272 This is the stderr of skip
273 </system-err>
274 </testcase>
275 </testsuite>
276 EOF
277
278     atf_check -s exit:0 -o file:report -e empty -x kyua report-junit \
279         --output=/dev/stdout "| ${strip_properties} | ${utils_strip_times}"
280     atf_check -s exit:0 -o empty -e save:stderr kyua report-junit \
281         --output=/dev/stderr
282     atf_check -s exit:0 -o file:report -x cat stderr \
283         "| ${strip_properties} | ${utils_strip_times}"
284
285     atf_check -s exit:0 -o empty -e empty kyua report-junit \
286         --output=my-file
287     atf_check -s exit:0 -o file:report -x cat my-file \
288         "| ${strip_properties} | ${utils_strip_times}"
289 }
290
291
292 atf_init_test_cases() {
293     atf_add_test_case default_behavior__ok
294     atf_add_test_case default_behavior__no_store
295
296     atf_add_test_case results_file__explicit
297     atf_add_test_case results_file__not_found
298
299     atf_add_test_case output__explicit
300 }