Importing NetBSD "Kyua" test framework

To do so, a few dependencies have been imported:

 * external/bsd/lutok
 * external/mit/lua
 * external/public-domain/sqlite
 * external/public-domain/xz

The Kyua framework is the new generation of ATF (Automated Test
Framework), it is composed of:

 * external/bsd/atf
 * external/bsd/kyua-atf-compat
 * external/bsd/kyua-cli
 * external/bsd/kyua-tester
 * tests

Kyua/ATF being written in C++, it depends on libstdc++ which is
provided by GCC. As this is not part of the sources, Kyua is only
compiled when the native GCC utils are installed.

To install Kyua do the following:

 * In a cross-build enviromnent, add the following to the build.sh
   commandline: -V MKBINUTILS=yes -V MKGCCCMDS=yes

WARNING:
  At this point the import is still experimental, and not supported
  on native builds (a.k.a make build).

Change-Id: I26aee23c5bbd2d64adcb7c1beb98fe0d479d7ada
This commit is contained in:
2013-07-23 20:43:41 +02:00
committed by Gerrit Code Review
parent 003ff52ebb
commit 11be35a165
2893 changed files with 502052 additions and 2630 deletions
+18
View File
@@ -0,0 +1,18 @@
# $NetBSD: Makefile,v 1.2 2012/06/11 18:32:59 njoly Exp $
.include <bsd.own.mk>
TESTSDIR= ${TESTSBASE}/bin/sh
TESTS_SH= t_compexit
TESTS_SH+= t_exit
TESTS_SH+= t_expand
TESTS_SH+= t_evaltested
TESTS_SH+= t_fsplit
TESTS_SH+= t_here
TESTS_SH+= t_set_e
TESTS_SH+= t_ulimit
TESTS_SH+= t_varquote
TESTS_SH+= t_wait
.include <bsd.test.mk>
+63
View File
@@ -0,0 +1,63 @@
# $NetBSD: t_compexit.sh,v 1.1 2012/03/17 16:33:11 jruoho Exp $
#
# Copyright (c) 2007 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The standard
# http://www.opengroup.org/onlinepubs/007904975/utilities/set.html
# says:
#
# -e
#
# When this option is on, if a simple command fails for any of the
# reasons listed in Consequences of Shell Errors or returns an exit
# status value >0, and is not part of the compound list following a
# while, until, or if keyword, and is not a part of an AND or OR list,
# and is not a pipeline preceded by the ! reserved word, then the shell
# shall immediately exit.
crud() {
set -e
for x in a
do
BAR="foo"
false && echo true
echo mumble
done
}
atf_test_case set_e
set_e_head() {
atf_set "descr" "Tests that 'set -e' turns on error detection" \
"and that it behaves as defined by the standard"
}
set_e_body() {
foo=`crud`
atf_check_equal 'x$foo' 'xmumble'
}
atf_init_test_cases() {
atf_add_test_case set_e
}
+60
View File
@@ -0,0 +1,60 @@
# $NetBSD: t_evaltested.sh,v 1.1 2012/03/17 16:33:11 jruoho Exp $
#
# Copyright (c) 2011 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
atf_test_case evaltested
evaltested_head() {
atf_set "descr" "Tests that eval in a tested context does not exit"
}
evaltested_body() {
set -e
cat > helper.sh << EOF
set -e
if eval false
then
echo "'eval false' returned true"
exit 1
fi
echo "passed"
exit 0
EOF
output="$(/bin/sh helper.sh)"
[ $? = 0 ] && return
if [ -n "$output" ]
then
atf_fail "$output"
else
atf_fail "'eval false' exited from a tested context"
fi
}
atf_init_test_cases() {
atf_add_test_case evaltested
}
+105
View File
@@ -0,0 +1,105 @@
# $NetBSD: t_exit.sh,v 1.3 2012/04/13 06:12:32 jruoho Exp $
#
# Copyright (c) 2007 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
crud() {
test yes = no
cat <<EOF
$?
EOF
}
atf_test_case background
background_head() {
atf_set "descr" "Tests that sh(1) sets '$?' properly when running " \
"a command in the background (PR bin/46327)"
}
background_body() {
atf_check -s exit:0 -o ignore -e ignore -x "true; true & echo $?"
atf_check -s exit:0 -o ignore -e ignore -x "false; true & echo $?"
}
atf_test_case function
function_head() {
atf_set "descr" "Tests that \$? is correctly updated inside" \
"a function"
}
function_body() {
foo=`crud`
atf_check_equal 'x$foo' 'x1'
}
atf_test_case readout
readout_head() {
atf_set "descr" "Tests that \$? is correctly updated in a" \
"compound expression"
}
readout_body() {
atf_check_equal '$( true && ! true | false; echo $? )' '0'
}
atf_test_case trap_subshell
trap_subshell_head() {
atf_set "descr" "Tests that the trap statement in a subshell" \
"works when the subshell exits"
}
trap_subshell_body() {
atf_check -s eq:0 -o inline:'exiting\n' -x \
'( trap "echo exiting" EXIT; /usr/bin/true )'
}
atf_test_case trap_zero__implicit_exit
trap_zero__implicit_exit_body() {
# PR bin/6764: sh works but ksh does not"
echo '( trap "echo exiting" 0 )' >helper.sh
atf_check -s eq:0 -o match:exiting -e empty /bin/sh helper.sh
atf_check -s eq:0 -o match:exiting -e empty /bin/ksh helper.sh
}
atf_test_case trap_zero__explicit_exit
trap_zero__explicit_exit_body() {
echo '( trap "echo exiting" 0; exit )' >helper.sh
atf_check -s eq:0 -o match:exiting -e empty /bin/sh helper.sh
atf_check -s eq:0 -o match:exiting -e empty /bin/ksh helper.sh
}
atf_test_case trap_zero__explicit_return
trap_zero__explicit_return_body() {
echo '( trap "echo exiting" 0; return )' >helper.sh
atf_check -s eq:0 -o match:exiting -e empty /bin/sh helper.sh
atf_check -s eq:0 -o match:exiting -e empty /bin/ksh helper.sh
}
atf_init_test_cases() {
atf_add_test_case background
atf_add_test_case function
atf_add_test_case readout
atf_add_test_case trap_subshell
atf_add_test_case trap_zero__implicit_exit
atf_add_test_case trap_zero__explicit_exit
atf_add_test_case trap_zero__explicit_return
}
+128
View File
@@ -0,0 +1,128 @@
# $NetBSD: t_expand.sh,v 1.1 2012/03/17 16:33:11 jruoho Exp $
#
# Copyright (c) 2007, 2009 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#
# This file tests the functions in expand.c.
#
delim_argv() {
str=
while [ $# -gt 0 ]; do
if [ -z "${str}" ]; then
str=">$1<"
else
str="${str} >$1<"
fi
shift
done
echo ${str}
}
atf_test_case dollar_at
dollar_at_head() {
atf_set "descr" "Somewhere between 2.0.2 and 3.0 the expansion" \
"of the \$@ variable had been broken. Check for" \
"this behavior."
}
dollar_at_body() {
# This one should work everywhere.
got=`echo "" "" | sed 's,$,EOL,'`
atf_check_equal ' EOL' '$got'
# This code triggered the bug.
set -- "" ""
got=`echo "$@" | sed 's,$,EOL,'`
atf_check_equal ' EOL' '$got'
set -- -
shift
n_arg() { echo $#; }
n_args=`n_arg "$@"`
atf_check_equal '0' '$n_args'
}
atf_test_case dollar_at_with_text
dollar_at_with_text_head() {
atf_set "descr" "Test \$@ expansion when it is surrounded by text" \
"within the quotes. PR bin/33956."
}
dollar_at_with_text_body() {
set --
atf_check_equal '' "$(delim_argv "$@")"
atf_check_equal '>foobar<' "$(delim_argv "foo$@bar")"
atf_check_equal '>foo bar<' "$(delim_argv "foo $@ bar")"
set -- a b c
atf_check_equal '>a< >b< >c<' "$(delim_argv "$@")"
atf_check_equal '>fooa< >b< >cbar<' "$(delim_argv "foo$@bar")"
atf_check_equal '>foo a< >b< >c bar<' "$(delim_argv "foo $@ bar")"
}
atf_test_case strip
strip_head() {
atf_set "descr" "Checks that the %% operator works and strips" \
"the contents of a variable from the given point" \
"to the end"
}
strip_body() {
line='#define bindir "/usr/bin" /* comment */'
stripped='#define bindir "/usr/bin" '
atf_expect_fail "PR bin/43469"
atf_check_equal '$stripped' '${line%%/\**}'
}
atf_test_case varpattern_backslashes
varpattern_backslashes_head() {
atf_set "descr" "Tests that protecting wildcards with backslashes" \
"works in variable patterns."
}
varpattern_backslashes_body() {
line='/foo/bar/*/baz'
stripped='/foo/bar/'
atf_check_equal $stripped ${line%%\**}
}
atf_test_case arithmetic
arithmetic_head() {
atf_set "descr" "POSIX requires shell arithmetic to use signed" \
"long or a wider type. We use intmax_t, so at" \
"least 64 bits should be available. Make sure" \
"this is true."
}
arithmetic_body() {
atf_check_equal '3' '$((1 + 2))'
atf_check_equal '2147483647' '$((0x7fffffff))'
atf_check_equal '9223372036854775807' '$(((1 << 63) - 1))'
}
atf_init_test_cases() {
atf_add_test_case dollar_at
atf_add_test_case dollar_at_with_text
atf_add_test_case strip
atf_add_test_case varpattern_backslashes
atf_add_test_case arithmetic
}
+186
View File
@@ -0,0 +1,186 @@
# $NetBSD: t_fsplit.sh,v 1.1 2012/03/17 16:33:11 jruoho Exp $
#
# Copyright (c) 2007 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The standard
# http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html
# explains (section 2.6) that Field splitting should be performed on the
# result of variable expansions.
# In particular this means that in ${x-word}, 'word' must be expanded as if
# the "${x-" and "}" were absent from the input line.
#
# So: sh -c 'set ${x-a b c}; echo $#' should give 3.
#
nl='
'
check()
{
result="$(eval $1)"
# Remove newlines
oifs="$IFS"
IFS="$nl"
result="$(echo $result)"
IFS="$oifs"
if [ "$2" != "$result" ]
then
atf_fail "expected [$2], found [$result]"
fi
}
atf_test_case for
for_head() {
atf_set "descr" "Checks field splitting in for loops"
}
for_body() {
unset x
# Since I managed to break this, leave the test in
check 'for f in $x; do echo x${f}y; done' ''
}
atf_test_case default_val
default_val_head() {
atf_set "descr" "Checks field splitting in variable default values"
}
default_val_body() {
unset x
# Check that IFS is applied to text from ${x-...} unless it is inside
# any set of "..."
check 'set ${x-a b c}; echo $#' 3
check 'for i in ${x-a b c}; do echo "z${i}z"; done' 'zaz zbz zcz'
check 'for i in ${x-"a b" c}; do echo "z${i}z"; done' 'za bz zcz'
check 'for i in ${x-"a ${x-b c}" d}; do echo "z${i}z"; done' 'za b cz zdz'
check 'for i in ${x-"a ${x-"b c"}" d}; do echo "z${i}z"; done' 'za b cz zdz'
check 'for i in ${x-a ${x-"b c"} d}; do echo "z${i}z"; done' 'zaz zb cz zdz'
check 'for i in ${x-a ${x-b c} d}; do echo "z${i}z"; done' 'zaz zbz zcz zdz'
}
atf_test_case ifs_alpha
ifs_alpha_head() {
atf_set "descr" "Checks that field splitting works with alphabetic" \
"characters"
}
ifs_alpha_body() {
unset x
# repeat with an alphabetic in IFS
check 'IFS=q; set ${x-aqbqc}; echo $#' 3
check 'IFS=q; for i in ${x-aqbqc}; do echo "z${i}z"; done' 'zaz zbz zcz'
check 'IFS=q; for i in ${x-"aqb"qc}; do echo "z${i}z"; done' 'zaqbz zcz'
check 'IFS=q; for i in ${x-"aq${x-bqc}"qd}; do echo "z${i}z"; done' 'zaqbqcz zdz'
check 'IFS=q; for i in ${x-"aq${x-"bqc"}"qd}; do echo "z${i}z"; done' 'zaqbqcz zdz'
check 'IFS=q; for i in ${x-aq${x-"bqc"}qd}; do echo "z${i}z"; done' 'zaz zbqcz zdz'
}
atf_test_case quote
quote_head() {
atf_set "descr" "Checks that field splitting works with multi-word" \
"fields"
}
quote_body() {
unset x
# Some quote propagation checks
check 'set "${x-a b c}"; echo $#' 1
check 'set "${x-"a b" c}"; echo $1' 'a b c'
check 'for i in "${x-a b c}"; do echo "z${i}z"; done' 'za b cz'
}
atf_test_case dollar_at
dollar_at_head() {
atf_set "descr" "Checks that field splitting works when expanding" \
"\$@"
}
dollar_at_body() {
unset x
# Check we get "$@" right
check 'set ""; for i; do echo "z${i}z"; done' 'zz'
check 'set ""; for i in "$@"; do echo "z${i}z"; done' 'zz'
check 'set "" ""; for i; do echo "z${i}z"; done' 'zz zz'
check 'set "" ""; for i in "$@"; do echo "z${i}z"; done' 'zz zz'
check 'set "" ""; for i in $@; do echo "z${i}z"; done' ''
check 'set "a b" c; for i; do echo "z${i}z"; done' 'za bz zcz'
check 'set "a b" c; for i in "$@"; do echo "z${i}z"; done' 'za bz zcz'
check 'set "a b" c; for i in $@; do echo "z${i}z"; done' 'zaz zbz zcz'
check 'set " a b " c; for i in "$@"; do echo "z${i}z"; done' 'z a b z zcz'
check 'set --; for i in x"$@"x; do echo "z${i}z"; done' 'zxxz'
check 'set a; for i in x"$@"x; do echo "z${i}z"; done' 'zxaxz'
check 'set a b; for i in x"$@"x; do echo "z${i}z"; done' 'zxaz zbxz'
}
atf_test_case ifs
ifs_head() {
atf_set "descr" "Checks that IFS correctly configures field" \
"splitting behavior"
}
ifs_body() {
unset x
# Some IFS tests
check 't="-- "; IFS=" "; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '0'
check 't=" x"; IFS=" x"; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '1'
check 't=" x "; IFS=" x"; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '1'
check 't=axb; IFS="x"; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '2 a:b'
check 't="a x b"; IFS="x"; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '2 a : b'
check 't="a xx b"; IFS="x"; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '3 a :: b'
check 't="a xx b"; IFS="x "; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '3 a::b'
# A recent 'clarification' means that a single trailing IFS non-whitespace
# doesn't generate an empty parameter
check 't="xax"; IFS="x"; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '2 :a'
check 't="xax "; IFS="x "; set $t; IFS=":"; r="$*"; IFS=; echo $# $r' '2 :a'
# Verify that IFS isn't being applied where it shouldn't be.
check 'IFS="x"; set axb; IFS=":"; r="$*"; IFS=; echo $# $r' '1 axb'
}
atf_test_case var_length
var_length_head() {
atf_set "descr" "Checks that field splitting works when expanding" \
"a variable's length"
}
var_length_body() {
unset x
# Check that we apply IFS to ${#var}
long=12345678123456781234567812345678
long=$long$long$long$long
check 'echo ${#long}; IFS=2; echo ${#long}; set 1 ${#long};echo $#' '128 1 8 3'
check 'IFS=2; set ${x-${#long}}; IFS=" "; echo $* $#' '1 8 2'
check 'IFS=2; set ${x-"${#long}"}; IFS=" "; echo $* $#' '128 1'
}
atf_init_test_cases() {
atf_add_test_case for
atf_add_test_case default_val
atf_add_test_case ifs_alpha
atf_add_test_case quote
atf_add_test_case dollar_at
atf_add_test_case ifs
atf_add_test_case var_length
}
+73
View File
@@ -0,0 +1,73 @@
# $NetBSD: t_here.sh,v 1.1 2012/03/17 16:33:11 jruoho Exp $
#
# Copyright (c) 2007 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
nl='
'
check()
{
SVIFS="$IFS"
result="$(eval $1)"
# Remove newlines
oifs="$IFS"
IFS="$nl"
result="$(echo $result)"
IFS="$oifs"
if [ "$2" != "$result" ]
then
atf_fail "expected [$2], found [$result]"
fi
IFS="$SVIFS"
}
atf_test_case all
all_head() {
atf_set "descr" "Basic tests for here documents"
}
all_body() {
y=x
IFS=
check 'x=`cat <<EOF'$nl'text'${nl}EOF$nl'`; echo $x' 'text'
check 'x=`cat <<\EOF'$nl'text'${nl}EOF$nl'`; echo $x' 'text'
check 'x=`cat <<EOF'$nl'te${y}t'${nl}EOF$nl'`; echo $x' 'text'
check 'x=`cat <<\EOF'$nl'te${y}t'${nl}EOF$nl'`; echo $x' 'te${y}t'
check 'x=`cat <<"EOF"'$nl'te${y}t'${nl}EOF$nl'`; echo $x' 'te${y}t'
check 'x=`cat <<'"'EOF'"$nl'te${y}t'${nl}EOF$nl'`; echo $x' 'te${y}t'
check 'x=`cat <<EOF'$nl'te'"'"'xt'${nl}EOF$nl'`; echo $x' 'te'"'"'xt'
check 'x=`cat <<\EOF'$nl'te'"'"'xt'${nl}EOF$nl'`; echo $x' 'te'"'"'xt'
check 'x=`cat <<"EOF"'$nl'te'"'"'xt'${nl}EOF$nl'`; echo $x' 'te'"'"'xt'
check 'x=`cat <<EOF'$nl'te'"'"'${y}t'${nl}EOF$nl'`; echo $x' 'te'"'"'xt'
check 'x=`cat <<EOF'$nl'te'"''"'${y}t'${nl}EOF$nl'`; echo $x' 'te'"''"'xt'
}
atf_init_test_cases() {
atf_add_test_case all
}
+289
View File
@@ -0,0 +1,289 @@
# $NetBSD: t_set_e.sh,v 1.1 2012/03/17 16:33:11 jruoho Exp $
#
# Copyright (c) 2007 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# references:
# http://www.opengroup.org/onlinepubs/009695399/utilities/set.html
# http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html
# the implementation of "sh" to test
: ${TEST_SH:="sh"}
failwith()
{
case "$SH_FAILS" in
"") SH_FAILS=`echo "$1"`;;
*) SH_FAILS="$SH_FAILS"`echo; echo "$1"`;;
esac
}
check1()
{
#echo "$TEST_SH -c $1"
result=`$TEST_SH -c "$1" 2>/dev/null | tr '\n' ' ' | sed 's/ *$//'`
if [ "$result" != "$2" ]; then
MSG=`printf "%-56s %-8s %s" "$3" "$result" "$2"`
failwith "$MSG"
failcount=`expr $failcount + 1`
fi
count=`expr $count + 1`
}
# direct check: try the given expression.
dcheck()
{
check1 "$1" "$2" "$1"
}
# eval check: indirect through eval.
# as of this writing, this changes the behavior pretty drastically and
# is thus important to test. (PR bin/29861)
echeck()
{
check1 'eval '"'($1)'" "$2" "eval '($1)'"
}
atf_test_case all
all_head() {
atf_set "descr" "Tests that 'set -e' works correctly"
}
all_body() {
count=0
failcount=0
# make sure exiting from a subshell behaves as expected
dcheck '(set -e; exit 1; echo ERR$?); echo OK$?' 'OK1'
echeck '(set -e; exit 1; echo ERR$?); echo OK$?' 'OK1'
# first, check basic functioning.
# The ERR shouldn't print; the result of the () should be 1.
# Henceforth we'll assume that we don't need to check $?.
dcheck '(set -e; false; echo ERR$?); echo -n OK$?' 'OK1'
echeck '(set -e; false; echo ERR$?); echo -n OK$?' 'OK1'
# these cases should be equivalent to the preceding.
dcheck '(set -e; /nonexistent; echo ERR); echo OK' 'OK'
echeck '(set -e; /nonexistent; echo ERR); echo OK' 'OK'
dcheck '(set -e; nonexistent-program-on-path; echo ERR); echo OK' 'OK'
echeck '(set -e; nonexistent-program-on-path; echo ERR); echo OK' 'OK'
dcheck 'f() { false; }; (set -e; f; echo ERR); echo OK' 'OK'
echeck 'f() { false; }; (set -e; f; echo ERR); echo OK' 'OK'
dcheck 'f() { return 1; }; (set -e; f; echo ERR); echo OK' 'OK'
echeck 'f() { return 1; }; (set -e; f; echo ERR); echo OK' 'OK'
# but! with set -e, the false should cause an *immediate* exit.
# The return form should not, as such, but there's no way to
# distinguish it.
dcheck 'f() { false; echo ERR; }; (set -e; f); echo OK' 'OK'
echeck 'f() { false; echo ERR; }; (set -e; f); echo OK' 'OK'
# set is not scoped, so these should not exit at all.
dcheck 'f() { set +e; false; echo OK; }; (set -e; f); echo OK' 'OK OK'
echeck 'f() { set +e; false; echo OK; }; (set -e; f); echo OK' 'OK OK'
# according to the standard, only failing *simple* commands
# cause an exit under -e. () is not a simple command.
# Correct (per POSIX):
#dcheck '(set -e; (set +e; false; echo OK; false); echo OK)' 'OK OK'
#echeck '(set -e; (set +e; false; echo OK; false); echo OK)' 'OK OK'
# Wrong current behavior:
dcheck '(set -e; (set +e; false; echo OK; false); echo OK)' 'OK'
echeck '(set -e; (set +e; false; echo OK; false); echo OK)' 'OK'
# make sure an inner nested shell does exit though.
dcheck '(set -e; (false; echo ERR)); echo OK' 'OK'
# The left hand side of an || or && is explicitly tested and
# thus should not cause an exit. Furthermore, because a || or
# && expression is not a simple command, there should be no
# exit even if the overall result is false.
dcheck '(set -e; false || true; echo OK); echo OK' 'OK OK'
echeck '(set -e; false || true; echo OK); echo OK' 'OK OK'
dcheck '(set -e; false && true; echo OK); echo OK' 'OK OK'
echeck '(set -e; false && true; echo OK); echo OK' 'OK OK'
# However, the right hand side is not tested, so a failure
# there *should* cause an exit, regardless of whether it
# appears inside a non-simple command.
#
# Note that in at least one place the standard does not
# distinguish between the left and right hand sides of
# logical operators. It is possible that for strict
# compliance these need to not exit; however, if so that
# should probably be limited to when some strict-posix setting
# is in effect and tested accordingly.
#
dcheck '(set -e; false || false; echo ERR); echo OK' 'OK'
dcheck '(set -e; true && false; echo ERR); echo OK' 'OK'
echeck '(set -e; false || false; echo ERR); echo OK' 'OK'
echeck '(set -e; true && false; echo ERR); echo OK' 'OK'
# correct:
#dcheck '(set -e; false && false; echo ERR); echo OK' 'OK'
#echeck '(set -e; false && false; echo ERR); echo OK' 'OK'
# wrong current behavior:
dcheck '(set -e; false && false; echo ERR); echo OK' 'ERR OK'
echeck '(set -e; false && false; echo ERR); echo OK' 'ERR OK'
# A failure that is not reached because of short-circuit
# evaluation should not cause an exit, however.
dcheck '(set -e; true || false; echo OK); echo OK' 'OK OK'
echeck '(set -e; true || false; echo OK); echo OK' 'OK OK'
# For completeness, test the other two combinations.
dcheck '(set -e; true || true; echo OK); echo OK' 'OK OK'
dcheck '(set -e; true && true; echo OK); echo OK' 'OK OK'
echeck '(set -e; true || true; echo OK); echo OK' 'OK OK'
echeck '(set -e; true && true; echo OK); echo OK' 'OK OK'
# likewise, none of these should exit.
dcheck '(set -e; while false; do :; done; echo OK); echo OK' 'OK OK'
dcheck '(set -e; if false; then :; fi; echo OK); echo OK' 'OK OK'
# problematic :-)
#dcheck '(set -e; until false; do :; done; echo OK); echo OK' 'OK OK'
dcheck '(set -e; until [ "$t" = 1 ]; do t=1; done; echo OK); echo OK' \
'OK OK'
echeck '(set -e; while false; do :; done; echo OK); echo OK' 'OK OK'
echeck '(set -e; if false; then :; fi; echo OK); echo OK' 'OK OK'
echeck '(set -e; until [ "$t" = 1 ]; do t=1; done; echo OK); echo OK' \
'OK OK'
# the bang operator tests its argument and thus the argument
# should not cause an exit. it is also not a simple command (I
# believe) so it also shouldn't exit even if it yields a false
# result.
dcheck '(set -e; ! false; echo OK); echo OK' 'OK OK'
dcheck '(set -e; ! true; echo OK); echo OK' 'OK OK'
echeck '(set -e; ! false; echo OK); echo OK' 'OK OK'
echeck '(set -e; ! true; echo OK); echo OK' 'OK OK'
# combined case with () and &&; the inner expression is false
# but does not itself exit, and the () should not cause an
# exit even when failing.
# correct:
#dcheck '(set -e; (false && true); echo OK); echo OK' 'OK OK'
#echeck '(set -e; (false && true); echo OK); echo OK' 'OK OK'
# wrong current behavior:
dcheck '(set -e; (false && true); echo OK); echo OK' 'OK'
echeck '(set -e; (false && true); echo OK); echo OK' 'OK'
# pipelines. only the right-hand end is significant.
dcheck '(set -e; false | true; echo OK); echo OK' 'OK OK'
echeck '(set -e; false | true; echo OK); echo OK' 'OK OK'
dcheck '(set -e; true | false; echo ERR); echo OK' 'OK'
echeck '(set -e; true | false; echo ERR); echo OK' 'OK'
dcheck '(set -e; while true | false; do :; done; echo OK); echo OK' \
'OK OK'
dcheck '(set -e; if true | false; then :; fi; echo OK); echo OK' \
'OK OK'
# According to dsl@ in PR bin/32282, () is not defined as a
# subshell, only as a grouping operator [and a scope, I guess]
# so the nested false ought to cause the whole shell to exit,
# not just the subshell. dholland@ would like to see C&V,
# because that seems like a bad idea. (Among other things, it
# would break all the above test logic, which relies on being
# able to isolate set -e behavior inside ().) However, I'm
# going to put these tests here to make sure the issue gets
# dealt with sometime.
#
# XXX: the second set has been disabled in the name of making
# all tests "pass".
# 1. error if the whole shell exits (current behavior)
dcheck 'echo OK; (set -e; false); echo OK' 'OK OK'
echeck 'echo OK; (set -e; false); echo OK' 'OK OK'
# 2. error if the whole shell does not exit (dsl's suggested behavior)
#dcheck 'echo OK; (set -e; false); echo ERR' 'OK'
#echeck 'echo OK; (set -e; false); echo ERR' 'OK'
# The current behavior of the shell is that it exits out as
# far as -e is set and then stops. This is probably a
# consequence of it handling () wrong, but it's a somewhat
# curious compromise position between 1. and 2. above.
dcheck '(set -e; (false; echo ERR); echo ERR); echo OK' 'OK'
echeck '(set -e; (false; echo ERR); echo ERR); echo OK' 'OK'
# backquote expansion (PR bin/17514)
# correct
#dcheck '(set -e; echo ERR `false`; echo ERR); echo OK' 'OK'
#dcheck '(set -e; echo ERR $(false); echo ERR); echo OK' 'OK'
#dcheck '(set -e; echo ERR `exit 3`; echo ERR); echo OK' 'OK'
#dcheck '(set -e; echo ERR $(exit 3); echo ERR); echo OK' 'OK'
# wrong current behavior
dcheck '(set -e; echo ERR `false`; echo ERR); echo OK' 'ERR ERR OK'
dcheck '(set -e; echo ERR $(false); echo ERR); echo OK' 'ERR ERR OK'
dcheck '(set -e; echo ERR `exit 3`; echo ERR); echo OK' 'ERR ERR OK'
dcheck '(set -e; echo ERR $(exit 3); echo ERR); echo OK' 'ERR ERR OK'
dcheck '(set -e; x=`false`; echo ERR); echo OK' 'OK'
dcheck '(set -e; x=$(false); echo ERR); echo OK' 'OK'
dcheck '(set -e; x=`exit 3`; echo ERR); echo OK' 'OK'
dcheck '(set -e; x=$(exit 3); echo ERR); echo OK' 'OK'
# correct
#echeck '(set -e; echo ERR `false`; echo ERR); echo OK' 'OK'
#echeck '(set -e; echo ERR $(false); echo ERR); echo OK' 'OK'
#echeck '(set -e; echo ERR `exit 3`; echo ERR); echo OK' 'OK'
#echeck '(set -e; echo ERR $(exit 3); echo ERR); echo OK' 'OK'
# wrong current behavior
echeck '(set -e; echo ERR `false`; echo ERR); echo OK' 'ERR ERR OK'
echeck '(set -e; echo ERR $(false); echo ERR); echo OK' 'ERR ERR OK'
echeck '(set -e; echo ERR `exit 3`; echo ERR); echo OK' 'ERR ERR OK'
echeck '(set -e; echo ERR $(exit 3); echo ERR); echo OK' 'ERR ERR OK'
echeck '(set -e; x=`false`; echo ERR); echo OK' 'OK'
echeck '(set -e; x=$(false); echo ERR); echo OK' 'OK'
echeck '(set -e; x=`exit 3`; echo ERR); echo OK' 'OK'
echeck '(set -e; x=$(exit 3); echo ERR); echo OK' 'OK'
# shift (PR bin/37493)
# correct
#dcheck '(set -e; shift || true; echo OK); echo OK' 'OK OK'
#echeck '(set -e; shift || true; echo OK); echo OK' 'OK OK'
# wrong current behavior
dcheck '(set -e; shift || true; echo OK); echo OK' 'OK'
echeck '(set -e; shift || true; echo OK); echo OK' 'OK'
# Done.
if [ "x$SH_FAILS" != x ]; then
printf '%-56s %-8s %s\n' "Expression" "Result" "Should be"
echo "$SH_FAILS"
atf_fail "$failcount of $count failed cases"
else
atf_pass
fi
}
atf_init_test_cases() {
atf_add_test_case all
}
+46
View File
@@ -0,0 +1,46 @@
# $NetBSD: t_ulimit.sh,v 1.1 2012/06/11 18:32:59 njoly Exp $
#
# Copyright (c) 2012 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# ulimit builtin test.
atf_test_case limits
limits_head() {
atf_set "descr" "Checks for limits flags"
}
limits_body() {
atf_check -s eq:0 -o ignore -e empty \
/bin/sh -c "ulimit -a"
for l in $(ulimit -a | sed 's,^.*(,,;s, .*$,,');
do
atf_check -s eq:0 -o ignore -e empty \
/bin/sh -c "ulimit $l"
done
}
atf_init_test_cases() {
atf_add_test_case limits
}
+81
View File
@@ -0,0 +1,81 @@
# $NetBSD: t_varquote.sh,v 1.2 2012/03/25 18:50:19 christos Exp $
#
# Copyright (c) 2007 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Variable quoting test.
check() {
if [ "$1" != "$2" ]
then
atf_fail "expected [$2], found [$1]" 1>&2
fi
}
atf_test_case all
all_head() {
atf_set "descr" "Basic checks for variable quoting"
}
all_body() {
foo='${a:-foo}'
check "$foo" '${a:-foo}'
foo="${a:-foo}"
check "$foo" "foo"
foo=${a:-"'{}'"}
check "$foo" "'{}'"
foo=${a:-${b:-"'{}'"}}
check "$foo" "'{}'"
foo="${a:-"'{}'"}"
check "$foo" "'{}'"
foo="${a:-${b:-"${c:-${d:-"x}"}}y}"}}z}"
# " z*"
# ${a:- }
# ${b:- }
# " y*"
# ${c:- }
# ${d:- }
# "x*"
check "$foo" "x}y}z}"
}
atf_test_case nested_quotes_multiword
nested_quotes_multiword_head() {
atf_set "descr" "Tests that having nested quoting in a multi-word" \
"string works (PR bin/43597)"
}
nested_quotes_multiword_body() {
atf_check -s eq:0 -o match:"first-word second-word" -e empty \
/bin/sh -c 'echo "${foo:="first-word"} second-word"'
}
atf_init_test_cases() {
atf_add_test_case all
atf_add_test_case nested_quotes_multiword
}
+59
View File
@@ -0,0 +1,59 @@
# $NetBSD: t_wait.sh,v 1.1 2012/03/17 16:33:11 jruoho Exp $
#
# Copyright (c) 2008, 2009, 2010 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
atf_test_case individual
individual_head() {
atf_set "descr" "Tests that waiting for individual jobs works"
}
individual_body() {
# atf-sh confuses wait for some reason; work it around by creating
# a helper script that executes /bin/sh directly.
cat >helper.sh <<EOF
sleep 3 &
sleep 1 &
wait %1
if [ \$? -ne 0 ]; then
echo "Waiting of first job failed"
exit 1
fi
wait %2
if [ \$? -ne 0 ]; then
echo "Waiting of second job failed"
exit 1
fi
exit 0
EOF
output=$(/bin/sh helper.sh)
[ $? -eq 0 ] || atf_fail "${output}"
}
atf_init_test_cases() {
atf_add_test_case individual
}