summaryrefslogtreecommitdiff
path: root/t/test-lib.sh
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2010-10-17 02:36:58 +0800
committerJunio C Hamano <gitster@pobox.com>2010-10-18 16:20:19 -0700
commit05236a5e9d29a2628a8f1de96a2a256185687e6c (patch)
tree7de359a6c33a36a8d0195a742449d1929f8e5fe7 /t/test-lib.sh
parente23f436c35c3e7fd12feeed783064e08aaf27869 (diff)
downloadgit-05236a5e9d29a2628a8f1de96a2a256185687e6c.tar.gz
test-lib: allow test code to check the list of declared prerequisites
This is plumbing to prepare helpers like test_terminal to notice buggy test scripts that do not declare all of the necessary prerequisites. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/test-lib.sh')
-rw-r--r--t/test-lib.sh26
1 files changed, 19 insertions, 7 deletions
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 2af8f10c83..31366e10a3 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -362,6 +362,15 @@ test_have_prereq () {
test $total_prereq = $ok_prereq
}
+test_declared_prereq () {
+ case ",$test_prereq," in
+ *,$1,*)
+ return 0
+ ;;
+ esac
+ return 1
+}
+
# You are not expected to call test_ok_ and test_failure_ directly, use
# the text_expect_* functions instead.
@@ -414,17 +423,17 @@ test_skip () {
break
esac
done
- if test -z "$to_skip" && test -n "$prereq" &&
- ! test_have_prereq "$prereq"
+ if test -z "$to_skip" && test -n "$test_prereq" &&
+ ! test_have_prereq "$test_prereq"
then
to_skip=t
fi
case "$to_skip" in
t)
of_prereq=
- if test "$missing_prereq" != "$prereq"
+ if test "$missing_prereq" != "$test_prereq"
then
- of_prereq=" of $prereq"
+ of_prereq=" of $test_prereq"
fi
say_color skip >&3 "skipping test: $@"
@@ -438,9 +447,10 @@ test_skip () {
}
test_expect_failure () {
- test "$#" = 3 && { prereq=$1; shift; } || prereq=
+ test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
test "$#" = 2 ||
error "bug in the test script: not 2 or 3 parameters to test-expect-failure"
+ export test_prereq
if ! test_skip "$@"
then
say >&3 "checking known breakage: $2"
@@ -456,9 +466,10 @@ test_expect_failure () {
}
test_expect_success () {
- test "$#" = 3 && { prereq=$1; shift; } || prereq=
+ test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
test "$#" = 2 ||
error "bug in the test script: not 2 or 3 parameters to test-expect-success"
+ export test_prereq
if ! test_skip "$@"
then
say >&3 "expecting success: $2"
@@ -500,11 +511,12 @@ test_expect_code () {
# Usage: test_external description command arguments...
# Example: test_external 'Perl API' perl ../path/to/test.pl
test_external () {
- test "$#" = 4 && { prereq=$1; shift; } || prereq=
+ test "$#" = 4 && { test_prereq=$1; shift; } || test_prereq=
test "$#" = 3 ||
error >&5 "bug in the test script: not 3 or 4 parameters to test_external"
descr="$1"
shift
+ export test_prereq
if ! test_skip "$descr" "$@"
then
# Announce the script to reduce confusion about the