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 utils_test_case no_args
34 test_suite("integration")
35 atf_test_program{name="simple_all_pass"}
37 utils_cp_helper simple_all_pass .
40 Usage error for command debug: Not enough arguments.
41 Type 'kyua help debug' for usage information.
43 atf_check -s exit:3 -o empty -e file:experr kyua debug
47 utils_test_case many_args
51 test_suite("integration")
52 atf_test_program{name="first"}
53 atf_test_program{name="second"}
55 utils_cp_helper simple_all_pass first
56 utils_cp_helper simple_all_pass second
59 Usage error for command debug: Too many arguments.
60 Type 'kyua help debug' for usage information.
62 atf_check -s exit:3 -o empty -e file:experr kyua debug first:pass \
67 utils_test_case one_arg__ok_pass
68 one_arg__ok_pass_body() {
71 test_suite("integration")
72 atf_test_program{name="first"}
73 atf_test_program{name="second"}
75 utils_cp_helper expect_all_pass first
76 utils_cp_helper simple_all_pass second
79 This is the stdout of pass
83 This is the stderr of pass
85 atf_check -s exit:0 -o file:expout -e file:experr kyua debug second:pass
89 utils_test_case one_arg__ok_fail
90 one_arg__ok_fail_body() {
93 test_suite("integration")
94 atf_test_program{name="first"}
96 utils_cp_helper simple_some_fail first
99 This is the stdout of fail
100 first:fail -> failed: This fails on purpose
103 This is the stderr of fail
105 atf_check -s exit:1 -o file:expout -e file:experr kyua debug first:fail
109 utils_test_case one_arg__no_match
110 one_arg__no_match_body() {
113 test_suite("integration")
114 atf_test_program{name="first"}
115 atf_test_program{name="second"}
117 utils_cp_helper expect_all_pass first
118 utils_cp_helper simple_all_pass second
121 kyua: E: Unknown test case 'second:die'.
123 atf_check -s exit:2 -o empty -e file:experr kyua debug second:die
127 utils_test_case one_arg__no_test_case
128 one_arg__no_test_case_body() {
129 # CHECK_STYLE_DISABLE
131 Usage error for command debug: 'foo' is not a test case identifier (missing ':'?).
132 Type 'kyua help debug' for usage information.
135 atf_check -s exit:3 -o empty -e file:experr kyua debug foo
139 utils_test_case one_arg__bad_filter
140 one_arg__bad_filter_body() {
142 kyua: E: Test case component in 'foo:' is empty.
144 atf_check -s exit:2 -o empty -e file:experr kyua debug foo:
148 utils_test_case body_and_cleanup
149 body_and_cleanup_body() {
152 test_suite("integration")
153 atf_test_program{name="single"}
155 utils_cp_helper metadata single
158 single:with_cleanup -> passed
160 atf_check -s exit:0 -o file:expout -e empty kyua debug \
161 --stdout=saved.out --stderr=saved.err single:with_cleanup
164 Body message to stdout
165 Cleanup message to stdout
167 atf_check -s exit:0 -o file:expout -e empty cat saved.out
170 Body message to stderr
171 Cleanup message to stderr
173 atf_check -s exit:0 -o file:experr -e empty cat saved.err
177 utils_test_case stdout_stderr_flags
178 stdout_stderr_flags_body() {
181 test_suite("integration")
182 atf_test_program{name="first"}
183 atf_test_program{name="second"}
185 utils_cp_helper expect_all_pass first
186 utils_cp_helper simple_all_pass second
189 second:pass -> passed
191 atf_check -s exit:0 -o file:expout -e empty kyua debug \
192 --stdout=saved.out --stderr=saved.err second:pass
195 This is the stdout of pass
197 cmp -s saved.out expout || atf_fail "--stdout did not redirect the" \
198 "standard output to the desired file"
201 This is the stderr of pass
203 cmp -s saved.err experr || atf_fail "--stderr did not redirect the" \
204 "standard error to the desired file"
208 utils_test_case args_are_relative
209 args_are_relative_body() {
211 cat >root/Kyuafile <<EOF
213 test_suite("integration")
214 include("subdir/Kyuafile")
215 atf_test_program{name="prog"}
217 utils_cp_helper simple_all_pass root/prog
220 cat >root/subdir/Kyuafile <<EOF
222 test_suite("integration")
223 atf_test_program{name="prog"}
225 utils_cp_helper simple_some_fail root/subdir/prog
228 This is the stdout of fail
229 subdir/prog:fail -> failed: This fails on purpose
232 This is the stderr of fail
234 atf_check -s exit:1 -o file:expout -e file:experr kyua debug \
235 -k "$(pwd)/root/Kyuafile" subdir/prog:fail
239 utils_test_case only_load_used_test_programs
240 only_load_used_test_programs_body() {
243 test_suite("integration")
244 atf_test_program{name="first"}
245 atf_test_program{name="second"}
247 utils_cp_helper simple_all_pass first
248 utils_cp_helper bad_test_program second
251 This is the stdout of pass
255 This is the stderr of pass
257 CREATE_COOKIE="$(pwd)/cookie"; export CREATE_COOKIE
258 atf_check -s exit:0 -o file:expout -e file:experr kyua debug first:pass
259 if [ -f "${CREATE_COOKIE}" ]; then
260 atf_fail "An unmatched test case has been executed, which harms" \
266 utils_test_case config_behavior
267 config_behavior_body() {
268 cat >"my-config" <<EOF
270 test_suites.suite1["the-variable"] = "value1"
271 test_suites.suite2["the-variable"] = "override me"
276 atf_test_program{name="config1", test_suite="suite1"}
277 atf_test_program{name="config2", test_suite="suite2"}
278 atf_test_program{name="config3", test_suite="suite3"}
280 utils_cp_helper config config1
281 utils_cp_helper config config2
282 utils_cp_helper config config3
284 atf_check -s exit:1 -o match:'failed' -e empty \
285 kyua -c my-config -v test_suites.suite2.the-variable=value2 \
286 debug config1:get_variable
287 atf_check -s exit:0 -o match:'passed' -e empty \
288 kyua -c my-config -v test_suites.suite2.the-variable=value2 \
289 debug config2:get_variable
290 atf_check -s exit:0 -o match:'skipped' -e empty \
291 kyua -c my-config -v test_suites.suite2.the-variable=value2 \
292 debug config3:get_variable
296 utils_test_case build_root_flag
297 build_root_flag_body() {
300 test_suite("integration")
301 atf_test_program{name="first"}
302 atf_test_program{name="second"}
305 utils_cp_helper expect_all_pass build/first
306 utils_cp_helper simple_all_pass build/second
309 This is the stdout of pass
310 second:pass -> passed
313 This is the stderr of pass
315 atf_check -s exit:0 -o file:expout -e file:experr \
316 kyua debug --build-root=build second:pass
320 utils_test_case kyuafile_flag__ok
321 kyuafile_flag__ok_body() {
323 This file is bogus but it is not loaded.
328 test_suite("hello-world")
329 atf_test_program{name="sometest"}
331 utils_cp_helper simple_all_pass sometest
333 atf_check -s exit:0 -o match:passed -e empty kyua test -k myfile sometest
334 atf_check -s exit:0 -o match:passed -e empty kyua test --kyuafile=myfile \
339 utils_test_case missing_kyuafile
340 missing_kyuafile_body() {
342 kyua: E: Load of 'Kyuafile' failed: File 'Kyuafile' not found.
344 atf_check -s exit:2 -o empty -e file:experr kyua debug foo:bar
348 utils_test_case bogus_kyuafile
349 bogus_kyuafile_body() {
353 atf_check -s exit:2 -o empty \
354 -e match:"Load of 'Kyuafile' failed: .* Kyuafile:2:" kyua list
358 utils_test_case bogus_test_program
359 bogus_test_program_body() {
362 test_suite("integration")
363 atf_test_program{name="crash_on_list"}
364 atf_test_program{name="non_executable"}
366 utils_cp_helper bad_test_program crash_on_list
367 echo 'I am not executable' >non_executable
370 kyua: E: Unknown test case 'crash_on_list:a'.
372 atf_check -s exit:2 -o empty -e file:experr kyua debug crash_on_list:a
375 kyua: E: Unknown test case 'non_executable:a'.
377 atf_check -s exit:2 -o empty -e file:experr kyua debug non_executable:a
379 # CHECK_STYLE_DISABLE
381 crash_on_list:__test_cases_list__ -> broken: Invalid header for test case list; expecting Content-Type for application/X-atf-tp version 1, got ''
384 atf_check -s exit:1 -o file:expout -e empty kyua debug \
385 crash_on_list:__test_cases_list__
387 # CHECK_STYLE_DISABLE
389 non_executable:__test_cases_list__ -> broken: Permission denied to run test program
392 atf_check -s exit:1 -o file:expout -e empty kyua debug \
393 non_executable:__test_cases_list__
397 atf_init_test_cases() {
398 atf_add_test_case no_args
399 atf_add_test_case many_args
400 atf_add_test_case one_arg__ok_pass
401 atf_add_test_case one_arg__ok_fail
402 atf_add_test_case one_arg__no_match
403 atf_add_test_case one_arg__no_test_case
404 atf_add_test_case one_arg__bad_filter
406 atf_add_test_case body_and_cleanup
408 atf_add_test_case stdout_stderr_flags
410 atf_add_test_case args_are_relative
412 atf_add_test_case only_load_used_test_programs
414 atf_add_test_case config_behavior
416 atf_add_test_case build_root_flag
417 atf_add_test_case kyuafile_flag__ok
418 atf_add_test_case missing_kyuafile
419 atf_add_test_case bogus_kyuafile
420 atf_add_test_case bogus_test_program