]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/kyua/integration/cmd_test_test.sh
contrib/kyua: Merge vendor import
[FreeBSD/FreeBSD.git] / contrib / kyua / integration / cmd_test_test.sh
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
30 utils_test_case one_test_program__all_pass
31 one_test_program__all_pass_body() {
32     utils_install_stable_test_wrapper
33
34     cat >Kyuafile <<EOF
35 syntax(2)
36 test_suite("integration")
37 atf_test_program{name="simple_all_pass"}
38 EOF
39
40     cat >expout <<EOF
41 simple_all_pass:pass  ->  passed  [S.UUUs]
42 simple_all_pass:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
43
44 Results file id is $(utils_results_id)
45 Results saved to $(utils_results_file)
46
47 2/2 passed (0 failed)
48 EOF
49
50     utils_cp_helper simple_all_pass .
51     atf_check -s exit:0 -o file:expout -e empty kyua test
52 }
53
54
55 utils_test_case one_test_program__some_fail
56 one_test_program__some_fail_body() {
57     utils_install_stable_test_wrapper
58
59     cat >Kyuafile <<EOF
60 syntax(2)
61 test_suite("integration")
62 atf_test_program{name="simple_some_fail"}
63 EOF
64
65     cat >expout <<EOF
66 simple_some_fail:fail  ->  failed: This fails on purpose  [S.UUUs]
67 simple_some_fail:pass  ->  passed  [S.UUUs]
68
69 Results file id is $(utils_results_id)
70 Results saved to $(utils_results_file)
71
72 1/2 passed (1 failed)
73 EOF
74
75     utils_cp_helper simple_some_fail .
76     atf_check -s exit:1 -o file:expout -e empty kyua test
77 }
78
79
80 utils_test_case many_test_programs__all_pass
81 many_test_programs__all_pass_body() {
82     utils_install_stable_test_wrapper
83
84     cat >Kyuafile <<EOF
85 syntax(2)
86 test_suite("integration")
87 atf_test_program{name="first"}
88 atf_test_program{name="second"}
89 atf_test_program{name="third"}
90 plain_test_program{name="fourth", required_files="/non-existent/foo"}
91 EOF
92
93     cat >expout <<EOF
94 first:pass  ->  passed  [S.UUUs]
95 first:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
96 fourth:main  ->  skipped: Required file '/non-existent/foo' not found  [S.UUUs]
97 second:pass  ->  passed  [S.UUUs]
98 second:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
99 third:pass  ->  passed  [S.UUUs]
100 third:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
101
102 Results file id is $(utils_results_id)
103 Results saved to $(utils_results_file)
104
105 7/7 passed (0 failed)
106 EOF
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
116 utils_test_case many_test_programs__some_fail
117 many_test_programs__some_fail_body() {
118     utils_install_stable_test_wrapper
119
120     cat >Kyuafile <<EOF
121 syntax(2)
122 test_suite("integration")
123 atf_test_program{name="first"}
124 atf_test_program{name="second"}
125 atf_test_program{name="third"}
126 plain_test_program{name="fourth"}
127 EOF
128
129     cat >expout <<EOF
130 first:fail  ->  failed: This fails on purpose  [S.UUUs]
131 first:pass  ->  passed  [S.UUUs]
132 fourth:main  ->  failed: Returned non-success exit status 76  [S.UUUs]
133 second:fail  ->  failed: This fails on purpose  [S.UUUs]
134 second:pass  ->  passed  [S.UUUs]
135 third:pass  ->  passed  [S.UUUs]
136 third:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
137
138 Results file id is $(utils_results_id)
139 Results saved to $(utils_results_file)
140
141 4/7 passed (3 failed)
142 EOF
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
154 utils_test_case expect__all_pass
155 expect__all_pass_body() {
156     utils_install_stable_test_wrapper
157
158     cat >Kyuafile <<EOF
159 syntax(2)
160 test_suite("integration")
161 atf_test_program{name="expect_all_pass"}
162 EOF
163
164 # CHECK_STYLE_DISABLE
165     cat >expout <<EOF
166 expect_all_pass:die  ->  expected_failure: This is the reason for death  [S.UUUs]
167 expect_all_pass:exit  ->  expected_failure: Exiting with correct code  [S.UUUs]
168 expect_all_pass:failure  ->  expected_failure: Oh no: Forced failure  [S.UUUs]
169 expect_all_pass:signal  ->  expected_failure: Exiting with correct signal  [S.UUUs]
170 expect_all_pass:timeout  ->  expected_failure: This times out  [S.UUUs]
171
172 Results file id is $(utils_results_id)
173 Results saved to $(utils_results_file)
174
175 5/5 passed (0 failed)
176 EOF
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
184 utils_test_case expect__some_fail
185 expect__some_fail_body() {
186     utils_install_stable_test_wrapper
187
188     cat >Kyuafile <<EOF
189 syntax(2)
190 test_suite("integration")
191 atf_test_program{name="expect_some_fail"}
192 EOF
193
194 # CHECK_STYLE_DISABLE
195     cat >expout <<EOF
196 expect_some_fail:die  ->  failed: Test case was expected to terminate abruptly but it continued execution  [S.UUUs]
197 expect_some_fail:exit  ->  failed: Test case expected to exit with code 12 but got code 34  [S.UUUs]
198 expect_some_fail:failure  ->  failed: Test case was expecting a failure but none were raised  [S.UUUs]
199 expect_some_fail:pass  ->  passed  [S.UUUs]
200 expect_some_fail:signal  ->  failed: Test case expected to receive signal 15 but got 9  [S.UUUs]
201 expect_some_fail:timeout  ->  failed: Test case was expected to hang but it continued execution  [S.UUUs]
202
203 Results file id is $(utils_results_id)
204 Results saved to $(utils_results_file)
205
206 1/6 passed (5 failed)
207 EOF
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
215 utils_test_case premature_exit
216 premature_exit_body() {
217     utils_install_stable_test_wrapper
218
219     cat >Kyuafile <<EOF
220 syntax(2)
221 test_suite("integration")
222 atf_test_program{name="bogus_test_cases"}
223 EOF
224
225 # CHECK_STYLE_DISABLE
226     cat >expout <<EOF
227 bogus_test_cases:die  ->  broken: Premature exit; test case received signal 9  [S.UUUs]
228 bogus_test_cases:exit  ->  broken: Premature exit; test case exited with code 0  [S.UUUs]
229 bogus_test_cases:pass  ->  passed  [S.UUUs]
230
231 Results file id is $(utils_results_id)
232 Results saved to $(utils_results_file)
233
234 1/3 passed (2 failed)
235 EOF
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
243 utils_test_case no_args
244 no_args_body() {
245     utils_install_stable_test_wrapper
246
247     cat >Kyuafile <<EOF
248 syntax(2)
249 test_suite("integration")
250 atf_test_program{name="simple_all_pass"}
251 include("subdir/Kyuafile")
252 EOF
253     utils_cp_helper metadata .
254     utils_cp_helper simple_all_pass .
255
256     mkdir subdir
257     cat >subdir/Kyuafile <<EOF
258 syntax(2)
259 test_suite("integration2")
260 atf_test_program{name="simple_some_fail"}
261 EOF
262     utils_cp_helper simple_some_fail subdir
263
264     cat >expout <<EOF
265 simple_all_pass:pass  ->  passed  [S.UUUs]
266 simple_all_pass:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
267 subdir/simple_some_fail:fail  ->  failed: This fails on purpose  [S.UUUs]
268 subdir/simple_some_fail:pass  ->  passed  [S.UUUs]
269
270 Results file id is $(utils_results_id)
271 Results saved to $(utils_results_file)
272
273 3/4 passed (1 failed)
274 EOF
275     atf_check -s exit:1 -o file:expout -e empty kyua test
276 }
277
278
279 utils_test_case one_arg__subdir
280 one_arg__subdir_body() {
281     utils_install_stable_test_wrapper
282
283     cat >Kyuafile <<EOF
284 syntax(2)
285 test_suite("top-level")
286 include("subdir/Kyuafile")
287 EOF
288
289     mkdir subdir
290     cat >subdir/Kyuafile <<EOF
291 syntax(2)
292 test_suite("in-subdir")
293 atf_test_program{name="simple_all_pass"}
294 EOF
295     utils_cp_helper simple_all_pass subdir
296
297 # CHECK_STYLE_DISABLE
298     cat >expout <<EOF
299 subdir/simple_all_pass:pass  ->  passed  [S.UUUs]
300 subdir/simple_all_pass:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
301
302 Results file id is $(utils_results_id)
303 Results saved to $(utils_results_file)
304
305 2/2 passed (0 failed)
306 EOF
307 # CHECK_STYLE_ENABLE
308     atf_check -s exit:0 -o file:expout -e empty kyua test subdir
309 }
310
311
312 utils_test_case one_arg__test_case
313 one_arg__test_case_body() {
314     utils_install_stable_test_wrapper
315
316     cat >Kyuafile <<EOF
317 syntax(2)
318 test_suite("top-level")
319 atf_test_program{name="first"}
320 atf_test_program{name="second"}
321 EOF
322     utils_cp_helper simple_all_pass first
323     utils_cp_helper simple_all_pass second
324
325     cat >expout <<EOF
326 first:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
327
328 Results file id is $(utils_results_id)
329 Results saved to $(utils_results_file)
330
331 1/1 passed (0 failed)
332 EOF
333     atf_check -s exit:0 -o file:expout -e empty kyua test first:skip
334 }
335
336
337 utils_test_case one_arg__test_program
338 one_arg__test_program_body() {
339     utils_install_stable_test_wrapper
340
341     cat >Kyuafile <<EOF
342 syntax(2)
343 test_suite("top-level")
344 atf_test_program{name="first"}
345 atf_test_program{name="second"}
346 EOF
347     utils_cp_helper simple_all_pass first
348     utils_cp_helper simple_some_fail second
349
350     cat >expout <<EOF
351 second:fail  ->  failed: This fails on purpose  [S.UUUs]
352 second:pass  ->  passed  [S.UUUs]
353
354 Results file id is $(utils_results_id)
355 Results saved to $(utils_results_file)
356
357 1/2 passed (1 failed)
358 EOF
359     atf_check -s exit:1 -o file:expout -e empty kyua test second
360 }
361
362
363 utils_test_case one_arg__invalid
364 one_arg__invalid_body() {
365 cat >experr <<EOF
366 kyua: E: Test case component in 'foo:' is empty.
367 EOF
368     atf_check -s exit:2 -o empty -e file:experr kyua test foo:
369
370 cat >experr <<EOF
371 kyua: E: Program name '/a/b' must be relative to the test suite, not absolute.
372 EOF
373     atf_check -s exit:2 -o empty -e file:experr kyua test /a/b
374 }
375
376
377 utils_test_case many_args__ok
378 many_args__ok_body() {
379     utils_install_stable_test_wrapper
380
381     cat >Kyuafile <<EOF
382 syntax(2)
383 test_suite("top-level")
384 include("subdir/Kyuafile")
385 atf_test_program{name="first"}
386 EOF
387     utils_cp_helper simple_all_pass first
388
389     mkdir subdir
390     cat >subdir/Kyuafile <<EOF
391 syntax(2)
392 test_suite("in-subdir")
393 atf_test_program{name="second"}
394 EOF
395     utils_cp_helper simple_some_fail subdir/second
396
397     cat >expout <<EOF
398 first:pass  ->  passed  [S.UUUs]
399 subdir/second:fail  ->  failed: This fails on purpose  [S.UUUs]
400 subdir/second:pass  ->  passed  [S.UUUs]
401
402 Results file id is $(utils_results_id)
403 Results saved to $(utils_results_file)
404
405 2/3 passed (1 failed)
406 EOF
407     atf_check -s exit:1 -o file:expout -e empty kyua test subdir first:pass
408 }
409
410
411 utils_test_case many_args__invalid
412 many_args__invalid_body() {
413 cat >experr <<EOF
414 kyua: E: Program name component in ':badbad' is empty.
415 EOF
416     atf_check -s exit:2 -o empty -e file:experr kyua test this-is-ok :badbad
417
418 cat >experr <<EOF
419 kyua: E: Program name '/foo' must be relative to the test suite, not absolute.
420 EOF
421     atf_check -s exit:2 -o empty -e file:experr kyua test this-is-ok /foo
422 }
423
424
425 utils_test_case many_args__no_match__all
426 many_args__no_match__all_body() {
427     utils_install_stable_test_wrapper
428
429     cat >Kyuafile <<EOF
430 syntax(2)
431 test_suite("top-level")
432 atf_test_program{name="first"}
433 atf_test_program{name="second"}
434 EOF
435     utils_cp_helper simple_all_pass first
436     utils_cp_helper simple_all_pass second
437
438     cat >expout <<EOF
439 Results file id is $(utils_results_id)
440 Results saved to $(utils_results_file)
441 EOF
442     cat >experr <<EOF
443 kyua: W: No test cases matched by the filter 'first1'.
444 EOF
445     atf_check -s exit:1 -o file:expout -e file:experr kyua test first1
446 }
447
448
449 utils_test_case many_args__no_match__some
450 many_args__no_match__some_body() {
451     utils_install_stable_test_wrapper
452
453     cat >Kyuafile <<EOF
454 syntax(2)
455 test_suite("top-level")
456 atf_test_program{name="first"}
457 atf_test_program{name="second"}
458 atf_test_program{name="third"}
459 EOF
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
465 first:pass  ->  passed  [S.UUUs]
466 first:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
467 third:fail  ->  failed: This fails on purpose  [S.UUUs]
468 third:pass  ->  passed  [S.UUUs]
469
470 Results file id is $(utils_results_id)
471 Results saved to $(utils_results_file)
472
473 3/4 passed (1 failed)
474 EOF
475
476     cat >experr <<EOF
477 kyua: W: No test cases matched by the filter 'fifth'.
478 kyua: W: No test cases matched by the filter 'fourth'.
479 EOF
480     atf_check -s exit:1 -o file:expout -e file:experr kyua test first fourth \
481         third fifth
482 }
483
484
485 utils_test_case args_are_relative
486 args_are_relative_body() {
487     utils_install_stable_test_wrapper
488
489     mkdir root
490     cat >root/Kyuafile <<EOF
491 syntax(2)
492 test_suite("integration-1")
493 atf_test_program{name="first"}
494 atf_test_program{name="second"}
495 include("subdir/Kyuafile")
496 EOF
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
502 syntax(2)
503 test_suite("integration-2")
504 atf_test_program{name="third"}
505 atf_test_program{name="fourth"}
506 EOF
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
511 first:pass  ->  passed  [S.UUUs]
512 first:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
513 subdir/fourth:fail  ->  failed: This fails on purpose  [S.UUUs]
514
515 Results file id is $(utils_results_id root)
516 Results saved to $(utils_results_file root)
517
518 2/3 passed (1 failed)
519 EOF
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
525 utils_test_case only_load_used_test_programs
526 only_load_used_test_programs_body() {
527     utils_install_stable_test_wrapper
528
529     cat >Kyuafile <<EOF
530 syntax(2)
531 test_suite("integration")
532 atf_test_program{name="first"}
533 atf_test_program{name="second"}
534 EOF
535     utils_cp_helper simple_all_pass first
536     utils_cp_helper bad_test_program second
537
538     cat >expout <<EOF
539 first:pass  ->  passed  [S.UUUs]
540 first:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
541
542 Results file id is $(utils_results_id)
543 Results saved to $(utils_results_file)
544
545 2/2 passed (0 failed)
546 EOF
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
556 utils_test_case config_behavior
557 config_behavior_body() {
558     cat >"my-config" <<EOF
559 syntax(2)
560 test_suites.suite1["the-variable"] = "value1"
561 test_suites.suite2["the-variable"] = "override me"
562 EOF
563
564     cat >Kyuafile <<EOF
565 syntax(2)
566 atf_test_program{name="config1", test_suite="suite1"}
567 atf_test_program{name="config2", test_suite="suite2"}
568 atf_test_program{name="config3", test_suite="suite3"}
569 EOF
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
599 utils_test_case store_contents
600 store_contents_body() {
601     utils_install_stable_test_wrapper
602
603     cat >Kyuafile <<EOF
604 syntax(2)
605 atf_test_program{name="some-program", test_suite="suite1"}
606 EOF
607     utils_cp_helper simple_some_fail some-program
608     cat >expout <<EOF
609 some-program:fail  ->  failed: This fails on purpose  [S.UUUs]
610 some-program:pass  ->  passed  [S.UUUs]
611
612 Results file id is $(utils_results_id)
613 Results saved to $(utils_results_file)
614
615 1/2 passed (1 failed)
616 EOF
617
618     atf_check -s exit:1 -o file:expout -e empty kyua test
619
620 cat >expout <<EOF
621 some-program,fail,failed,This fails on purpose
622 some-program,pass,passed,NULL
623 EOF
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
638 utils_test_case results_file__ok
639 results_file__ok_body() {
640     cat >Kyuafile <<EOF
641 syntax(2)
642 atf_test_program{name="config1", test_suite="suite1"}
643 EOF
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
654 utils_test_case results_file__fail
655 results_file__fail_body() {
656     cat >Kyuafile <<EOF
657 syntax(2)
658 atf_test_program{name="config1", test_suite="suite1"}
659 EOF
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
667 utils_test_case results_file__reuse
668 results_file__reuse_body() {
669     utils_install_stable_test_wrapper
670
671     cat >Kyuafile <<EOF
672 syntax(2)
673 atf_test_program{name="simple_all_pass", test_suite="integration"}
674 EOF
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
683 utils_test_case build_root_flag
684 build_root_flag_body() {
685     utils_install_stable_test_wrapper
686
687     cat >Kyuafile <<EOF
688 syntax(2)
689 test_suite("integration")
690 atf_test_program{name="first"}
691 include("subdir/Kyuafile")
692 EOF
693
694     mkdir subdir
695     cat >subdir/Kyuafile <<EOF
696 syntax(2)
697 test_suite("integration")
698 atf_test_program{name="second"}
699 atf_test_program{name="third"}
700 EOF
701
702     cat >expout <<EOF
703 first:pass  ->  passed  [S.UUUs]
704 first:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
705 subdir/second:pass  ->  passed  [S.UUUs]
706 subdir/second:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
707 subdir/third:pass  ->  passed  [S.UUUs]
708 subdir/third:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
709
710 Results file id is $(utils_results_id)
711 Results saved to $(utils_results_file)
712
713 6/6 passed (0 failed)
714 EOF
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
726 utils_test_case kyuafile_flag__no_args
727 kyuafile_flag__no_args_body() {
728     utils_install_stable_test_wrapper
729
730     cat >Kyuafile <<EOF
731 This file is bogus but it is not loaded.
732 EOF
733
734     cat >myfile <<EOF
735 syntax(2)
736 test_suite("integration")
737 atf_test_program{name="sometest"}
738 EOF
739     utils_cp_helper simple_all_pass sometest
740
741     cat >expout <<EOF
742 sometest:pass  ->  passed  [S.UUUs]
743 sometest:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
744
745 Results file id is $(utils_results_id)
746 Results saved to $(utils_results_file)
747
748 2/2 passed (0 failed)
749 EOF
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
755 utils_test_case kyuafile_flag__some_args
756 kyuafile_flag__some_args_body() {
757     utils_install_stable_test_wrapper
758
759     cat >Kyuafile <<EOF
760 This file is bogus but it is not loaded.
761 EOF
762
763     cat >myfile <<EOF
764 syntax(2)
765 test_suite("hello-world")
766 atf_test_program{name="sometest"}
767 EOF
768     utils_cp_helper simple_all_pass sometest
769
770     cat >expout <<EOF
771 sometest:pass  ->  passed  [S.UUUs]
772 sometest:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
773
774 Results file id is $(utils_results_id)
775 Results saved to $(utils_results_file)
776
777 2/2 passed (0 failed)
778 EOF
779     atf_check -s exit:0 -o file:expout -e empty kyua test -k myfile sometest
780     cat >expout <<EOF
781 sometest:pass  ->  passed  [S.UUUs]
782 sometest:skip  ->  skipped: The reason for skipping is this  [S.UUUs]
783
784 Results file id is $(utils_results_id)
785 Results saved to $(utils_results_file)
786
787 2/2 passed (0 failed)
788 EOF
789     atf_check -s exit:0 -o file:expout -e empty kyua test --kyuafile=myfile \
790         sometest
791 }
792
793
794 utils_test_case interrupt
795 interrupt_body() {
796     cat >Kyuafile <<EOF
797 syntax(2)
798 test_suite("integration")
799 atf_test_program{name="interrupts"}
800 EOF
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
836 utils_test_case exclusive_tests
837 exclusive_tests_body() {
838     cat >Kyuafile <<EOF
839 syntax(2)
840 test_suite("integration")
841 EOF
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
857 utils_test_case no_test_program_match
858 no_test_program_match_body() {
859     utils_install_stable_test_wrapper
860
861     cat >Kyuafile <<EOF
862 syntax(2)
863 test_suite("integration")
864 atf_test_program{name="first"}
865 EOF
866     utils_cp_helper simple_all_pass first
867     utils_cp_helper simple_all_pass second
868
869     cat >expout <<EOF
870 Results file id is $(utils_results_id)
871 Results saved to $(utils_results_file)
872 EOF
873     cat >experr <<EOF
874 kyua: W: No test cases matched by the filter 'second'.
875 EOF
876     atf_check -s exit:1 -o file:expout -e file:experr kyua test second
877 }
878
879
880 utils_test_case no_test_case_match
881 no_test_case_match_body() {
882     utils_install_stable_test_wrapper
883
884     cat >Kyuafile <<EOF
885 syntax(2)
886 test_suite("integration")
887 atf_test_program{name="first"}
888 EOF
889     utils_cp_helper simple_all_pass first
890
891     cat >expout <<EOF
892 Results file id is $(utils_results_id)
893 Results saved to $(utils_results_file)
894 EOF
895     cat >experr <<EOF
896 kyua: W: No test cases matched by the filter 'first:foobar'.
897 EOF
898     atf_check -s exit:1 -o file:expout -e file:experr kyua test first:foobar
899 }
900
901
902 utils_test_case missing_kyuafile__no_args
903 missing_kyuafile__no_args_body() {
904     cat >experr <<EOF
905 kyua: E: Load of 'Kyuafile' failed: File 'Kyuafile' not found.
906 EOF
907     atf_check -s exit:2 -o empty -e file:experr kyua test
908 }
909
910
911 utils_test_case missing_kyuafile__test_program
912 missing_kyuafile__test_program_body() {
913     mkdir subdir
914     cat >subdir/Kyuafile <<EOF
915 syntax(2)
916 test_suite("integration")
917 atf_test_program{name="unused"}
918 EOF
919     utils_cp_helper simple_all_pass subdir/unused
920
921     cat >experr <<EOF
922 kyua: E: Load of 'Kyuafile' failed: File 'Kyuafile' not found.
923 EOF
924     atf_check -s exit:2 -o empty -e file:experr kyua test subdir/unused
925 }
926
927
928 utils_test_case missing_kyuafile__subdir
929 missing_kyuafile__subdir_body() {
930     mkdir subdir
931     cat >subdir/Kyuafile <<EOF
932 syntax(2)
933 test_suite("integration")
934 atf_test_program{name="unused"}
935 EOF
936     utils_cp_helper simple_all_pass subdir/unused
937
938     cat >experr <<EOF
939 kyua: E: Load of 'Kyuafile' failed: File 'Kyuafile' not found.
940 EOF
941     atf_check -s exit:2 -o empty -e file:experr kyua test subdir
942 }
943
944
945 utils_test_case bogus_config
946 bogus_config_body() {
947     mkdir .kyua
948     cat >"${HOME}/.kyua/kyua.conf" <<EOF
949 Hello, world.
950 EOF
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
959 utils_test_case bogus_kyuafile
960 bogus_kyuafile_body() {
961     cat >Kyuafile <<EOF
962 Hello, world.
963 EOF
964     atf_check -s exit:2 -o empty \
965         -e match:"Load of 'Kyuafile' failed: .* Kyuafile:2:" kyua list
966 }
967
968
969 utils_test_case bogus_test_program
970 bogus_test_program_body() {
971     utils_install_stable_test_wrapper
972
973     cat >Kyuafile <<EOF
974 syntax(2)
975 test_suite("integration")
976 atf_test_program{name="crash_on_list"}
977 atf_test_program{name="non_executable"}
978 EOF
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
984 crash_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]
985 non_executable:__test_cases_list__  ->  broken: Permission denied to run test program  [S.UUUs]
986
987 Results file id is $(utils_results_id)
988 Results saved to $(utils_results_file)
989
990 0/2 passed (2 failed)
991 EOF
992 # CHECK_STYLE_ENABLE
993     atf_check -s exit:1 -o file:expout -e empty kyua test
994 }
995
996
997 utils_test_case missing_test_program
998 missing_test_program_body() {
999     cat >Kyuafile <<EOF
1000 syntax(2)
1001 include("subdir/Kyuafile")
1002 EOF
1003     mkdir subdir
1004     cat >subdir/Kyuafile <<EOF
1005 syntax(2)
1006 test_suite("integration")
1007 atf_test_program{name="ok"}
1008 atf_test_program{name="i-am-missing"}
1009 EOF
1010     echo 'I should not be touched because the Kyuafile is bogus' >subdir/ok
1011
1012 # CHECK_STYLE_DISABLE
1013     cat >experr <<EOF
1014 kyua: E: Load of 'Kyuafile' failed: .*Non-existent test program 'subdir/i-am-missing'.
1015 EOF
1016 # CHECK_STYLE_ENABLE
1017     atf_check -s exit:2 -o empty -e "match:$(cat experr)" kyua list
1018 }
1019
1020
1021 atf_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 }