| 1 |
# |
| 2 |
# fstrcmp - fuzzy string compare library |
| 3 |
# Copyright (C) 2009, 2012 Peter Miller |
| 4 |
# Written by Peter Miller <[email protected]> |
| 5 |
# |
| 6 |
# This program is free software; you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation; either version 3 of the License, or (at |
| 9 |
# your option) any later version. |
| 10 |
# |
| 11 |
# This program is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
# General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License along |
| 17 |
# with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
# |
| 19 |
|
| 20 |
if [ "$TEST_SUBJECT" = "fill me in" -o "$TEST_SUBJECT" = "" ] |
| 21 |
then |
| 22 |
echo ' You must set the TEST_SUBJECT environment variable' 1>&2 |
| 23 |
echo ' at the top of your test script to something' 1>&2 |
| 24 |
echo ' descriptive.' 1>&2 |
| 25 |
exit 2 |
| 26 |
fi |
| 27 |
|
| 28 |
LIB_OPTIONS='debug, no-numeric-errno, no-dialect-specific, |
| 29 |
no-program-name' |
| 30 |
export LIB_OPTIONS |
| 31 |
|
| 32 |
# |
| 33 |
# Remember where we came from, so that we can refer back to it as necessary. |
| 34 |
# |
| 35 |
here=$(pwd) |
| 36 |
test $? -eq 0 || exit 2 |
| 37 |
arch=${1-.} |
| 38 |
bindir=$here/$arch/bin |
| 39 |
|
| 40 |
# |
| 41 |
# We are going to create a temporary directory for running tests within. |
| 42 |
# This makes it easy to clean up after tests (just rm -r) and it means |
| 43 |
# tests can be run even if the development directory is read only (e.g. |
| 44 |
# for reviewers). |
| 45 |
# |
| 46 |
testdir=/tmp/fstrcmp-$$ |
| 47 |
|
| 48 |
# |
| 49 |
# The tear_down function is used by all the ways of leaving a test |
| 50 |
# script, so that they all clean up in exactly the same way. |
| 51 |
# |
| 52 |
tear_down() |
| 53 |
{ |
| 54 |
set +x |
| 55 |
cd $here |
| 56 |
rm -rf $testdir |
| 57 |
} |
| 58 |
|
| 59 |
# |
| 60 |
# The pass function (command) is used to declare a test to have passed, |
| 61 |
# and exit. The exit code of 0 is dictated by Aegis, so Aegis can know |
| 62 |
# the result of running the test. |
| 63 |
# |
| 64 |
# Note that we don't say what was being tested, because only failed |
| 65 |
# tests are interesting, especially when your project get to the point |
| 66 |
# of having hundreds of tests. |
| 67 |
# |
| 68 |
pass() |
| 69 |
{ |
| 70 |
tear_down |
| 71 |
echo PASSED |
| 72 |
exit 0 |
| 73 |
} |
| 74 |
|
| 75 |
# |
| 76 |
# The fail function (command) is used to declare a test to have failed, |
| 77 |
# and exit. The exit code of 1 is dictated by Aegis, so Aegis can know |
| 78 |
# the result of running the test. |
| 79 |
# |
| 80 |
fail() |
| 81 |
{ |
| 82 |
tear_down |
| 83 |
echo "FAILED test of $TEST_SUBJECT" |
| 84 |
exit 1 |
| 85 |
} |
| 86 |
|
| 87 |
# |
| 88 |
# The no_result function (command) is used to declare a test to have |
| 89 |
# failed in an unexpected way, and exit. This is used for any case |
| 90 |
# where the "scaffolding" of a test does no succeed, effectively making |
| 91 |
# the correctedness of the functionality being tested indeterminate. |
| 92 |
# The exit code of 2 is dictated by Aegis, so Aegis can know the result |
| 93 |
# of running the test. |
| 94 |
# |
| 95 |
no_result() |
| 96 |
{ |
| 97 |
tear_down |
| 98 |
echo "NO RESULT for test of $TEST_SUBJECT" |
| 99 |
exit 1 |
| 100 |
} |
| 101 |
|
| 102 |
# |
| 103 |
# Create our testing directory and cd into it. |
| 104 |
# |
| 105 |
mkdir $testdir |
| 106 |
test $? -eq 0 || exit 2 |
| 107 |
cd $testdir |
| 108 |
test $? -eq 0 || no_result |
| 109 |
|
| 110 |
# On cygwin, we need to have diff ignore the CR in CRLF sequences |
| 111 |
# otherwise we see diff output which looks to be identical but which |
| 112 |
# diff things differs. And it does, by a carriage return. |
| 113 |
if diff --strip-trailing-cr /dev/null /dev/null > /dev/null 2>&1 |
| 114 |
then |
| 115 |
diffpath=`which diff` |
| 116 |
diff() { |
| 117 |
$diffpath --strip-trailing-cr "$@" |
| 118 |
} |
| 119 |
fi |