further generalization of the testing script
[edward.git] / run-tests
CommitLineData
341bb4d5
AE
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
a3c531c3 20NUM_TESTS=1
341bb4d5 21
a3c531c3 22function _main {
341bb4d5 23
a3c531c3
AE
24 COUNT=$1
25
9bd7bfbc
AE
26 SCRIPT_DIR="$(_get_script_dir)"
27 TESTS_DIR="$SCRIPT_DIR/tests"
28 G_HOME="$TESTS_DIR/testgnupghome"
33ecbb5e
AE
29 EDWARD="$SCRIPT_DIR/edward"
30 FLATTEN_MIME="$TESTS_DIR/flatten-mime"
9bd7bfbc 31
a3c531c3
AE
32 ERROR_COUNT="0"
33 for i in $(seq "$COUNT") ; do
34
33ecbb5e
AE
35 TEST_INPUT="$TESTS_DIR/gpg-flatten-$i.eml"
36 TEST_OUTPUT="$TESTS_DIR/gpg-flatten-$i.out"
a3c531c3 37
33ecbb5e 38 ERROR="$(_exec_gpg_flatten "$i" "$G_HOME" "$EDWARD" "$FLATTEN_MIME" "$TEST_INPUT" "$TEST_OUTPUT")"
a3c531c3
AE
39
40 ERROR_COUNT="$(expr "$ERROR_COUNT" + "$ERROR")"
9bd7bfbc 41
a3c531c3
AE
42 done
43
9bd7bfbc 44 if [ "$ERROR_COUNT" -ne "0" ] ; then
a3c531c3
AE
45 echo "*** Failed test count: $ERROR_COUNT" >&2
46 exit 1
47 fi
48
49 exit 0
50
51}
52
33ecbb5e 53function _exec_gpg_flatten {
a3c531c3 54
33ecbb5e
AE
55 TEST_NUM="$1"
56 G_HOME="$2"
57 TEST_EXEC_1="$3"
58 TEST_EXEC_2="$4"
59 TEST_INPUT="$5"
60 TEST_OUTPUT="$6"
a3c531c3 61
33ecbb5e
AE
62 PROGRAM_OUT="$(time "$TEST_EXEC_1" < "$TEST_INPUT" | GNUPGHOME="$G_HOME" gpg 2> /dev/null | "$TEST_EXEC_2" )"
63
64 ERROR="$(_diff "$TEST_NUM" "$TEST_OUTPUT" "$PROGRAM_OUT")"
65
66 echo "$ERROR"
67
68}
69
70function _diff {
71
72 TEST_NUM="$1"
73 TEST_OUT="$2"
74 PROGRAM_OUT="$3"
75
76 OUT_DIFF="$(echo "$PROGRAM_OUT" | diff -u "$TEST_OUT" - )"
a3c531c3
AE
77
78 if [ -n "$OUT_DIFF" ] ; then
33ecbb5e 79 echo "*** TEST $TEST_NUM FAILED! Output difference:" >&2
a3c531c3
AE
80 echo "$OUT_DIFF" >&2
81
33ecbb5e
AE
82 echo -n "1"
83 return
a3c531c3
AE
84 fi
85
33ecbb5e 86 echo -n "0"
a3c531c3
AE
87}
88
9bd7bfbc
AE
89function _get_script_dir {
90
91 # gives the directory containing this script
92 # https://stackoverflow.com/questions/59895
93 SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
94
95 echo -n "$SCRIPT_DIR"
96
97}
98
a3c531c3 99_main $NUM_TESTS
341bb4d5 100