regress: setup_git_repo can assert that the repo is setup as intended
[guilt.git] / regression / run-tests
bloba10e79662102b17513d202ce114863ee7b8696fe
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 "$REG_DIR/t-$1.sh" 2>&1 > "$LOGFILE"
59 ERR=$?
60 cd - > /dev/null
62 [ $? -ne 0 ] && test_failed
63 diff -u "t-$1.out" "$LOGFILE" || test_failed
65 echo "done."
67 rm -rf "$REPODIR" "$LOGFILE"
70 case "$1" in
71 -h|--help)
72 echo "Usage: $0 [<testnum> [<testnum [<testnum [...]]]]"
73 exit 0
75 esac
77 if [ $# -eq 0 ]; then
78 for t in t-*.sh ; do
79 run_test `echo "$t" | sed -e 's/^t-//' -e 's/\.sh$//'`
80 done
81 else
82 for t in "$@" ; do
83 check_test "$t"
84 done
86 for t in "$@" ; do
87 run_test "$t"
88 done
91 echo "All tests completed."