Skip to content

Commit ce60653

Browse files
avargitster
authored andcommitted
test-lib: Multi-prereq support only checked the last prereq
The support for multiple test prerequisites added by me in "test-lib: Add support for multiple test prerequisites" was broken. The for iterated over each prerequisite and returned true/false within a case statement, but since it missed a return statement only the last prerequisite in the list of prerequisites was ever considered, the rest were ignored. Fix that by changing the test_have_prereq code to something less clever that keeps a count of the total prereqs and the ones we have and compares the count at the end. This comes with the added advantage that it's easy to list the missing prerequisites in the test output, implement that while I'm at it. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent c91cfd1 commit ce60653

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

t/t0000-basic.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ donthaveit=yes
8484
test_expect_success HAVEIT,DONTHAVEIT 'unmet prerequisites causes test to be skipped' '
8585
donthaveit=no
8686
'
87-
if test $haveit$donthaveit != yesyes
87+
donthaveiteither=yes
88+
test_expect_success DONTHAVEIT,HAVEIT 'unmet prerequisites causes test to be skipped' '
89+
donthaveiteither=no
90+
'
91+
if test $haveit$donthaveit$donthaveiteither != yesyesyes
8892
then
8993
say "bug in test framework: multiple prerequisite tags do not work reliably"
9094
exit 1

t/test-lib.sh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,15 +332,30 @@ test_have_prereq () {
332332
IFS=,
333333
set -- $*
334334
IFS=$save_IFS
335+
336+
total_prereq=0
337+
ok_prereq=0
338+
missing_prereq=
339+
335340
for prerequisite
336341
do
342+
total_prereq=$(($total_prereq + 1))
337343
case $satisfied in
338344
*" $prerequisite "*)
339-
: yes, have it ;;
345+
ok_prereq=$(($ok_prereq + 1))
346+
;;
340347
*)
341-
! : nope ;;
348+
# Keep a list of missing prerequisites
349+
if test -z "$missing_prereq"
350+
then
351+
missing_prereq=$prerequisite
352+
else
353+
missing_prereq="$prerequisite,$missing_prereq"
354+
fi
342355
esac
343356
done
357+
358+
test $total_prereq = $ok_prereq
344359
}
345360

346361
# You are not expected to call test_ok_ and test_failure_ directly, use
@@ -403,7 +418,7 @@ test_skip () {
403418
case "$to_skip" in
404419
t)
405420
say_color skip >&3 "skipping test: $@"
406-
say_color skip "ok $test_count # skip $1 (prereqs: $prereq)"
421+
say_color skip "ok $test_count # skip $1 (missing $missing_prereq of $prereq)"
407422
: true
408423
;;
409424
*)

0 commit comments

Comments
 (0)