Guilt v0.37-rc1
[guilt.git] / regression / run-tests
blob8e0af9f0d3d2399010179b2a02ca2fc62cdc29e5
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 Log file: $LOGFILE
26 Repo dir: "$REPODIR"
28 DONE
29 exit 1
32 # usage: check_test <test number>
33 function check_test
35 if [ ! -x "t-$1.sh" ]; then
36 echo "Test $1 does not exist or is not runnable" >&2
37 return 1
40 return 0
43 # usage: run_test <test number>
44 function run_test
46 # We make sure we can handle space characters
47 # by including one in REPODIR.
48 export REPODIR="/tmp/guilt reg.$RANDOM"
49 export LOGFILE="/tmp/guilt.log.$RANDOM"
50 export TESTNAME="$1"
52 echo -n "$1: "
54 empty_repo
56 # run the test
57 cd "$REPODIR" > /dev/null
58 if "$REG_DIR/t-$1.sh" 2>&1 > "$LOGFILE"; then
59 ERR=false
60 else
61 ERR=true
64 cd - > /dev/null
66 $ERR && test_failed
67 diff -u "t-$1.out" "$LOGFILE" || test_failed
69 echo "done."
71 rm -rf "$REPODIR" "$LOGFILE"
74 case "$1" in
75 -h|--help)
76 echo "Usage: $0 [<testnum> [<testnum [<testnum [...]]]]"
77 exit 0
79 esac
81 if [ $# -eq 0 ]; then
82 for t in t-*.sh ; do
83 run_test `echo "$t" | sed -e 's/^t-//' -e 's/\.sh$//'`
84 done
85 else
86 for t in "$@" ; do
87 check_test "$t"
88 done
90 for t in "$@" ; do
91 run_test "$t"
92 done
95 echo "All tests completed."