Initial checkin of a testsuite
authorJosh Bressers <josh@bress.net>
Tue, 17 Apr 2007 01:02:08 +0000 (01:02 +0000)
committerJosh Bressers <josh@bress.net>
Tue, 17 Apr 2007 01:02:08 +0000 (01:02 +0000)
test/README [new file with mode: 0644]
test/runalltests [new file with mode: 0755]
test/runtest [new file with mode: 0755]
test/setup-test [new file with mode: 0755]
test/teardown-test [new file with mode: 0755]
test/test-temp-dir [new file with mode: 0644]
test/tests/folder/test-create [new file with mode: 0644]
test/tests/folder/test-total [new file with mode: 0644]
test/tests/pick/test-pick [new file with mode: 0644]
test/tests/scan/test-scan [new file with mode: 0644]

diff --git a/test/README b/test/README
new file mode 100644 (file)
index 0000000..ddfa381
--- /dev/null
@@ -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 (executable)
index 0000000..b43d42c
--- /dev/null
@@ -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 (executable)
index 0000000..d970b18
--- /dev/null
@@ -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 (executable)
index 0000000..d197295
--- /dev/null
@@ -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 <<EOF
+From: Test$i <test$i@example.com>
+To: Some User <user@example.com>
+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 (executable)
index 0000000..7e169e4
--- /dev/null
@@ -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 (file)
index 0000000..5ca70d0
--- /dev/null
@@ -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 (file)
index 0000000..a5b71ba
--- /dev/null
@@ -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 (file)
index 0000000..6da3174
--- /dev/null
@@ -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 (file)
index 0000000..2bb8d86
--- /dev/null
@@ -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 (file)
index 0000000..4aca55f
--- /dev/null
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+expected_text="   1  09/29*Test1              Testing message 1<<This is message number 1 >>
+   2  09/29*Test2              Testing message 2<<This is message number 2 >>
+   3  09/29*Test3              Testing message 3<<This is message number 3 >>
+   4  09/29*Test4              Testing message 4<<This is message number 4 >>
+   5  09/29*Test5              Testing message 5<<This is message number 5 >>
+   6  09/29*Test6              Testing message 6<<This is message number 6 >>
+   7  09/29*Test7              Testing message 7<<This is message number 7 >>
+   8  09/29*Test8              Testing message 8<<This is message number 8 >>
+   9  09/29*Test9              Testing message 9<<This is message number 9 >>
+  10  09/29*Test10             Testing message 10<<This is message number 10 >>"
+
+output=`scan -width 80 +inbox`
+
+if test x"$output" != x"$expected_text" ; then
+    exit 1
+fi