1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-03 22:56:33 +02:00

Add some tests.

This commit is contained in:
Werner Koch 2008-02-22 15:47:18 +00:00
parent 898a341f50
commit f5f14d6556
12 changed files with 467 additions and 43 deletions

View file

@ -17,17 +17,31 @@
# along with this program; if not, see <http://www.gnu.org/licenses/>.
# reset some environment variables because we do not want to test locals
export LANG=C
export LANGUAGE=C
export LC_ALL=C
LANG=C
LANGUAGE=C
LC_ALL=C
export LANG LANGUAGE LC_ALL
pgmname=`basename $0`
[ "$VERBOSE" = yes ] && set -x
if [ "$1" = "--debug" ]; then
debug=yes
set -x
else
debug=
fi
[ -z "$srcdir" ] && srcdir="."
[ -z "$top_srcdir" ] && top_srcdir=".."
[ -z "$GPGSM" ] && GPGSM="../../sm/gpgsm"
[ -z "$silent" ] && silent=no
AWK=awk
SCRATCH="scratch.$$.tmp"
# We use this as the faked system time for certain tests.
MYTIME="20080508T120000"
if [ "$GNUPGHOME" != "`pwd`" ]; then
echo "inittests: please set GNUPGHOME to the tests/pkits directory" >&2
exit 1
@ -41,7 +55,14 @@ fi
if [ -f PKITS_data.tar.bz2 ]; then
:
else
# Exit code 77 is used by the makefile for skipping a tests.
if [ "$pgmname" = "import-all-certs" ]; then
if [ "$silent" = "yes" ]; then tmp1="Note: "; tmp2=' '
else tmp1="- ____ "; tmp2="$tmp1"
fi
echo "${tmp1}PKITS_data.tar.bz2 is not installed"
echo "${tmp2}All tests will be skipped (this is not an error)"
fi
# Exit code 77 is used by the Makefile for skipping a tests.
exit 77
fi
@ -115,7 +136,9 @@ pass () {
pass_count=`expr ${pass_count} + 1`
if [ "$silent" != "yes" ]; then
echo_n "$section_out PASS"
[ -n "$description" ] && echo_n " ($description)"
if [ -n "$1" ]; then echo_n " $1"
elif [ -n "$description" ]; then echo_n " ($description)"
fi
echo
fi
}
@ -126,7 +149,22 @@ fail () {
fail_count=`expr ${fail_count} + 1`
if [ "$silent" != "yes" ]; then
echo_n "$section_out FAIL"
[ -n "$description" ] && echo_n " ($description)"
if [ -n "$1" ]; then echo_n " $1"
elif [ -n "$description" ]; then echo_n " ($description)"
fi
echo
fi
}
skip () {
setup_output
echo "SKIP: " $* >&2
skip_count=`expr ${skip_count} + 1`
if [ "$silent" != "yes" ]; then
echo_n "$section_out SKIP"
if [ -n "$1" ]; then echo_n " $1"
elif [ -n "$description" ]; then echo_n " ($description)"
fi
echo
fi
}
@ -137,18 +175,9 @@ unresolved () {
unresolved_count=`expr ${unresolved_count} + 1`
if [ "$silent" != "yes" ]; then
echo_n "$section_out UNRESOLVED"
[ -n "$description" ] && echo_n " ($description)"
echo
fi
}
unsupported () {
setup_output
echo "UNSUPPORTED: " $* >&2
unsupported_count=`expr ${unsupported_count} + 1`
if [ "$silent" != "yes" ]; then
echo_n "$section_out UNSUPPORTED"
[ -n "$description" ] && echo_n " ($description)"
if [ -n "$1" ]; then echo_n " $1"
elif [ -n "$description" ]; then echo_n " ($description)"
fi
echo
fi
}
@ -158,8 +187,9 @@ final_result () {
section=$first_section_set
[ $pass_count = 0 ] || info "$pass_count tests passed"
[ $fail_count = 0 ] || info "$fail_count tests failed"
[ $skip_count = 0 ] || info "$unsupported_count tests skipped"
[ $unresolved_count = 0 ] || info "$unresolved_count tests unresolved"
[ $unsupported_count = 0 ] || info "$unsupported_count tests unsupported"
[ -z "$debug" -a -f "$SCRATCH" ] && rm "$SCRATCH"
if [ $fail_count = 0 ]; then
info "all tests passed"
else
@ -167,21 +197,79 @@ final_result () {
fi
}
set -e
pgmname=`basename $0`
clean_homedir () {
[ -f pubring.kbx ] && rm pubring.kbx
if [ -d private-keys-v1.d ]; then
rm private-keys-v1.d/* 2>/dev/null || true
rmdir private-keys-v1.d
fi
}
start_test () {
section="$1"
description="$2"
test_status=none
echo "BEGIN TEST $section ($description)" >&2
}
end_test () {
case "$test_status" in
none) skip "($description) - test not implemented";;
pass) pass "($description)";;
fail) fail "($description)";;
setup) fail "($description) - setup failed";;
ns) skip "($description) - not supported";;
nys) skip "($description) - not yet supported";;
*) unresolved "$(description)";;
esac
echo "END TEST $section" >&2
}
set_status () {
if [ "$test_status" = "none" ]; then
test_status=$1
fi
}
need_cert () {
if [ "$2" = "--import-anyway" ]; then
if ! ${GPGSM} -q --debug-no-chain-validation --import certs/$1.crt
then
set_status setup
fi
else
if ! ${GPGSM} -q --import certs/$1.crt; then
set_status setup
fi
fi
}
need_crl () {
# CRL are not yet implemented
#set_status setup
:
}
set -e
pass_count=0
fail_count=0
skip_count=0
unresolved_count=0
unsupported_count=0
first_section_set=""
section_out=""
test_status=none
# User settable variables
section=""
description=""
#trap cleanup SIGHUP SIGINT SIGQUIT
exec 2> ${pgmname}.log
[ -z "$debug" ] && exec 2> ${pgmname}.log
:
# end