@matheusbsbs / matheus-bagliano / commits / ce60653e59
Fork 0

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>

Ævar Arnfjörð Bjarmason committed Aug 11, 2010 at 12:04 UTC ce60653e59f89b409b80a1a381275914fddce07f
2 files changed +23 -4
t/t0000-basic.sh
+5 -1
@@ -84,7 +84,11 @@ donthaveit=yes
84 test_expect_success HAVEIT,DONTHAVEIT 'unmet prerequisites causes test to be skipped' '
85 donthaveit=no
86 '
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
92 then
93 say "bug in test framework: multiple prerequisite tags do not work reliably"
94 exit 1
t/test-lib.sh
+18 -3
@@ -332,15 +332,30 @@ test_have_prereq () {
332 IFS=,
333 set -- $*
334 IFS=$save_IFS
335 +
336 + total_prereq=0
337 + ok_prereq=0
338 + missing_prereq=
339 +
340 for prerequisite
341 do
342 + total_prereq=$(($total_prereq + 1))
343 case $satisfied in
344 *" $prerequisite "*)
339 - : yes, have it ;;
345 + ok_prereq=$(($ok_prereq + 1))
346 + ;;
347 *)
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
355 esac
356 done
357 +
358 + test $total_prereq = $ok_prereq
359 }
360
361 # You are not expected to call test_ok_ and test_failure_ directly, use
@@ -403,7 +418,7 @@ test_skip () {
418 case "$to_skip" in
419 t)
420 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)"
422 : true
423 ;;
424 *)