1 # Copyright 2011 Google Inc.
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.
36 # \return The action identifier of the committed action.
45 test_suite("integration")
46 atf_test_program{name="simple_all_pass"}
49 utils_cp_helper simple_all_pass .
50 test -d ..
/.kyua || mkdir ..
/.kyua
52 atf_check
-s exit:0 -o save
:stdout
-e empty env \
53 HOME
="$(pwd)/home" MOCK
="${mock_env}" \
54 "${kyua}" test --store=..
/.kyua
/store.db
56 action_id
=$
(grep '^Committed action ' stdout | cut
-d ' ' -f 3)
57 echo "New action is ${action_id}"
60 # Ensure the results of 'report' come from the database.
67 utils_test_case default_behavior__ok
68 default_behavior__ok_body
() {
69 utils_install_timestamp_wrapper
75 simple_all_pass:skip -> skipped: The reason for skipping is this [S.UUUs]
78 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
81 atf_check
-s exit:0 -o file:expout
-e empty kyua report
87 simple_all_pass:skip -> skipped: The reason for skipping is this [S.UUUs]
90 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
93 atf_check
-s exit:0 -o file:expout
-e empty kyua report
97 utils_test_case default_behavior__no_actions
98 default_behavior__no_actions_body
() {
99 kyua db-exec
"SELECT * FROM actions"
101 echo 'kyua: E: No actions in the database.' >experr
102 atf_check
-s exit:2 -o empty
-e file:experr kyua report
106 utils_test_case default_behavior__no_store
107 default_behavior__no_store_body
() {
108 atf_check
-s exit:2 -o empty \
109 -e match
:"kyua: E: Cannot open '.*/.kyua/store.db': " kyua report
113 utils_test_case action__explicit
114 action__explicit_body
() {
115 run_tests
"mock1"; action1
=$?
116 run_tests
"mock2"; action2
=$?
118 atf_check
-s exit:0 -o match
:"MOCK=mock1" -o not-match
:"MOCK=mock2" \
119 -o match
:"Action: 1" -o not-match
:"Action: 2" \
120 -e empty kyua report
--action="${action1}" --show-context
121 atf_check
-s exit:0 -o not-match
:"MOCK=mock1" -o match
:"MOCK=mock2" \
122 -o match
:"Action: 2" -o not-match
:"Action: 1" \
123 -e empty kyua report
--action="${action2}" --show-context
127 utils_test_case action__not_found
128 action__not_found_body
() {
129 kyua db-exec
"SELECT * FROM actions"
131 echo 'kyua: E: Error loading action 514: does not exist.' >experr
132 atf_check
-s exit:2 -o empty
-e file:experr kyua report
--action=514
136 utils_test_case show_context
137 show_context_body
() {
141 ===> Execution context
142 Current directory: $(pwd)/testsuite
143 Environment variables:
146 ( cd testsuite
&& HOME
=$
(pwd)/home MOCK
=mock1 env
) \
147 |
sort |
sed -e 's,^, ,' |
grep -v '^ _.*=.*' >>expout
151 simple_all_pass:skip -> skipped: The reason for skipping is this [S.UUUs]
154 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
157 atf_check
-s exit:0 -o file:expout
-e empty
-x kyua report
--show-context \
158 "| ${utils_strip_timestamp} | grep -v '^ _.*=.*'"
162 utils_test_case output__change_file
163 output__change_file_body
() {
168 simple_all_pass:skip -> skipped: The reason for skipping is this [S.UUUs]
171 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
175 atf_check
-s exit:0 -o file:report
-e empty
-x kyua report \
176 --output=/dev
/stdout
"| ${utils_strip_timestamp}"
177 atf_check
-s exit:0 -o empty
-e save
:stderr kyua report \
179 atf_check
-s exit:0 -o file:report
-x cat stderr \
180 "| ${utils_strip_timestamp}"
182 atf_check
-s exit:0 -o empty
-e empty kyua report \
184 atf_check
-s exit:0 -o file:report
-x cat my-file \
185 "| ${utils_strip_timestamp}"
189 utils_test_case results_filter__empty
190 results_filter__empty_body
() {
191 utils_install_timestamp_wrapper
197 simple_all_pass:pass -> passed [S.UUUs]
199 simple_all_pass:skip -> skipped: The reason for skipping is this [S.UUUs]
202 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
205 atf_check
-s exit:0 -o file:expout
-e empty kyua report
--results-filter=
209 utils_test_case results_filter__one
210 results_filter__one_body
() {
211 utils_install_timestamp_wrapper
217 simple_all_pass:pass -> passed [S.UUUs]
220 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
223 atf_check
-s exit:0 -o file:expout
-e empty kyua report \
224 --results-filter=passed
228 utils_test_case results_filter__multiple_all_match
229 results_filter__multiple_all_match_body
() {
230 utils_install_timestamp_wrapper
236 simple_all_pass:skip -> skipped: The reason for skipping is this [S.UUUs]
238 simple_all_pass:pass -> passed [S.UUUs]
241 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
244 atf_check
-s exit:0 -o file:expout
-e empty kyua report \
245 --results-filter=skipped
,passed
249 utils_test_case results_filter__multiple_some_match
250 results_filter__multiple_some_match_body
() {
251 utils_install_timestamp_wrapper
257 simple_all_pass:skip -> skipped: The reason for skipping is this [S.UUUs]
260 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
263 atf_check
-s exit:0 -o file:expout
-e empty kyua report \
264 --results-filter=skipped
,xfail
,broken
,failed
268 atf_init_test_cases
() {
269 atf_add_test_case default_behavior__ok
270 atf_add_test_case default_behavior__no_actions
271 atf_add_test_case default_behavior__no_store
273 atf_add_test_case action__explicit
274 atf_add_test_case action__not_found
276 atf_add_test_case show_context
278 atf_add_test_case output__change_file
280 atf_add_test_case results_filter__empty
281 atf_add_test_case results_filter__one
282 atf_add_test_case results_filter__multiple_all_match
283 atf_add_test_case results_filter__multiple_some_match