xref: /freebsd/contrib/kyua/integration/cmd_list_test.sh (revision 2dfa4b66b3d0caaaae6ce2df476b5615f8415a19)
1# Copyright 2011 The Kyua Authors.
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met:
7#
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.
16#
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.
28
29
30utils_test_case no_args
31no_args_body() {
32    cat >Kyuafile <<EOF
33syntax(2)
34test_suite("integration")
35atf_test_program{name="metadata"}
36atf_test_program{name="simple_all_pass"}
37include("subdir/Kyuafile")
38EOF
39    utils_cp_helper metadata .
40    utils_cp_helper simple_all_pass .
41
42    mkdir subdir
43    cat >subdir/Kyuafile <<EOF
44syntax(2)
45test_suite("integration2")
46atf_test_program{name="simple_some_fail"}
47EOF
48    utils_cp_helper simple_some_fail subdir
49
50    cat >expout <<EOF
51metadata:many_properties
52metadata:no_properties
53metadata:one_property
54metadata:with_cleanup
55simple_all_pass:pass
56simple_all_pass:skip
57subdir/simple_some_fail:fail
58subdir/simple_some_fail:pass
59EOF
60    atf_check -s exit:0 -o file:expout -e empty kyua list
61}
62
63
64utils_test_case one_arg__subdir
65one_arg__subdir_body() {
66    cat >Kyuafile <<EOF
67syntax(2)
68test_suite("top-level")
69include("subdir/Kyuafile")
70EOF
71
72    mkdir subdir
73    cat >subdir/Kyuafile <<EOF
74syntax(2)
75test_suite("in-subdir")
76atf_test_program{name="simple_all_pass"}
77EOF
78    utils_cp_helper simple_all_pass subdir
79
80    cat >expout <<EOF
81subdir/simple_all_pass:pass
82subdir/simple_all_pass:skip
83EOF
84    atf_check -s exit:0 -o file:expout -e empty kyua list subdir
85}
86
87
88utils_test_case one_arg__test_case
89one_arg__test_case_body() {
90    cat >Kyuafile <<EOF
91syntax(2)
92test_suite("top-level")
93atf_test_program{name="first"}
94atf_test_program{name="second"}
95EOF
96    utils_cp_helper simple_all_pass first
97    utils_cp_helper simple_all_pass second
98
99    cat >expout <<EOF
100first:skip
101EOF
102    atf_check -s exit:0 -o file:expout -e empty kyua list first:skip
103}
104
105
106utils_test_case one_arg__test_program
107one_arg__test_program_body() {
108    cat >Kyuafile <<EOF
109syntax(2)
110test_suite("top-level")
111atf_test_program{name="first"}
112atf_test_program{name="second"}
113EOF
114    utils_cp_helper simple_all_pass first
115    utils_cp_helper simple_some_fail second
116
117    cat >expout <<EOF
118second:fail
119second:pass
120EOF
121    atf_check -s exit:0 -o file:expout -e empty kyua list second
122}
123
124
125utils_test_case one_arg__invalid
126one_arg__invalid_body() {
127cat >experr <<EOF
128kyua: E: Test case component in 'foo:' is empty.
129EOF
130    atf_check -s exit:2 -o empty -e file:experr kyua list foo:
131
132cat >experr <<EOF
133kyua: E: Program name '/a/b' must be relative to the test suite, not absolute.
134EOF
135    atf_check -s exit:2 -o empty -e file:experr kyua list /a/b
136}
137
138
139utils_test_case many_args__ok
140many_args__ok_body() {
141    cat >Kyuafile <<EOF
142syntax(2)
143test_suite("top-level")
144include("subdir/Kyuafile")
145atf_test_program{name="first"}
146EOF
147    utils_cp_helper simple_all_pass first
148
149    mkdir subdir
150    cat >subdir/Kyuafile <<EOF
151syntax(2)
152test_suite("in-subdir")
153atf_test_program{name="second"}
154EOF
155    utils_cp_helper simple_some_fail subdir/second
156
157    cat >expout <<EOF
158subdir/second:fail (in-subdir)
159subdir/second:pass (in-subdir)
160first:pass (top-level)
161EOF
162    atf_check -s exit:0 -o file:expout -e empty kyua list -v subdir first:pass
163}
164
165
166utils_test_case many_args__invalid
167many_args__invalid_body() {
168cat >experr <<EOF
169kyua: E: Program name component in ':badbad' is empty.
170EOF
171    atf_check -s exit:2 -o empty -e file:experr kyua list this-is-ok :badbad
172
173cat >experr <<EOF
174kyua: E: Program name '/foo' must be relative to the test suite, not absolute.
175EOF
176    atf_check -s exit:2 -o empty -e file:experr kyua list this-is-ok /foo
177}
178
179
180utils_test_case many_args__no_match__all
181many_args__no_match__all_body() {
182    cat >Kyuafile <<EOF
183syntax(2)
184test_suite("top-level")
185atf_test_program{name="first"}
186atf_test_program{name="second"}
187EOF
188    utils_cp_helper simple_all_pass first
189    utils_cp_helper simple_all_pass second
190
191    cat >experr <<EOF
192kyua: W: No test cases matched by the filter 'first1'.
193EOF
194    atf_check -s exit:1 -o empty -e file:experr kyua list first1
195}
196
197
198utils_test_case many_args__no_match__some
199many_args__no_match__some_body() {
200    cat >Kyuafile <<EOF
201syntax(2)
202test_suite("top-level")
203atf_test_program{name="first"}
204atf_test_program{name="second"}
205atf_test_program{name="third"}
206EOF
207    utils_cp_helper simple_all_pass first
208    utils_cp_helper simple_all_pass second
209    utils_cp_helper simple_some_fail third
210
211    cat >expout <<EOF
212first:pass
213first:skip
214third:fail
215third:pass
216EOF
217
218    cat >experr <<EOF
219kyua: W: No test cases matched by the filter 'fifth'.
220kyua: W: No test cases matched by the filter 'fourth'.
221EOF
222    atf_check -s exit:1 -o file:expout -e file:experr kyua list first fourth \
223        third fifth
224}
225
226
227utils_test_case args_are_relative
228args_are_relative_body() {
229    mkdir root
230    cat >root/Kyuafile <<EOF
231syntax(2)
232test_suite("integration-1")
233atf_test_program{name="first"}
234atf_test_program{name="second"}
235include("subdir/Kyuafile")
236EOF
237    utils_cp_helper simple_all_pass root/first
238    utils_cp_helper simple_some_fail root/second
239
240    mkdir root/subdir
241    cat >root/subdir/Kyuafile <<EOF
242syntax(2)
243test_suite("integration-2")
244atf_test_program{name="third"}
245atf_test_program{name="fourth"}
246EOF
247    utils_cp_helper simple_all_pass root/subdir/third
248    utils_cp_helper simple_some_fail root/subdir/fourth
249
250    cat >expout <<EOF
251first:pass (integration-1)
252first:skip (integration-1)
253subdir/fourth:fail (integration-2)
254EOF
255    atf_check -s exit:0 -o file:expout -e empty kyua list \
256        -v -k "$(pwd)/root/Kyuafile" first subdir/fourth:fail
257}
258
259
260utils_test_case only_load_used_test_programs
261only_load_used_test_programs_body() {
262    cat >Kyuafile <<EOF
263syntax(2)
264test_suite("integration")
265atf_test_program{name="first"}
266atf_test_program{name="second"}
267EOF
268    utils_cp_helper simple_all_pass first
269    utils_cp_helper bad_test_program second
270
271    cat >expout <<EOF
272first:pass
273first:skip
274EOF
275    CREATE_COOKIE="$(pwd)/cookie"; export CREATE_COOKIE
276    atf_check -s exit:0 -o file:expout -e empty kyua list first
277    if [ -f "${CREATE_COOKIE}" ]; then
278        atf_fail "An unmatched test case has been executed, which harms" \
279            "performance"
280    fi
281}
282
283
284utils_test_case config_behavior
285config_behavior_body() {
286    cat >"my-config" <<EOF
287syntax(2)
288test_suites.suite1["the-variable"] = "value1"
289EOF
290
291    cat >Kyuafile <<EOF
292syntax(2)
293atf_test_program{name="config1", test_suite="suite1"}
294EOF
295    utils_cp_helper config config1
296
297    CONFIG_VAR_FILE="$(pwd)/cookie"; export CONFIG_VAR_FILE
298    if [ -f "${CONFIG_VAR_FILE}" ]; then
299        atf_fail "Cookie file already created; test case list may have gotten" \
300            "a bad configuration"
301    fi
302    atf_check -s exit:0 -o ignore -e empty kyua -c my-config list
303    [ -f "${CONFIG_VAR_FILE}" ] || \
304        atf_fail "Cookie file not created; test case list did not get" \
305            "configuration variables"
306    value="$(cat "${CONFIG_VAR_FILE}")"
307    [ "${value}" = "value1" ] || \
308        atf_fail "Invalid value (${value}) in cookie file; test case list did" \
309            "not get the correct configuration variables"
310}
311
312
313utils_test_case build_root_flag
314build_root_flag_body() {
315    mkdir subdir
316    mkdir build
317    mkdir build/subdir
318
319    cat >Kyuafile <<EOF
320syntax(2)
321test_suite("top-level")
322include("subdir/Kyuafile")
323atf_test_program{name="first"}
324EOF
325    echo 'invalid' >first
326    utils_cp_helper simple_all_pass build/first
327
328    cat >subdir/Kyuafile <<EOF
329syntax(2)
330test_suite("in-subdir")
331atf_test_program{name="second"}
332EOF
333    echo 'invalid' >subdir/second
334    utils_cp_helper simple_some_fail build/subdir/second
335
336    cat >expout <<EOF
337subdir/second:fail
338subdir/second:pass
339first:pass
340EOF
341    atf_check -s exit:0 -o file:expout -e empty kyua list --build-root=build \
342        subdir first:pass
343}
344
345
346utils_test_case kyuafile_flag__no_args
347kyuafile_flag__no_args_body() {
348    cat >Kyuafile <<EOF
349This file is bogus but it is not loaded.
350EOF
351
352    cat >myfile <<EOF
353syntax(2)
354test_suite("integration")
355atf_test_program{name="sometest"}
356EOF
357    utils_cp_helper simple_all_pass sometest
358
359    cat >expout <<EOF
360sometest:pass
361sometest:skip
362EOF
363    atf_check -s exit:0 -o file:expout -e empty kyua list -k myfile
364    atf_check -s exit:0 -o file:expout -e empty kyua list --kyuafile=myfile
365}
366
367
368utils_test_case kyuafile_flag__some_args
369kyuafile_flag__some_args_body() {
370    cat >Kyuafile <<EOF
371This file is bogus but it is not loaded.
372EOF
373
374    cat >myfile <<EOF
375syntax(2)
376test_suite("hello-world")
377atf_test_program{name="sometest"}
378EOF
379    utils_cp_helper simple_all_pass sometest
380
381    cat >expout <<EOF
382sometest:pass (hello-world)
383sometest:skip (hello-world)
384EOF
385    atf_check -s exit:0 -o file:expout -e empty kyua list -v -k myfile sometest
386    atf_check -s exit:0 -o file:expout -e empty kyua list -v --kyuafile=myfile \
387        sometest
388}
389
390
391utils_test_case verbose_flag
392verbose_flag_body() {
393    cat >Kyuafile <<EOF
394syntax(2)
395test_suite("integration-suite-1")
396atf_test_program{name="simple_all_pass"}
397plain_test_program{name="i_am_plain", timeout=654}
398include("subdir/Kyuafile")
399EOF
400    utils_cp_helper simple_all_pass .
401    touch i_am_plain
402
403    mkdir subdir
404    cat >subdir/Kyuafile <<EOF
405syntax(2)
406test_suite("integration-suite-2")
407atf_test_program{name="metadata"}
408EOF
409    utils_cp_helper metadata subdir
410
411    cat >expout <<EOF
412simple_all_pass:pass (integration-suite-1)
413simple_all_pass:skip (integration-suite-1)
414i_am_plain:main (integration-suite-1)
415    timeout = 654
416subdir/metadata:many_properties (integration-suite-2)
417    allowed_architectures = some-architecture
418    allowed_platforms = some-platform
419    custom.no-meaning = I am a custom variable
420    description =     A description with some padding
421    required_configs = var1 var2 var3
422    required_files = /my/file1 /some/other/file
423    required_programs = /nonexistent/bin3 bin1 bin2
424    required_user = root
425subdir/metadata:no_properties (integration-suite-2)
426subdir/metadata:one_property (integration-suite-2)
427    description = Does nothing but has one metadata property
428subdir/metadata:with_cleanup (integration-suite-2)
429    has_cleanup = true
430    timeout = 250
431EOF
432    atf_check -s exit:0 -o file:expout -e empty kyua list -v
433    atf_check -s exit:0 -o file:expout -e empty kyua list --verbose
434}
435
436
437utils_test_case no_test_program_match
438no_test_program_match_body() {
439    cat >Kyuafile <<EOF
440syntax(2)
441test_suite("integration")
442atf_test_program{name="first"}
443EOF
444    utils_cp_helper simple_all_pass first
445    utils_cp_helper simple_all_pass second
446
447    cat >experr <<EOF
448kyua: W: No test cases matched by the filter 'second'.
449EOF
450    atf_check -s exit:1 -o empty -e file:experr kyua list second
451}
452
453
454utils_test_case no_test_case_match
455no_test_case_match_body() {
456    cat >Kyuafile <<EOF
457syntax(2)
458test_suite("integration")
459atf_test_program{name="first"}
460EOF
461    utils_cp_helper simple_all_pass first
462
463    cat >experr <<EOF
464kyua: W: No test cases matched by the filter 'first:foobar'.
465EOF
466    atf_check -s exit:1 -o empty -e file:experr kyua list first:foobar
467}
468
469
470utils_test_case missing_kyuafile__no_args
471missing_kyuafile__no_args_body() {
472    cat >experr <<EOF
473kyua: E: Load of 'Kyuafile' failed: File 'Kyuafile' not found.
474EOF
475    atf_check -s exit:2 -o empty -e file:experr kyua list
476}
477
478
479utils_test_case missing_kyuafile__test_program
480missing_kyuafile__test_program_body() {
481    mkdir subdir
482    cat >subdir/Kyuafile <<EOF
483syntax(2)
484test_suite("integration")
485atf_test_program{name="unused"}
486EOF
487    utils_cp_helper simple_all_pass subdir/unused
488
489    cat >experr <<EOF
490kyua: E: Load of 'Kyuafile' failed: File 'Kyuafile' not found.
491EOF
492    atf_check -s exit:2 -o empty -e file:experr kyua list subdir/unused
493}
494
495
496utils_test_case missing_kyuafile__subdir
497missing_kyuafile__subdir_body() {
498    mkdir subdir
499    cat >subdir/Kyuafile <<EOF
500syntax(2)
501test_suite("integration")
502atf_test_program{name="unused"}
503EOF
504    utils_cp_helper simple_all_pass subdir/unused
505
506    cat >experr <<EOF
507kyua: E: Load of 'Kyuafile' failed: File 'Kyuafile' not found.
508EOF
509    atf_check -s exit:2 -o empty -e file:experr kyua list subdir
510}
511
512
513utils_test_case bogus_kyuafile
514bogus_kyuafile_body() {
515    cat >Kyuafile <<EOF
516Hello, world.
517EOF
518    atf_check -s exit:2 -o empty \
519        -e match:"Load of 'Kyuafile' failed: .* Kyuafile:2:" kyua list
520}
521
522
523utils_test_case bogus_test_program
524bogus_test_program_body() {
525    cat >Kyuafile <<EOF
526syntax(2)
527test_suite("integration")
528atf_test_program{name="crash_on_list"}
529atf_test_program{name="non_executable"}
530EOF
531    utils_cp_helper bad_test_program crash_on_list
532    echo 'I am not executable' >non_executable
533
534    cat >expout <<EOF
535crash_on_list:__test_cases_list__
536non_executable:__test_cases_list__
537EOF
538    atf_check -s exit:0 -o file:expout -e empty kyua list
539}
540
541
542utils_test_case missing_test_program
543missing_test_program_body() {
544    cat >Kyuafile <<EOF
545syntax(2)
546include("subdir/Kyuafile")
547EOF
548    mkdir subdir
549    cat >subdir/Kyuafile <<EOF
550syntax(2)
551test_suite("integration")
552atf_test_program{name="ok"}
553atf_test_program{name="i-am-missing"}
554EOF
555    echo 'I should not be touched because the Kyuafile is bogus' >subdir/ok
556
557# CHECK_STYLE_DISABLE
558    cat >experr <<EOF
559kyua: E: Load of 'Kyuafile' failed: .*Non-existent test program 'subdir/i-am-missing'.
560EOF
561# CHECK_STYLE_ENABLE
562    atf_check -s exit:2 -o empty -e "match:$(cat experr)" kyua list
563}
564
565
566atf_init_test_cases() {
567    atf_add_test_case no_args
568    atf_add_test_case one_arg__subdir
569    atf_add_test_case one_arg__test_case
570    atf_add_test_case one_arg__test_program
571    atf_add_test_case one_arg__invalid
572    atf_add_test_case many_args__ok
573    atf_add_test_case many_args__invalid
574    atf_add_test_case many_args__no_match__all
575    atf_add_test_case many_args__no_match__some
576
577    atf_add_test_case args_are_relative
578
579    atf_add_test_case only_load_used_test_programs
580
581    atf_add_test_case config_behavior
582
583    atf_add_test_case build_root_flag
584
585    atf_add_test_case kyuafile_flag__no_args
586    atf_add_test_case kyuafile_flag__some_args
587
588    atf_add_test_case verbose_flag
589
590    atf_add_test_case no_test_program_match
591    atf_add_test_case no_test_case_match
592
593    atf_add_test_case missing_kyuafile__no_args
594    atf_add_test_case missing_kyuafile__test_program
595    atf_add_test_case missing_kyuafile__subdir
596
597    atf_add_test_case bogus_kyuafile
598    atf_add_test_case bogus_test_program
599    atf_add_test_case missing_test_program
600}
601