]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/kyua/integration/cmd_report_test.sh
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / kyua / integration / cmd_report_test.sh
1 # Copyright 2011 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 \
49         MOCK="${mock_env}" _='fake-value' kyua test
50     grep '^Results saved to ' stdout | cut -d ' ' -f 4 >"${dbfile_name}"
51     rm stdout
52
53     # Ensure the results of 'report' come from the database.
54     rm Kyuafile simple_all_pass
55 }
56
57
58 utils_test_case default_behavior__ok
59 default_behavior__ok_body() {
60     utils_install_times_wrapper
61
62     run_tests "mock1" dbfile_name1
63
64     cat >expout <<EOF
65 ===> Skipped tests
66 simple_all_pass:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
67 ===> Summary
68 Results read from $(cat dbfile_name1)
69 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
70 Total time: S.UUUs
71 EOF
72     atf_check -s exit:0 -o file:expout -e empty kyua report
73
74     run_tests "mock2" dbfile_name2
75
76     cat >expout <<EOF
77 ===> Skipped tests
78 simple_all_pass:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
79 ===> Summary
80 Results read from $(cat dbfile_name2)
81 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
82 Total time: S.UUUs
83 EOF
84     atf_check -s exit:0 -o file:expout -e empty kyua report
85 }
86
87
88 utils_test_case default_behavior__no_store
89 default_behavior__no_store_body() {
90     echo 'kyua: E: No previous results file found for test suite' \
91         "$(utils_test_suite_id)." >experr
92     atf_check -s exit:2 -o empty -e file:experr kyua report
93 }
94
95
96 utils_test_case results_file__explicit
97 results_file__explicit_body() {
98     run_tests "mock1" dbfile_name1
99     run_tests "mock2" dbfile_name2
100
101     atf_check -s exit:0 -o match:"MOCK=mock1" -o not-match:"MOCK=mock2" \
102         -e empty kyua report --results-file="$(cat dbfile_name1)" \
103         --verbose
104     atf_check -s exit:0 -o not-match:"MOCK=mock1" -o match:"MOCK=mock2" \
105         -e empty kyua report --results-file="$(cat dbfile_name2)" \
106         --verbose
107 }
108
109
110 utils_test_case results_file__not_found
111 results_file__not_found_body() {
112     atf_check -s exit:2 -o empty -e match:"kyua: E: No previous results.*foo" \
113         kyua report --results-file=foo
114 }
115
116
117 utils_test_case output__explicit
118 output__explicit_body() {
119     run_tests unused_mock dbfile_name
120
121     cat >report <<EOF
122 ===> Skipped tests
123 simple_all_pass:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
124 ===> Summary
125 Results read from $(cat dbfile_name)
126 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
127 Total time: S.UUUs
128 EOF
129
130     atf_check -s exit:0 -o file:report -e empty -x kyua report \
131         --output=/dev/stdout "| ${utils_strip_times_but_not_ids}"
132     atf_check -s exit:0 -o empty -e save:stderr kyua report \
133         --output=/dev/stderr
134     atf_check -s exit:0 -o file:report -x cat stderr \
135         "| ${utils_strip_times_but_not_ids}"
136
137     atf_check -s exit:0 -o empty -e empty kyua report \
138         --output=my-file
139     atf_check -s exit:0 -o file:report -x cat my-file \
140         "| ${utils_strip_times_but_not_ids}"
141 }
142
143
144 utils_test_case filter__ok
145 filter__ok_body() {
146     utils_install_times_wrapper
147
148     run_tests "mock1" dbfile_name1
149
150     cat >expout <<EOF
151 ===> Skipped tests
152 simple_all_pass:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
153 ===> Summary
154 Results read from $(cat dbfile_name1)
155 Test cases: 1 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
156 Total time: S.UUUs
157 EOF
158     atf_check -s exit:0 -o file:expout -e empty kyua report \
159         simple_all_pass:skip
160 }
161
162
163 utils_test_case filter__ok_passed_excluded_by_default
164 filter__ok_passed_excluded_by_default_body() {
165     utils_install_times_wrapper
166
167     run_tests "mock1" dbfile_name1
168
169     # Passed results are excluded by default so they are not displayed even if
170     # requested with a test case filter.  This might be somewhat confusing...
171     cat >expout <<EOF
172 ===> Summary
173 Results read from $(cat dbfile_name1)
174 Test cases: 1 total, 0 skipped, 0 expected failures, 0 broken, 0 failed
175 Total time: S.UUUs
176 EOF
177     atf_check -s exit:0 -o file:expout -e empty kyua report \
178         simple_all_pass:pass
179     cat >expout <<EOF
180 ===> Passed tests
181 simple_all_pass:pass  ->  passed  [S.UUUs]
182 ===> Summary
183 Results read from $(cat dbfile_name1)
184 Test cases: 1 total, 0 skipped, 0 expected failures, 0 broken, 0 failed
185 Total time: S.UUUs
186 EOF
187     atf_check -s exit:0 -o file:expout -e empty kyua report \
188         --results-filter= simple_all_pass:pass
189 }
190
191
192 utils_test_case filter__no_match
193 filter__no_match_body() {
194     utils_install_times_wrapper
195
196     run_tests "mock1" dbfile_name1
197
198     cat >expout <<EOF
199 ===> Skipped tests
200 simple_all_pass:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
201 ===> Summary
202 Results read from $(cat dbfile_name1)
203 Test cases: 1 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
204 Total time: S.UUUs
205 EOF
206     cat >experr <<EOF
207 kyua: W: No test cases matched by the filter 'first'.
208 kyua: W: No test cases matched by the filter 'simple_all_pass:second'.
209 EOF
210     atf_check -s exit:1 -o file:expout -e file:experr kyua report \
211         first simple_all_pass:skip simple_all_pass:second
212 }
213
214
215 utils_test_case verbose
216 verbose_body() {
217     # Switch to the current directory using its physical location and update
218     # HOME accordingly.  Otherwise, the test below where we compare the value
219     # of HOME in the output might fail if the path to HOME contains a symlink
220     # (as is the case in OS X when HOME points to the temporary directory.)
221     local real_cwd="$(pwd -P)"
222     cd "${real_cwd}"
223     HOME="${real_cwd}"
224
225     run_tests "mock1
226 has multiple lines
227 and terminates here" dbfile_name
228
229     cat >expout <<EOF
230 ===> Execution context
231 Current directory: ${real_cwd}
232 Environment variables:
233 EOF
234     # $_ is a bash variable.  To keep our tests stable, we override its value
235     # below to match the hardcoded value in run_tests.
236     env \
237         HOME="${real_cwd}" \
238         MOCK="mock1
239 has multiple lines
240 and terminates here" \
241         _='fake-value' \
242         "$(atf_get_srcdir)/helpers/dump_env" '    ' '        ' >>expout
243     cat >>expout <<EOF
244 ===> simple_all_pass:skip
245 Result:     skipped: The reason for skipping is this
246 Start time: YYYY-MM-DDTHH:MM:SS.ssssssZ
247 End time:   YYYY-MM-DDTHH:MM:SS.ssssssZ
248 Duration:   S.UUUs
249
250 Metadata:
251     allowed_architectures is empty
252     allowed_platforms is empty
253     description is empty
254     has_cleanup = false
255     is_exclusive = false
256     required_configs is empty
257     required_disk_space = 0
258     required_files is empty
259     required_memory = 0
260     required_programs is empty
261     required_user is empty
262     timeout = 300
263
264 Standard output:
265 This is the stdout of skip
266
267 Standard error:
268 This is the stderr of skip
269 ===> Skipped tests
270 simple_all_pass:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
271 ===> Summary
272 Results read from $(cat dbfile_name)
273 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
274 Start time: YYYY-MM-DDTHH:MM:SS.ssssssZ
275 End time:   YYYY-MM-DDTHH:MM:SS.ssssssZ
276 Total time: S.UUUs
277 EOF
278     atf_check -s exit:0 -o file:expout -e empty -x kyua report --verbose \
279         "| ${utils_strip_times_but_not_ids}"
280 }
281
282
283 utils_test_case results_filter__empty
284 results_filter__empty_body() {
285     utils_install_times_wrapper
286
287     run_tests "mock1" dbfile_name1
288
289     cat >expout <<EOF
290 ===> Passed tests
291 simple_all_pass:pass  ->  passed  [S.UUUs]
292 ===> Skipped tests
293 simple_all_pass:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
294 ===> Summary
295 Results read from $(cat dbfile_name1)
296 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
297 Total time: S.UUUs
298 EOF
299     atf_check -s exit:0 -o file:expout -e empty kyua report --results-filter=
300 }
301
302
303 utils_test_case results_filter__one
304 results_filter__one_body() {
305     utils_install_times_wrapper
306
307     run_tests "mock1" dbfile_name1
308
309     cat >expout <<EOF
310 ===> Passed tests
311 simple_all_pass:pass  ->  passed  [S.UUUs]
312 ===> Summary
313 Results read from $(cat dbfile_name1)
314 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
315 Total time: S.UUUs
316 EOF
317     atf_check -s exit:0 -o file:expout -e empty kyua report \
318         --results-filter=passed
319 }
320
321
322 utils_test_case results_filter__multiple_all_match
323 results_filter__multiple_all_match_body() {
324     utils_install_times_wrapper
325
326     run_tests "mock1" dbfile_name1
327
328     cat >expout <<EOF
329 ===> Skipped tests
330 simple_all_pass:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
331 ===> Passed tests
332 simple_all_pass:pass  ->  passed  [S.UUUs]
333 ===> Summary
334 Results read from $(cat dbfile_name1)
335 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
336 Total time: S.UUUs
337 EOF
338     atf_check -s exit:0 -o file:expout -e empty kyua report \
339         --results-filter=skipped,passed
340 }
341
342
343 utils_test_case results_filter__multiple_some_match
344 results_filter__multiple_some_match_body() {
345     utils_install_times_wrapper
346
347     run_tests "mock1" dbfile_name1
348
349     cat >expout <<EOF
350 ===> Skipped tests
351 simple_all_pass:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
352 ===> Summary
353 Results read from $(cat dbfile_name1)
354 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
355 Total time: S.UUUs
356 EOF
357     atf_check -s exit:0 -o file:expout -e empty kyua report \
358         --results-filter=skipped,xfail,broken,failed
359 }
360
361
362 atf_init_test_cases() {
363     atf_add_test_case default_behavior__ok
364     atf_add_test_case default_behavior__no_store
365
366     atf_add_test_case results_file__explicit
367     atf_add_test_case results_file__not_found
368
369     atf_add_test_case filter__ok
370     atf_add_test_case filter__ok_passed_excluded_by_default
371     atf_add_test_case filter__no_match
372
373     atf_add_test_case verbose
374
375     atf_add_test_case output__explicit
376
377     atf_add_test_case results_filter__empty
378     atf_add_test_case results_filter__one
379     atf_add_test_case results_filter__multiple_all_match
380     atf_add_test_case results_filter__multiple_some_match
381 }