Path: blob/main/contrib/atf/test-programs/expect_test.sh
39481 views
# Copyright (c) 2007 The NetBSD Foundation, Inc.1# All rights reserved.2#3# Redistribution and use in source and binary forms, with or without4# modification, are permitted provided that the following conditions5# are met:6# 1. Redistributions of source code must retain the above copyright7# notice, this list of conditions and the following disclaimer.8# 2. Redistributions in binary form must reproduce the above copyright9# notice, this list of conditions and the following disclaimer in the10# documentation and/or other materials provided with the distribution.11#12# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND13# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,14# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF15# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.16# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY17# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE19# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS20# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER21# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR22# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN23# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.2425check_result() {26file="${1}"; shift2728atf_check -s eq:0 -o match:"${*}" -e empty cat "${file}"29rm "${file}"30}3132atf_test_case expect_pass33expect_pass_body() {34for h in $(get_helpers); do35atf_check -s eq:0 -e ignore "${h}" -r result expect_pass_and_pass36check_result result "passed"3738atf_check -s eq:1 -e ignore "${h}" -r result \39expect_pass_but_fail_requirement40check_result result "failed: Some reason"4142# atf-sh does not support non-fatal failures yet; skip checks for43# such conditions.44case "${h}" in *sh_helpers*) continue ;; esac4546atf_check -s eq:1 -o empty -e match:"Some reason" \47"${h}" -r result expect_pass_but_fail_check48check_result result "failed: 1 checks failed"49done50}5152atf_test_case expect_fail53expect_fail_body() {54for h in $(get_helpers c_helpers cpp_helpers); do55atf_check -s eq:0 "${h}" -r result expect_fail_and_fail_requirement56check_result result "expected_failure: Fail reason: The failure"5758atf_check -s eq:1 -e match:"Expected check failure: Fail first: abc" \59-e not-match:"And fail again" "${h}" -r result expect_fail_but_pass60check_result result "failed: .*expecting a failure"6162# atf-sh does not support non-fatal failures yet; skip checks for63# such conditions.64case "${h}" in *sh_helpers*) continue ;; esac6566atf_check -s eq:0 -e match:"Expected check failure: Fail first: abc" \67-e match:"Expected check failure: And fail again: def" \68"${h}" -r result expect_fail_and_fail_check69check_result result "expected_failure: And fail again: 2 checks" \70"failed as expected"71done7273# atf-sh does not support non-fatal failures yet; skip checks for74# such conditions.75for h in $(get_helpers sh_helpers); do76atf_check -s eq:0 -e ignore "${h}" -r result \77expect_fail_and_fail_requirement78check_result result "expected_failure: Fail reason: The failure"7980atf_check -s eq:1 -e ignore "${h}" -r result expect_fail_but_pass81check_result result "failed: .*expecting a failure"82done83}8485atf_test_case expect_exit86expect_exit_body() {87for h in $(get_helpers); do88atf_check -s eq:0 -e ignore "${h}" -r result expect_exit_any_and_exit89check_result result "expected_exit: Call will exit"9091atf_check -s eq:123 -e ignore "${h}" -r result expect_exit_code_and_exit92check_result result "expected_exit\(123\): Call will exit"9394atf_check -s eq:1 -e ignore "${h}" -r result expect_exit_but_pass95check_result result "failed: .*expected to exit"96done97}9899atf_test_case expect_signal100expect_signal_body() {101for h in $(get_helpers); do102atf_check -s signal:9 -e ignore "${h}" -r result \103expect_signal_any_and_signal104check_result result "expected_signal: Call will signal"105106atf_check -s signal:hup -e ignore "${h}" -r result \107expect_signal_no_and_signal108check_result result "expected_signal\(1\): Call will signal"109110atf_check -s eq:1 -e ignore "${h}" -r result \111expect_signal_but_pass112check_result result "failed: .*termination signal"113done114}115116atf_test_case expect_death117expect_death_body() {118for h in $(get_helpers); do119atf_check -s eq:123 -e ignore "${h}" -r result expect_death_and_exit120check_result result "expected_death: Exit case"121122atf_check -s signal:kill -e ignore "${h}" -r result \123expect_death_and_signal124check_result result "expected_death: Signal case"125126atf_check -s eq:1 -e ignore "${h}" -r result expect_death_but_pass127check_result result "failed: .*terminate abruptly"128done129}130131atf_test_case expect_timeout132expect_timeout_body() {133for h in $(get_helpers); do134atf_check -s eq:1 -e ignore "${h}" -r result expect_timeout_but_pass135check_result result "failed: Test case was expected to hang but it" \136"continued execution"137done138}139140atf_init_test_cases()141{142atf_add_test_case expect_pass143atf_add_test_case expect_fail144atf_add_test_case expect_exit145atf_add_test_case expect_signal146atf_add_test_case expect_death147atf_add_test_case expect_timeout148}149150# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4151152153