]> the.earth.li Git - onak.git/commitdiff
Cleanup tests to be able to run from a different directory
authorJonathan McDowell <noodles@earth.li>
Wed, 10 Apr 2019 18:05:10 +0000 (19:05 +0100)
committerJonathan McDowell <noodles@earth.li>
Wed, 10 Apr 2019 18:05:10 +0000 (19:05 +0100)
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.

16 files changed:
runtests
t/all-020-get.t
t/all-030-get-fail.t
t/all-040-index-text.t
t/all-050-get-hash.t
t/all-060-get-fingerprint.t
t/all-070-get-short.t
t/all-080-get-subkey.t
t/all-090-get-subkey-short.t
t/db4-000-add.t
t/file-000-add.t
t/file-010-del.t
t/fs-000-add.t
t/fs-010-del.t
t/test-in.conf
t/test-in.ini

index 973aa598f4683a5cd48872f369a2366c4addf5bc..b65b6e052b81165d3e58b8a03c16d0ffc68fa4d1 100755 (executable)
--- 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
index 75649286a469ea7d8ed7eec5d7eb5b02a3d231a4..7fd617a3a72155322d009db161b039599047f116 100755 (executable)
@@ -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
index 8d1bea66896b95810b3348c53af18a117971a195..77268043ad5b21924140d5ca35481ff58def9cc9 100755 (executable)
@@ -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
index af82b9e3961861ee43d549b1c1c07905b62e3003..f0055f63f3ffff87b820a416b3195cfd62f958a2 100755 (executable)
@@ -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
index ef83dc255dfc6fee4db2f84046f2a68648591951..dee252c9998ba3cd26dd7dab7378852c961d3bd2 100755 (executable)
@@ -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
index e79c636f7eb6beda0821abb58d5d4feb3812df0c..993e15f5bb4b5b6b7884da10dd7d6d9f0a918f9b 100755 (executable)
@@ -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
index b8431a61feeae453ef8976e3e42c11129eca8bd7..74e48920fed320f3431c41e7c679aac3eb530016 100755 (executable)
@@ -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
index 449b5687f7017bb54ead83ecdeec2d10fc0c4df3..e934dd8e3112692cdb6bf4976a1aebc3a68c4cc9 100755 (executable)
@@ -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
index d120598969ea13a181778b336c23ed1875a072fc..9927a1ef845f5d740f9290fc27828f23f22b0e4b 100755 (executable)
@@ -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
index 83bece671859269904c0aae1ffc3f0aee69c1133..9eb519ba621c7b305f293878998f6eb19ef9f534 100755 (executable)
@@ -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
index dbfb8118aa469589c12c8a6387a32d2a25e7bea3..bd4a5f5b71074fbe02b0103553eb03ac82337061 100755 (executable)
@@ -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
index edceea1bf172327434669f868581b3a094a67147..b1ab0aac7be927c1f6f76f6e78b4bad78553f01d 100755 (executable)
@@ -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
index 1864417c57726d99c6cc1bd47ea81c22c997a01f..536514a43d312f18c59f30c3fe900520b598a969 100755 (executable)
@@ -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
index 5ea794b0ed88ae14477d26f7f282704b0dd9bb3e..a30df73bf2be254bc22d24b71661bf172abd048d 100755 (executable)
@@ -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
index b5309a099766fc2337b2abcb93b068ba88bccdde..329fc4cbca7cf7438e8cd8ad334cba8b1aaf5473 100644 (file)
@@ -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
index fba8033c6cdd7144c665541ebdcb3b832b54f65e..b7414018c1219e2d7951f6da8bcd346286f325da 100644 (file)
@@ -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