Guilt v0.30
[guilt.git] / regression / run-tests
blob8f572eb4749fbdd81c42a4d95717d4d69ba925a9
1 #!/bin/bash
3 export REG_DIR="$PWD"
4 export PATH="$PWD/bin:$PATH"
6 source scaffold
8 # usage: empty_repo
9 function empty_repo
11 rm -rf $REPODIR
12 mkdir $REPODIR
13 cd $REPODIR > /dev/null
14 git-init-db 2> /dev/null > /dev/null
15 cd - > /dev/null
18 function test_failed
20 cat >&2 <<DONE
21 Test failed!
23 Test: $TESTNAME
24 Repo dir: $REPODIR
25 Log file: $LOGFILE
26 DONE
27 exit 1
30 # usage: check_test <test number>
31 function check_test
33 if [ ! -x "t-$1.sh" ]; then
34 echo "Test $1 does not exist or is not runnable" >&2
35 return 1
38 return 0
41 # usage: run_test <test number>
42 function run_test
44 export REPODIR="/tmp/guilt.reg.$RANDOM"
45 export LOGFILE="/tmp/guilt.log.$RANDOM"
46 export TESTNAME="$1"
48 echo -n "$1: "
50 empty_repo
52 # run the test
53 cd $REPODIR > /dev/null
54 "$REG_DIR/t-$1.sh" 2>&1 > "$LOGFILE"
55 ERR=$?
56 cd - > /dev/null
58 [ $? -ne 0 ] && test_failed
59 diff -u "t-$1.out" "$LOGFILE" || test_failed
61 echo "done."
63 rm -rf $REPODIR $LOGFILE
66 case "$1" in
67 -h|--help)
68 echo "Usage: $0 [<testnum> [<testnum [<testnum [...]]]]"
69 exit 0
71 esac
73 if [ $# -eq 0 ]; then
74 for t in t-*.sh ; do
75 run_test `echo "$t" | sed -e 's/^t-//' -e 's/\.sh$//'`
76 done
77 else
78 for t in "$@" ; do
79 check_test "$t"
80 done
82 for t in "$@" ; do
83 run_test "$t"
84 done
87 echo "All tests completed."