Improve the process for GNU tools
[minix3.git] / external / bsd / kyua-cli / dist / integration / cmd_report_test.sh
blob703aa6728fac9e224634968a78b7deb93980117e
1 # Copyright 2011 Google Inc.
2 # All rights reserved.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
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.
37 run_tests() {
38 local mock_env="${1}"
40 mkdir testsuite
41 cd testsuite
43 cat >Kyuafile <<EOF
44 syntax(2)
45 test_suite("integration")
46 atf_test_program{name="simple_all_pass"}
47 EOF
49 utils_cp_helper simple_all_pass .
50 test -d ../.kyua || mkdir ../.kyua
51 kyua=$(which 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}"
59 cd -
60 # Ensure the results of 'report' come from the database.
61 rm -rf testsuite
63 return "${action_id}"
67 utils_test_case default_behavior__ok
68 default_behavior__ok_body() {
69 utils_install_timestamp_wrapper
71 run_tests "mock1"
73 cat >expout <<EOF
74 ===> Skipped tests
75 simple_all_pass:skip -> skipped: The reason for skipping is this [S.UUUs]
76 ===> Summary
77 Action: 1
78 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
79 Total time: S.UUUs
80 EOF
81 atf_check -s exit:0 -o file:expout -e empty kyua report
83 run_tests "mock2"
85 cat >expout <<EOF
86 ===> Skipped tests
87 simple_all_pass:skip -> skipped: The reason for skipping is this [S.UUUs]
88 ===> Summary
89 Action: 2
90 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
91 Total time: S.UUUs
92 EOF
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() {
138 run_tests "mock1"
140 cat >expout <<EOF
141 ===> Execution context
142 Current directory: $(pwd)/testsuite
143 Environment variables:
145 mkdir testsuite
146 ( cd testsuite && HOME=$(pwd)/home MOCK=mock1 env ) \
147 | sort | sed -e 's,^, ,' | grep -v '^ _.*=.*' >>expout
148 rmdir testsuite
149 cat >>expout <<EOF
150 ===> Skipped tests
151 simple_all_pass:skip -> skipped: The reason for skipping is this [S.UUUs]
152 ===> Summary
153 Action: 1
154 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
155 Total time: S.UUUs
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() {
164 run_tests
166 cat >report <<EOF
167 ===> Skipped tests
168 simple_all_pass:skip -> skipped: The reason for skipping is this [S.UUUs]
169 ===> Summary
170 Action: 1
171 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
172 Total time: S.UUUs
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 \
178 --output=/dev/stderr
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 \
183 --output=my-file
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
193 run_tests "mock1"
195 cat >expout <<EOF
196 ===> Passed tests
197 simple_all_pass:pass -> passed [S.UUUs]
198 ===> Skipped tests
199 simple_all_pass:skip -> skipped: The reason for skipping is this [S.UUUs]
200 ===> Summary
201 Action: 1
202 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
203 Total time: S.UUUs
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
213 run_tests "mock1"
215 cat >expout <<EOF
216 ===> Passed tests
217 simple_all_pass:pass -> passed [S.UUUs]
218 ===> Summary
219 Action: 1
220 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
221 Total time: S.UUUs
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
232 run_tests "mock1"
234 cat >expout <<EOF
235 ===> Skipped tests
236 simple_all_pass:skip -> skipped: The reason for skipping is this [S.UUUs]
237 ===> Passed tests
238 simple_all_pass:pass -> passed [S.UUUs]
239 ===> Summary
240 Action: 1
241 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
242 Total time: S.UUUs
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
253 run_tests "mock1"
255 cat >expout <<EOF
256 ===> Skipped tests
257 simple_all_pass:skip -> skipped: The reason for skipping is this [S.UUUs]
258 ===> Summary
259 Action: 1
260 Test cases: 2 total, 1 skipped, 0 expected failures, 0 broken, 0 failed
261 Total time: S.UUUs
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