xref: /freebsd/contrib/kyua/integration/cmd_test_test.sh (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
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 one_test_program__all_pass
31one_test_program__all_pass_body() {
32    utils_install_stable_test_wrapper
33
34    cat >Kyuafile <<EOF
35syntax(2)
36test_suite("integration")
37atf_test_program{name="simple_all_pass"}
38EOF
39
40    cat >expout <<EOF
41simple_all_pass:pass  ->  passed  [S.UUUs]
42simple_all_pass:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
43
44Results file id is $(utils_results_id)
45Results saved to $(utils_results_file)
46
472/2 passed (0 failed)
48EOF
49
50    utils_cp_helper simple_all_pass .
51    atf_check -s exit:0 -o file:expout -e empty kyua test
52}
53
54
55utils_test_case one_test_program__some_fail
56one_test_program__some_fail_body() {
57    utils_install_stable_test_wrapper
58
59    cat >Kyuafile <<EOF
60syntax(2)
61test_suite("integration")
62atf_test_program{name="simple_some_fail"}
63EOF
64
65    cat >expout <<EOF
66simple_some_fail:fail  ->  failed: This fails on purpose  [S.UUUs]
67simple_some_fail:pass  ->  passed  [S.UUUs]
68
69Results file id is $(utils_results_id)
70Results saved to $(utils_results_file)
71
721/2 passed (1 failed)
73EOF
74
75    utils_cp_helper simple_some_fail .
76    atf_check -s exit:1 -o file:expout -e empty kyua test
77}
78
79
80utils_test_case many_test_programs__all_pass
81many_test_programs__all_pass_body() {
82    utils_install_stable_test_wrapper
83
84    cat >Kyuafile <<EOF
85syntax(2)
86test_suite("integration")
87atf_test_program{name="first"}
88atf_test_program{name="second"}
89atf_test_program{name="third"}
90plain_test_program{name="fourth", required_files="/non-existent/foo"}
91EOF
92
93    cat >expout <<EOF
94first:pass  ->  passed  [S.UUUs]
95first:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
96fourth:main  ->  skipped: Required file '/non-existent/foo' not found  [S.UUUs]
97second:pass  ->  passed  [S.UUUs]
98second:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
99third:pass  ->  passed  [S.UUUs]
100third:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
101
102Results file id is $(utils_results_id)
103Results saved to $(utils_results_file)
104
1057/7 passed (0 failed)
106EOF
107
108    utils_cp_helper simple_all_pass first
109    utils_cp_helper simple_all_pass second
110    utils_cp_helper simple_all_pass third
111    echo "not executed" >fourth; chmod +x fourth
112    atf_check -s exit:0 -o file:expout -e empty kyua test
113}
114
115
116utils_test_case many_test_programs__some_fail
117many_test_programs__some_fail_body() {
118    utils_install_stable_test_wrapper
119
120    cat >Kyuafile <<EOF
121syntax(2)
122test_suite("integration")
123atf_test_program{name="first"}
124atf_test_program{name="second"}
125atf_test_program{name="third"}
126plain_test_program{name="fourth"}
127EOF
128
129    cat >expout <<EOF
130first:fail  ->  failed: This fails on purpose  [S.UUUs]
131first:pass  ->  passed  [S.UUUs]
132fourth:main  ->  failed: Returned non-success exit status 76  [S.UUUs]
133second:fail  ->  failed: This fails on purpose  [S.UUUs]
134second:pass  ->  passed  [S.UUUs]
135third:pass  ->  passed  [S.UUUs]
136third:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
137
138Results file id is $(utils_results_id)
139Results saved to $(utils_results_file)
140
1414/7 passed (3 failed)
142EOF
143
144    utils_cp_helper simple_some_fail first
145    utils_cp_helper simple_some_fail second
146    utils_cp_helper simple_all_pass third
147    echo '#! /bin/sh' >fourth
148    echo 'exit 76' >>fourth
149    chmod +x fourth
150    atf_check -s exit:1 -o file:expout -e empty kyua test
151}
152
153
154utils_test_case expect__all_pass
155expect__all_pass_body() {
156    utils_install_stable_test_wrapper
157
158    cat >Kyuafile <<EOF
159syntax(2)
160test_suite("integration")
161atf_test_program{name="expect_all_pass"}
162EOF
163
164# CHECK_STYLE_DISABLE
165    cat >expout <<EOF
166expect_all_pass:die  ->  expected_failure: This is the reason for death  [S.UUUs]
167expect_all_pass:exit  ->  expected_failure: Exiting with correct code  [S.UUUs]
168expect_all_pass:failure  ->  expected_failure: Oh no: Forced failure  [S.UUUs]
169expect_all_pass:signal  ->  expected_failure: Exiting with correct signal  [S.UUUs]
170expect_all_pass:timeout  ->  expected_failure: This times out  [S.UUUs]
171
172Results file id is $(utils_results_id)
173Results saved to $(utils_results_file)
174
1755/5 passed (0 failed)
176EOF
177# CHECK_STYLE_ENABLE
178
179    utils_cp_helper expect_all_pass .
180    atf_check -s exit:0 -o file:expout -e empty kyua test
181}
182
183
184utils_test_case expect__some_fail
185expect__some_fail_body() {
186    utils_install_stable_test_wrapper
187
188    cat >Kyuafile <<EOF
189syntax(2)
190test_suite("integration")
191atf_test_program{name="expect_some_fail"}
192EOF
193
194# CHECK_STYLE_DISABLE
195    cat >expout <<EOF
196expect_some_fail:die  ->  failed: Test case was expected to terminate abruptly but it continued execution  [S.UUUs]
197expect_some_fail:exit  ->  failed: Test case expected to exit with code 12 but got code 34  [S.UUUs]
198expect_some_fail:failure  ->  failed: Test case was expecting a failure but none were raised  [S.UUUs]
199expect_some_fail:pass  ->  passed  [S.UUUs]
200expect_some_fail:signal  ->  failed: Test case expected to receive signal 15 but got 9  [S.UUUs]
201expect_some_fail:timeout  ->  failed: Test case was expected to hang but it continued execution  [S.UUUs]
202
203Results file id is $(utils_results_id)
204Results saved to $(utils_results_file)
205
2061/6 passed (5 failed)
207EOF
208# CHECK_STYLE_ENABLE
209
210    utils_cp_helper expect_some_fail .
211    atf_check -s exit:1 -o file:expout -e empty kyua test
212}
213
214
215utils_test_case premature_exit
216premature_exit_body() {
217    utils_install_stable_test_wrapper
218
219    cat >Kyuafile <<EOF
220syntax(2)
221test_suite("integration")
222atf_test_program{name="bogus_test_cases"}
223EOF
224
225# CHECK_STYLE_DISABLE
226    cat >expout <<EOF
227bogus_test_cases:die  ->  broken: Premature exit; test case received signal 9  [S.UUUs]
228bogus_test_cases:exit  ->  broken: Premature exit; test case exited with code 0  [S.UUUs]
229bogus_test_cases:pass  ->  passed  [S.UUUs]
230
231Results file id is $(utils_results_id)
232Results saved to $(utils_results_file)
233
2341/3 passed (2 failed)
235EOF
236# CHECK_STYLE_ENABLE
237
238    utils_cp_helper bogus_test_cases .
239    atf_check -s exit:1 -o file:expout -e empty kyua test
240}
241
242
243utils_test_case no_args
244no_args_body() {
245    utils_install_stable_test_wrapper
246
247    cat >Kyuafile <<EOF
248syntax(2)
249test_suite("integration")
250atf_test_program{name="simple_all_pass"}
251include("subdir/Kyuafile")
252EOF
253    utils_cp_helper metadata .
254    utils_cp_helper simple_all_pass .
255
256    mkdir subdir
257    cat >subdir/Kyuafile <<EOF
258syntax(2)
259test_suite("integration2")
260atf_test_program{name="simple_some_fail"}
261EOF
262    utils_cp_helper simple_some_fail subdir
263
264    cat >expout <<EOF
265simple_all_pass:pass  ->  passed  [S.UUUs]
266simple_all_pass:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
267subdir/simple_some_fail:fail  ->  failed: This fails on purpose  [S.UUUs]
268subdir/simple_some_fail:pass  ->  passed  [S.UUUs]
269
270Results file id is $(utils_results_id)
271Results saved to $(utils_results_file)
272
2733/4 passed (1 failed)
274EOF
275    atf_check -s exit:1 -o file:expout -e empty kyua test
276}
277
278
279utils_test_case one_arg__subdir
280one_arg__subdir_body() {
281    utils_install_stable_test_wrapper
282
283    cat >Kyuafile <<EOF
284syntax(2)
285test_suite("top-level")
286include("subdir/Kyuafile")
287EOF
288
289    mkdir subdir
290    cat >subdir/Kyuafile <<EOF
291syntax(2)
292test_suite("in-subdir")
293atf_test_program{name="simple_all_pass"}
294EOF
295    utils_cp_helper simple_all_pass subdir
296
297# CHECK_STYLE_DISABLE
298    cat >expout <<EOF
299subdir/simple_all_pass:pass  ->  passed  [S.UUUs]
300subdir/simple_all_pass:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
301
302Results file id is $(utils_results_id)
303Results saved to $(utils_results_file)
304
3052/2 passed (0 failed)
306EOF
307# CHECK_STYLE_ENABLE
308    atf_check -s exit:0 -o file:expout -e empty kyua test subdir
309}
310
311
312utils_test_case one_arg__test_case
313one_arg__test_case_body() {
314    utils_install_stable_test_wrapper
315
316    cat >Kyuafile <<EOF
317syntax(2)
318test_suite("top-level")
319atf_test_program{name="first"}
320atf_test_program{name="second"}
321EOF
322    utils_cp_helper simple_all_pass first
323    utils_cp_helper simple_all_pass second
324
325    cat >expout <<EOF
326first:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
327
328Results file id is $(utils_results_id)
329Results saved to $(utils_results_file)
330
3311/1 passed (0 failed)
332EOF
333    atf_check -s exit:0 -o file:expout -e empty kyua test first:skip
334}
335
336
337utils_test_case one_arg__test_program
338one_arg__test_program_body() {
339    utils_install_stable_test_wrapper
340
341    cat >Kyuafile <<EOF
342syntax(2)
343test_suite("top-level")
344atf_test_program{name="first"}
345atf_test_program{name="second"}
346EOF
347    utils_cp_helper simple_all_pass first
348    utils_cp_helper simple_some_fail second
349
350    cat >expout <<EOF
351second:fail  ->  failed: This fails on purpose  [S.UUUs]
352second:pass  ->  passed  [S.UUUs]
353
354Results file id is $(utils_results_id)
355Results saved to $(utils_results_file)
356
3571/2 passed (1 failed)
358EOF
359    atf_check -s exit:1 -o file:expout -e empty kyua test second
360}
361
362
363utils_test_case one_arg__invalid
364one_arg__invalid_body() {
365cat >experr <<EOF
366kyua: E: Test case component in 'foo:' is empty.
367EOF
368    atf_check -s exit:2 -o empty -e file:experr kyua test foo:
369
370cat >experr <<EOF
371kyua: E: Program name '/a/b' must be relative to the test suite, not absolute.
372EOF
373    atf_check -s exit:2 -o empty -e file:experr kyua test /a/b
374}
375
376
377utils_test_case many_args__ok
378many_args__ok_body() {
379    utils_install_stable_test_wrapper
380
381    cat >Kyuafile <<EOF
382syntax(2)
383test_suite("top-level")
384include("subdir/Kyuafile")
385atf_test_program{name="first"}
386EOF
387    utils_cp_helper simple_all_pass first
388
389    mkdir subdir
390    cat >subdir/Kyuafile <<EOF
391syntax(2)
392test_suite("in-subdir")
393atf_test_program{name="second"}
394EOF
395    utils_cp_helper simple_some_fail subdir/second
396
397    cat >expout <<EOF
398first:pass  ->  passed  [S.UUUs]
399subdir/second:fail  ->  failed: This fails on purpose  [S.UUUs]
400subdir/second:pass  ->  passed  [S.UUUs]
401
402Results file id is $(utils_results_id)
403Results saved to $(utils_results_file)
404
4052/3 passed (1 failed)
406EOF
407    atf_check -s exit:1 -o file:expout -e empty kyua test subdir first:pass
408}
409
410
411utils_test_case many_args__invalid
412many_args__invalid_body() {
413cat >experr <<EOF
414kyua: E: Program name component in ':badbad' is empty.
415EOF
416    atf_check -s exit:2 -o empty -e file:experr kyua test this-is-ok :badbad
417
418cat >experr <<EOF
419kyua: E: Program name '/foo' must be relative to the test suite, not absolute.
420EOF
421    atf_check -s exit:2 -o empty -e file:experr kyua test this-is-ok /foo
422}
423
424
425utils_test_case many_args__no_match__all
426many_args__no_match__all_body() {
427    utils_install_stable_test_wrapper
428
429    cat >Kyuafile <<EOF
430syntax(2)
431test_suite("top-level")
432atf_test_program{name="first"}
433atf_test_program{name="second"}
434EOF
435    utils_cp_helper simple_all_pass first
436    utils_cp_helper simple_all_pass second
437
438    cat >expout <<EOF
439Results file id is $(utils_results_id)
440Results saved to $(utils_results_file)
441EOF
442    cat >experr <<EOF
443kyua: W: No test cases matched by the filter 'first1'.
444EOF
445    atf_check -s exit:1 -o file:expout -e file:experr kyua test first1
446}
447
448
449utils_test_case many_args__no_match__some
450many_args__no_match__some_body() {
451    utils_install_stable_test_wrapper
452
453    cat >Kyuafile <<EOF
454syntax(2)
455test_suite("top-level")
456atf_test_program{name="first"}
457atf_test_program{name="second"}
458atf_test_program{name="third"}
459EOF
460    utils_cp_helper simple_all_pass first
461    utils_cp_helper simple_all_pass second
462    utils_cp_helper simple_some_fail third
463
464    cat >expout <<EOF
465first:pass  ->  passed  [S.UUUs]
466first:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
467third:fail  ->  failed: This fails on purpose  [S.UUUs]
468third:pass  ->  passed  [S.UUUs]
469
470Results file id is $(utils_results_id)
471Results saved to $(utils_results_file)
472
4733/4 passed (1 failed)
474EOF
475
476    cat >experr <<EOF
477kyua: W: No test cases matched by the filter 'fifth'.
478kyua: W: No test cases matched by the filter 'fourth'.
479EOF
480    atf_check -s exit:1 -o file:expout -e file:experr kyua test first fourth \
481        third fifth
482}
483
484
485utils_test_case args_are_relative
486args_are_relative_body() {
487    utils_install_stable_test_wrapper
488
489    mkdir root
490    cat >root/Kyuafile <<EOF
491syntax(2)
492test_suite("integration-1")
493atf_test_program{name="first"}
494atf_test_program{name="second"}
495include("subdir/Kyuafile")
496EOF
497    utils_cp_helper simple_all_pass root/first
498    utils_cp_helper simple_some_fail root/second
499
500    mkdir root/subdir
501    cat >root/subdir/Kyuafile <<EOF
502syntax(2)
503test_suite("integration-2")
504atf_test_program{name="third"}
505atf_test_program{name="fourth"}
506EOF
507    utils_cp_helper simple_all_pass root/subdir/third
508    utils_cp_helper simple_some_fail root/subdir/fourth
509
510    cat >expout <<EOF
511first:pass  ->  passed  [S.UUUs]
512first:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
513subdir/fourth:fail  ->  failed: This fails on purpose  [S.UUUs]
514
515Results file id is $(utils_results_id root)
516Results saved to $(utils_results_file root)
517
5182/3 passed (1 failed)
519EOF
520    atf_check -s exit:1 -o file:expout -e empty kyua test \
521        -k "$(pwd)/root/Kyuafile" first subdir/fourth:fail
522}
523
524
525utils_test_case only_load_used_test_programs
526only_load_used_test_programs_body() {
527    utils_install_stable_test_wrapper
528
529    cat >Kyuafile <<EOF
530syntax(2)
531test_suite("integration")
532atf_test_program{name="first"}
533atf_test_program{name="second"}
534EOF
535    utils_cp_helper simple_all_pass first
536    utils_cp_helper bad_test_program second
537
538    cat >expout <<EOF
539first:pass  ->  passed  [S.UUUs]
540first:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
541
542Results file id is $(utils_results_id)
543Results saved to $(utils_results_file)
544
5452/2 passed (0 failed)
546EOF
547    CREATE_COOKIE="$(pwd)/cookie"; export CREATE_COOKIE
548    atf_check -s exit:0 -o file:expout -e empty kyua test first
549    if [ -f "${CREATE_COOKIE}" ]; then
550        atf_fail "An unmatched test case has been executed, which harms" \
551            "performance"
552    fi
553}
554
555
556utils_test_case config_behavior
557config_behavior_body() {
558    cat >"my-config" <<EOF
559syntax(2)
560test_suites.suite1["the-variable"] = "value1"
561test_suites.suite2["the-variable"] = "override me"
562EOF
563
564    cat >Kyuafile <<EOF
565syntax(2)
566atf_test_program{name="config1", test_suite="suite1"}
567atf_test_program{name="config2", test_suite="suite2"}
568atf_test_program{name="config3", test_suite="suite3"}
569EOF
570    utils_cp_helper config config1
571    utils_cp_helper config config2
572    utils_cp_helper config config3
573
574    atf_check -s exit:1 -o save:stdout -e empty \
575        kyua -c my-config -v test_suites.suite2.the-variable=value2 test
576    atf_check -s exit:0 -o ignore -e empty \
577        grep 'config1:get_variable.*failed' stdout
578    atf_check -s exit:0 -o ignore -e empty \
579        grep 'config2:get_variable.*passed' stdout
580    atf_check -s exit:0 -o ignore -e empty \
581        grep 'config3:get_variable.*skipped' stdout
582
583    CONFIG_VAR_FILE="$(pwd)/cookie"; export CONFIG_VAR_FILE
584    if [ -f "${CONFIG_VAR_FILE}" ]; then
585        atf_fail "Cookie file already created; test case list may have gotten" \
586            "a bad configuration"
587    fi
588    atf_check -s exit:1 -o ignore -e empty kyua -c my-config test config1
589    [ -f "${CONFIG_VAR_FILE}" ] || \
590        atf_fail "Cookie file not created; test case list did not get" \
591            "configuration variables"
592    value="$(cat "${CONFIG_VAR_FILE}")"
593    [ "${value}" = "value1" ] || \
594        atf_fail "Invalid value (${value}) in cookie file; test case list did" \
595            "not get the correct configuration variables"
596}
597
598
599utils_test_case store_contents
600store_contents_body() {
601    utils_install_stable_test_wrapper
602
603    cat >Kyuafile <<EOF
604syntax(2)
605atf_test_program{name="some-program", test_suite="suite1"}
606EOF
607    utils_cp_helper simple_some_fail some-program
608    cat >expout <<EOF
609some-program:fail  ->  failed: This fails on purpose  [S.UUUs]
610some-program:pass  ->  passed  [S.UUUs]
611
612Results file id is $(utils_results_id)
613Results saved to $(utils_results_file)
614
6151/2 passed (1 failed)
616EOF
617
618    atf_check -s exit:1 -o file:expout -e empty kyua test
619
620cat >expout <<EOF
621some-program,fail,failed,This fails on purpose
622some-program,pass,passed,NULL
623EOF
624    atf_check -s exit:0 -o file:expout -e empty \
625        kyua db-exec --no-headers \
626        "SELECT " \
627        "       test_programs.relative_path, test_cases.name, " \
628        "       test_results.result_type, test_results.result_reason " \
629        "FROM test_programs " \
630        "     JOIN test_cases " \
631        "     ON test_programs.test_program_id = test_cases.test_program_id " \
632        "     JOIN test_results " \
633        "     ON test_cases.test_case_id = test_results.test_case_id " \
634        "ORDER BY test_programs.relative_path, test_cases.name"
635}
636
637
638utils_test_case results_file__ok
639results_file__ok_body() {
640    cat >Kyuafile <<EOF
641syntax(2)
642atf_test_program{name="config1", test_suite="suite1"}
643EOF
644    utils_cp_helper config config1
645
646    atf_check -s exit:0 -o ignore -e empty kyua test -r foo1.db
647   test -f foo1.db || atf_fail "-s did not work"
648    atf_check -s exit:0 -o ignore -e empty kyua test --results-file=foo2.db
649    test -f foo2.db || atf_fail "--results-file did not work"
650    test ! -f .kyua/store.db || atf_fail "Default database created"
651}
652
653
654utils_test_case results_file__fail
655results_file__fail_body() {
656    cat >Kyuafile <<EOF
657syntax(2)
658atf_test_program{name="config1", test_suite="suite1"}
659EOF
660    utils_cp_helper config config1
661
662    atf_check -s exit:3 -o empty -e match:"Invalid.*--results-file" \
663        kyua test --results-file=
664}
665
666
667utils_test_case results_file__reuse
668results_file__reuse_body() {
669    utils_install_stable_test_wrapper
670
671    cat >Kyuafile <<EOF
672syntax(2)
673atf_test_program{name="simple_all_pass", test_suite="integration"}
674EOF
675    utils_cp_helper simple_all_pass .
676    atf_check -s exit:0 -o ignore -e empty kyua test -r results.db
677
678    atf_check -s exit:2 -o empty -e match:"results.db already exists" \
679        kyua test --results-file="results.db"
680}
681
682
683utils_test_case build_root_flag
684build_root_flag_body() {
685    utils_install_stable_test_wrapper
686
687    cat >Kyuafile <<EOF
688syntax(2)
689test_suite("integration")
690atf_test_program{name="first"}
691include("subdir/Kyuafile")
692EOF
693
694    mkdir subdir
695    cat >subdir/Kyuafile <<EOF
696syntax(2)
697test_suite("integration")
698atf_test_program{name="second"}
699atf_test_program{name="third"}
700EOF
701
702    cat >expout <<EOF
703first:pass  ->  passed  [S.UUUs]
704first:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
705subdir/second:pass  ->  passed  [S.UUUs]
706subdir/second:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
707subdir/third:pass  ->  passed  [S.UUUs]
708subdir/third:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
709
710Results file id is $(utils_results_id)
711Results saved to $(utils_results_file)
712
7136/6 passed (0 failed)
714EOF
715
716    mkdir build
717    mkdir build/subdir
718    utils_cp_helper simple_all_pass build/first
719    utils_cp_helper simple_all_pass build/subdir/second
720    utils_cp_helper simple_all_pass build/subdir/third
721
722    atf_check -s exit:0 -o file:expout -e empty kyua test --build-root=build
723}
724
725
726utils_test_case kyuafile_flag__no_args
727kyuafile_flag__no_args_body() {
728    utils_install_stable_test_wrapper
729
730    cat >Kyuafile <<EOF
731This file is bogus but it is not loaded.
732EOF
733
734    cat >myfile <<EOF
735syntax(2)
736test_suite("integration")
737atf_test_program{name="sometest"}
738EOF
739    utils_cp_helper simple_all_pass sometest
740
741    cat >expout <<EOF
742sometest:pass  ->  passed  [S.UUUs]
743sometest:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
744
745Results file id is $(utils_results_id)
746Results saved to $(utils_results_file)
747
7482/2 passed (0 failed)
749EOF
750    atf_check -s exit:0 -o file:expout -e empty kyua test -k myfile
751    atf_check -s exit:0 -o file:expout -e empty kyua test --kyuafile=myfile
752}
753
754
755utils_test_case kyuafile_flag__some_args
756kyuafile_flag__some_args_body() {
757    utils_install_stable_test_wrapper
758
759    cat >Kyuafile <<EOF
760This file is bogus but it is not loaded.
761EOF
762
763    cat >myfile <<EOF
764syntax(2)
765test_suite("hello-world")
766atf_test_program{name="sometest"}
767EOF
768    utils_cp_helper simple_all_pass sometest
769
770    cat >expout <<EOF
771sometest:pass  ->  passed  [S.UUUs]
772sometest:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
773
774Results file id is $(utils_results_id)
775Results saved to $(utils_results_file)
776
7772/2 passed (0 failed)
778EOF
779    atf_check -s exit:0 -o file:expout -e empty kyua test -k myfile sometest
780    cat >expout <<EOF
781sometest:pass  ->  passed  [S.UUUs]
782sometest:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
783
784Results file id is $(utils_results_id)
785Results saved to $(utils_results_file)
786
7872/2 passed (0 failed)
788EOF
789    atf_check -s exit:0 -o file:expout -e empty kyua test --kyuafile=myfile \
790        sometest
791}
792
793
794utils_test_case interrupt
795interrupt_body() {
796    cat >Kyuafile <<EOF
797syntax(2)
798test_suite("integration")
799atf_test_program{name="interrupts"}
800EOF
801    utils_cp_helper interrupts .
802
803    kyua \
804        -v test_suites.integration.body-cookie="$(pwd)/body" \
805        -v test_suites.integration.cleanup-cookie="$(pwd)/cleanup" \
806        test >stdout 2>stderr &
807    pid=${!}
808    echo "Kyua subprocess is PID ${pid}"
809
810    while [ ! -f body ]; do
811        echo "Waiting for body to start"
812        sleep 1
813    done
814    echo "Body started"
815    sleep 1
816
817    echo "Sending INT signal to ${pid}"
818    kill -INT ${pid}
819    echo "Waiting for process ${pid} to exit"
820    wait ${pid}
821    ret=${?}
822    sed -e 's,^,kyua stdout:,' stdout
823    sed -e 's,^,kyua stderr:,' stderr
824    echo "Process ${pid} exited"
825    [ ${ret} -ne 0 ] || atf_fail 'No error code reported'
826
827    [ -f cleanup ] || atf_fail 'Cleanup part not executed after signal'
828    atf_expect_pass
829
830    atf_check -s exit:0 -o ignore -e empty grep 'Signal caught' stderr
831    atf_check -s exit:0 -o ignore -e empty \
832        grep 'kyua: E: Interrupted by signal' stderr
833}
834
835
836utils_test_case exclusive_tests
837exclusive_tests_body() {
838    cat >Kyuafile <<EOF
839syntax(2)
840test_suite("integration")
841EOF
842    for i in $(seq 100); do
843        echo 'plain_test_program{name="race", is_exclusive=true}' >>Kyuafile
844    done
845    utils_cp_helper race .
846
847    atf_check \
848        -s exit:0 \
849        -o match:"100/100 passed" \
850        kyua \
851        -v parallelism=20 \
852        -v test_suites.integration.shared_file="$(pwd)/shared_file" \
853        test
854}
855
856
857utils_test_case no_test_program_match
858no_test_program_match_body() {
859    utils_install_stable_test_wrapper
860
861    cat >Kyuafile <<EOF
862syntax(2)
863test_suite("integration")
864atf_test_program{name="first"}
865EOF
866    utils_cp_helper simple_all_pass first
867    utils_cp_helper simple_all_pass second
868
869    cat >expout <<EOF
870Results file id is $(utils_results_id)
871Results saved to $(utils_results_file)
872EOF
873    cat >experr <<EOF
874kyua: W: No test cases matched by the filter 'second'.
875EOF
876    atf_check -s exit:1 -o file:expout -e file:experr kyua test second
877}
878
879
880utils_test_case no_test_case_match
881no_test_case_match_body() {
882    utils_install_stable_test_wrapper
883
884    cat >Kyuafile <<EOF
885syntax(2)
886test_suite("integration")
887atf_test_program{name="first"}
888EOF
889    utils_cp_helper simple_all_pass first
890
891    cat >expout <<EOF
892Results file id is $(utils_results_id)
893Results saved to $(utils_results_file)
894EOF
895    cat >experr <<EOF
896kyua: W: No test cases matched by the filter 'first:foobar'.
897EOF
898    atf_check -s exit:1 -o file:expout -e file:experr kyua test first:foobar
899}
900
901
902utils_test_case missing_kyuafile__no_args
903missing_kyuafile__no_args_body() {
904    cat >experr <<EOF
905kyua: E: Load of 'Kyuafile' failed: File 'Kyuafile' not found.
906EOF
907    atf_check -s exit:2 -o empty -e file:experr kyua test
908}
909
910
911utils_test_case missing_kyuafile__test_program
912missing_kyuafile__test_program_body() {
913    mkdir subdir
914    cat >subdir/Kyuafile <<EOF
915syntax(2)
916test_suite("integration")
917atf_test_program{name="unused"}
918EOF
919    utils_cp_helper simple_all_pass subdir/unused
920
921    cat >experr <<EOF
922kyua: E: Load of 'Kyuafile' failed: File 'Kyuafile' not found.
923EOF
924    atf_check -s exit:2 -o empty -e file:experr kyua test subdir/unused
925}
926
927
928utils_test_case missing_kyuafile__subdir
929missing_kyuafile__subdir_body() {
930    mkdir subdir
931    cat >subdir/Kyuafile <<EOF
932syntax(2)
933test_suite("integration")
934atf_test_program{name="unused"}
935EOF
936    utils_cp_helper simple_all_pass subdir/unused
937
938    cat >experr <<EOF
939kyua: E: Load of 'Kyuafile' failed: File 'Kyuafile' not found.
940EOF
941    atf_check -s exit:2 -o empty -e file:experr kyua test subdir
942}
943
944
945utils_test_case bogus_config
946bogus_config_body() {
947    mkdir .kyua
948    cat >"${HOME}/.kyua/kyua.conf" <<EOF
949Hello, world.
950EOF
951
952    file_re='.*\.kyua/kyua.conf'
953    atf_check -s exit:2 -o empty \
954        -e match:"^kyua: E: Load of '${file_re}' failed: Failed to load Lua" \
955        kyua test
956}
957
958
959utils_test_case bogus_kyuafile
960bogus_kyuafile_body() {
961    cat >Kyuafile <<EOF
962Hello, world.
963EOF
964    atf_check -s exit:2 -o empty \
965        -e match:"Load of 'Kyuafile' failed: .* Kyuafile:2:" kyua list
966}
967
968
969utils_test_case bogus_test_program
970bogus_test_program_body() {
971    utils_install_stable_test_wrapper
972
973    cat >Kyuafile <<EOF
974syntax(2)
975test_suite("integration")
976atf_test_program{name="crash_on_list"}
977atf_test_program{name="non_executable"}
978EOF
979    utils_cp_helper bad_test_program crash_on_list
980    echo 'I am not executable' >non_executable
981
982# CHECK_STYLE_DISABLE
983    cat >expout <<EOF
984crash_on_list:__test_cases_list__  ->  broken: Invalid header for test case list; expecting Content-Type for application/X-atf-tp version 1, got ''  [S.UUUs]
985non_executable:__test_cases_list__  ->  broken: Permission denied to run test program  [S.UUUs]
986
987Results file id is $(utils_results_id)
988Results saved to $(utils_results_file)
989
9900/2 passed (2 failed)
991EOF
992# CHECK_STYLE_ENABLE
993    atf_check -s exit:1 -o file:expout -e empty kyua test
994}
995
996
997utils_test_case missing_test_program
998missing_test_program_body() {
999    cat >Kyuafile <<EOF
1000syntax(2)
1001include("subdir/Kyuafile")
1002EOF
1003    mkdir subdir
1004    cat >subdir/Kyuafile <<EOF
1005syntax(2)
1006test_suite("integration")
1007atf_test_program{name="ok"}
1008atf_test_program{name="i-am-missing"}
1009EOF
1010    echo 'I should not be touched because the Kyuafile is bogus' >subdir/ok
1011
1012# CHECK_STYLE_DISABLE
1013    cat >experr <<EOF
1014kyua: E: Load of 'Kyuafile' failed: .*Non-existent test program 'subdir/i-am-missing'.
1015EOF
1016# CHECK_STYLE_ENABLE
1017    atf_check -s exit:2 -o empty -e "match:$(cat experr)" kyua list
1018}
1019
1020
1021atf_init_test_cases() {
1022    atf_add_test_case one_test_program__all_pass
1023    atf_add_test_case one_test_program__some_fail
1024    atf_add_test_case many_test_programs__all_pass
1025    atf_add_test_case many_test_programs__some_fail
1026    atf_add_test_case expect__all_pass
1027    atf_add_test_case expect__some_fail
1028    atf_add_test_case premature_exit
1029
1030    atf_add_test_case no_args
1031    atf_add_test_case one_arg__subdir
1032    atf_add_test_case one_arg__test_case
1033    atf_add_test_case one_arg__test_program
1034    atf_add_test_case one_arg__invalid
1035    atf_add_test_case many_args__ok
1036    atf_add_test_case many_args__invalid
1037    atf_add_test_case many_args__no_match__all
1038    atf_add_test_case many_args__no_match__some
1039
1040    atf_add_test_case args_are_relative
1041
1042    atf_add_test_case only_load_used_test_programs
1043
1044    atf_add_test_case config_behavior
1045
1046    atf_add_test_case store_contents
1047    atf_add_test_case results_file__ok
1048    atf_add_test_case results_file__fail
1049    atf_add_test_case results_file__reuse
1050
1051    atf_add_test_case build_root_flag
1052
1053    atf_add_test_case kyuafile_flag__no_args
1054    atf_add_test_case kyuafile_flag__some_args
1055
1056    atf_add_test_case interrupt
1057
1058    atf_add_test_case exclusive_tests
1059
1060    atf_add_test_case no_test_program_match
1061    atf_add_test_case no_test_case_match
1062
1063    atf_add_test_case missing_kyuafile__no_args
1064    atf_add_test_case missing_kyuafile__test_program
1065    atf_add_test_case missing_kyuafile__subdir
1066
1067    atf_add_test_case bogus_config
1068    atf_add_test_case bogus_kyuafile
1069    atf_add_test_case bogus_test_program
1070    atf_add_test_case missing_test_program
1071}
1072