Path: blob/main/contrib/atf/atf-sh/integration_test.sh
39478 views
# Copyright (c) 2010 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.2425: ${ATF_SH:="__ATF_SH__"}2627create_test_program() {28local output="${1}"; shift29echo "#! ${ATF_SH} ${*}" >"${output}"30cat >>"${output}"31chmod +x "${output}"32}3334atf_test_case no_args35no_args_body()36{37cat >experr <<EOF38atf-sh: ERROR: No test program provided39atf-sh: See atf-sh(1) for usage details.40EOF41atf_check -s eq:1 -o ignore -e file:experr "${ATF_SH}"42}4344atf_test_case missing_script45missing_script_body()46{47cat >experr <<EOF48atf-sh: ERROR: The test program 'non-existent' does not exist49EOF50atf_check -s eq:1 -o ignore -e file:experr "${ATF_SH}" non-existent51}5253atf_test_case arguments54arguments_body()55{56create_test_program tp <<EOF57main() {58echo ">>>\${0}<<<"59while test \${#} -gt 0; do60echo ">>>\${1}<<<"61shift62done63true64}65EOF6667cat >expout <<EOF68>>>./tp<<<69>>> a b <<<70>>>foo<<<71EOF72atf_check -s eq:0 -o file:expout -e empty ./tp ' a b ' foo7374cat >expout <<EOF75>>>tp<<<76>>> hello bye <<<77>>>foo bar<<<78EOF79atf_check -s eq:0 -o file:expout -e empty "${ATF_SH}" tp \80' hello bye ' 'foo bar'81}8283atf_test_case custom_shell__command_line84custom_shell__command_line_body()85{86cat >expout <<EOF87This is the custom shell88This is the test program89EOF9091cat >custom-shell <<EOF92#! /bin/sh93echo "This is the custom shell"94exec /bin/sh "\${@}"95EOF96chmod +x custom-shell9798echo 'main() { echo "This is the test program"; }' | create_test_program tp99atf_check -s eq:0 -o file:expout -e empty "${ATF_SH}" -s ./custom-shell tp100}101102atf_test_case custom_shell__shebang103custom_shell__shebang_body()104{105cat >expout <<EOF106This is the custom shell107This is the test program108EOF109110cat >custom-shell <<EOF111#! /bin/sh112echo "This is the custom shell"113exec /bin/sh "\${@}"114EOF115chmod +x custom-shell116117echo 'main() { echo "This is the test program"; }' | create_test_program \118tp "-s$(pwd)/custom-shell"119atf_check -s eq:0 -o file:expout -e empty ./tp120}121122atf_test_case set_e123set_e_head()124{125atf_set "descr" "Simple test to validate that atf-sh works even when" \126"set -e is enabled"127}128set_e_body()129{130cat >custom-shell <<EOF131#! /bin/sh132exec /bin/sh -e "\${@}"133EOF134chmod +x custom-shell135136cat >tp <<EOF137atf_test_case helper138helper_body() {139atf_skip "reached"140}141atf_init_test_cases() {142atf_add_test_case helper143}144EOF145atf_check -s eq:0 -o match:skipped.*reached \146"${ATF_SH}" -s ./custom-shell tp helper147}148149atf_init_test_cases()150{151atf_add_test_case no_args152atf_add_test_case missing_script153atf_add_test_case arguments154atf_add_test_case custom_shell__command_line155atf_add_test_case custom_shell__shebang156atf_add_test_case set_e157}158159# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4160161162