From 031871c2ede845956070da603e8494690f7beb70 Mon Sep 17 00:00:00 2001 From: Josh Bressers Date: Tue, 17 Apr 2007 01:02:08 +0000 Subject: [PATCH] Initial checkin of a testsuite --- test/README | 29 +++++++++++++++++++++++++++++ test/runalltests | 6 ++++++ test/runtest | 15 +++++++++++++++ test/setup-test | 30 ++++++++++++++++++++++++++++++ test/teardown-test | 4 ++++ test/test-temp-dir | 1 + test/tests/folder/test-create | 20 ++++++++++++++++++++ test/tests/folder/test-total | 14 ++++++++++++++ test/tests/pick/test-pick | 3 +++ test/tests/scan/test-scan | 18 ++++++++++++++++++ 10 files changed, 140 insertions(+) create mode 100644 test/README create mode 100755 test/runalltests create mode 100755 test/runtest create mode 100755 test/setup-test create mode 100755 test/teardown-test create mode 100644 test/test-temp-dir create mode 100644 test/tests/folder/test-create create mode 100644 test/tests/folder/test-total create mode 100644 test/tests/pick/test-pick create mode 100644 test/tests/scan/test-scan diff --git a/test/README b/test/README new file mode 100644 index 0000000..ddfa381 --- /dev/null +++ b/test/README @@ -0,0 +1,29 @@ +nmh unit test suite. + +The purpose of these tests is to verify the functionality of the nmh +commands. The goal of the suite is to create an environment where testing +nmh commands is easy and useful. Each test is a shell script, and is +launched via the 'sh' command. + +The Suite is arranged as such: + +setup-test + Create the unit test framework. This will re-generate your configure + script and make files. + +teardown-test + Remove the temporary files created as part of the unit tests. + +runtest + Run a single test. + +runalltests + Run all tests in the suite + +tests + Directory containing the tests. All files found in this and all + subsequent directories which have the name test-* will be treated as a + single test. + +Complex tests may be given their own directory as long as there is a file +named 'test-*' in the directory which will launch the test. diff --git a/test/runalltests b/test/runalltests new file mode 100755 index 0000000..b43d42c --- /dev/null +++ b/test/runalltests @@ -0,0 +1,6 @@ +#!/bin/sh + +for i in `find tests -name 'test-*' -type f`; +do + ./runtest $i +done diff --git a/test/runtest b/test/runtest new file mode 100755 index 0000000..d970b18 --- /dev/null +++ b/test/runtest @@ -0,0 +1,15 @@ +#!/bin/sh + +export MH=`cat test-temp-dir`/mh_profile +export MH_TEST_DIR=`cat test-temp-dir` +export PATH=$MH_TEST_DIR/bin:$PATH + +/bin/sh $1 + +return_value=$? + +if [ $return_value -eq 0 ] ; then + echo Test $1 PASS +else + echo Test $1 FAIL +fi diff --git a/test/setup-test b/test/setup-test new file mode 100755 index 0000000..d197295 --- /dev/null +++ b/test/setup-test @@ -0,0 +1,30 @@ +#!/bin/sh + +TEMPDIR=`mktemp -d /tmp/nmh-test-XXXXXXXX` +echo $TEMPDIR > test-temp-dir + +pushd .. +aclocal +autoheader +autoconf +./configure --prefix=$TEMPDIR --with-locking=fcntl +make install + +echo "Path: $TEMPDIR/Mail" > $TEMPDIR/mh_profile +mkdir $TEMPDIR/Mail + +MH=$TEMPDIR/mh_profile $TEMPDIR/bin/folder -create +inbox + +for i in `seq 1 10`; +do + cat > $TEMPDIR/Mail/inbox/$i < +To: Some User +Date: Fri, 29 Sep 2006 00:00:00 +Subject: Testing message $i + +This is message number $i +EOF +done + +popd diff --git a/test/teardown-test b/test/teardown-test new file mode 100755 index 0000000..7e169e4 --- /dev/null +++ b/test/teardown-test @@ -0,0 +1,4 @@ +#!/bin/sh + +rm -rf `cat test-temp-dir` +rm -f test-temp-dir diff --git a/test/test-temp-dir b/test/test-temp-dir new file mode 100644 index 0000000..5ca70d0 --- /dev/null +++ b/test/test-temp-dir @@ -0,0 +1 @@ +/tmp/nmh-test-rWzU1325 diff --git a/test/tests/folder/test-create b/test/tests/folder/test-create new file mode 100644 index 0000000..a5b71ba --- /dev/null +++ b/test/tests/folder/test-create @@ -0,0 +1,20 @@ +#!/bin/sh +###################################################### +# +# Test the creation and removal of a folder. +# +###################################################### + +BINDIR=$MH_TEST_DIR/bin + + +folder -create +testfolder > /dev/null +if [ ! -d "$MH_TEST_DIR/Mail/testfolder" ]; then + exit 1 +fi + +rmf +testfolder > /dev/null +if [ -d "$MH_TEST_DIR/Mail/testfolder" ]; then + # Test failed + exit 1 +fi diff --git a/test/tests/folder/test-total b/test/tests/folder/test-total new file mode 100644 index 0000000..6da3174 --- /dev/null +++ b/test/tests/folder/test-total @@ -0,0 +1,14 @@ +#!/bin/sh +###################################################### +# +# Test the -total switch +# +###################################################### + +BINDIR=$MH_TEST_DIR/bin + + +output=`folder -total +inbox` +if test x"$output" != x'TOTAL = 10 messages in 1 folder.' ; then + exit 1 +fi diff --git a/test/tests/pick/test-pick b/test/tests/pick/test-pick new file mode 100644 index 0000000..2bb8d86 --- /dev/null +++ b/test/tests/pick/test-pick @@ -0,0 +1,3 @@ +#!/bin/sh + +exit 1 diff --git a/test/tests/scan/test-scan b/test/tests/scan/test-scan new file mode 100644 index 0000000..4aca55f --- /dev/null +++ b/test/tests/scan/test-scan @@ -0,0 +1,18 @@ +#!/bin/sh + +expected_text=" 1 09/29*Test1 Testing message 1<> + 2 09/29*Test2 Testing message 2<> + 3 09/29*Test3 Testing message 3<> + 4 09/29*Test4 Testing message 4<> + 5 09/29*Test5 Testing message 5<> + 6 09/29*Test6 Testing message 6<> + 7 09/29*Test7 Testing message 7<> + 8 09/29*Test8 Testing message 8<> + 9 09/29*Test9 Testing message 9<> + 10 09/29*Test10 Testing message 10<>" + +output=`scan -width 80 +inbox` + +if test x"$output" != x"$expected_text" ; then + exit 1 +fi -- 1.7.10.4