git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] test-lib: Multi-prereq support only checked the last prereq

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Aug 10, 2010, 23:21 UTC
Message-ID
<1281482511-2461-1-git-send-email-avarab@gmail.com>

The support for multiple test prerequisites added by me in "test-lib: Add support for multiple test prerequisites" was broken.

The clever for-loop (which I blindly copied from Junio) iterated over each prerequisite and returned true/false within a case statement. Thus 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.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
I should have spotted this earlier.
 t/t0000-basic.sh |    6 +++++-
 t/test-lib.sh    |   21 ++++++++++++++++++---
 2 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index 2887677..9602085 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -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
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 4e73fff..8c8e129 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -337,15 +337,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
@@ -408,7 +423,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
 		;;
 	*)
-- 
1.7.2.1.295.gd03d
Next: Jonathan Nieder
Message 1 of 7 in “test-lib: Multi-prereq support only checked the last prereq”
  1. test-lib: Multi-prereq support only checked the last prereqÆvar Arnfjörð Bjarmason, Aug 10, 2010
  2. Jonathan NiederAug 11, 2010
  3. test-lib: Multi-prereq support only checked the last prereqÆvar Arnfjörð Bjarmason, Aug 11, 2010
  4. Johannes SixtAug 13, 2010
  5. tests: simplify "missing PREREQ" messageJonathan Nieder, Aug 24, 2010
  6. Johannes SixtAug 24, 2010
  7. Junio C HamanoAug 24, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.