From 93a31f9b884f8e8f3f7a7d50cf90ffd365a14f7c Mon Sep 17 00:00:00 2001 From: David Levine Date: Thu, 16 Feb 2012 21:30:43 -0600 Subject: [PATCH] Rearranged test suite environment variables so that individual tests can now be run standalone (outside of make). But see WARNING in test/README about how it's better to use "make check" because that ensures that the current code in your workspace is tested. Also, the clean script no longer needs to call setup_test. --- Makefile.am | 8 ++++---- test/README | 19 ++++++++++++++----- test/bad-input/test-header | 7 ++++--- test/cleanup | 9 ++++----- test/common.sh.in | 27 +++++++++++++++++++-------- test/folder/test-create | 7 ++++--- test/folder/test-total | 7 ++++--- test/format/test-localmbox | 7 ++++--- test/format/test-myhost | 7 ++++--- test/format/test-mymbox | 7 ++++--- test/format/test-myname | 7 ++++--- test/inc/test-deb359167 | 9 +++++++-- test/inc/test-eom-align | 9 +++++++-- test/manpages/test-manpages | 7 ++++++- test/mhbuild/test-forw | 7 ++++--- test/mhshow/test-cte-binary | 7 ++++--- test/mhshow/test-qp | 7 ++++--- test/mhshow/test-subpart | 7 ++++--- test/new/test-basic | 14 ++++++++++---- test/pick/test-stderr | 7 ++++--- test/repl/test-if-str | 7 ++++--- test/scan/test-scan | 7 ++++--- test/whatnow/test-attach-detach | 7 ++++--- test/whatnow/test-cd | 7 ++++--- test/whatnow/test-ls | 7 ++++--- 25 files changed, 139 insertions(+), 82 deletions(-) diff --git a/Makefile.am b/Makefile.am index 5b473c3..2a986b0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -34,10 +34,10 @@ auxexecdir = @libdir@ ## nmh _does_ have a test suite! ## -TESTS_ENVIRONMENT = MH_TEST_DIR=`pwd`/test/testdir \ - MH_TEST_COMMON=`pwd`/test/common.sh \ - MH_OBJ_DIR=`pwd` mandir=$(mandir) bindir=$(bindir) \ - sysconfdir=$(sysconfdir) auxexecdir=$(auxexecdir) +TESTS_ENVIRONMENT = MH_OBJ_DIR=@abs_srcdir@ \ + MH_TEST_DIR=@abs_srcdir@/test/testdir \ + auxexecdir=$(auxexecdir) bindir=$(bindir) \ + mandir=$(mandir) sysconfdir=$(sysconfdir) ## ## Important note: the "cleanup" test should always be last ## diff --git a/test/README b/test/README index 3d7d478..9f890e2 100644 --- a/test/README +++ b/test/README @@ -17,18 +17,27 @@ designed to work with Automake. To run these tests you can do "make check" via the top-level Makefile. This is also done automatically via "make distcheck". -If you wish to write a new test, here are the steps: +WARNING: The test suite installs nmh and run the tests on that test +installation. If you run tests individually, they will not remove +that test installation or check to see if it remains up to date with +your nmh workspace. You can run test/clean after a test to remove the +test installation. "make check" will do that, so it is best to use +it. -- Make sure your test script sources common.sh (the location of this script - is in the MH_TEST_COMMON environment variable and calls the setup_test - shell function (the other scripts have examples of this). +If you wish to write a new test script, here are the steps: + +- Make sure your test script sources $MH_OBJ_DIR/test/common.sh and + calls the setup_test shell function (the other scripts have examples + of this). - Your path will be set up to find the locations of the test nmh binaries. - Add your script to the TESTS variable in the toplevel Makefile.am. + By convention, test script names start with "test-", though that + is not a requirement. - If you need additional files for your tests, be sure to add them to the EXTRA_DIST variable in Makefile.am. Note that you should insure - that you access these files relative to the ${srcdir} environment variable. + that you access these files relative to the $MH_OBJ_DIR environment variable. - Verify that the test works with both "make check" and "make distcheck". diff --git a/test/bad-input/test-header b/test/bad-input/test-header index 35d680a..71a63a9 100755 --- a/test/bad-input/test-header +++ b/test/bad-input/test-header @@ -5,11 +5,12 @@ # ###################################################### -if [ -z "${MH_TEST_COMMON}" ]; then - echo "MH_TEST_COMMON not set; try running via 'make check'" +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname $0`/../.. + MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR fi -. ${MH_TEST_COMMON} +. "$MH_OBJ_DIR/test/common.sh" setup_test diff --git a/test/cleanup b/test/cleanup index 82b2261..97d8341 100755 --- a/test/cleanup +++ b/test/cleanup @@ -5,12 +5,11 @@ # another "make check", you will get new binaries to test against. # -if [ -z "${MH_TEST_COMMON}" ]; then - echo "MH_TEST_COMMON not set; try running via 'make check'" +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname $0`/.. + MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR fi -. ${MH_TEST_COMMON} - -setup_test +. "$MH_OBJ_DIR/test/common.sh" rm -rf ${MH_INST_DIR} diff --git a/test/common.sh.in b/test/common.sh.in index d5a9d7e..7596a48 100644 --- a/test/common.sh.in +++ b/test/common.sh.in @@ -1,6 +1,24 @@ # Common helper routines for test shell scripts -- intended to be sourced by them # @configure_input@ + +#### The following exported variables are set by "make check". Ensure +#### that they are set here so that individual tests can be run +#### outside of make. Requires that MH_OBJ_DIR be set on entry. +test -z "$MH_TEST_DIR" && MH_TEST_DIR="$MH_OBJ_DIR/test/testdir" +test -z "$prefix" && prefix=@prefix@ +test -z "$datarootdir" && datarootdir=@datarootdir@ +test -z "$exec_prefix" && exec_prefix=@exec_prefix@ +test -z "$auxexecdir" && auxexecdir="@libdir@" +test -z "$bindir" && bindir="@bindir@" +test -z "$mandir" && mandir="@mandir@" +test -z "$sysconfdir" && sysconfdir="@sysconfdir@" +export MH_TEST_DIR auxexecdir bindir mandir sysconfdir + +test -z "$MH_INST_DIR" && MH_INST_DIR=${MH_TEST_DIR}/inst +export MH_INST_DIR + + output_md5() { @MD5SUM@ $* | @MD5FMT@ @@ -61,20 +79,13 @@ progress_done () setup_test () { export MH=${MH_TEST_DIR}/Mail/.mh_profile - export MH_INST_DIR=${MH_TEST_DIR}/inst export MHMTSCONF=${MH_INST_DIR}${sysconfdir}/mts.conf export PATH=${MH_INST_DIR}${bindir}:${PATH} export MH_LIB_DIR=${MH_INST_DIR}${auxexecdir} - if [ -z "${srcdir}" ]; then - echo "srcdir not set; aborting" - exit 1 - fi - # - # Only do this once + # Only install once # - if [ ! -d ${MH_INST_DIR}${bindir} ]; then (cd ${MH_OBJ_DIR} && make DESTDIR=${MH_INST_DIR} install) || exit 1 fi diff --git a/test/folder/test-create b/test/folder/test-create index a3460ee..2e9e627 100755 --- a/test/folder/test-create +++ b/test/folder/test-create @@ -5,11 +5,12 @@ # ###################################################### -if [ -z "${MH_TEST_COMMON}" ]; then - echo "MH_TEST_COMMON not set; try running via 'make check'" +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname $0`/../.. + MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR fi -. ${MH_TEST_COMMON} +. "$MH_OBJ_DIR/test/common.sh" setup_test diff --git a/test/folder/test-total b/test/folder/test-total index 86b304f..c222792 100755 --- a/test/folder/test-total +++ b/test/folder/test-total @@ -5,11 +5,12 @@ # ###################################################### -if [ -z "${MH_TEST_COMMON}" ]; then - echo "MH_TEST_COMMON not set; try running via 'make check'" +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname $0`/../.. + MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR fi -. ${MH_TEST_COMMON} +. "$MH_OBJ_DIR/test/common.sh" setup_test diff --git a/test/format/test-localmbox b/test/format/test-localmbox index 196b03b..8ee6884 100755 --- a/test/format/test-localmbox +++ b/test/format/test-localmbox @@ -4,11 +4,12 @@ # component functions # -if [ -z "${MH_TEST_COMMON}" ]; then - echo "MH_TEST_COMMON not set; try running via 'make check'" +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname $0`/../.. + MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR fi -. ${MH_TEST_COMMON} +. "$MH_OBJ_DIR/test/common.sh" setup_test diff --git a/test/format/test-myhost b/test/format/test-myhost index d303a8f..c132565 100755 --- a/test/format/test-myhost +++ b/test/format/test-myhost @@ -4,11 +4,12 @@ # the localname entry out of the mts configuration file. # -if [ -z "${MH_TEST_COMMON}" ]; then - echo "MH_TEST_COMMON not set; try running via 'make check'" +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname $0`/../.. + MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR fi -. ${MH_TEST_COMMON} +. "$MH_OBJ_DIR/test/common.sh" setup_test diff --git a/test/format/test-mymbox b/test/format/test-mymbox index 82f0879..5a8ef41 100755 --- a/test/format/test-mymbox +++ b/test/format/test-mymbox @@ -4,11 +4,12 @@ # a particular email address is "mine" or not # -if [ -z "${MH_TEST_COMMON}" ]; then - echo "MH_TEST_COMMON not set; try running via 'make check'" +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname $0`/../.. + MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR fi -. ${MH_TEST_COMMON} +. "$MH_OBJ_DIR/test/common.sh" setup_test diff --git a/test/format/test-myname b/test/format/test-myname index 4e1dfaa..97a0539 100755 --- a/test/format/test-myname +++ b/test/format/test-myname @@ -4,11 +4,12 @@ # the Signature profile entry, and via SIGNATURE environment variable. # -if [ -z "${MH_TEST_COMMON}" ]; then - echo "MH_TEST_COMMON not set; try running via 'make check'" +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname $0`/../.. + MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR fi -. ${MH_TEST_COMMON} +. "$MH_OBJ_DIR/test/common.sh" setup_test diff --git a/test/inc/test-deb359167 b/test/inc/test-deb359167 index 72c6b7f..d2b2302 100755 --- a/test/inc/test-deb359167 +++ b/test/inc/test-deb359167 @@ -2,11 +2,16 @@ # Test a variant of a mailbox which caused debian bug 359167. set -e -. ${MH_TEST_COMMON} +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname $0`/../.. + MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR +fi + +. "$MH_OBJ_DIR/test/common.sh" setup_test -THISDIR="${srcdir}/test/inc" +THISDIR="${MH_OBJ_DIR}/test/inc" require_prog valgrind diff --git a/test/inc/test-eom-align b/test/inc/test-eom-align index 276d70c..06c972b 100755 --- a/test/inc/test-eom-align +++ b/test/inc/test-eom-align @@ -4,11 +4,16 @@ set -e -. ${MH_TEST_COMMON} +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname $0`/../.. + MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR +fi + +. "$MH_OBJ_DIR/test/common.sh" setup_test -THISDIR="${srcdir}/test/inc" +THISDIR="${MH_OBJ_DIR}/test/inc" if [ ! -z "$VALGRIND_ME" ]; then require_prog valgrind diff --git a/test/manpages/test-manpages b/test/manpages/test-manpages index 7c221ba..7cb7db8 100755 --- a/test/manpages/test-manpages +++ b/test/manpages/test-manpages @@ -6,7 +6,12 @@ # ###################################################### -. ${MH_TEST_COMMON} +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname $0`/../.. + MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR +fi + +. "$MH_OBJ_DIR/test/common.sh" setup_test diff --git a/test/mhbuild/test-forw b/test/mhbuild/test-forw index c92242f..e9a1b2f 100755 --- a/test/mhbuild/test-forw +++ b/test/mhbuild/test-forw @@ -5,11 +5,12 @@ # ###################################################### -if [ -z "${MH_TEST_COMMON}" ]; then - echo "MH_TEST_COMMON not set; try running via 'make check'" +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname $0`/../.. + MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR fi -. ${MH_TEST_COMMON} +. "$MH_OBJ_DIR/test/common.sh" setup_test diff --git a/test/mhshow/test-cte-binary b/test/mhshow/test-cte-binary index e5654bb..7d2125d 100755 --- a/test/mhshow/test-cte-binary +++ b/test/mhshow/test-cte-binary @@ -5,11 +5,12 @@ # ###################################################### -if [ -z "${MH_TEST_COMMON}" ]; then - echo "MH_TEST_COMMON not set; try running via 'make check'" +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname $0`/../.. + MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR fi -. ${MH_TEST_COMMON} +. "$MH_OBJ_DIR/test/common.sh" setup_test expected=$MH_TEST_DIR/$$.expected diff --git a/test/mhshow/test-qp b/test/mhshow/test-qp index c19a343..8116b21 100755 --- a/test/mhshow/test-qp +++ b/test/mhshow/test-qp @@ -7,11 +7,12 @@ set -e -if [ -z "${MH_TEST_COMMON}" ]; then - echo "MH_TEST_COMMON not set; try running via 'make check'" +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname $0`/../.. + MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR fi -. ${MH_TEST_COMMON} +. "$MH_OBJ_DIR/test/common.sh" setup_test diff --git a/test/mhshow/test-subpart b/test/mhshow/test-subpart index 9d8fe29..353962d 100755 --- a/test/mhshow/test-subpart +++ b/test/mhshow/test-subpart @@ -8,11 +8,12 @@ set -e -if [ -z "${MH_TEST_COMMON}" ]; then - echo "MH_TEST_COMMON not set; try running via 'make check'" +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname $0`/../.. + MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR fi -. ${MH_TEST_COMMON} +. "$MH_OBJ_DIR/test/common.sh" setup_test diff --git a/test/new/test-basic b/test/new/test-basic index 3b2befd..ca1a4cf 100755 --- a/test/new/test-basic +++ b/test/new/test-basic @@ -1,10 +1,16 @@ #!/bin/sh - -if [ -z "${MH_TEST_COMMON}" ]; then - echo "MH_TEST_COMMON not set; try running via 'make check'" +###################################################### +# +# Test many basic nmh capabilities. +# +###################################################### + +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname $0`/../.. + MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR fi -. ${MH_TEST_COMMON} +. "$MH_OBJ_DIR/test/common.sh" setup_test # TODO: Move to a common file tests can source; need more framework... diff --git a/test/pick/test-stderr b/test/pick/test-stderr index f3212da..07a2cf2 100755 --- a/test/pick/test-stderr +++ b/test/pick/test-stderr @@ -5,11 +5,12 @@ # ###################################################### -if [ -z "${MH_TEST_COMMON}" ]; then - echo "MH_TEST_COMMON not set; try running via 'make check'" +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname $0`/../.. + MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR fi -. ${MH_TEST_COMMON} +. "$MH_OBJ_DIR/test/common.sh" setup_test diff --git a/test/repl/test-if-str b/test/repl/test-if-str index 6bc0e09..2ed4fd0 100755 --- a/test/repl/test-if-str +++ b/test/repl/test-if-str @@ -8,11 +8,12 @@ # ###################################################### -if [ -z "${MH_TEST_COMMON}" ]; then - echo "MH_TEST_COMMON not set; try running via 'make check'" +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname $0`/../.. + MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR fi -. ${MH_TEST_COMMON} +. "$MH_OBJ_DIR/test/common.sh" setup_test diff --git a/test/scan/test-scan b/test/scan/test-scan index 1b688e0..8e59b96 100755 --- a/test/scan/test-scan +++ b/test/scan/test-scan @@ -5,11 +5,12 @@ # ###################################################### -if [ -z "${MH_TEST_COMMON}" ]; then - echo "MH_TEST_COMMON not set; try running via 'make check'" +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname $0`/../.. + MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR fi -. ${MH_TEST_COMMON} +. "$MH_OBJ_DIR/test/common.sh" setup_test diff --git a/test/whatnow/test-attach-detach b/test/whatnow/test-attach-detach index 4314553..5c359de 100755 --- a/test/whatnow/test-attach-detach +++ b/test/whatnow/test-attach-detach @@ -6,11 +6,12 @@ # ###################################################### -if [ -z "${MH_TEST_COMMON}" ]; then - echo "MH_TEST_COMMON not set; try running via 'make check'" +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname $0`/../.. + MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR fi -. ${MH_TEST_COMMON} +. "$MH_OBJ_DIR/test/common.sh" setup_test diff --git a/test/whatnow/test-cd b/test/whatnow/test-cd index d92f334..d39d9cf 100755 --- a/test/whatnow/test-cd +++ b/test/whatnow/test-cd @@ -6,11 +6,12 @@ # ###################################################### -if [ -z "${MH_TEST_COMMON}" ]; then - echo "MH_TEST_COMMON not set; try running via 'make check'" +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname $0`/../.. + MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR fi -. ${MH_TEST_COMMON} +. "$MH_OBJ_DIR/test/common.sh" setup_test diff --git a/test/whatnow/test-ls b/test/whatnow/test-ls index 58ee2f6..0504036 100755 --- a/test/whatnow/test-ls +++ b/test/whatnow/test-ls @@ -6,11 +6,12 @@ # ###################################################### -if [ -z "${MH_TEST_COMMON}" ]; then - echo "MH_TEST_COMMON not set; try running via 'make check'" +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname $0`/../.. + MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR fi -. ${MH_TEST_COMMON} +. "$MH_OBJ_DIR/test/common.sh" setup_test -- 1.7.10.4