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. *
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. *
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/>. *
17 # Copyright (C) 2015 Andrew Engelbrecht (AGPLv3+) *
18 #*************************************************************************
21 #TEST_TYPES="gpg-flatten flatten plain"
22 TEST_TYPES
="gpg-flatten plain"
27 SCRIPT_DIR
="$(_get_script_dir)"
29 _run_all_tests
"$SCRIPT_DIR" "$TEST_TYPES"
32 function _run_all_tests
{
38 for TYPE
in $TEST_TYPES ; do
39 ERRORS
="$(_run_test_type "$SCRIPT_DIR" "$TYPE")"
41 ERROR_COUNT
="$(expr "$ERROR_COUNT" + "$ERRORS")"
44 if [ "$ERROR_COUNT" -ne "0" ] ; then
45 echo "*** Failed test count: $ERROR_COUNT" >&2
53 function _run_test_type
{
58 TESTS_DIR
="$SCRIPT_DIR/tests"
59 G_HOME
="$TESTS_DIR/testgnupghome"
60 EDWARD
="$SCRIPT_DIR/edward"
61 FLATTEN_MIME
="$TESTS_DIR/flatten-mime"
64 for TEST_NAME
in $
(ls $TESTS_DIR/$TEST_TYPE-*.eml
) ; do
66 TEST_INPUT
="$TEST_NAME"
67 TEST_OUTPUT
="$(dirname "$TEST_NAME")/$(basename -s .eml "$TEST_NAME").out"
69 if [ ! -f "$TEST_OUTPUT" ] ; then
70 echo "*** $PROGNAME: ERROR: File not found: $TEST_OUTPUT" >&2
71 ERROR_COUNT
="$(expr "$ERROR_COUNT" + 1 )"
75 ERROR
="$("_exec_
$TEST_TYPE" "$TEST_NAME" "$G_HOME" "$EDWARD" "$FLATTEN_MIME" "$TEST_INPUT" "$TEST_OUTPUT")"
77 ERROR_COUNT
="$(expr "$ERROR_COUNT" + "$ERROR")"
84 function _exec_gpg-flatten
{
93 PROGRAM_OUT
="$(time "$TEST_EXEC_1" < "$TEST_INPUT" | GNUPGHOME="$G_HOME" gpg 2> /dev/null | "$TEST_EXEC_2" )"
95 ERROR
="$(_diff "$TEST_NAME" "$TEST_OUTPUT" "$PROGRAM_OUT")"
100 function _exec_flatten
{
108 PROGRAM_OUT
="$(time "$TEST_EXEC_1" < "$TEST_INPUT" | "$TEST_EXEC_2" )"
110 ERROR
="$(_diff "$TEST_NAME" "$TEST_OUTPUT" "$PROGRAM_OUT")"
115 function _exec_plain
{
122 PROGRAM_OUT
="$(time "$TEST_EXEC_1" < "$TEST_INPUT" )"
124 ERROR
="$(_diff "$TEST_NAME" "$TEST_OUTPUT" "$PROGRAM_OUT")"
135 OUT_DIFF
="$(echo "$PROGRAM_OUT" | diff -u "$TEST_OUT" - )"
137 if [ -n "$OUT_DIFF" ] ; then
138 echo "*** $PROGNAME: TEST $(basename "$TEST_NAME") FAILED! Output difference:" >&2
148 function _get_script_dir
{
150 # gives the directory containing this script
151 # https://stackoverflow.com/questions/59895
152 SCRIPT_DIR
=$
( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
154 echo -n "$SCRIPT_DIR"
157 PROGNAME
="$(basename $0)"