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>
Jonathan Nieder committed
Oct 17, 2010 at 02:36 UTC
05236a5e9d29a2628a8f1de96a2a256185687e6c
1 file changed
+19
-7
t/test-lib.sh
+19
-7
@@ -362,6 +362,15 @@ test_have_prereq () {
362
test $total_prereq = $ok_prereq
363
}
364
365
+test_declared_prereq () {
366
+ case ",$test_prereq," in
367
+ *,$1,*)
368
+ return 0
369
+ ;;
370
+ esac
371
+ return 1
372
+}
373
+
374
# You are not expected to call test_ok_ and test_failure_ directly, use
375
# the text_expect_* functions instead.
376
@@ -414,17 +423,17 @@ test_skip () {
423
break
424
esac
425
done
417
- if test -z "$to_skip" && test -n "$prereq" &&
418
- ! test_have_prereq "$prereq"
426
+ if test -z "$to_skip" && test -n "$test_prereq" &&
427
+ ! test_have_prereq "$test_prereq"
428
then
429
to_skip=t
430
fi
431
case "$to_skip" in
432
t)
433
of_prereq=
425
- if test "$missing_prereq" != "$prereq"
434
+ if test "$missing_prereq" != "$test_prereq"
435
then
427
- of_prereq=" of $prereq"
436
+ of_prereq=" of $test_prereq"
437
fi
438
439
say_color skip >&3 "skipping test: $@"
@@ -438,9 +447,10 @@ test_skip () {
447
}
448
449
test_expect_failure () {
441
- test "$#" = 3 && { prereq=$1; shift; } || prereq=
450
+ test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
451
test "$#" = 2 ||
452
error "bug in the test script: not 2 or 3 parameters to test-expect-failure"
453
+ export test_prereq
454
if ! test_skip "$@"
455
then
456
say >&3 "checking known breakage: $2"
@@ -456,9 +466,10 @@ test_expect_failure () {
466
}
467
468
test_expect_success () {
459
- test "$#" = 3 && { prereq=$1; shift; } || prereq=
469
+ test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
470
test "$#" = 2 ||
471
error "bug in the test script: not 2 or 3 parameters to test-expect-success"
472
+ export test_prereq
473
if ! test_skip "$@"
474
then
475
say >&3 "expecting success: $2"
@@ -500,11 +511,12 @@ test_expect_code () {
511
# Usage: test_external description command arguments...
512
# Example: test_external 'Perl API' perl ../path/to/test.pl
513
test_external () {
503
- test "$#" = 4 && { prereq=$1; shift; } || prereq=
514
+ test "$#" = 4 && { test_prereq=$1; shift; } || test_prereq=
515
test "$#" = 3 ||
516
error >&5 "bug in the test script: not 3 or 4 parameters to test_external"
517
descr="$1"
518
shift
519
+ export test_prereq
520
if ! test_skip "$descr" "$@"
521
then
522
# Announce the script to reduce confusion about the