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 471/2 passed (0 broken, 0 failed, 1 skipped) 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 (0 broken, 1 failed, 0 skipped) 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 1053/7 passed (0 broken, 0 failed, 4 skipped) 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 1413/7 passed (0 broken, 3 failed, 1 skipped) 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 broken, 0 failed, 0 skipped) 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 (0 broken, 5 failed, 0 skipped) 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 broken, 0 failed, 0 skipped) 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 2732/4 passed (0 broken, 1 failed, 1 skipped) 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 3051/2 passed (0 broken, 0 failed, 1 skipped) 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 3310/1 passed (0 broken, 0 failed, 1 skipped) 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 (0 broken, 1 failed, 0 skipped) 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 (0 broken, 1 failed, 0 skipped) 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 4732/4 passed (0 broken, 1 failed, 1 skipped) 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 5181/3 passed (0 broken, 1 failed, 1 skipped) 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 5451/2 passed (0 broken, 0 failed, 1 skipped) 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 config_unprivileged_user 600config_unprivileged_user_body() { 601 cat >"my-config" <<EOF 602syntax(2) 603unprivileged_user = "nobody" 604EOF 605 cat >Kyuafile <<EOF 606syntax(2) 607atf_test_program{name="config1", test_suite="suite1"} 608EOF 609 utils_cp_helper config config1 610 611 CONFIG_VAR_FILE="$(pwd)/cookie"; export CONFIG_VAR_FILE 612 if [ -f "${CONFIG_VAR_FILE}" ]; then 613 atf_fail "Cookie file already created; test case list may have gotten" \ 614 "a bad configuration" 615 fi 616 617 CONFIG_VAR_NAME="unprivileged-user"; export CONFIG_VAR_NAME 618 atf_check -s exit:1 -o ignore -e ignore kyua -c my-config test config1 619 [ -f "${CONFIG_VAR_FILE}" ] || \ 620 atf_fail "Cookie file not created; test case list did not get" \ 621 "configuration variables" 622 value="$(cat "${CONFIG_VAR_FILE}")" 623 [ "${value}" = "nobody" ] || \ 624 atf_fail "Invalid value (${value}) in cookie file; test case list did" \ 625 "not get the correct configuration variables" 626 627 rm "${CONFIG_VAR_FILE}" 628 629 CONFIG_VAR_NAME="unprivileged_user"; export CONFIG_VAR_NAME 630 atf_check -s exit:1 -o ignore -e ignore kyua -c my-config test config1 631 [ -f "${CONFIG_VAR_FILE}" ] || \ 632 atf_fail "Cookie file not created; test case list did not get" \ 633 "configuration variables" 634 value="$(cat "${CONFIG_VAR_FILE}")" 635 [ "${value}" = "nobody" ] || \ 636 atf_fail "Invalid value (${value}) in cookie file; test case list did" \ 637 "not get the correct configuration variables" 638} 639 640 641utils_test_case store_contents 642store_contents_body() { 643 utils_install_stable_test_wrapper 644 645 cat >Kyuafile <<EOF 646syntax(2) 647atf_test_program{name="some-program", test_suite="suite1"} 648EOF 649 utils_cp_helper simple_some_fail some-program 650 cat >expout <<EOF 651some-program:fail -> failed: This fails on purpose [S.UUUs] 652some-program:pass -> passed [S.UUUs] 653 654Results file id is $(utils_results_id) 655Results saved to $(utils_results_file) 656 6571/2 passed (0 broken, 1 failed, 0 skipped) 658EOF 659 660 atf_check -s exit:1 -o file:expout -e empty kyua test 661 662cat >expout <<EOF 663some-program,fail,failed,This fails on purpose 664some-program,pass,passed,NULL 665EOF 666 atf_check -s exit:0 -o file:expout -e empty \ 667 kyua db-exec --no-headers \ 668 "SELECT " \ 669 " test_programs.relative_path, test_cases.name, " \ 670 " test_results.result_type, test_results.result_reason " \ 671 "FROM test_programs " \ 672 " JOIN test_cases " \ 673 " ON test_programs.test_program_id = test_cases.test_program_id " \ 674 " JOIN test_results " \ 675 " ON test_cases.test_case_id = test_results.test_case_id " \ 676 "ORDER BY test_programs.relative_path, test_cases.name" 677} 678 679 680utils_test_case results_file__ok 681results_file__ok_body() { 682 cat >Kyuafile <<EOF 683syntax(2) 684atf_test_program{name="config1", test_suite="suite1"} 685EOF 686 utils_cp_helper config config1 687 688 atf_check -s exit:0 -o ignore -e empty kyua test -r foo1.db 689 test -f foo1.db || atf_fail "-s did not work" 690 atf_check -s exit:0 -o ignore -e empty kyua test --results-file=foo2.db 691 test -f foo2.db || atf_fail "--results-file did not work" 692 test ! -f .kyua/store.db || atf_fail "Default database created" 693} 694 695 696utils_test_case results_file__fail 697results_file__fail_body() { 698 cat >Kyuafile <<EOF 699syntax(2) 700atf_test_program{name="config1", test_suite="suite1"} 701EOF 702 utils_cp_helper config config1 703 704 atf_check -s exit:3 -o empty -e match:"Invalid.*--results-file" \ 705 kyua test --results-file= 706} 707 708 709utils_test_case results_file__reuse 710results_file__reuse_body() { 711 utils_install_stable_test_wrapper 712 713 cat >Kyuafile <<EOF 714syntax(2) 715atf_test_program{name="simple_all_pass", test_suite="integration"} 716EOF 717 utils_cp_helper simple_all_pass . 718 atf_check -s exit:0 -o ignore -e empty kyua test -r results.db 719 720 atf_check -s exit:2 -o empty -e match:"results.db already exists" \ 721 kyua test --results-file="results.db" 722} 723 724 725utils_test_case build_root_flag 726build_root_flag_body() { 727 utils_install_stable_test_wrapper 728 729 cat >Kyuafile <<EOF 730syntax(2) 731test_suite("integration") 732atf_test_program{name="first"} 733include("subdir/Kyuafile") 734EOF 735 736 mkdir subdir 737 cat >subdir/Kyuafile <<EOF 738syntax(2) 739test_suite("integration") 740atf_test_program{name="second"} 741atf_test_program{name="third"} 742EOF 743 744 cat >expout <<EOF 745first:pass -> passed [S.UUUs] 746first:skip -> skipped: The reason for skipping is this [S.UUUs] 747subdir/second:pass -> passed [S.UUUs] 748subdir/second:skip -> skipped: The reason for skipping is this [S.UUUs] 749subdir/third:pass -> passed [S.UUUs] 750subdir/third:skip -> skipped: The reason for skipping is this [S.UUUs] 751 752Results file id is $(utils_results_id) 753Results saved to $(utils_results_file) 754 7553/6 passed (0 broken, 0 failed, 3 skipped) 756EOF 757 758 mkdir build 759 mkdir build/subdir 760 utils_cp_helper simple_all_pass build/first 761 utils_cp_helper simple_all_pass build/subdir/second 762 utils_cp_helper simple_all_pass build/subdir/third 763 764 atf_check -s exit:0 -o file:expout -e empty kyua test --build-root=build 765} 766 767 768utils_test_case kyuafile_flag__no_args 769kyuafile_flag__no_args_body() { 770 utils_install_stable_test_wrapper 771 772 cat >Kyuafile <<EOF 773This file is bogus but it is not loaded. 774EOF 775 776 cat >myfile <<EOF 777syntax(2) 778test_suite("integration") 779atf_test_program{name="sometest"} 780EOF 781 utils_cp_helper simple_all_pass sometest 782 783 cat >expout <<EOF 784sometest:pass -> passed [S.UUUs] 785sometest:skip -> skipped: The reason for skipping is this [S.UUUs] 786 787Results file id is $(utils_results_id) 788Results saved to $(utils_results_file) 789 7901/2 passed (0 broken, 0 failed, 1 skipped) 791EOF 792 atf_check -s exit:0 -o file:expout -e empty kyua test -k myfile 793 atf_check -s exit:0 -o file:expout -e empty kyua test --kyuafile=myfile 794} 795 796 797utils_test_case kyuafile_flag__some_args 798kyuafile_flag__some_args_body() { 799 utils_install_stable_test_wrapper 800 801 cat >Kyuafile <<EOF 802This file is bogus but it is not loaded. 803EOF 804 805 cat >myfile <<EOF 806syntax(2) 807test_suite("hello-world") 808atf_test_program{name="sometest"} 809EOF 810 utils_cp_helper simple_all_pass sometest 811 812 cat >expout <<EOF 813sometest:pass -> passed [S.UUUs] 814sometest:skip -> skipped: The reason for skipping is this [S.UUUs] 815 816Results file id is $(utils_results_id) 817Results saved to $(utils_results_file) 818 8191/2 passed (0 broken, 0 failed, 1 skipped) 820EOF 821 atf_check -s exit:0 -o file:expout -e empty kyua test -k myfile sometest 822 cat >expout <<EOF 823sometest:pass -> passed [S.UUUs] 824sometest:skip -> skipped: The reason for skipping is this [S.UUUs] 825 826Results file id is $(utils_results_id) 827Results saved to $(utils_results_file) 828 8291/2 passed (0 broken, 0 failed, 1 skipped) 830EOF 831 atf_check -s exit:0 -o file:expout -e empty kyua test --kyuafile=myfile \ 832 sometest 833} 834 835 836utils_test_case interrupt 837interrupt_body() { 838 cat >Kyuafile <<EOF 839syntax(2) 840test_suite("integration") 841atf_test_program{name="interrupts"} 842EOF 843 utils_cp_helper interrupts . 844 845 kyua \ 846 -v test_suites.integration.body-cookie="$(pwd)/body" \ 847 -v test_suites.integration.cleanup-cookie="$(pwd)/cleanup" \ 848 test >stdout 2>stderr & 849 pid=${!} 850 echo "Kyua subprocess is PID ${pid}" 851 852 while [ ! -f body ]; do 853 echo "Waiting for body to start" 854 sleep 1 855 done 856 echo "Body started" 857 sleep 1 858 859 echo "Sending INT signal to ${pid}" 860 kill -INT ${pid} 861 echo "Waiting for process ${pid} to exit" 862 wait ${pid} 863 ret=${?} 864 sed -e 's,^,kyua stdout:,' stdout 865 sed -e 's,^,kyua stderr:,' stderr 866 echo "Process ${pid} exited" 867 [ ${ret} -ne 0 ] || atf_fail 'No error code reported' 868 869 [ -f cleanup ] || atf_fail 'Cleanup part not executed after signal' 870 atf_expect_pass 871 872 atf_check -s exit:0 -o ignore -e empty grep 'Signal caught' stderr 873 atf_check -s exit:0 -o ignore -e empty \ 874 grep 'kyua: E: Interrupted by signal' stderr 875} 876 877 878utils_test_case exclusive_tests 879exclusive_tests_body() { 880 cat >Kyuafile <<EOF 881syntax(2) 882test_suite("integration") 883EOF 884 for i in $(seq 100); do 885 echo 'plain_test_program{name="race", is_exclusive=true}' >>Kyuafile 886 done 887 utils_cp_helper race . 888 889 atf_check \ 890 -s exit:0 \ 891 -o match:"100/100 passed" \ 892 kyua \ 893 -v parallelism=20 \ 894 -v test_suites.integration.shared_file="$(pwd)/shared_file" \ 895 test 896} 897 898 899utils_test_case no_test_program_match 900no_test_program_match_body() { 901 utils_install_stable_test_wrapper 902 903 cat >Kyuafile <<EOF 904syntax(2) 905test_suite("integration") 906atf_test_program{name="first"} 907EOF 908 utils_cp_helper simple_all_pass first 909 utils_cp_helper simple_all_pass second 910 911 cat >expout <<EOF 912Results file id is $(utils_results_id) 913Results saved to $(utils_results_file) 914EOF 915 cat >experr <<EOF 916kyua: W: No test cases matched by the filter 'second'. 917EOF 918 atf_check -s exit:1 -o file:expout -e file:experr kyua test second 919} 920 921 922utils_test_case no_test_case_match 923no_test_case_match_body() { 924 utils_install_stable_test_wrapper 925 926 cat >Kyuafile <<EOF 927syntax(2) 928test_suite("integration") 929atf_test_program{name="first"} 930EOF 931 utils_cp_helper simple_all_pass first 932 933 cat >expout <<EOF 934Results file id is $(utils_results_id) 935Results saved to $(utils_results_file) 936EOF 937 cat >experr <<EOF 938kyua: W: No test cases matched by the filter 'first:foobar'. 939EOF 940 atf_check -s exit:1 -o file:expout -e file:experr kyua test first:foobar 941} 942 943 944utils_test_case missing_kyuafile__no_args 945missing_kyuafile__no_args_body() { 946 cat >experr <<EOF 947kyua: E: Load of 'Kyuafile' failed: File 'Kyuafile' not found. 948EOF 949 atf_check -s exit:2 -o empty -e file:experr kyua test 950} 951 952 953utils_test_case missing_kyuafile__test_program 954missing_kyuafile__test_program_body() { 955 mkdir subdir 956 cat >subdir/Kyuafile <<EOF 957syntax(2) 958test_suite("integration") 959atf_test_program{name="unused"} 960EOF 961 utils_cp_helper simple_all_pass subdir/unused 962 963 cat >experr <<EOF 964kyua: E: Load of 'Kyuafile' failed: File 'Kyuafile' not found. 965EOF 966 atf_check -s exit:2 -o empty -e file:experr kyua test subdir/unused 967} 968 969 970utils_test_case missing_kyuafile__subdir 971missing_kyuafile__subdir_body() { 972 mkdir subdir 973 cat >subdir/Kyuafile <<EOF 974syntax(2) 975test_suite("integration") 976atf_test_program{name="unused"} 977EOF 978 utils_cp_helper simple_all_pass subdir/unused 979 980 cat >experr <<EOF 981kyua: E: Load of 'Kyuafile' failed: File 'Kyuafile' not found. 982EOF 983 atf_check -s exit:2 -o empty -e file:experr kyua test subdir 984} 985 986 987utils_test_case bogus_config 988bogus_config_body() { 989 mkdir .kyua 990 cat >"${HOME}/.kyua/kyua.conf" <<EOF 991Hello, world. 992EOF 993 994 file_re='.*\.kyua/kyua.conf' 995 atf_check -s exit:2 -o empty \ 996 -e match:"^kyua: E: Load of '${file_re}' failed: Failed to load Lua" \ 997 kyua test 998} 999 1000 1001utils_test_case bogus_kyuafile 1002bogus_kyuafile_body() { 1003 cat >Kyuafile <<EOF 1004Hello, world. 1005EOF 1006 atf_check -s exit:2 -o empty \ 1007 -e match:"Load of 'Kyuafile' failed: .* Kyuafile:2:" kyua list 1008} 1009 1010 1011utils_test_case bogus_test_program 1012bogus_test_program_body() { 1013 utils_install_stable_test_wrapper 1014 1015 cat >Kyuafile <<EOF 1016syntax(2) 1017test_suite("integration") 1018atf_test_program{name="crash_on_list"} 1019atf_test_program{name="non_executable"} 1020EOF 1021 utils_cp_helper bad_test_program crash_on_list 1022 echo 'I am not executable' >non_executable 1023 1024# CHECK_STYLE_DISABLE 1025 cat >expout <<EOF 1026crash_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] 1027non_executable:__test_cases_list__ -> broken: Permission denied to run test program [S.UUUs] 1028 1029Results file id is $(utils_results_id) 1030Results saved to $(utils_results_file) 1031 10320/2 passed (2 broken, 0 failed, 0 skipped) 1033EOF 1034# CHECK_STYLE_ENABLE 1035 atf_check -s exit:1 -o file:expout -e empty kyua test 1036} 1037 1038 1039utils_test_case missing_test_program 1040missing_test_program_body() { 1041 cat >Kyuafile <<EOF 1042syntax(2) 1043include("subdir/Kyuafile") 1044EOF 1045 mkdir subdir 1046 cat >subdir/Kyuafile <<EOF 1047syntax(2) 1048test_suite("integration") 1049atf_test_program{name="ok"} 1050atf_test_program{name="i-am-missing"} 1051EOF 1052 echo 'I should not be touched because the Kyuafile is bogus' >subdir/ok 1053 1054# CHECK_STYLE_DISABLE 1055 cat >experr <<EOF 1056kyua: E: Load of 'Kyuafile' failed: .*Non-existent test program 'subdir/i-am-missing'. 1057EOF 1058# CHECK_STYLE_ENABLE 1059 atf_check -s exit:2 -o empty -e "match:$(cat experr)" kyua list 1060} 1061 1062 1063atf_init_test_cases() { 1064 atf_add_test_case one_test_program__all_pass 1065 atf_add_test_case one_test_program__some_fail 1066 atf_add_test_case many_test_programs__all_pass 1067 atf_add_test_case many_test_programs__some_fail 1068 atf_add_test_case expect__all_pass 1069 atf_add_test_case expect__some_fail 1070 atf_add_test_case premature_exit 1071 1072 atf_add_test_case no_args 1073 atf_add_test_case one_arg__subdir 1074 atf_add_test_case one_arg__test_case 1075 atf_add_test_case one_arg__test_program 1076 atf_add_test_case one_arg__invalid 1077 atf_add_test_case many_args__ok 1078 atf_add_test_case many_args__invalid 1079 atf_add_test_case many_args__no_match__all 1080 atf_add_test_case many_args__no_match__some 1081 1082 atf_add_test_case args_are_relative 1083 1084 atf_add_test_case only_load_used_test_programs 1085 1086 atf_add_test_case config_behavior 1087 atf_add_test_case config_unprivileged_user 1088 1089 atf_add_test_case store_contents 1090 atf_add_test_case results_file__ok 1091 atf_add_test_case results_file__fail 1092 atf_add_test_case results_file__reuse 1093 1094 atf_add_test_case build_root_flag 1095 1096 atf_add_test_case kyuafile_flag__no_args 1097 atf_add_test_case kyuafile_flag__some_args 1098 1099 atf_add_test_case interrupt 1100 1101 atf_add_test_case exclusive_tests 1102 1103 atf_add_test_case no_test_program_match 1104 atf_add_test_case no_test_case_match 1105 1106 atf_add_test_case missing_kyuafile__no_args 1107 atf_add_test_case missing_kyuafile__test_program 1108 atf_add_test_case missing_kyuafile__subdir 1109 1110 atf_add_test_case bogus_config 1111 atf_add_test_case bogus_kyuafile 1112 atf_add_test_case bogus_test_program 1113 atf_add_test_case missing_test_program 1114} 1115