| 1 |
# Copyright (C) 2011 Loïc Minier <[email protected]> |
| 2 |
|
| 3 |
# This program is free software; you can redistribute it and/or |
| 4 |
# modify it under the terms of the GNU General Public License |
| 5 |
# as published by the Free Software Foundation; either version 2 |
| 6 |
# of the License, or (at your option) any later version. |
| 7 |
# |
| 8 |
# This program is distributed in the hope that it will be useful, |
| 9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
# GNU General Public License for more details. |
| 12 |
# |
| 13 |
# You should have received a copy of the GNU General Public License |
| 14 |
# along with this program; if not, write to the Free Software |
| 15 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, |
| 16 |
# USA. |
| 17 |
|
| 18 |
set -e |
| 19 |
|
| 20 |
self="$(basename "$0")" |
| 21 |
|
| 22 |
# space separated list of tests |
| 23 |
all_tests="" |
| 24 |
add_test() { |
| 25 |
all_tests="${all_tests:+$all_tests }$*" |
| 26 |
} |
| 27 |
|
| 28 |
run_tests() { |
| 29 |
local passed_count=0 |
| 30 |
local skipped_count=0 |
| 31 |
local failed_count=0 |
| 32 |
# space separated lists of skipped and failed tests |
| 33 |
local skipped_tests="" |
| 34 |
local failed_tests="" |
| 35 |
|
| 36 |
for t; do |
| 37 |
count=$(($count + 1)) |
| 38 |
# look for skip_test_foo which tells us whether dependencies for this |
| 39 |
# test are satisfied |
| 40 |
if type skip_$t 2>&1 >/dev/null && skip_$t; then |
| 41 |
skipped="$skipped_tests $t" |
| 42 |
skipped_count="$(($skipped_count + 1))" |
| 43 |
continue |
| 44 |
fi |
| 45 |
if ($t); then |
| 46 |
passed_count=$(($passed_count + 1)) |
| 47 |
else |
| 48 |
failed_tests="$failed_tests $t" |
| 49 |
failed_count=$(($failed_count + 1)) |
| 50 |
fi |
| 51 |
done |
| 52 |
echo "passed: $passed_count; skipped: $skipped_count; failed: $failed_count" >&2 |
| 53 |
if [ -n "$skipped_tests" ]; then |
| 54 |
for t in $skipped_tests; do |
| 55 |
echo "skipped: $t" >&2 |
| 56 |
done |
| 57 |
fi |
| 58 |
if [ -n "$failed_tests" ]; then |
| 59 |
for t in $failed_tests; do |
| 60 |
echo "failed: $t" >&2 |
| 61 |
done |
| 62 |
return 1 |
| 63 |
fi |
| 64 |
return 0 |
| 65 |
} |
| 66 |
|
| 67 |
# space separated list of tempfiles; XXX doesn't support spaces in pathnames |
| 68 |
tempfiles="" |
| 69 |
last_tempfile="" |
| 70 |
cleanup_tempfiles(){ |
| 71 |
for t in $tempfiles "$last_tempfile"; do |
| 72 |
if [ -n "$t" ]; then |
| 73 |
rm -f "$t" |
| 74 |
fi |
| 75 |
done |
| 76 |
} |
| 77 |
trap cleanup_tempfiles EXIT HUP INT QUIT ILL KILL SEGV PIPE TERM |
| 78 |
|
| 79 |
get_tempfile() { |
| 80 |
last_tempfile="$(mktemp -t "$self.XXXXXXXX")" |
| 81 |
tempfiles="$tempfiles $last_tempfile" |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
test_main() { |
| 86 |
if [ $# = 0 ]; then |
| 87 |
run_tests $all_tests |
| 88 |
else |
| 89 |
run_tests "$@" |
| 90 |
fi |
| 91 |
} |
| 92 |
|
| 93 |
# vim:syntax=sh |