#! /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" EDWARD="$SCRIPT_DIR/edward" FLATTEN_MIME="$TESTS_DIR/flatten-mime" ERROR_COUNT="0" for i in $(seq "$COUNT") ; do TEST_INPUT="$TESTS_DIR/gpg-flatten-$i.eml" TEST_OUTPUT="$TESTS_DIR/gpg-flatten-$i.out" ERROR="$(_exec_gpg_flatten "$i" "$G_HOME" "$EDWARD" "$FLATTEN_MIME" "$TEST_INPUT" "$TEST_OUTPUT")" 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_gpg_flatten { TEST_NUM="$1" G_HOME="$2" TEST_EXEC_1="$3" TEST_EXEC_2="$4" TEST_INPUT="$5" TEST_OUTPUT="$6" PROGRAM_OUT="$(time "$TEST_EXEC_1" < "$TEST_INPUT" | GNUPGHOME="$G_HOME" gpg 2> /dev/null | "$TEST_EXEC_2" )" ERROR="$(_diff "$TEST_NUM" "$TEST_OUTPUT" "$PROGRAM_OUT")" echo "$ERROR" } function _diff { TEST_NUM="$1" TEST_OUT="$2" PROGRAM_OUT="$3" OUT_DIFF="$(echo "$PROGRAM_OUT" | diff -u "$TEST_OUT" - )" if [ -n "$OUT_DIFF" ] ; then echo "*** TEST $TEST_NUM FAILED! Output difference:" >&2 echo "$OUT_DIFF" >&2 echo -n "1" return fi echo -n "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