1 # Copyright 2014 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 MOCK="${mock_env}" kyua test
49 grep '^Results saved to ' stdout | cut -d ' ' -f 4 >"${dbfile_name}"
52 # Ensure the results of 'report-junit' come from the database.
53 rm Kyuafile simple_all_pass
57 # Removes the contents of a properties tag from stdout.
58 strip_properties='awk "
62 print \"</properties>\";
68 print \"<properties>\";
69 print \"CONTENTS STRIPPED BY TEST\";
74 { if (!skip) print; }"'
77 utils_test_case default_behavior__ok
78 default_behavior__ok_body() {
79 utils_install_times_wrapper
82 this should not be seen
83 mock1 new line" unused_dbfile_name
86 <?xml version="1.0" encoding="iso-8859-1"?>
89 CONTENTS STRIPPED BY TEST
91 <testcase classname="simple_all_pass" name="pass" time="S.UUU">
92 <system-out>This is the stdout of pass
94 <system-err>Test case metadata
97 allowed_architectures is empty
98 allowed_platforms is empty
102 required_configs is empty
103 required_disk_space = 0
104 required_files is empty
106 required_programs is empty
107 required_user is empty
113 Start time: YYYY-MM-DDTHH:MM:SS.ssssssZ
114 End time: YYYY-MM-DDTHH:MM:SS.ssssssZ
120 This is the stderr of pass
123 <testcase classname="simple_all_pass" name="skip" time="S.UUU">
125 <system-out>This is the stdout of skip
127 <system-err>Skipped result details
128 ----------------------
130 The reason for skipping is this
135 allowed_architectures is empty
136 allowed_platforms is empty
140 required_configs is empty
141 required_disk_space = 0
142 required_files is empty
144 required_programs is empty
145 required_user is empty
151 Start time: YYYY-MM-DDTHH:MM:SS.ssssssZ
152 End time: YYYY-MM-DDTHH:MM:SS.ssssssZ
158 This is the stderr of skip
163 atf_check -s exit:0 -o file:expout -e empty -x "kyua report-junit" \
164 "| ${strip_properties}"
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
176 utils_test_case results_file__explicit
177 results_file__explicit_body() {
178 run_tests "mock1" dbfile_name1
179 run_tests "mock2" dbfile_name2
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)"
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
195 utils_test_case output__explicit
196 output__explicit_body() {
197 run_tests unused_mock unused_dbfile_name
200 <?xml version="1.0" encoding="iso-8859-1"?>
203 CONTENTS STRIPPED BY TEST
205 <testcase classname="simple_all_pass" name="pass" time="S.UUU">
206 <system-out>This is the stdout of pass
208 <system-err>Test case metadata
211 allowed_architectures is empty
212 allowed_platforms is empty
216 required_configs is empty
217 required_disk_space = 0
218 required_files is empty
220 required_programs is empty
221 required_user is empty
227 Start time: YYYY-MM-DDTHH:MM:SS.ssssssZ
228 End time: YYYY-MM-DDTHH:MM:SS.ssssssZ
234 This is the stderr of pass
237 <testcase classname="simple_all_pass" name="skip" time="S.UUU">
239 <system-out>This is the stdout of skip
241 <system-err>Skipped result details
242 ----------------------
244 The reason for skipping is this
249 allowed_architectures is empty
250 allowed_platforms is empty
254 required_configs is empty
255 required_disk_space = 0
256 required_files is empty
258 required_programs is empty
259 required_user is empty
265 Start time: YYYY-MM-DDTHH:MM:SS.ssssssZ
266 End time: YYYY-MM-DDTHH:MM:SS.ssssssZ
272 This is the stderr of skip
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 \
282 atf_check -s exit:0 -o file:report -x cat stderr \
283 "| ${strip_properties} | ${utils_strip_times}"
285 atf_check -s exit:0 -o empty -e empty kyua report-junit \
287 atf_check -s exit:0 -o file:report -x cat my-file \
288 "| ${strip_properties} | ${utils_strip_times}"
292 atf_init_test_cases() {
293 atf_add_test_case default_behavior__ok
294 atf_add_test_case default_behavior__no_store
296 atf_add_test_case results_file__explicit
297 atf_add_test_case results_file__not_found
299 atf_add_test_case output__explicit