automatically find the tests directory
[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
22 function _main {
23
24 COUNT=$1
25
26 SCRIPT_DIR="$(_get_script_dir)"
27 TESTS_DIR="$SCRIPT_DIR/tests"
28 G_HOME="$TESTS_DIR/testgnupghome"
29
30 ERROR_COUNT="0"
31 for i in $(seq "$COUNT") ; do
32
33 TEST_INPUT="$TESTS_DIR/test$i.eml"
34 TEST_OUTPUT="$TESTS_DIR/out$i.txt"
35
36 _exec_compare "$TEST_INPUT" "$TEST_OUTPUT" "$G_HOME"
37 ERROR="$?"
38
39 ERROR_COUNT="$(expr "$ERROR_COUNT" + "$ERROR")"
40
41 done
42
43 if [ "$ERROR_COUNT" -ne "0" ] ; then
44 echo "*** Failed test count: $ERROR_COUNT" >&2
45 exit 1
46 fi
47
48 exit 0
49
50 }
51
52 function _exec_compare {
53
54 TEST_INPUT="$1"
55 TEST_OUTPUT="$2"
56 G_HOME="$3"
57
58 OUT_DIFF="$(time ./edward < "$TEST_INPUT" | GNUPGHOME="$G_HOME" gpg 2> /dev/null | ./tests/flatten-mime | diff -Z -u "$TEST_OUTPUT" - )"
59
60 if [ -n "$OUT_DIFF" ] ; then
61 echo "*** test 1 failed! difference:" >&2
62 echo "$OUT_DIFF" >&2
63
64 return 1
65 fi
66
67 return 0
68 }
69
70 function _get_script_dir {
71
72 # gives the directory containing this script
73 # https://stackoverflow.com/questions/59895
74 SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
75
76 echo -n "$SCRIPT_DIR"
77
78 }
79
80 _main $NUM_TESTS
81