regression: fixed git invocation
[guilt.git] / regression / run-tests
blob4cb3eb40872fba143eddef3db7a203aa9259b5f2
1 #!/bin/bash
3 export REG_DIR="$PWD"
4 export PATH="$PWD/bin:$PATH"
5 export LC_ALL=C
7 source scaffold
9 # usage: empty_repo
10 function empty_repo
12 rm -rf $REPODIR
13 mkdir $REPODIR
14 cd $REPODIR > /dev/null
15 git init 2> /dev/null > /dev/null
16 cd - > /dev/null
19 function test_failed
21 cat >&2 <<DONE
22 Test failed!
24 Test: $TESTNAME
25 Repo dir: $REPODIR
26 Log file: $LOGFILE
27 DONE
28 exit 1
31 # usage: check_test <test number>
32 function check_test
34 if [ ! -x "t-$1.sh" ]; then
35 echo "Test $1 does not exist or is not runnable" >&2
36 return 1
39 return 0
42 # usage: run_test <test number>
43 function run_test
45 export REPODIR="/tmp/guilt.reg.$RANDOM"
46 export LOGFILE="/tmp/guilt.log.$RANDOM"
47 export TESTNAME="$1"
49 echo -n "$1: "
51 empty_repo
53 # run the test
54 cd $REPODIR > /dev/null
55 "$REG_DIR/t-$1.sh" 2>&1 > "$LOGFILE"
56 ERR=$?
57 cd - > /dev/null
59 [ $? -ne 0 ] && test_failed
60 diff -u "t-$1.out" "$LOGFILE" || test_failed
62 echo "done."
64 rm -rf $REPODIR $LOGFILE
67 case "$1" in
68 -h|--help)
69 echo "Usage: $0 [<testnum> [<testnum [<testnum [...]]]]"
70 exit 0
72 esac
74 if [ $# -eq 0 ]; then
75 for t in t-*.sh ; do
76 run_test `echo "$t" | sed -e 's/^t-//' -e 's/\.sh$//'`
77 done
78 else
79 for t in "$@" ; do
80 check_test "$t"
81 done
83 for t in "$@" ; do
84 run_test "$t"
85 done
88 echo "All tests completed."