1 # Copyright 2012 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"}
47 atf_test_program{name="simple_some_fail"}
48 atf_test_program{name="metadata"}
51 utils_cp_helper simple_all_pass .
52 utils_cp_helper simple_some_fail .
53 utils_cp_helper metadata .
54 test -d ..
/.kyua || mkdir ..
/.kyua
56 atf_check
-s exit:1 -o save
:stdout
-e empty env \
57 HOME
="$(pwd)/home" MOCK
="${mock_env}" \
58 "${kyua}" test --store=..
/.kyua
/store.db
60 action_id
=$
(grep '^Committed action ' stdout | cut
-d ' ' -f 3)
61 echo "New action is ${action_id}"
64 # Ensure the results of 'report' come from the database.
71 # Ensure a file has a set of strings.
73 # \param file The name of the file to check.
74 # \param ... List of strings to check.
76 local file="${1}"; shift
78 while [ ${#} -gt 0 ]; do
79 echo "Checking for presence of '${1}' in ${file}"
80 if grep "${1}" "${file}" >/dev
/null
; then
83 atf_fail
"Test case output not found in HTML page ${file}"
90 # Ensure a file does not have a set of strings.
92 # \param file The name of the file to check.
93 # \param ... List of strings to check.
95 local file="${1}"; shift
97 while [ ${#} -gt 0 ]; do
98 echo "Checking for lack of '${1}' in ${file}"
99 if grep "${1}" "${file}" >/dev
/null
; then
100 atf_fail
"Spurious test case output found in HTML page"
107 utils_test_case default_behavior__ok
108 default_behavior__ok_body
() {
109 utils_install_timestamp_wrapper
113 atf_check
-s exit:0 -o ignore
-e empty kyua report-html
117 html
/simple_all_pass_skip.html \
118 html
/simple_some_fail_fail.html
120 test -f "${f}" || atf_fail
"Missing ${f}"
123 atf_check
-o match
:"2 TESTS FAILING" cat html
/index.html
125 check_in_file html
/simple_all_pass_skip.html \
126 "This is the stdout of skip" "This is the stderr of skip"
127 check_not_in_file html
/simple_all_pass_skip.html \
128 "This is the stdout of pass" "This is the stderr of pass" \
129 "This is the stdout of fail" "This is the stderr of fail" \
130 "Test case did not write anything to"
132 check_in_file html
/simple_some_fail_fail.html \
133 "This is the stdout of fail" "This is the stderr of fail"
134 check_not_in_file html
/simple_some_fail_fail.html \
135 "This is the stdout of pass" "This is the stderr of pass" \
136 "This is the stdout of skip" "This is the stderr of skip" \
137 "Test case did not write anything to"
139 check_in_file html
/metadata_one_property.html \
140 "description = Does nothing but has one metadata property"
141 check_not_in_file html
/metadata_one_property.html \
142 "allowed_architectures = some-architecture"
144 check_in_file html
/metadata_many_properties.html \
145 "allowed_architectures = some-architecture"
146 check_not_in_file html
/metadata_many_properties.html \
147 "description = Does nothing but has one metadata property"
151 utils_test_case default_behavior__no_actions
152 default_behavior__no_actions_body
() {
153 kyua db-exec
"SELECT * FROM actions"
155 echo 'kyua: E: No actions in the database.' >experr
156 atf_check
-s exit:2 -o empty
-e file:experr kyua report-html
160 utils_test_case default_behavior__no_store
161 default_behavior__no_store_body
() {
162 atf_check
-s exit:2 -o empty \
163 -e match
:"kyua: E: Cannot open '.*/.kyua/store.db': " kyua report-html
167 utils_test_case action__explicit
168 action__explicit_body
() {
169 run_tests
"mock1"; action1
=$?
170 run_tests
"mock2"; action2
=$?
172 atf_check
-s exit:0 -o ignore
-e empty kyua report-html \
173 --action="${action1}"
174 grep "action 1" html
/index.html || atf_fail
"Invalid action in report"
175 grep "MOCK.*mock1" html
/context.html || atf_fail
"Invalid context in report"
178 atf_check
-s exit:0 -o ignore
-e empty kyua report-html \
179 --action="${action2}"
180 grep "action 2" html
/index.html || atf_fail
"Invalid action in report"
181 grep "MOCK.*mock2" html
/context.html || atf_fail
"Invalid context in report"
185 utils_test_case action__not_found
186 action__not_found_body
() {
187 kyua db-exec
"SELECT * FROM actions"
189 echo 'kyua: E: Error loading action 514: does not exist.' >experr
190 atf_check
-s exit:2 -o empty
-e file:experr kyua report-html
--action=514
194 utils_test_case force__yes
198 atf_check
-s exit:0 -o ignore
-e empty kyua report-html
199 test -f html
/index.html || atf_fail
"Expected file not created"
201 atf_check
-s exit:0 -o ignore
-e empty kyua report-html
--force
202 test -f html
/index.html || atf_fail
"Expected file not created"
206 utils_test_case force__no
210 atf_check
-s exit:0 -o ignore
-e empty kyua report-html
211 test -f html
/index.html || atf_fail
"Expected file not created"
215 kyua: E: Output directory 'html' already exists; maybe use --force?.
217 atf_check
-s exit:2 -o empty
-e file:experr kyua report-html
218 test ! -f html
/index.html || atf_fail
"Not expected file created"
222 utils_test_case output__explicit
223 output__explicit_body
() {
227 atf_check
-s exit:0 -o ignore
-e empty kyua report-html
--output=output
/foo
228 test ! -d html || atf_fail
"Not expected directory created"
229 test -f output
/foo
/index.html || atf_fail
"Expected file not created"
233 utils_test_case results_filter__ok
234 results_filter__ok_body
() {
235 utils_install_timestamp_wrapper
239 atf_check
-s exit:0 -o ignore
-e empty kyua report-html \
240 --results-filter=passed
244 html
/simple_all_pass_pass.html \
245 html
/simple_some_fail_pass.html \
246 html
/metadata_no_properties.html \
247 html
/metadata_with_cleanup.html
249 test -f "${f}" || atf_fail
"Missing ${f}"
252 atf_check
-o match
:"2 TESTS FAILING" cat html
/index.html
254 check_in_file html
/simple_all_pass_pass.html \
255 "This is the stdout of pass" "This is the stderr of pass"
256 check_not_in_file html
/simple_all_pass_pass.html \
257 "This is the stdout of skip" "This is the stderr of skip" \
258 "This is the stdout of fail" "This is the stderr of fail" \
259 "Test case did not write anything to"
261 check_in_file html
/simple_some_fail_pass.html \
262 "Test case did not write anything to stdout" \
263 "Test case did not write anything to stderr"
264 check_not_in_file html
/simple_some_fail_pass.html \
265 "This is the stdout of pass" "This is the stderr of pass" \
266 "This is the stdout of skip" "This is the stderr of skip" \
267 "This is the stdout of fail" "This is the stderr of fail"
271 utils_test_case results_filter__invalid
272 results_filter__invalid_body
() {
273 kyua db-exec
"SELECT * FROM actions"
275 echo "kyua: E: Unknown result type 'foo-bar'." >experr
276 atf_check
-s exit:2 -o empty
-e file:experr kyua report-html \
277 --results-filter=passed
,foo-bar
281 atf_init_test_cases
() {
282 atf_add_test_case default_behavior__ok
283 atf_add_test_case default_behavior__no_actions
284 atf_add_test_case default_behavior__no_store
286 atf_add_test_case action__explicit
287 atf_add_test_case action__not_found
289 atf_add_test_case force__yes
290 atf_add_test_case force__no
292 atf_add_test_case output__explicit
294 atf_add_test_case results_filter__ok
295 atf_add_test_case results_filter__invalid