Skip to content

Commit 05236a5

Browse files
jrngitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e23f436 commit 05236a5

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

t/test-lib.sh

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,15 @@ test_have_prereq () {
362362
test $total_prereq = $ok_prereq
363363
}
364364

365+
test_declared_prereq () {
366+
case ",$test_prereq," in
367+
*,$1,*)
368+
return 0
369+
;;
370+
esac
371+
return 1
372+
}
373+
365374
# You are not expected to call test_ok_ and test_failure_ directly, use
366375
# the text_expect_* functions instead.
367376

@@ -414,17 +423,17 @@ test_skip () {
414423
break
415424
esac
416425
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"
419428
then
420429
to_skip=t
421430
fi
422431
case "$to_skip" in
423432
t)
424433
of_prereq=
425-
if test "$missing_prereq" != "$prereq"
434+
if test "$missing_prereq" != "$test_prereq"
426435
then
427-
of_prereq=" of $prereq"
436+
of_prereq=" of $test_prereq"
428437
fi
429438

430439
say_color skip >&3 "skipping test: $@"
@@ -438,9 +447,10 @@ test_skip () {
438447
}
439448

440449
test_expect_failure () {
441-
test "$#" = 3 && { prereq=$1; shift; } || prereq=
450+
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
442451
test "$#" = 2 ||
443452
error "bug in the test script: not 2 or 3 parameters to test-expect-failure"
453+
export test_prereq
444454
if ! test_skip "$@"
445455
then
446456
say >&3 "checking known breakage: $2"
@@ -456,9 +466,10 @@ test_expect_failure () {
456466
}
457467

458468
test_expect_success () {
459-
test "$#" = 3 && { prereq=$1; shift; } || prereq=
469+
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
460470
test "$#" = 2 ||
461471
error "bug in the test script: not 2 or 3 parameters to test-expect-success"
472+
export test_prereq
462473
if ! test_skip "$@"
463474
then
464475
say >&3 "expecting success: $2"
@@ -500,11 +511,12 @@ test_expect_code () {
500511
# Usage: test_external description command arguments...
501512
# Example: test_external 'Perl API' perl ../path/to/test.pl
502513
test_external () {
503-
test "$#" = 4 && { prereq=$1; shift; } || prereq=
514+
test "$#" = 4 && { test_prereq=$1; shift; } || test_prereq=
504515
test "$#" = 3 ||
505516
error >&5 "bug in the test script: not 3 or 4 parameters to test_external"
506517
descr="$1"
507518
shift
519+
export test_prereq
508520
if ! test_skip "$descr" "$@"
509521
then
510522
# Announce the script to reduce confusion about the

0 commit comments

Comments
 (0)