Allow test harness to be run from any directory.

Also add missing copyright notice.
This commit is contained in:
Todd C. Miller
2022-02-28 19:39:33 -07:00
parent a4f847b1d6
commit c2bd52edf8
2 changed files with 85 additions and 46 deletions

View File

@@ -1,9 +1,24 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2022 Todd C. Miller <Todd.Miller@sudo.ws>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# Simple test harness for libsudo_util tests. # Simple test harness for libsudo_util tests.
# usage: harness [-v] test_group [test_name ...] # usage: harness [-v] test_group [test_name ...]
# #
srcdir="@abs_srcdir@" srcdir="@abs_srcdir@"
builddir="@abs_builddir@"
SHELL=@SHELL@ SHELL=@SHELL@
verbose=0 verbose=0
rval=0 rval=0
@@ -24,37 +39,38 @@ fi
group="$1" group="$1"
shift shift
srcdir=${srcdir%"/regress"} srcdir=${srcdir%"/regress"}
builddir=${builddir%"/regress"}
if [ ! -d "$srcdir/regress/$group" ]; then cd $srcdir || exit 1
echo "missing test group: $srcdir/regress/$group" >&2
if [ ! -d "regress/$group" ]; then
echo "missing test group: regress/$group" >&2
exit 1 exit 1
fi fi
mkdir -p "regress/$group" mkdir -p "$builddir/regress/$group"
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
tests= tests=
for t in $srcdir/regress/$group/*.in; do for t in regress/$group/*.in; do
tests="$tests `basename $t .in`" tests="$tests `basename $t .in`"
done done
set -- $tests set -- $tests
fi fi
build_dir=`pwd`
cd $srcdir
while [ $# -ne 0 ]; do while [ $# -ne 0 ]; do
test="$1" test="$1"
shift shift
in="regress/$group/${test}.in" in="regress/$group/${test}.in"
out="$build_dir/regress/$group/${test}.out" out="$builddir/regress/$group/${test}.out"
out_ok="regress/$group/${test}.out.ok" out_ok="regress/$group/${test}.out.ok"
err="$build_dir/regress/$group/${test}.err" err="$builddir/regress/$group/${test}.err"
err_ok="regress/$group/${test}.err.ok" err_ok="regress/$group/${test}.err.ok"
if [ "$group" = "sudo_conf" ]; then if [ "$group" = "sudo_conf" ]; then
$build_dir/conf_test $in >$out 2>$err $builddir/conf_test $in >$out 2>$err
else else
$build_dir/parseln_test <$in >$out 2>$err $builddir/parseln_test <$in >$out 2>$err
fi fi
ntests=`expr $ntests + 1` ntests=`expr $ntests + 1`

View File

@@ -1,9 +1,24 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2022 Todd C. Miller <Todd.Miller@sudo.ws>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# Simple test harness for sudoers tests. # Simple test harness for sudoers tests.
# usage: harness [-v] test_group [test_name ...] # usage: harness [-v] test_group [test_name ...]
# #
srcdir="@abs_srcdir@" srcdir="@abs_srcdir@"
builddir="@abs_builddir@"
SHELL=@SHELL@ SHELL=@SHELL@
verbose=0 verbose=0
rval=0 rval=0
@@ -24,15 +39,16 @@ fi
group="$1" group="$1"
shift shift
srcdir=${srcdir%"/regress"} srcdir=${srcdir%"/regress"}
builddir=${builddir%"/regress"}
if [ ! -d "$srcdir/regress/$group" ]; then if [ ! -d "$srcdir/regress/$group" ]; then
echo "missing test group: $srcdir/regress/$group" >&2 echo "missing test group: regress/$group" >&2
exit 1 exit 1
fi fi
case "$group" in case "$group" in
sudoers) sudoers)
mkdir -p "regress/$group" mkdir -p "$builddir/regress/$group"
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
tests= tests=
for t in $srcdir/regress/$group/*.in; do for t in $srcdir/regress/$group/*.in; do
@@ -44,83 +60,88 @@ sudoers)
test="$1" test="$1"
shift shift
in="$srcdir/regress/sudoers/${test}.in" in="$srcdir/regress/sudoers/${test}.in"
out="regress/sudoers/${test}.out" out="$builddir/regress/sudoers/${test}.out"
toke="regress/sudoers/${test}.toke" out_ok="$srcdir/regress/sudoers/${test}.out.ok"
json="regress/sudoers/${test}.json" toke="$builddir/regress/sudoers/${test}.toke"
ldif="regress/sudoers/${test}.ldif" toke_ok="$srcdir/regress/sudoers/${test}.toke.ok"
sudo="regress/sudoers/${test}.sudo" json="$builddir/regress/sudoers/${test}.json"
ldif2sudo="regress/sudoers/${test}.ldif2sudo" json_ok="$srcdir/regress/sudoers/${test}.json.ok"
ldif="$builddir/regress/sudoers/${test}.ldif"
ldif_ok="$srcdir/regress/sudoers/${test}.ldif.ok"
ldif2sudo="$builddir/regress/sudoers/${test}.ldif2sudo"
ldif2sudo_ok="$srcdir/regress/sudoers/${test}.ldif2sudo.ok"
sudo="$builddir/regress/sudoers/${test}.sudo"
./testsudoers -dt <$in >$out 2>$toke || true $builddir/testsudoers -dt <$in >$out 2>$toke || true
ntests=`expr $ntests + 1` ntests=`expr $ntests + 1`
if cmp $out $srcdir/$out.ok >/dev/null; then if cmp $out $out_ok >/dev/null; then
if [ $verbose -eq 1 ]; then if [ $verbose -eq 1 ]; then
echo "$group/$test (parse): OK" echo "$group/$test (parse): OK"
fi fi
else else
errors=`expr $errors + 1` errors=`expr $errors + 1`
echo "$group/$test (parse): FAIL" echo "$group/$test (parse): FAIL"
diff $out $srcdir/$out.ok || true diff $out $out_ok || true
fi fi
ntests=`expr $ntests + 1` ntests=`expr $ntests + 1`
if cmp $toke $srcdir/$toke.ok >/dev/null; then if cmp $toke $toke_ok >/dev/null; then
if [ $verbose -eq 1 ]; then if [ $verbose -eq 1 ]; then
echo "$group/$test (toke): OK" echo "$group/$test (toke): OK"
fi fi
else else
errors=`expr $errors + 1` errors=`expr $errors + 1`
echo "$group/$test (toke): FAIL" echo "$group/$test (toke): FAIL"
diff $toke $srcdir/$toke.ok || true diff $toke $toke_ok || true
fi fi
./cvtsudoers -c "" -f json $in >$json 2>/dev/null || true $builddir/cvtsudoers -c "" -f json $in >$json 2>/dev/null || true
ntests=`expr $ntests + 1` ntests=`expr $ntests + 1`
if cmp $json $srcdir/$json.ok >/dev/null; then if cmp $json $json_ok >/dev/null; then
if [ $verbose -eq 1 ]; then if [ $verbose -eq 1 ]; then
echo "$group/$test (json): OK" echo "$group/$test (json): OK"
fi fi
else else
errors=`expr $errors + 1` errors=`expr $errors + 1`
echo "$group/$test (json): FAIL" echo "$group/$test (json): FAIL"
diff $json $srcdir/$json.ok || true diff $json $json_ok || true
fi fi
SUDOERS_BASE="ou=SUDOers,dc=sudo,dc=ws" \ SUDOERS_BASE="ou=SUDOers,dc=sudo,dc=ws" \
./cvtsudoers -c "" -f ldif < $in >$ldif 2>/dev/null || true $builddir/cvtsudoers -c "" -f ldif < $in >$ldif 2>/dev/null || true
ntests=`expr $ntests + 1` ntests=`expr $ntests + 1`
if cmp $ldif $srcdir/$ldif.ok >/dev/null; then if cmp $ldif $ldif_ok >/dev/null; then
if [ $verbose -eq 1 ]; then if [ $verbose -eq 1 ]; then
echo "$group/$test (ldif): OK" echo "$group/$test (ldif): OK"
fi fi
else else
errors=`expr $errors + 1` errors=`expr $errors + 1`
echo "$group/$test: (ldif) FAIL" echo "$group/$test: (ldif) FAIL"
diff $ldif $srcdir/$ldif.ok || true diff $ldif $ldif_ok || true
fi fi
./cvtsudoers -c "" -f sudoers $in >$sudo 2>/dev/null || true $builddir/cvtsudoers -c "" -f sudoers $in >$sudo 2>/dev/null || true
ntests=`expr $ntests + 1` ntests=`expr $ntests + 1`
if ./visudo -qcf $sudo; then if $builddir/visudo -qcf $sudo; then
if [ $verbose -eq 1 ]; then if [ $verbose -eq 1 ]; then
echo "$group/$test (reparse): OK" echo "$group/$test (reparse): OK"
fi fi
else else
errors=`expr $errors + 1` errors=`expr $errors + 1`
echo "$group/$test: (reparse) FAIL" echo "$group/$test: (reparse) FAIL"
./visudo -cf $sudo || true $builddir/visudo -cf $sudo || true
fi fi
if test -s $srcdir/$ldif.ok; then if test -s $ldif_ok; then
./cvtsudoers -c "" -i ldif -f sudoers $srcdir/$ldif.ok >$ldif2sudo || true $builddir/cvtsudoers -c "" -i ldif -f sudoers $ldif_ok >$ldif2sudo || true
ntests=`expr $ntests + 1` ntests=`expr $ntests + 1`
if cmp $ldif2sudo $srcdir/$ldif2sudo.ok >/dev/null; then if cmp $ldif2sudo $ldif2sudo_ok >/dev/null; then
if [ $verbose -eq 1 ]; then if [ $verbose -eq 1 ]; then
echo "$group/$test (ldif2sudo): OK" echo "$group/$test (ldif2sudo): OK"
fi fi
else else
errors=`expr $errors + 1` errors=`expr $errors + 1`
echo "$group/$test: (ldif2sudo) FAIL" echo "$group/$test: (ldif2sudo) FAIL"
diff $ldif $srcdir/$ldif.ok || true diff $ldif $ldif_ok || true
fi fi
fi fi
done done
@@ -131,9 +152,9 @@ sudoers)
fi fi
;; ;;
*) *)
TESTSUDOERS=./testsudoers; export TESTSUDOERS TESTSUDOERS=$builddir/testsudoers; export TESTSUDOERS
VISUDO=./visudo; export VISUDO VISUDO=$builddir/visudo; export VISUDO
CVTSUDOERS=./cvtsudoers; export CVTSUDOERS CVTSUDOERS=$builddir/cvtsudoers; export CVTSUDOERS
mkdir -p "regress/$group" mkdir -p "regress/$group"
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
tests= tests=
@@ -147,12 +168,14 @@ sudoers)
shift shift
cmd="$srcdir/regress/$group/${test}.sh" cmd="$srcdir/regress/$group/${test}.sh"
out="regress/$group/${test}.out" out="$builddir/regress/$group/${test}.out"
err="regress/$group/${test}.err" out_ok="$srcdir/regress/$group/${test}.out.ok"
err="$builddir/regress/$group/${test}.err"
err_ok="$srcdir/regress/$group/${test}.err.ok"
status=0 status=0
TESTDIR=$srcdir/regress/$group $SHELL $cmd >$out 2>$err || status=$? TESTDIR=$srcdir/regress/$group $SHELL $cmd >$out 2>$err || status=$?
ntests=`expr $ntests + 1` ntests=`expr $ntests + 1`
if cmp $out $srcdir/$out.ok >/dev/null; then if cmp $out $out_ok >/dev/null; then
if test $status -eq 0; then if test $status -eq 0; then
if [ $verbose -eq 1 ]; then if [ $verbose -eq 1 ]; then
echo "$group/$test: OK" echo "$group/$test: OK"
@@ -164,18 +187,18 @@ sudoers)
else else
errors=`expr $errors + 1` errors=`expr $errors + 1`
echo "$group/$test: FAIL" echo "$group/$test: FAIL"
diff $out $srcdir/$out.ok || true diff $out $out_ok || true
fi fi
if test -s $srcdir/$err.ok; then if test -s $err_ok; then
ntests=`expr $ntests + 1` ntests=`expr $ntests + 1`
if cmp $err $srcdir/$err.ok >/dev/null; then if cmp $err $err_ok >/dev/null; then
if [ $verbose -eq 1 ]; then if [ $verbose -eq 1 ]; then
echo "$group/$test (stderr): OK" echo "$group/$test (stderr): OK"
fi fi
else else
errors=`expr $errors + 1` errors=`expr $errors + 1`
echo "$group/$test (stderr): FAIL" echo "$group/$test (stderr): FAIL"
diff $err $srcdir/$err.ok || true diff $err $err_ok || true
fi fi
elif test -s $err; then elif test -s $err; then
errors=`expr $errors + 1` errors=`expr $errors + 1`