Thread (7 messages) flat view 7 messages, 5 authors, 2016-06-15

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

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:49:17

Ævar Arnfjörð Bjarmason wrote:
The clever for-loop (which I blindly copied from Junio)
You did not copy his “return” statement, though. :)
quoted hunk ↗ jump to hunk
+++ 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
 }
Wouldn’t

-		! : nope ;;
+		return 1 ;;

be simpler?

This and a small cleanup, including a test that catches this, are at
http://thread.gmane.org/gmane.comp.version-control.git/152814/focus=152875

Hope that helps,
Jonathan
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help