integration_test.sh (261897) | integration_test.sh (273929) |
---|---|
1# 2# Automated Testing Framework (atf) 3# | |
4# Copyright (c) 2010 The NetBSD Foundation, Inc. 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions 9# are met: 10# 1. Redistributions of source code must retain the above copyright 11# notice, this list of conditions and the following disclaimer. --- 8 unchanged lines hidden (view full) --- 20# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 21# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 23# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 1# Copyright (c) 2010 The NetBSD Foundation, Inc. 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 6# are met: 7# 1. Redistributions of source code must retain the above copyright 8# notice, this list of conditions and the following disclaimer. --- 8 unchanged lines hidden (view full) --- 17# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 18# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 20# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 22# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 24# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28# | |
29 | 25 |
26: ${ATF_SH:="__ATF_SH__"} 27 |
|
30create_test_program() { | 28create_test_program() { |
31 echo '#! /usr/bin/env atf-sh' >"${1}" 32 cat >>"${1}" 33 chmod +x "${1}" | 29 local output="${1}"; shift 30 echo "#! ${ATF_SH} ${*}" >"${output}" 31 cat >>"${output}" 32 chmod +x "${output}" |
34} 35 36atf_test_case no_args 37no_args_body() 38{ 39 cat >experr <<EOF 40atf-sh: ERROR: No test program provided 41atf-sh: See atf-sh(1) for usage details. 42EOF | 33} 34 35atf_test_case no_args 36no_args_body() 37{ 38 cat >experr <<EOF 39atf-sh: ERROR: No test program provided 40atf-sh: See atf-sh(1) for usage details. 41EOF |
43 atf_check -s eq:1 -o ignore -e file:experr atf-sh | 42 atf_check -s eq:1 -o ignore -e file:experr "${ATF_SH}" |
44} 45 46atf_test_case missing_script 47missing_script_body() 48{ 49 cat >experr <<EOF 50atf-sh: ERROR: The test program 'non-existent' does not exist 51EOF | 43} 44 45atf_test_case missing_script 46missing_script_body() 47{ 48 cat >experr <<EOF 49atf-sh: ERROR: The test program 'non-existent' does not exist 50EOF |
52 atf_check -s eq:1 -o ignore -e file:experr atf-sh non-existent | 51 atf_check -s eq:1 -o ignore -e file:experr "${ATF_SH}" non-existent |
53} 54 55atf_test_case arguments 56arguments_body() 57{ 58 create_test_program tp <<EOF 59main() { 60 echo ">>>\${0}<<<" --- 12 unchanged lines hidden (view full) --- 73EOF 74 atf_check -s eq:0 -o file:expout -e empty ./tp ' a b ' foo 75 76 cat >expout <<EOF 77>>>tp<<< 78>>> hello bye <<< 79>>>foo bar<<< 80EOF | 52} 53 54atf_test_case arguments 55arguments_body() 56{ 57 create_test_program tp <<EOF 58main() { 59 echo ">>>\${0}<<<" --- 12 unchanged lines hidden (view full) --- 72EOF 73 atf_check -s eq:0 -o file:expout -e empty ./tp ' a b ' foo 74 75 cat >expout <<EOF 76>>>tp<<< 77>>> hello bye <<< 78>>>foo bar<<< 79EOF |
81 atf_check -s eq:0 -o file:expout -e empty atf-sh tp ' hello bye ' 'foo bar' | 80 atf_check -s eq:0 -o file:expout -e empty "${ATF_SH}" tp \ 81 ' hello bye ' 'foo bar' |
82} 83 | 82} 83 |
84atf_test_case custom_shell__command_line 85custom_shell__command_line_body() 86{ 87 cat >expout <<EOF 88This is the custom shell 89This is the test program 90EOF 91 92 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 |
|
84atf_init_test_cases() 85{ 86 atf_add_test_case no_args 87 atf_add_test_case missing_script 88 atf_add_test_case arguments | 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 |
|
89} 90 91# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4 | 158} 159 160# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4 |