1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#!/bin/bash
export REG_DIR="$PWD"
export PATH="$PWD/bin:$PATH"
export LC_ALL=C
source scaffold
# usage: empty_repo
function empty_repo
{
rm -rf "$REPODIR"
mkdir "$REPODIR"
cd "$REPODIR" > /dev/null
git init 2> /dev/null > /dev/null
cd - > /dev/null
}
function test_failed
{
cat >&2 <<DONE
Test failed!
Test: $TESTNAME
Log file: $LOGFILE
Repo dir: "$REPODIR"
DONE
exit 1
}
# usage: check_test <test number>
function check_test
{
if [ ! -x "t-$1.sh" ]; then
echo "Test $1 does not exist or is not runnable" >&2
return 1
fi
return 0
}
# usage: run_test <test number>
function run_test
{
# We make sure we can handle space characters
# by including one in REPODIR.
export REPODIR="/tmp/guilt reg.$RANDOM"
export LOGFILE="/tmp/guilt.log.$RANDOM"
export TESTNAME="$1"
echo -n "$1: "
empty_repo
# run the test
cd "$REPODIR" > /dev/null
if "$REG_DIR/t-$1.sh" 2>&1 > "$LOGFILE"; then
ERR=false
else
ERR=true
fi
cd - > /dev/null
$ERR && test_failed
diff -u "t-$1.out" "$LOGFILE" || test_failed
echo "done."
rm -rf "$REPODIR" "$LOGFILE"
}
case "$1" in
-h|--help)
echo "Usage: $0 [<testnum> [<testnum [<testnum [...]]]]"
exit 0
;;
esac
if [ $# -eq 0 ]; then
for t in t-*.sh ; do
run_test `echo "$t" | sed -e 's/^t-//' -e 's/\.sh$//'`
done
else
for t in "$@" ; do
check_test "$t"
done
for t in "$@" ; do
run_test "$t"
done
fi
echo "All tests completed."
|