From: Jonathan McDowell Date: Wed, 10 Apr 2019 18:05:10 +0000 (+0100) Subject: Cleanup tests to be able to run from a different directory X-Git-Tag: onak-0.6.0~63 X-Git-Url: https://the.earth.li/gitweb/?a=commitdiff_plain;h=94422621d7c1300ae7001d13590570f9d4ad2a07;p=onak.git Cleanup tests to be able to run from a different directory runtests assumes its run from the directory it lives in, and that this is the build directory. Improve it to be able to cope with a build in a different directory to the source and work out the correct paths. --- diff --git a/runtests b/runtests index 973aa59..b65b6e0 100755 --- a/runtests +++ b/runtests @@ -1,51 +1,69 @@ #!/bin/sh set -e -fail=0 -total=0 +# Work out where everything is +# Binary should be in current directory if [ ! -e onak ]; then echo "** onak binary doesn't exist, cannot run test suite" >&2 exit 1 fi +BUILDDIR=$PWD -if [ -e t/db/ ]; then - rm -rf t/db/ -fi +# Tests live in the t/ dir underneath where this script is +TESTSDIR=$(dirname $(readlink -f "$0"))/t + +# We create a temporary directory to work in +WORKDIR=$(mktemp -d -t onak-test.XXXXXXXX) +trap cleanup exit +cleanup () { + rm -rf "$WORKDIR" +} + +export BUILDDIR TESTSDIR WORKDIR + +echo "BUILDDIR: ${BUILDDIR}" +echo "TESTSDIR: ${TESTSDIR}" +echo "WORKDIR : ${WORKDIR}" + +fail=0 +total=0 for t in libkeydb_*.so; do backend=${t##libkeydb_} backend=${backend%%.so} - if [ "`echo t/$backend-*`" != "t/$backend-*" ]; then + if [ "`echo ${TESTSDIR}/$backend-*`" != "${TESTSDIR}/$backend-*" ]; then echo "* testing $backend backend [conf]" - (sed -e "s;DIR;`pwd`;" t/test-in.conf ; \ - echo db_backend $backend) > t/test.conf - for t in t/$backend-*.t t/all-*.t; do + (sed -e "s;BUILDDIR;${BUILDDIR};" -e "s;WORKDIR;${WORKDIR};" \ + ${TESTSDIR}/test-in.conf ; \ + echo db_backend $backend) > ${WORKDIR}/test.conf + for t in ${TESTSDIR}/$backend-*.t ${TESTSDIR}/all-*.t; do total=`expr $total + 1` - mkdir t/db/ - if ! $t test.conf $backend; then + mkdir ${WORKDIR}/db/ + if ! $t ${WORKDIR}/test.conf $backend; then echo "test $t failed" >&2 fail=`expr $fail + 1` fi - rm -rf t/db/ + rm -rf ${WORKDIR}/db/ done - rm t/test.conf + rm ${WORKDIR}/test.conf fi - if [ "`echo t/$backend-*`" != "t/$backend-*" ]; then + if [ "`echo ${TESTSDIR}/$backend-*`" != "${TESTSDIR}/$backend-*" ]; then echo "* testing $backend backend [ini]" - sed -e "s;DIR;`pwd`;" -e "s;DB;${backend};" t/test-in.ini \ - > t/test.ini - for t in t/$backend-*.t t/all-*.t; do + sed -e "s;BUILDDIR;${BUILDDIR};" -e "s;WORKDIR;${WORKDIR};" \ + -e "s;DB;${backend};" \ + ${TESTSDIR}/test-in.ini > ${WORKDIR}/test.ini + for t in ${TESTSDIR}/$backend-*.t ${TESTSDIR}/all-*.t; do total=`expr $total + 1` - mkdir t/db/ - if ! $t test.ini $backend; then + mkdir ${WORKDIR}/db/ + if ! $t ${WORKDIR}/test.ini $backend; then echo "test $t failed" >&2 fail=`expr $fail + 1` fi - rm -rf t/db/ + rm -rf ${WORKDIR}/db/ done - rm t/test.ini + rm ${WORKDIR}/test.ini fi done @@ -53,5 +71,5 @@ if [ "$fail" -gt 0 ]; then echo "** failed $fail/$total tests" >&2 exit 1 else - echo "** all tests succeeded" + echo "** all tests succeeded ($total)" fi diff --git a/t/all-020-get.t b/t/all-020-get.t index 7564928..7fd617a 100755 --- a/t/all-020-get.t +++ b/t/all-020-get.t @@ -3,9 +3,9 @@ set -e -cd t -../onak -b -c $1 add < ../keys/noodles.key -if ! ../onak -c $1 get 0x94FA372B2DA8B985 2> /dev/null | \ +cd ${WORKDIR} +${BUILDDIR}/onak -b -c $1 add < ${TESTSDIR}/../keys/noodles.key +if ! ${BUILDDIR}/onak -c $1 get 0x94FA372B2DA8B985 2> /dev/null | \ grep -q -- '-----BEGIN PGP PUBLIC KEY BLOCK-----'; then echo "* Did not correctly retrieve key by keyid." exit 1 diff --git a/t/all-030-get-fail.t b/t/all-030-get-fail.t index 8d1bea6..7726804 100755 --- a/t/all-030-get-fail.t +++ b/t/all-030-get-fail.t @@ -3,9 +3,9 @@ set -e -cd t -../onak -b -c $1 add < ../keys/noodles.key -if ! ../onak -c $1 get 0x12345678 2>&1 | \ +cd ${WORKDIR} +${BUILDDIR}/onak -b -c $1 add < ${TESTSDIR}/../keys/noodles.key +if ! ${BUILDDIR}/onak -c $1 get 0x12345678 2>&1 | \ grep -q 'Key not found'; then echo "* Did not correctly error on non-existent key" exit 1 diff --git a/t/all-040-index-text.t b/t/all-040-index-text.t index af82b9e..f0055f6 100755 --- a/t/all-040-index-text.t +++ b/t/all-040-index-text.t @@ -9,9 +9,9 @@ if [ "$2" = "file" ]; then exit 0 fi -cd t -../onak -b -c $1 add < ../keys/noodles.key -if ! ../onak -c $1 index noodles 2> /dev/null | \ +cd ${WORKDIR} +${BUILDDIR}/onak -b -c $1 add < ${TESTSDIR}/../keys/noodles.key +if ! ${BUILDDIR}/onak -c $1 index noodles 2> /dev/null | \ grep -q -- 'pub 4096R/2DA8B985 2008/06/03 Jonathan McDowell'; then echo "* Did not correctly retrieve key by text" exit 1 diff --git a/t/all-050-get-hash.t b/t/all-050-get-hash.t index ef83dc2..dee252c 100755 --- a/t/all-050-get-hash.t +++ b/t/all-050-get-hash.t @@ -9,9 +9,9 @@ if [ "$2" = "file" ]; then exit 0 fi -cd t -../onak -b -c $1 add < ../keys/noodles.key -if ! ../onak -c $1 hget 81929DAE08B8F80888DA524923B93067 2> /dev/null | \ +cd ${WORKDIR} +${BUILDDIR}/onak -b -c $1 add < ${TESTSDIR}/../keys/noodles.key +if ! ${BUILDDIR}/onak -c $1 hget 81929DAE08B8F80888DA524923B93067 2> /dev/null | \ grep -q -- '-----BEGIN PGP PUBLIC KEY BLOCK-----'; then echo "* Did not correctly retrieve key by text" exit 1 diff --git a/t/all-060-get-fingerprint.t b/t/all-060-get-fingerprint.t index e79c636..993e15f 100755 --- a/t/all-060-get-fingerprint.t +++ b/t/all-060-get-fingerprint.t @@ -3,9 +3,9 @@ set -e -cd t -../onak -b -c $1 add < ../keys/noodles.key -if ! ../onak -c $1 get 0x0E3A94C3E83002DAB88CCA1694FA372B2DA8B985 2> /dev/null | \ +cd ${WORKDIR} +${BUILDDIR}/onak -b -c $1 add < ${TESTSDIR}/../keys/noodles.key +if ! ${BUILDDIR}/onak -c $1 get 0x0E3A94C3E83002DAB88CCA1694FA372B2DA8B985 2> /dev/null | \ grep -q -- '-----BEGIN PGP PUBLIC KEY BLOCK-----'; then echo "* Did not correctly retrieve key by keyid." exit 1 diff --git a/t/all-070-get-short.t b/t/all-070-get-short.t index b8431a6..74e4892 100755 --- a/t/all-070-get-short.t +++ b/t/all-070-get-short.t @@ -3,9 +3,9 @@ set -e -cd t -../onak -b -c $1 add < ../keys/noodles.key -if ! ../onak -c $1 get 0x2DA8B985 2> /dev/null | \ +cd ${WORKDIR} +${BUILDDIR}/onak -b -c $1 add < ${TESTSDIR}/../keys/noodles.key +if ! ${BUILDDIR}/onak -c $1 get 0x2DA8B985 2> /dev/null | \ grep -q -- '-----BEGIN PGP PUBLIC KEY BLOCK-----'; then echo "* Did not correctly retrieve key by keyid." exit 1 diff --git a/t/all-080-get-subkey.t b/t/all-080-get-subkey.t index 449b568..e934dd8 100755 --- a/t/all-080-get-subkey.t +++ b/t/all-080-get-subkey.t @@ -9,14 +9,14 @@ if [ "$2" = "file" ]; then exit 0 fi -cd t -../onak -b -c $1 add < ../keys/noodles.key -if ! ../onak -c $1 get 0x045281F1B9A66E35 2> /dev/null | \ +cd ${WORKDIR} +${BUILDDIR}/onak -b -c $1 add < ${TESTSDIR}/../keys/noodles.key +if ! ${BUILDDIR}/onak -c $1 get 0x045281F1B9A66E35 2> /dev/null | \ grep -q -- '-----BEGIN PGP PUBLIC KEY BLOCK-----'; then echo "* Did not correctly retrieve key by subkey id." exit 1 fi -if ! ../onak -c $1 get 0xFF162FC5CF3FBAD1 2> /dev/null | \ +if ! ${BUILDDIR}/onak -c $1 get 0xFF162FC5CF3FBAD1 2> /dev/null | \ grep -q -- '-----BEGIN PGP PUBLIC KEY BLOCK-----'; then echo "* Did not correctly retrieve key by subkey id." exit 1 diff --git a/t/all-090-get-subkey-short.t b/t/all-090-get-subkey-short.t index d120598..9927a1e 100755 --- a/t/all-090-get-subkey-short.t +++ b/t/all-090-get-subkey-short.t @@ -9,14 +9,14 @@ if [ "$2" = "file" ]; then exit 0 fi -cd t -../onak -b -c $1 add < ../keys/noodles.key -if ! ../onak -c $1 get 0xB9A66E35 2> /dev/null | \ +cd ${WORKDIR} +${BUILDDIR}/onak -b -c $1 add < ${TESTSDIR}/../keys/noodles.key +if ! ${BUILDDIR}/onak -c $1 get 0xB9A66E35 2> /dev/null | \ grep -q -- '-----BEGIN PGP PUBLIC KEY BLOCK-----'; then echo "* Did not correctly retrieve key by subkey id." exit 1 fi -if ! ../onak -c $1 get 0xCF3FBAD1 2> /dev/null | \ +if ! ${BUILDDIR}/onak -c $1 get 0xCF3FBAD1 2> /dev/null | \ grep -q -- '-----BEGIN PGP PUBLIC KEY BLOCK-----'; then echo "* Did not correctly retrieve key by subkey id." exit 1 diff --git a/t/db4-000-add.t b/t/db4-000-add.t index 83bece6..9eb519b 100755 --- a/t/db4-000-add.t +++ b/t/db4-000-add.t @@ -3,8 +3,8 @@ set -e -cd t -../onak -b -c $1 add < ../keys/noodles.key +cd ${WORKDIR} +${BUILDDIR}/onak -b -c $1 add < ${TESTSDIR}/../keys/noodles.key if [ ! -e db/worddb -o ! -e db/id32db -o ! -e db/keydb.0.db ]; then echo Did not correctly add key using db4 backend. exit 1 diff --git a/t/file-000-add.t b/t/file-000-add.t index dbfb811..bd4a5f5 100755 --- a/t/file-000-add.t +++ b/t/file-000-add.t @@ -3,8 +3,8 @@ set -e -cd t -../onak -b -c $1 add < ../keys/noodles.key +cd ${WORKDIR} +${BUILDDIR}/onak -b -c $1 add < ${TESTSDIR}/../keys/noodles.key if [ ! -e db/0x2DA8B985 ]; then echo Did not correctly add key using file backend. exit 1 diff --git a/t/file-010-del.t b/t/file-010-del.t index edceea1..b1ab0aa 100755 --- a/t/file-010-del.t +++ b/t/file-010-del.t @@ -3,9 +3,9 @@ set -e -cd t -../onak -b -c $1 add < ../keys/noodles.key -../onak -b -c $1 delete 0x2DA8B985 +cd ${WORKDIR} +${BUILDDIR}/onak -b -c $1 add < ${TESTSDIR}/../keys/noodles.key +${BUILDDIR}/onak -b -c $1 delete 0x2DA8B985 if [ -e db/0x2DA8B985 ]; then echo "* Did not correctly delete key using file backend" exit 1 diff --git a/t/fs-000-add.t b/t/fs-000-add.t index 1864417..536514a 100755 --- a/t/fs-000-add.t +++ b/t/fs-000-add.t @@ -3,8 +3,8 @@ set -e -cd t -../onak -b -c $1 add < ../keys/noodles.key +cd ${WORKDIR} +${BUILDDIR}/onak -b -c $1 add < ${TESTSDIR}/../keys/noodles.key if [ ! -e db/key/2D/A8/2DA8B985/94FA372B2DA8B985 ]; then echo Did not correctly add key using fs backend. exit 1 diff --git a/t/fs-010-del.t b/t/fs-010-del.t index 5ea794b..a30df73 100755 --- a/t/fs-010-del.t +++ b/t/fs-010-del.t @@ -3,9 +3,9 @@ set -e -cd t -../onak -b -c $1 add < ../keys/noodles.key -../onak -b -c $1 delete 0x2DA8B985 +cd ${WORKDIR} +${BUILDDIR}/onak -b -c $1 add < ${TESTSDIR}/../keys/noodles.key +${BUILDDIR}/onak -b -c $1 delete 0x2DA8B985 if [ -e db/key/2D/A8/2DA8B985/94FA372B2DA8B985 ]; then echo "* Did not correctly delete key using fs backend" exit 1 diff --git a/t/test-in.conf b/t/test-in.conf index b5309a0..329fc4c 100644 --- a/t/test-in.conf +++ b/t/test-in.conf @@ -1,6 +1,6 @@ -pks_bin_dir DIR -backends_dir DIR -db_dir DIR/t/db/ +pks_bin_dir BUILDDIR +backends_dir BUILDDIR +db_dir WORKDIR/db/ logfile onak.log loglevel 7 use_keyd false diff --git a/t/test-in.ini b/t/test-in.ini index fba8033..b741401 100644 --- a/t/test-in.ini +++ b/t/test-in.ini @@ -1,6 +1,6 @@ [main] backend=test-DB -backends_dir=DIR +backends_dir=BUILDDIR logfile=onak.log loglevel=7 use_keyd=false @@ -8,8 +8,8 @@ max_reply_keys=128 [backend:test-DB] type=DB -location=DIR/t/db/ +location=WORKDIR/db/ [mail] -bin_dir=DIR +bin_dir=BUILDDIR this_site=pgp-public-keys@localhost