partially generalized the testing suite
[edward.git] / run-tests
1 #! /bin/bash
2
3 #*************************************************************************
4 # "run-tests" is free software: you can redistribute it and/or modify *
5 # it under the terms of the GNU Affero Public License as published by *
6 # the Free Software Foundation, either version 3 of the License, or *
7 # (at your option) any later version. *
8 # *
9 # "run-tests" is distributed in the hope that it will be useful, *
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 # GNU Affero Public License for more details. *
13 # *
14 # You should have received a copy of the GNU Affero Public License *
15 # along with Edward. If not, see <http://www.gnu.org/licenses/>. *
16 # *
17 # Copyright (C) 2015 Andrew Engelbrecht (AGPLv3+) *
18 #*************************************************************************
19
20 NUM_TESTS=1
21 G_HOME=./tests/testgnupghome
22
23 function _main {
24
25 COUNT=$1
26
27 ERROR_COUNT="0"
28 for i in $(seq "$COUNT") ; do
29
30 TEST_INPUT="./tests/test$i.eml"
31 TEST_OUTPUT="./tests/out$i.txt"
32
33 _exec_compare "$TEST_INPUT" "$TEST_OUTPUT"
34 ERROR=$?
35
36 ERROR_COUNT="$(expr "$ERROR_COUNT" + "$ERROR")"
37 done
38
39 if [ "$ERROR_COUNT" != "0" ] ; then
40 echo "*** Failed test count: $ERROR_COUNT" >&2
41 exit 1
42 fi
43
44 exit 0
45
46 }
47
48 function _exec_compare {
49
50 TEST_INPUT="$1"
51 TEST_OUTPUT="$2"
52
53 OUT_DIFF="$(time ./edward < "$TEST_INPUT" | GNUPGHOME="$G_HOME" gpg 2> /dev/null | ./tests/flatten-mime | diff -Z -u "$TEST_OUTPUT" - )"
54
55 if [ -n "$OUT_DIFF" ] ; then
56 echo "*** test 1 failed! difference:" >&2
57 echo "$OUT_DIFF" >&2
58
59 return 1
60 fi
61
62 return 0
63 }
64
65 _main $NUM_TESTS
66