1*11be35a1SLionel Sambuc# 2*11be35a1SLionel Sambuc# Automated Testing Framework (atf) 3*11be35a1SLionel Sambuc# 4*11be35a1SLionel Sambuc# Copyright (c) 2008 The NetBSD Foundation, Inc. 5*11be35a1SLionel Sambuc# All rights reserved. 6*11be35a1SLionel Sambuc# 7*11be35a1SLionel Sambuc# Redistribution and use in source and binary forms, with or without 8*11be35a1SLionel Sambuc# modification, are permitted provided that the following conditions 9*11be35a1SLionel Sambuc# are met: 10*11be35a1SLionel Sambuc# 1. Redistributions of source code must retain the above copyright 11*11be35a1SLionel Sambuc# notice, this list of conditions and the following disclaimer. 12*11be35a1SLionel Sambuc# 2. Redistributions in binary form must reproduce the above copyright 13*11be35a1SLionel Sambuc# notice, this list of conditions and the following disclaimer in the 14*11be35a1SLionel Sambuc# documentation and/or other materials provided with the distribution. 15*11be35a1SLionel Sambuc# 16*11be35a1SLionel Sambuc# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 17*11be35a1SLionel Sambuc# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 18*11be35a1SLionel Sambuc# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19*11be35a1SLionel Sambuc# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20*11be35a1SLionel Sambuc# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 21*11be35a1SLionel Sambuc# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22*11be35a1SLionel Sambuc# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 23*11be35a1SLionel Sambuc# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24*11be35a1SLionel Sambuc# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25*11be35a1SLionel Sambuc# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26*11be35a1SLionel Sambuc# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27*11be35a1SLionel Sambuc# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28*11be35a1SLionel Sambuc# 29*11be35a1SLionel Sambuc 30*11be35a1SLionel Sambuc# The Atf_Check and Atf-Shell variables are set by atf-sh. 31*11be35a1SLionel Sambuc 32*11be35a1SLionel Sambuch_pass() 33*11be35a1SLionel Sambuc{ 34*11be35a1SLionel Sambuc cmd="$1"; shift 35*11be35a1SLionel Sambuc 36*11be35a1SLionel Sambuc echo "Running [atf-check $*] against [${cmd}]" 37*11be35a1SLionel Sambuc 38*11be35a1SLionel Sambuc cat >script.sh <<EOF 39*11be35a1SLionel Sambuc#! ${Atf_Shell} 40*11be35a1SLionel Sambuc${cmd} 41*11be35a1SLionel SambucEOF 42*11be35a1SLionel Sambuc chmod +x script.sh 43*11be35a1SLionel Sambuc 44*11be35a1SLionel Sambuc if ! ${Atf_Check} "${@}" ./script.sh >tmp; then 45*11be35a1SLionel Sambuc cat tmp 46*11be35a1SLionel Sambuc atf_fail "atf-check failed" 47*11be35a1SLionel Sambuc fi 48*11be35a1SLionel Sambuc} 49*11be35a1SLionel Sambuc 50*11be35a1SLionel Sambuch_fail() 51*11be35a1SLionel Sambuc{ 52*11be35a1SLionel Sambuc cmd="$1"; shift 53*11be35a1SLionel Sambuc 54*11be35a1SLionel Sambuc echo "Running [atf-check $*] against [${cmd}]" 55*11be35a1SLionel Sambuc 56*11be35a1SLionel Sambuc cat >script.sh <<EOF 57*11be35a1SLionel Sambuc#! ${Atf_Shell} 58*11be35a1SLionel Sambuc${cmd} 59*11be35a1SLionel SambucEOF 60*11be35a1SLionel Sambuc chmod +x script.sh 61*11be35a1SLionel Sambuc 62*11be35a1SLionel Sambuc if ${Atf_Check} "${@}" ./script.sh 2>tmp; then 63*11be35a1SLionel Sambuc cat tmp 64*11be35a1SLionel Sambuc atf_fail "atf-check succeeded but should fail" 65*11be35a1SLionel Sambuc fi 66*11be35a1SLionel Sambuc} 67*11be35a1SLionel Sambuc 68*11be35a1SLionel Sambucatf_test_case sflag_eq_ne 69*11be35a1SLionel Sambucsflag_eq_ne_head() 70*11be35a1SLionel Sambuc{ 71*11be35a1SLionel Sambuc atf_set "descr" "Tests for the -s option using the 'eq' and 'ne' qualifiers" 72*11be35a1SLionel Sambuc} 73*11be35a1SLionel Sambucsflag_eq_ne_body() 74*11be35a1SLionel Sambuc{ 75*11be35a1SLionel Sambuc h_pass "true" -s eq:0 76*11be35a1SLionel Sambuc h_pass "false" -s ne:0 77*11be35a1SLionel Sambuc h_pass "exit 255" -s eq:255 78*11be35a1SLionel Sambuc h_pass "exit 0" -s ne:255 79*11be35a1SLionel Sambuc 80*11be35a1SLionel Sambuc h_fail "exit 256" -s eq:256 81*11be35a1SLionel Sambuc h_fail "exit -1" -s eq:-1 82*11be35a1SLionel Sambuc h_fail "true" -s ne:256 83*11be35a1SLionel Sambuc h_fail "true" -s ne:-1 84*11be35a1SLionel Sambuc} 85*11be35a1SLionel Sambuc 86*11be35a1SLionel Sambucatf_test_case sflag_exit 87*11be35a1SLionel Sambucsflag_exit_head() 88*11be35a1SLionel Sambuc{ 89*11be35a1SLionel Sambuc atf_set "descr" "Tests for the -s option using the 'exit' qualifier" 90*11be35a1SLionel Sambuc} 91*11be35a1SLionel Sambucsflag_exit_body() 92*11be35a1SLionel Sambuc{ 93*11be35a1SLionel Sambuc h_pass 'true' -s exit:0 94*11be35a1SLionel Sambuc h_pass 'false' -s not-exit:0 95*11be35a1SLionel Sambuc h_pass 'exit 255' -s exit:255 96*11be35a1SLionel Sambuc h_pass 'exit 0' -s not-exit:255 97*11be35a1SLionel Sambuc 98*11be35a1SLionel Sambuc h_fail 'exit 256' -s exit:256 99*11be35a1SLionel Sambuc h_fail 'exit -1' -s exit:-1 100*11be35a1SLionel Sambuc h_fail 'true' -s not-exit:256 101*11be35a1SLionel Sambuc h_fail 'true' -s not-exit:-1 102*11be35a1SLionel Sambuc 103*11be35a1SLionel Sambuc h_pass 'true' -s exit 104*11be35a1SLionel Sambuc h_pass 'false' -s exit 105*11be35a1SLionel Sambuc if ${Atf_Check} -s exit -x 'kill $$'; then 106*11be35a1SLionel Sambuc atf_fail "Signal detected as clean exit" 107*11be35a1SLionel Sambuc fi 108*11be35a1SLionel Sambuc} 109*11be35a1SLionel Sambuc 110*11be35a1SLionel Sambucatf_test_case sflag_ignore 111*11be35a1SLionel Sambucsflag_ignore_head() 112*11be35a1SLionel Sambuc{ 113*11be35a1SLionel Sambuc atf_set "descr" "Tests for the -s option using the 'ignore' qualifier" 114*11be35a1SLionel Sambuc} 115*11be35a1SLionel Sambucsflag_ignore_body() 116*11be35a1SLionel Sambuc{ 117*11be35a1SLionel Sambuc h_pass 'true' -s ignore 118*11be35a1SLionel Sambuc h_pass 'false' -s ignore 119*11be35a1SLionel Sambuc if ${Atf_Check} -s ignored -x 'kill $$'; then 120*11be35a1SLionel Sambuc atf_fail "Signal not ignored" 121*11be35a1SLionel Sambuc fi 122*11be35a1SLionel Sambuc} 123*11be35a1SLionel Sambuc 124*11be35a1SLionel Sambucatf_test_case sflag_signal 125*11be35a1SLionel Sambucsflag_signal_head() 126*11be35a1SLionel Sambuc{ 127*11be35a1SLionel Sambuc atf_set "descr" "Tests for the -s option using the 'signal' qualifier" 128*11be35a1SLionel Sambuc} 129*11be35a1SLionel Sambucsflag_signal_body() 130*11be35a1SLionel Sambuc{ 131*11be35a1SLionel Sambuc ${Atf_Check} -s signal:hup -x 'kill -1 $$' || atf_fail "Signal not detected" 132*11be35a1SLionel Sambuc ${Atf_Check} -s signal:sighup -x 'kill -1 $$' || atf_fail "Signal not" \ 133*11be35a1SLionel Sambuc "detected" 134*11be35a1SLionel Sambuc ${Atf_Check} -s signal:1 -x 'kill -1 $$' || atf_fail "Signal not detected" 135*11be35a1SLionel Sambuc ${Atf_Check} -s signal -x 'kill -1 $$' || atf_fail "Signal not detected" 136*11be35a1SLionel Sambuc 137*11be35a1SLionel Sambuc ${Atf_Check} -s not-signal:kill -x 'kill -9 $$' && \ 138*11be35a1SLionel Sambuc atf_fail "not-signal:kill matched kill -9" 139*11be35a1SLionel Sambuc ${Atf_Check} -s not-signal:kill -x 'kill -1 $$' || \ 140*11be35a1SLionel Sambuc atf_fail "not-signal:kill did not match kill -1" 141*11be35a1SLionel Sambuc 142*11be35a1SLionel Sambuc h_fail 'true' -s signal 143*11be35a1SLionel Sambuc h_fail 'false' -s signal 144*11be35a1SLionel Sambuc} 145*11be35a1SLionel Sambuc 146*11be35a1SLionel Sambucatf_test_case xflag 147*11be35a1SLionel Sambucxflag_head() 148*11be35a1SLionel Sambuc{ 149*11be35a1SLionel Sambuc atf_set "descr" "Tests for the -x option" 150*11be35a1SLionel Sambuc} 151*11be35a1SLionel Sambucxflag_body() 152*11be35a1SLionel Sambuc{ 153*11be35a1SLionel Sambuc ${Atf_Check} -s ne:0 -o ignore -e ignore "echo foo 2>&1" || \ 154*11be35a1SLionel Sambuc atf_fail "Shell command succeeded without -x" 155*11be35a1SLionel Sambuc 156*11be35a1SLionel Sambuc ${Atf_Check} -e inline:"foo\n" -x "echo foo 1>&2" || \ 157*11be35a1SLionel Sambuc atf_fail "Cannot run command with -x" 158*11be35a1SLionel Sambuc 159*11be35a1SLionel Sambuc ${Atf_Check} -o inline:"foo\n" -x echo foo || \ 160*11be35a1SLionel Sambuc atf_fail "Using -x does not respect all provided arguments" 161*11be35a1SLionel Sambuc} 162*11be35a1SLionel Sambuc 163*11be35a1SLionel Sambucatf_test_case oflag_empty 164*11be35a1SLionel Sambucoflag_empty_head() 165*11be35a1SLionel Sambuc{ 166*11be35a1SLionel Sambuc atf_set "descr" "Tests for the -o option using the 'empty' argument" 167*11be35a1SLionel Sambuc} 168*11be35a1SLionel Sambucoflag_empty_body() 169*11be35a1SLionel Sambuc{ 170*11be35a1SLionel Sambuc h_pass "true" -o empty 171*11be35a1SLionel Sambuc h_fail "echo foo" -o empty 172*11be35a1SLionel Sambuc} 173*11be35a1SLionel Sambuc 174*11be35a1SLionel Sambucatf_test_case oflag_ignore 175*11be35a1SLionel Sambucoflag_ignore_head() 176*11be35a1SLionel Sambuc{ 177*11be35a1SLionel Sambuc atf_set "descr" "Tests for the -o option using the 'ignore' argument" 178*11be35a1SLionel Sambuc} 179*11be35a1SLionel Sambucoflag_ignore_body() 180*11be35a1SLionel Sambuc{ 181*11be35a1SLionel Sambuc h_pass "true" -o ignore 182*11be35a1SLionel Sambuc h_pass "echo foo" -o ignore 183*11be35a1SLionel Sambuc} 184*11be35a1SLionel Sambuc 185*11be35a1SLionel Sambucatf_test_case oflag_file 186*11be35a1SLionel Sambucoflag_file_head() 187*11be35a1SLionel Sambuc{ 188*11be35a1SLionel Sambuc atf_set "descr" "Tests for the -o option using the 'file:' argument" 189*11be35a1SLionel Sambuc} 190*11be35a1SLionel Sambucoflag_file_body() 191*11be35a1SLionel Sambuc{ 192*11be35a1SLionel Sambuc touch empty 193*11be35a1SLionel Sambuc h_pass "true" -o file:empty 194*11be35a1SLionel Sambuc 195*11be35a1SLionel Sambuc echo foo >text 196*11be35a1SLionel Sambuc h_pass "echo foo" -o file:text 197*11be35a1SLionel Sambuc h_fail "echo bar" -o file:text 198*11be35a1SLionel Sambuc 199*11be35a1SLionel Sambuc dd if=/dev/urandom of=bin bs=1k count=10 200*11be35a1SLionel Sambuc h_pass "cat bin" -o file:bin 201*11be35a1SLionel Sambuc} 202*11be35a1SLionel Sambuc 203*11be35a1SLionel Sambucatf_test_case oflag_inline 204*11be35a1SLionel Sambucoflag_inline_head() 205*11be35a1SLionel Sambuc{ 206*11be35a1SLionel Sambuc atf_set "descr" "Tests for the -o option using the 'inline:' argument" 207*11be35a1SLionel Sambuc} 208*11be35a1SLionel Sambucoflag_inline_body() 209*11be35a1SLionel Sambuc{ 210*11be35a1SLionel Sambuc h_pass "true" -o inline: 211*11be35a1SLionel Sambuc h_pass "echo foo bar" -o inline:"foo bar\n" 212*11be35a1SLionel Sambuc h_pass "printf 'foo bar'" -o inline:"foo bar" 213*11be35a1SLionel Sambuc h_pass "printf '\t\n\t\n'" -o inline:"\t\n\t\n" 214*11be35a1SLionel Sambuc # XXX Ugly hack to workaround the lack of \e in FreeBSD. Also, \e doesn't 215*11be35a1SLionel Sambuc # seem to work as expected in Linux. Look for a nicer solution. 216*11be35a1SLionel Sambuc case $(uname) in 217*11be35a1SLionel Sambuc Darwin|FreeBSD|Linux) 218*11be35a1SLionel Sambuc h_pass "printf '\a\b\f\n\r\t\v'" -o inline:"\a\b\f\n\r\t\v" 219*11be35a1SLionel Sambuc ;; 220*11be35a1SLionel Sambuc *) 221*11be35a1SLionel Sambuc h_pass "printf '\a\b\e\f\n\r\t\v'" -o inline:"\a\b\e\f\n\r\t\v" 222*11be35a1SLionel Sambuc ;; 223*11be35a1SLionel Sambuc esac 224*11be35a1SLionel Sambuc h_pass "printf '\011\022\033\012'" -o inline:"\011\022\033\012" 225*11be35a1SLionel Sambuc 226*11be35a1SLionel Sambuc h_fail "echo foo bar" -o inline:"foo bar" 227*11be35a1SLionel Sambuc h_fail "echo -n foo bar" -o inline:"foo bar\n" 228*11be35a1SLionel Sambuc} 229*11be35a1SLionel Sambuc 230*11be35a1SLionel Sambucatf_test_case oflag_match 231*11be35a1SLionel Sambucoflag_match_head() 232*11be35a1SLionel Sambuc{ 233*11be35a1SLionel Sambuc atf_set "descr" "Tests for the -o option using the 'match:' argument" 234*11be35a1SLionel Sambuc} 235*11be35a1SLionel Sambucoflag_match_body() 236*11be35a1SLionel Sambuc{ 237*11be35a1SLionel Sambuc h_pass "printf no-newline" -o "match:^no-newline" 238*11be35a1SLionel Sambuc h_pass "echo line1; echo foo bar" -o "match:^foo" 239*11be35a1SLionel Sambuc h_pass "echo foo bar" -o "match:o b" 240*11be35a1SLionel Sambuc h_fail "echo foo bar" -o "match:baz" 241*11be35a1SLionel Sambuc h_fail "echo foo bar" -o "match:^bar" 242*11be35a1SLionel Sambuc} 243*11be35a1SLionel Sambuc 244*11be35a1SLionel Sambucatf_test_case oflag_save 245*11be35a1SLionel Sambucoflag_save_head() 246*11be35a1SLionel Sambuc{ 247*11be35a1SLionel Sambuc atf_set "descr" "Tests for the -o option using the 'save:' argument" 248*11be35a1SLionel Sambuc} 249*11be35a1SLionel Sambucoflag_save_body() 250*11be35a1SLionel Sambuc{ 251*11be35a1SLionel Sambuc h_pass "echo foo" -o save:out 252*11be35a1SLionel Sambuc echo foo >exp 253*11be35a1SLionel Sambuc cmp -s out exp || atf_fail "Saved output does not match expected results" 254*11be35a1SLionel Sambuc} 255*11be35a1SLionel Sambuc 256*11be35a1SLionel Sambucatf_test_case oflag_multiple 257*11be35a1SLionel Sambucoflag_multiple_head() 258*11be35a1SLionel Sambuc{ 259*11be35a1SLionel Sambuc atf_set "descr" "Tests for multiple occurrences of the -o option" 260*11be35a1SLionel Sambuc} 261*11be35a1SLionel Sambucoflag_multiple_body() 262*11be35a1SLionel Sambuc{ 263*11be35a1SLionel Sambuc h_pass "echo foo bar" -o match:foo -o match:bar 264*11be35a1SLionel Sambuc h_pass "echo foo; echo bar" -o match:foo -o match:bar 265*11be35a1SLionel Sambuc h_fail "echo foo baz" -o match:bar -o match:foo 266*11be35a1SLionel Sambuc h_fail "echo foo; echo baz" -o match:bar -o match:foo 267*11be35a1SLionel Sambuc} 268*11be35a1SLionel Sambuc 269*11be35a1SLionel Sambucatf_test_case oflag_negated 270*11be35a1SLionel Sambucoflag_negated_head() 271*11be35a1SLionel Sambuc{ 272*11be35a1SLionel Sambuc atf_set "descr" "Tests for negated occurrences of the -o option" 273*11be35a1SLionel Sambuc} 274*11be35a1SLionel Sambucoflag_negated_body() 275*11be35a1SLionel Sambuc{ 276*11be35a1SLionel Sambuc h_fail "echo foo" -o empty 277*11be35a1SLionel Sambuc h_pass "echo foo" -o not-empty 278*11be35a1SLionel Sambuc 279*11be35a1SLionel Sambuc h_pass "echo foo bar" -o match:foo 280*11be35a1SLionel Sambuc h_fail "echo foo bar" -o not-match:foo 281*11be35a1SLionel Sambuc} 282*11be35a1SLionel Sambuc 283*11be35a1SLionel Sambucatf_test_case eflag_empty 284*11be35a1SLionel Sambuceflag_empty_head() 285*11be35a1SLionel Sambuc{ 286*11be35a1SLionel Sambuc atf_set "descr" "Tests for the -e option using the 'empty' argument" 287*11be35a1SLionel Sambuc} 288*11be35a1SLionel Sambuceflag_empty_body() 289*11be35a1SLionel Sambuc{ 290*11be35a1SLionel Sambuc h_pass "true 1>&2" -e empty 291*11be35a1SLionel Sambuc h_fail "echo foo 1>&2" -e empty 292*11be35a1SLionel Sambuc} 293*11be35a1SLionel Sambuc 294*11be35a1SLionel Sambucatf_test_case eflag_ignore 295*11be35a1SLionel Sambuceflag_ignore_head() 296*11be35a1SLionel Sambuc{ 297*11be35a1SLionel Sambuc atf_set "descr" "Tests for the -e option using the 'ignore' argument" 298*11be35a1SLionel Sambuc} 299*11be35a1SLionel Sambuceflag_ignore_body() 300*11be35a1SLionel Sambuc{ 301*11be35a1SLionel Sambuc h_pass "true 1>&2" -e ignore 302*11be35a1SLionel Sambuc h_pass "echo foo 1>&2" -e ignore 303*11be35a1SLionel Sambuc} 304*11be35a1SLionel Sambuc 305*11be35a1SLionel Sambucatf_test_case eflag_file 306*11be35a1SLionel Sambuceflag_file_head() 307*11be35a1SLionel Sambuc{ 308*11be35a1SLionel Sambuc atf_set "descr" "Tests for the -e option using the 'file:' argument" 309*11be35a1SLionel Sambuc} 310*11be35a1SLionel Sambuceflag_file_body() 311*11be35a1SLionel Sambuc{ 312*11be35a1SLionel Sambuc touch empty 313*11be35a1SLionel Sambuc h_pass "true 1>&2" -e file:empty 314*11be35a1SLionel Sambuc 315*11be35a1SLionel Sambuc echo foo >text 316*11be35a1SLionel Sambuc h_pass "echo foo 1>&2" -e file:text 317*11be35a1SLionel Sambuc h_fail "echo bar 1>&2" -e file:text 318*11be35a1SLionel Sambuc 319*11be35a1SLionel Sambuc dd if=/dev/urandom of=bin bs=1k count=10 320*11be35a1SLionel Sambuc h_pass "cat bin 1>&2" -e file:bin 321*11be35a1SLionel Sambuc} 322*11be35a1SLionel Sambuc 323*11be35a1SLionel Sambucatf_test_case eflag_inline 324*11be35a1SLionel Sambuceflag_inline_head() 325*11be35a1SLionel Sambuc{ 326*11be35a1SLionel Sambuc atf_set "descr" "Tests for the -e option using the 'inline:' argument" 327*11be35a1SLionel Sambuc} 328*11be35a1SLionel Sambuceflag_inline_body() 329*11be35a1SLionel Sambuc{ 330*11be35a1SLionel Sambuc h_pass "true 1>&2" -e inline: 331*11be35a1SLionel Sambuc h_pass "echo foo bar 1>&2" -e inline:"foo bar\n" 332*11be35a1SLionel Sambuc h_pass "printf 'foo bar' 1>&2" -e inline:"foo bar" 333*11be35a1SLionel Sambuc h_pass "printf '\t\n\t\n' 1>&2" -e inline:"\t\n\t\n" 334*11be35a1SLionel Sambuc # XXX Ugly hack to workaround the lack of \e in FreeBSD. Also, \e doesn't 335*11be35a1SLionel Sambuc # seem to work as expected in Linux. Look for a nicer solution. 336*11be35a1SLionel Sambuc case $(uname) in 337*11be35a1SLionel Sambuc Darwin|FreeBSD|Linux) 338*11be35a1SLionel Sambuc h_pass "printf '\a\b\f\n\r\t\v' 1>&2" -e inline:"\a\b\f\n\r\t\v" 339*11be35a1SLionel Sambuc ;; 340*11be35a1SLionel Sambuc *) 341*11be35a1SLionel Sambuc h_pass "printf '\a\b\e\f\n\r\t\v' 1>&2" -e inline:"\a\b\e\f\n\r\t\v" 342*11be35a1SLionel Sambuc ;; 343*11be35a1SLionel Sambuc esac 344*11be35a1SLionel Sambuc h_pass "printf '\011\022\033\012' 1>&2" -e inline:"\011\022\033\012" 345*11be35a1SLionel Sambuc 346*11be35a1SLionel Sambuc h_fail "echo foo bar 1>&2" -e inline:"foo bar" 347*11be35a1SLionel Sambuc h_fail "echo -n foo bar 1>&2" -e inline:"foo bar\n" 348*11be35a1SLionel Sambuc} 349*11be35a1SLionel Sambuc 350*11be35a1SLionel Sambucatf_test_case eflag_save 351*11be35a1SLionel Sambuceflag_save_head() 352*11be35a1SLionel Sambuc{ 353*11be35a1SLionel Sambuc atf_set "descr" "Tests for the -e option using the 'save:' argument" 354*11be35a1SLionel Sambuc} 355*11be35a1SLionel Sambuceflag_save_body() 356*11be35a1SLionel Sambuc{ 357*11be35a1SLionel Sambuc h_pass "echo foo 1>&2" -e save:out 358*11be35a1SLionel Sambuc echo foo >exp 359*11be35a1SLionel Sambuc cmp -s out exp || atf_fail "Saved output does not match expected results" 360*11be35a1SLionel Sambuc} 361*11be35a1SLionel Sambuc 362*11be35a1SLionel Sambucatf_test_case eflag_match 363*11be35a1SLionel Sambuceflag_match_head() 364*11be35a1SLionel Sambuc{ 365*11be35a1SLionel Sambuc atf_set "descr" "Tests for the -e option using the 'match:' argument" 366*11be35a1SLionel Sambuc} 367*11be35a1SLionel Sambuceflag_match_body() 368*11be35a1SLionel Sambuc{ 369*11be35a1SLionel Sambuc h_pass "printf no-newline 1>&2" -e "match:^no-newline" 370*11be35a1SLionel Sambuc h_pass "echo line1 1>&2; echo foo bar 1>&2" -e "match:^foo" 371*11be35a1SLionel Sambuc h_pass "echo foo bar 1>&2" -e "match:o b" 372*11be35a1SLionel Sambuc h_fail "echo foo bar 1>&2" -e "match:baz" 373*11be35a1SLionel Sambuc h_fail "echo foo bar 1>&2" -e "match:^bar" 374*11be35a1SLionel Sambuc} 375*11be35a1SLionel Sambuc 376*11be35a1SLionel Sambucatf_test_case eflag_multiple 377*11be35a1SLionel Sambuceflag_multiple_head() 378*11be35a1SLionel Sambuc{ 379*11be35a1SLionel Sambuc atf_set "descr" "Tests for multiple occurrences of the -e option" 380*11be35a1SLionel Sambuc} 381*11be35a1SLionel Sambuceflag_multiple_body() 382*11be35a1SLionel Sambuc{ 383*11be35a1SLionel Sambuc h_pass "echo foo bar 1>&2" -e match:foo -e match:bar 384*11be35a1SLionel Sambuc h_pass "echo foo 1>&2; echo bar 1>&2" -e match:foo -e match:bar 385*11be35a1SLionel Sambuc h_fail "echo foo baz 1>&2" -e match:bar -e match:foo 386*11be35a1SLionel Sambuc h_fail "echo foo 1>&2; echo baz 1>&2" -e match:bar -e match:foo 387*11be35a1SLionel Sambuc} 388*11be35a1SLionel Sambuc 389*11be35a1SLionel Sambucatf_test_case eflag_negated 390*11be35a1SLionel Sambuceflag_negated_head() 391*11be35a1SLionel Sambuc{ 392*11be35a1SLionel Sambuc atf_set "descr" "Tests for negated occurrences of the -e option" 393*11be35a1SLionel Sambuc} 394*11be35a1SLionel Sambuceflag_negated_body() 395*11be35a1SLionel Sambuc{ 396*11be35a1SLionel Sambuc h_fail "echo foo 1>&2" -e empty 397*11be35a1SLionel Sambuc h_pass "echo foo 1>&2" -e not-empty 398*11be35a1SLionel Sambuc 399*11be35a1SLionel Sambuc h_pass "echo foo bar 1>&2" -e match:foo 400*11be35a1SLionel Sambuc h_fail "echo foo bar 1>&2" -e not-match:foo 401*11be35a1SLionel Sambuc} 402*11be35a1SLionel Sambuc 403*11be35a1SLionel Sambucatf_test_case stdin 404*11be35a1SLionel Sambucstdin_head() 405*11be35a1SLionel Sambuc{ 406*11be35a1SLionel Sambuc atf_set "descr" "Tests that stdin is preserved" 407*11be35a1SLionel Sambuc} 408*11be35a1SLionel Sambucstdin_body() 409*11be35a1SLionel Sambuc{ 410*11be35a1SLionel Sambuc echo "hello" | ${Atf_Check} -o match:"hello" cat || \ 411*11be35a1SLionel Sambuc atf_fail "atf-check does not seem to respect stdin" 412*11be35a1SLionel Sambuc} 413*11be35a1SLionel Sambuc 414*11be35a1SLionel Sambucatf_test_case invalid_umask 415*11be35a1SLionel Sambucinvalid_umask_head() 416*11be35a1SLionel Sambuc{ 417*11be35a1SLionel Sambuc atf_set "descr" "Tests for a correct error condition if the umask is" \ 418*11be35a1SLionel Sambuc "too restrictive" 419*11be35a1SLionel Sambuc} 420*11be35a1SLionel Sambucinvalid_umask_body() 421*11be35a1SLionel Sambuc{ 422*11be35a1SLionel Sambuc umask 0222 423*11be35a1SLionel Sambuc ${Atf_Check} false 2>stderr && \ 424*11be35a1SLionel Sambuc atf_fail "atf-check returned 0 but it should have failed" 425*11be35a1SLionel Sambuc cat stderr 426*11be35a1SLionel Sambuc grep 'temporary.*current umask.*0222' stderr >/dev/null || \ 427*11be35a1SLionel Sambuc atf_fail "atf-check did not report an error related to the" \ 428*11be35a1SLionel Sambuc "current umask" 429*11be35a1SLionel Sambuc} 430*11be35a1SLionel Sambuc 431*11be35a1SLionel Sambucatf_init_test_cases() 432*11be35a1SLionel Sambuc{ 433*11be35a1SLionel Sambuc atf_add_test_case sflag_eq_ne 434*11be35a1SLionel Sambuc atf_add_test_case sflag_exit 435*11be35a1SLionel Sambuc atf_add_test_case sflag_ignore 436*11be35a1SLionel Sambuc atf_add_test_case sflag_signal 437*11be35a1SLionel Sambuc 438*11be35a1SLionel Sambuc atf_add_test_case xflag 439*11be35a1SLionel Sambuc 440*11be35a1SLionel Sambuc atf_add_test_case oflag_empty 441*11be35a1SLionel Sambuc atf_add_test_case oflag_ignore 442*11be35a1SLionel Sambuc atf_add_test_case oflag_file 443*11be35a1SLionel Sambuc atf_add_test_case oflag_inline 444*11be35a1SLionel Sambuc atf_add_test_case oflag_match 445*11be35a1SLionel Sambuc atf_add_test_case oflag_save 446*11be35a1SLionel Sambuc atf_add_test_case oflag_multiple 447*11be35a1SLionel Sambuc atf_add_test_case oflag_negated 448*11be35a1SLionel Sambuc 449*11be35a1SLionel Sambuc atf_add_test_case eflag_empty 450*11be35a1SLionel Sambuc atf_add_test_case eflag_ignore 451*11be35a1SLionel Sambuc atf_add_test_case eflag_file 452*11be35a1SLionel Sambuc atf_add_test_case eflag_inline 453*11be35a1SLionel Sambuc atf_add_test_case eflag_match 454*11be35a1SLionel Sambuc atf_add_test_case eflag_save 455*11be35a1SLionel Sambuc atf_add_test_case eflag_multiple 456*11be35a1SLionel Sambuc atf_add_test_case eflag_negated 457*11be35a1SLionel Sambuc 458*11be35a1SLionel Sambuc atf_add_test_case stdin 459*11be35a1SLionel Sambuc 460*11be35a1SLionel Sambuc atf_add_test_case invalid_umask 461*11be35a1SLionel Sambuc} 462*11be35a1SLionel Sambuc 463*11be35a1SLionel Sambuc# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4 464