restore: Implemented with rebase and reset. (Do not forget to reset manually in case...
[gitgitconfig.git] / run-tests.sh
blobe9b374e9267cf1846f327351406509556854d773
1 #!/bin/bash
3 SRCDIR="$(dirname "$0")"
5 absolute() {
6 case "$1" in
7 /*)
8 echo "$1"
9 ;;
11 echo "$(pwd)/$t"
13 esac
16 SRCDIR="$(absolute "$SRCDIR")"
17 readonly SRCDIR
19 # Set env for the scripts and test scripts:
20 readonly DATADIR="$SRCDIR"
21 if [[ "$PATH" ]]; then
22 readonly PATH="$SRCDIR:$PATH"
23 else
24 readonly PATH="$SRCDIR"
26 export DATADIR PATH
28 if [[ "$1" ]]; then
29 readonly TESTS=("$@")
30 else
31 readonly TESTS=("$SRCDIR"/tests/*.sh)
34 status=0
35 for t in "${TESTS[@]}"; do
36 echo -n "################################### "
37 echo "Running $(basename "$t")..."
39 # The absolute path will be needed after a pushd:
40 t="$(absolute "$t")"
42 # Clean up what has been left by previous tests:
43 rm -rf "$TMP"/test-gitgitconfig
45 mkdir "$TMP"/test-gitgitconfig
46 pushd "$TMP"/test-gitgitconfig
47 if "$t"; then echo OK; else echo FAILED; let '++ status'; fi
48 popd
49 done
51 echo "$status tests failed."
53 # Clean up if there have been no errors. Otherwise leave it for inspection.
54 if (( status == 0 )); then
55 rm -rf "$TMP"/test-gitgitconfig
58 exit $status