integration_test.sh revision 275988
141681Sdfr# Copyright (c) 2010 The NetBSD Foundation, Inc. 241681Sdfr# All rights reserved. 341681Sdfr# 441681Sdfr# Redistribution and use in source and binary forms, with or without 541681Sdfr# modification, are permitted provided that the following conditions 641681Sdfr# are met: 741681Sdfr# 1. Redistributions of source code must retain the above copyright 841681Sdfr# notice, this list of conditions and the following disclaimer. 941681Sdfr# 2. Redistributions in binary form must reproduce the above copyright 1041681Sdfr# notice, this list of conditions and the following disclaimer in the 1141681Sdfr# documentation and/or other materials provided with the distribution. 1241681Sdfr# 1341681Sdfr# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 1441681Sdfr# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 1541681Sdfr# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 1641681Sdfr# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1741681Sdfr# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 1841681Sdfr# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1941681Sdfr# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 2041681Sdfr# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2141681Sdfr# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 2241681Sdfr# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 2341681Sdfr# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 2441681Sdfr# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2541681Sdfr 2641681Sdfr: ${ATF_SH:="__ATF_SH__"} 2741681Sdfr 2841681Sdfrcreate_test_program() { 2941681Sdfr local output="${1}"; shift 3041681Sdfr echo "#! ${ATF_SH} ${*}" >"${output}" 3141681Sdfr cat >>"${output}" 3241681Sdfr chmod +x "${output}" 3341681Sdfr} 3441681Sdfr 3541681Sdfratf_test_case no_args 3641681Sdfrno_args_body() 3741681Sdfr{ 3841681Sdfr cat >experr <<EOF 3941681Sdfratf-sh: ERROR: No test program provided 4041681Sdfratf-sh: See atf-sh(1) for usage details. 4141681SdfrEOF 4241681Sdfr atf_check -s eq:1 -o ignore -e file:experr "${ATF_SH}" 4341681Sdfr} 4441681Sdfr 4541681Sdfratf_test_case missing_script 4641681Sdfrmissing_script_body() 4741681Sdfr{ 4841681Sdfr cat >experr <<EOF 4941681Sdfratf-sh: ERROR: The test program 'non-existent' does not exist 5041681SdfrEOF 5141681Sdfr atf_check -s eq:1 -o ignore -e file:experr "${ATF_SH}" non-existent 5241681Sdfr} 5341681Sdfr 5441681Sdfratf_test_case arguments 5541681Sdfrarguments_body() 5641681Sdfr{ 5741681Sdfr create_test_program tp <<EOF 5841681Sdfrmain() { 5941681Sdfr echo ">>>\${0}<<<" 6041681Sdfr while test \${#} -gt 0; do 6141681Sdfr echo ">>>\${1}<<<" 6241681Sdfr shift 6341681Sdfr done 6441681Sdfr true 6541681Sdfr} 6641681SdfrEOF 6750476Speter 6841681Sdfr cat >expout <<EOF 6941681Sdfr>>>./tp<<< 7041681Sdfr>>> a b <<< 7141681Sdfr>>>foo<<< 7241681SdfrEOF 7341681Sdfr atf_check -s eq:0 -o file:expout -e empty ./tp ' a b ' foo 7441681Sdfr 7541681Sdfr cat >expout <<EOF 7641681Sdfr>>>tp<<< 7741681Sdfr>>> hello bye <<< 7841681Sdfr>>>foo bar<<< 7941681SdfrEOF 8041681Sdfr atf_check -s eq:0 -o file:expout -e empty "${ATF_SH}" tp \ 8141681Sdfr ' hello bye ' 'foo bar' 8241681Sdfr} 8341681Sdfr 8441681Sdfratf_test_case custom_shell__command_line 8541681Sdfrcustom_shell__command_line_body() 8641681Sdfr{ 8741681Sdfr cat >expout <<EOF 8841681SdfrThis is the custom shell 8941681SdfrThis is the test program 9041681SdfrEOF 9141681Sdfr 9241681Sdfr cat >custom-shell <<EOF 93#! /bin/sh 94echo "This is the custom shell" 95exec /bin/sh "\${@}" 96EOF 97 chmod +x custom-shell 98 99 echo 'main() { echo "This is the test program"; }' | create_test_program tp 100 atf_check -s eq:0 -o file:expout -e empty "${ATF_SH}" -s ./custom-shell tp 101} 102 103atf_test_case custom_shell__shebang 104custom_shell__shebang_body() 105{ 106 cat >expout <<EOF 107This is the custom shell 108This is the test program 109EOF 110 111 cat >custom-shell <<EOF 112#! /bin/sh 113echo "This is the custom shell" 114exec /bin/sh "\${@}" 115EOF 116 chmod +x custom-shell 117 118 echo 'main() { echo "This is the test program"; }' | create_test_program \ 119 tp "-s$(pwd)/custom-shell" 120 atf_check -s eq:0 -o file:expout -e empty ./tp 121} 122 123atf_test_case set_e 124set_e_head() 125{ 126 atf_set "descr" "Simple test to validate that atf-sh works even when" \ 127 "set -e is enabled" 128} 129set_e_body() 130{ 131 cat >custom-shell <<EOF 132#! /bin/sh 133exec /bin/sh -e "\${@}" 134EOF 135 chmod +x custom-shell 136 137 cat >tp <<EOF 138atf_test_case helper 139helper_body() { 140 atf_skip "reached" 141} 142atf_init_test_cases() { 143 atf_add_test_case helper 144} 145EOF 146 atf_check -s eq:0 -o match:skipped.*reached \ 147 "${ATF_SH}" -s ./custom-shell tp helper 148} 149 150atf_init_test_cases() 151{ 152 atf_add_test_case no_args 153 atf_add_test_case missing_script 154 atf_add_test_case arguments 155 atf_add_test_case custom_shell__command_line 156 atf_add_test_case custom_shell__shebang 157 atf_add_test_case set_e 158} 159 160# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4 161