#! /bin/bash #************************************************************************* # "run-tests" is free software: you can redistribute it and/or modify * # it under the terms of the GNU Affero Public License as published by * # the Free Software Foundation, either version 3 of the License, or * # (at your option) any later version. * # * # "run-tests" is distributed in the hope that it will be useful, * # but WITHOUT ANY WARRANTY; without even the implied warranty of * # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * # GNU Affero Public License for more details. * # * # You should have received a copy of the GNU Affero Public License * # along with Edward. If not, see . * # * # Copyright (C) 2015 Andrew Engelbrecht (AGPLv3+) * #************************************************************************* NUM_TESTS=1 function _main { COUNT=$1 SCRIPT_DIR="$(_get_script_dir)" TESTS_DIR="$SCRIPT_DIR/tests" G_HOME="$TESTS_DIR/testgnupghome" ERROR_COUNT="0" for i in $(seq "$COUNT") ; do TEST_INPUT="$TESTS_DIR/test$i.eml" TEST_OUTPUT="$TESTS_DIR/out$i.txt" _exec_compare "$TEST_INPUT" "$TEST_OUTPUT" "$G_HOME" ERROR="$?" ERROR_COUNT="$(expr "$ERROR_COUNT" + "$ERROR")" done if [ "$ERROR_COUNT" -ne "0" ] ; then echo "*** Failed test count: $ERROR_COUNT" >&2 exit 1 fi exit 0 } function _exec_compare { TEST_INPUT="$1" TEST_OUTPUT="$2" G_HOME="$3" OUT_DIFF="$(time ./edward < "$TEST_INPUT" | GNUPGHOME="$G_HOME" gpg 2> /dev/null | ./tests/flatten-mime | diff -Z -u "$TEST_OUTPUT" - )" if [ -n "$OUT_DIFF" ] ; then echo "*** test 1 failed! difference:" >&2 echo "$OUT_DIFF" >&2 return 1 fi return 0 } function _get_script_dir { # gives the directory containing this script # https://stackoverflow.com/questions/59895 SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) echo -n "$SCRIPT_DIR" } _main $NUM_TESTS