1 # Copyright 2011 The Kyua Authors.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
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.
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.
30 # Executes a mock test suite to generate data in the database.
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
38 local mock_env="${1}"; shift
39 local dbfile_name="${1}"; shift
43 test_suite("integration")
44 atf_test_program{name="simple_all_pass"}
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}"
53 # Ensure the results of 'report' come from the database.
54 rm Kyuafile simple_all_pass
58 utils_test_case default_behavior__ok
59 default_behavior__ok_body() {
60 utils_install_times_wrapper
62 run_tests "mock1" dbfile_name1
66 simple_all_pass:skip -> skipped: The reason for skipping is this [S.UUUs]
68 Results read from $(cat dbfile_name1)
69 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
72 atf_check -s exit:0 -o file:expout -e empty kyua report
74 run_tests "mock2" dbfile_name2
78 simple_all_pass:skip -> skipped: The reason for skipping is this [S.UUUs]
80 Results read from $(cat dbfile_name2)
81 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
84 atf_check -s exit:0 -o file:expout -e empty kyua report
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
96 utils_test_case results_file__explicit
97 results_file__explicit_body() {
98 run_tests "mock1" dbfile_name1
99 run_tests "mock2" dbfile_name2
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)" \
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)" \
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
117 utils_test_case output__explicit
118 output__explicit_body() {
119 run_tests unused_mock dbfile_name
123 simple_all_pass:skip -> skipped: The reason for skipping is this [S.UUUs]
125 Results read from $(cat dbfile_name)
126 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
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 \
134 atf_check -s exit:0 -o file:report -x cat stderr \
135 "| ${utils_strip_times_but_not_ids}"
137 atf_check -s exit:0 -o empty -e empty kyua report \
139 atf_check -s exit:0 -o file:report -x cat my-file \
140 "| ${utils_strip_times_but_not_ids}"
144 utils_test_case filter__ok
146 utils_install_times_wrapper
148 run_tests "mock1" dbfile_name1
152 simple_all_pass:skip -> skipped: The reason for skipping is this [S.UUUs]
154 Results read from $(cat dbfile_name1)
155 Test cases: 1 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
158 atf_check -s exit:0 -o file:expout -e empty kyua report \
163 utils_test_case filter__ok_passed_excluded_by_default
164 filter__ok_passed_excluded_by_default_body() {
165 utils_install_times_wrapper
167 run_tests "mock1" dbfile_name1
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...
173 Results read from $(cat dbfile_name1)
174 Test cases: 1 total, 0 skipped, 0 expected failures, 0 broken, 0 failed
177 atf_check -s exit:0 -o file:expout -e empty kyua report \
181 simple_all_pass:pass -> passed [S.UUUs]
183 Results read from $(cat dbfile_name1)
184 Test cases: 1 total, 0 skipped, 0 expected failures, 0 broken, 0 failed
187 atf_check -s exit:0 -o file:expout -e empty kyua report \
188 --results-filter= simple_all_pass:pass
192 utils_test_case filter__no_match
193 filter__no_match_body() {
194 utils_install_times_wrapper
196 run_tests "mock1" dbfile_name1
200 simple_all_pass:skip -> skipped: The reason for skipping is this [S.UUUs]
202 Results read from $(cat dbfile_name1)
203 Test cases: 1 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
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'.
210 atf_check -s exit:1 -o file:expout -e file:experr kyua report \
211 first simple_all_pass:skip simple_all_pass:second
215 utils_test_case verbose
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)"
227 and terminates here" dbfile_name
230 ===> Execution context
231 Current directory: ${real_cwd}
232 Environment variables:
234 # $_ is a bash variable. To keep our tests stable, we override its value
235 # below to match the hardcoded value in run_tests.
240 and terminates here" \
242 "$(atf_get_srcdir)/helpers/dump_env" ' ' ' ' >>expout
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
251 allowed_architectures is empty
252 allowed_platforms is empty
256 required_configs is empty
257 required_disk_space = 0
258 required_files is empty
260 required_programs is empty
261 required_user is empty
265 This is the stdout of skip
268 This is the stderr of skip
270 simple_all_pass:skip -> skipped: The reason for skipping is this [S.UUUs]
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
278 atf_check -s exit:0 -o file:expout -e empty -x kyua report --verbose \
279 "| ${utils_strip_times_but_not_ids}"
283 utils_test_case results_filter__empty
284 results_filter__empty_body() {
285 utils_install_times_wrapper
287 run_tests "mock1" dbfile_name1
291 simple_all_pass:pass -> passed [S.UUUs]
293 simple_all_pass:skip -> skipped: The reason for skipping is this [S.UUUs]
295 Results read from $(cat dbfile_name1)
296 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
299 atf_check -s exit:0 -o file:expout -e empty kyua report --results-filter=
303 utils_test_case results_filter__one
304 results_filter__one_body() {
305 utils_install_times_wrapper
307 run_tests "mock1" dbfile_name1
311 simple_all_pass:pass -> passed [S.UUUs]
313 Results read from $(cat dbfile_name1)
314 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
317 atf_check -s exit:0 -o file:expout -e empty kyua report \
318 --results-filter=passed
322 utils_test_case results_filter__multiple_all_match
323 results_filter__multiple_all_match_body() {
324 utils_install_times_wrapper
326 run_tests "mock1" dbfile_name1
330 simple_all_pass:skip -> skipped: The reason for skipping is this [S.UUUs]
332 simple_all_pass:pass -> passed [S.UUUs]
334 Results read from $(cat dbfile_name1)
335 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
338 atf_check -s exit:0 -o file:expout -e empty kyua report \
339 --results-filter=skipped,passed
343 utils_test_case results_filter__multiple_some_match
344 results_filter__multiple_some_match_body() {
345 utils_install_times_wrapper
347 run_tests "mock1" dbfile_name1
351 simple_all_pass:skip -> skipped: The reason for skipping is this [S.UUUs]
353 Results read from $(cat dbfile_name1)
354 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
357 atf_check -s exit:0 -o file:expout -e empty kyua report \
358 --results-filter=skipped,xfail,broken,failed
362 atf_init_test_cases() {
363 atf_add_test_case default_behavior__ok
364 atf_add_test_case default_behavior__no_store
366 atf_add_test_case results_file__explicit
367 atf_add_test_case results_file__not_found
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
373 atf_add_test_case verbose
375 atf_add_test_case output__explicit
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