Code

test-lib: Multi-prereq support only checked the last prereq
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Wed, 11 Aug 2010 12:04:38 +0000 (12:04 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 Aug 2010 19:42:04 +0000 (12:42 -0700)
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>
t/t0000-basic.sh
t/test-lib.sh

index 2887677391e795c70c210368970df6ff6350fbd0..960208504b3f93364995e8f89edc2aeaee101020 100755 (executable)
@@ -84,7 +84,11 @@ donthaveit=yes
 test_expect_success HAVEIT,DONTHAVEIT 'unmet prerequisites causes test to be skipped' '
     donthaveit=no
 '
-if test $haveit$donthaveit != yesyes
+donthaveiteither=yes
+test_expect_success DONTHAVEIT,HAVEIT 'unmet prerequisites causes test to be skipped' '
+    donthaveiteither=no
+'
+if test $haveit$donthaveit$donthaveiteither != yesyesyes
 then
        say "bug in test framework: multiple prerequisite tags do not work reliably"
        exit 1
index 78c4874465c8713c5306c9d3ec708ebfc2c63be5..46179988a393761afed8013c67533658bdda657b 100644 (file)
@@ -332,15 +332,30 @@ test_have_prereq () {
        IFS=,
        set -- $*
        IFS=$save_IFS
+
+       total_prereq=0
+       ok_prereq=0
+       missing_prereq=
+
        for prerequisite
        do
+               total_prereq=$(($total_prereq + 1))
                case $satisfied in
                *" $prerequisite "*)
-                       : yes, have it ;;
+                       ok_prereq=$(($ok_prereq + 1))
+                       ;;
                *)
-                       ! : nope ;;
+                       # Keep a list of missing prerequisites
+                       if test -z "$missing_prereq"
+                       then
+                               missing_prereq=$prerequisite
+                       else
+                               missing_prereq="$prerequisite,$missing_prereq"
+                       fi
                esac
        done
+
+       test $total_prereq = $ok_prereq
 }
 
 # You are not expected to call test_ok_ and test_failure_ directly, use
@@ -403,7 +418,7 @@ test_skip () {
        case "$to_skip" in
        t)
                say_color skip >&3 "skipping test: $@"
-               say_color skip "ok $test_count # skip $1 (prereqs: $prereq)"
+               say_color skip "ok $test_count # skip $1 (missing $missing_prereq of $prereq)"
                : true
                ;;
        *)