1#!/bin/sh
2
3# Set default variables.
4#
5FAILED=0
6[ "$TEST_RESULTS" = "" ] && TEST_RESULTS=results.def
7ANOMY=..
8PERL5LIB=
9export ANOMY PERL5LIB
10
11# Charset related issues.
12if (echo $LANG | grep -c -i utf >/dev/null); then
13    echo
14    echo "WARNING: Your default language setting is $LANG, which may enable"
15    echo "UTF-8 (unicode) support in various programs, including Perl.  This"
16    echo "may cause the Anomy Sanitizer to malfunction."
17    echo "Please read the file UNICODE.TXT for further information."
18    echo
19    sleep 5
20fi
21LC_ALL=C
22LANG=en_US
23export LC_ALL LANG
24
25# Do we have/need the TNEF stuff?
26TNEF=0
27[ -e ../bin/Anomy/TNEFStream.pm ] && TNEF=1
28
29# Does "use bytes" work?
30if ! perl -Mbytes -e 1 2>/dev/null >/dev/null; then
31    echo "WARNING: Your perl is old, creating dummy 'bytes' module..."
32    echo "package bytes; sub unimport { 1; } 1;" > $ANOMY/bin/bytes.pm
33fi
34# Does "use warnings" work?
35if ! perl -Mwarnings -e 1 2>/dev/null >/dev/null; then
36    echo "WARNING: Your perl is old, creating dummy 'warnings' module..."
37    echo "package warnings; sub unimport { 1; } 1;" > $ANOMY/bin/warnings.pm
38fi
39
40# Check prerequisites.
41#
42echo -n "Checking prerequisites... "
43REQ="-MDigest::MD5 -MMIME::Base64 -MMIME::QuotedPrint -MIO::File -MIO::Socket::INET"
44[ $TNEF = 1 ] && REQ="$REQ -MMIME::Body"
45perl $REQ -e1 2>/dev/null
46if [ $? != 0 ] ; then
47    echo failed.
48    echo
49    echo "One or more of the following Perl modules were missing from your"
50    echo "system.  You need to install them before you can use the Anomy"
51    echo "Mail Sanitizer:"
52    echo
53    echo "    IO::File"
54    echo "    IO::Socket::INET"
55[ $TNEF = 1 ] && \
56    echo "    MIME::Body"
57    echo "    MIME::Base64"
58    echo "    MIME::QuotedPrint"
59    echo "    Digest::MD5"
60    echo
61    echo "Try 'perldoc CPAN' for information on how to obtain them.  But"
62    echo "beware - the CPAN module likes to upgrade your perl installation,"
63    echo "which may not be what you want. :-)"
64    echo
65    exit 1
66else
67    echo ok.
68fi
69
70# Load local configuration, if it exists.
71#
72if [ -f tests.conf ]; then
73    . tests.conf
74    echo "Using configuration from tests.conf - results go in $TEST_RESULTS."
75fi
76export TEST_RESULTS SAN_CONF
77
78# Minor sanity checks...
79#
80if [ ! -d "$TEST_RESULTS" ]; then
81    echo "No such directory: $TEST_RESULTS"
82    exit 1
83fi
84if [ "$SAN_CONF" != "" -a ! -r "$SAN_CONF" ]; then
85    echo "No such file: $SAN_CONF"
86    exit 1
87fi
88
89# Run tests!
90#
91WHICH=$1
92echo "Running tests ..."
93echo
94for a in *.t; do
95  if [ "$WHICH" = "" -o "$a" = "$WHICH" ]; then
96        test=`echo $a |sed -e 's/\.t$//'`
97	/bin/echo -n "$test:	"
98	sh $a
99	if [ -e "$TEST_RESULTS/$test.ok.rot13" ]; then
100            perl -npe 'tr/a-zA-Z/n-za-mN-ZA-M/' \
101              < "$TEST_RESULTS/$test.ok.rot13" > "$TEST_RESULTS/$test.ok"
102        fi
103	if [ ! -f "$TEST_RESULTS/$test.ok" ]; then
104	    cp test.out "$TEST_RESULTS/$test.ok"
105	    echo installed
106
107        else
108	    if diff -u -b "$TEST_RESULTS/$test.ok" test.out >test.diff; then
109	        T="$TEST_RESULTS/$test"
110	        rm -f test.* $T.out $T.log $T.diff
111	        echo ok
112            else
113		for t in test.*; do
114		    mv -f $t "$TEST_RESULTS"/`echo $t |sed -e "s/^test/$test/"`
115		done
116	        echo "failed  (moved result files to $TEST_RESULTS)"
117	 	let FAILED=$FAILED+1
118	    fi
119        fi
120	[ -e "$TEST_RESULTS/$test.ok.rot13" ] && rm -f "$TEST_RESULTS/$test.ok"
121  fi
122done
123
124rm -f test.*
125echo
126[ $FAILED = 0 ] && exit 0
127
128# Beg for feedback...
129#
130cat <<tac
131One or more tests failed!  There are two possible reasons for this:
132
133 1) Something was fixed, and your test-case results need to be updated.
134 2) I (the author) broke something.
135
136Please check the change-log to see which it is.  If it's number 1), then
137just replace the .ok file with the .out file generated by the failed test,
138in your result directory.
139
140Otherwise - if you think something is broken (case 2), please send the
141following info to anomy-bugs@mailtools.anomy.net:
142
143 - Architecture (e.g. Sparc, Intel, Alpha. ...)
144 - Operating system (e.g. RedHat 6.2, Solaris 8, HP-UX, ...)
145 - Perl version (the output of "perl -V")
146 - Any relevant Anomy configuration files (e.g. for the sanitizer).
147 - Copies of all result files for the failed tests (they should have the
148   extensions .ok, .out, .diff and .log).
149
150Thanks!
151
152tac
153exit 1
154
155