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

Re: [RFC/PATCH 2/2] test: allow prerequisite to be evaluated lazily

From
Jeff King <peff@peff.net>
Date
Jul 27, 2012, 15:50 UTC
Message-ID
<20120727155000.GB11957@sigill.intra.peff.net>
In-Reply-To
<20120727154500.GA11957@sigill.intra.peff.net>
On Fri, Jul 27, 2012 at 11:45:00AM -0400, Jeff King wrote:
Show 7 quoted lines
> And of course with non-broken probes, "-v" would also help to see exactly
> when the probe is run, using which commands, and what output they
> produced. E.g., for SYMLINKS, we should probably drop the stderr
> redirection from the probe so we can see how "ln" complains.
> 
> It might also be worth doing a "say >&3" at the end of the check, too,
> to tell "-v" users the outcome.

Here is an updated version of my suggestion that does both of those things. I think it should just be squashed into your patch.

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 2214388..d2ebe24 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -232,6 +232,26 @@ test_lazy_prereq () {
 	eval test_prereq_lazily_$1=\$2
 }
 
+test_run_prereq_ () {
+	script='
+mkdir -p "$TRASH_DIRECTORY/prereq-test-dir" &&
+(cd "$TRASH_DIRECTORY/prereq-test-dir" &&
+'"$2"'
+)
+'
+	say >&3 "checking prerequisite: $1"
+	say >&3 "$script"
+	test_eval_ "$script"
+	eval_ret=$?
+	rm -rf "$TRASH_DIRECTORY/prereq-test-dir"
+	if test "$eval_ret" = 0; then
+		say >&3 "prerequisite $1 ok"
+	else
+		say >&3 "prerequisite $1 not fulfilled"
+	fi
+	return $eval_ret
+}
+
 test_have_prereq () {
 	# prerequisites can be concatenated with ','
 	save_IFS=$IFS
@@ -251,16 +271,11 @@ test_have_prereq () {
 		*)
 			case " $lazy_testable_prereq " in
 			*" $prerequisite "*)
-				mkdir -p "$TRASH_DIRECTORY/prereq-test-dir"
-				if (
-					eval "script=\$test_prereq_lazily_$prerequisite" &&
-					cd "$TRASH_DIRECTORY/prereq-test-dir" &&
-					eval "$script"
-				)
+				eval "script=\$test_prereq_lazily_$prerequisite" &&
+				if test_run_prereq_ "$prerequisite" "$script"
 				then
 					test_set_prereq $prerequisite
 				fi
-				rm -fr "$TRASH_DIRECTORY/prereq-test-dir"
 				lazy_tested_prereq="$lazy_tested_prereq$prerequisite "
 			esac
 			;;
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 878d000..35739b9 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -661,7 +661,7 @@ test_i18ngrep () {
 
 test_lazy_prereq SYMLINKS '
 	# test whether the filesystem supports symbolic links
-	ln -s x y 2>/dev/null && test -h y 2>/dev/null
+	ln -s x y && test -h y
 '
 
 # When the tests are run as root, permission tests will report that
Previous: Jeff KingNext: Junio C Hamano
Message 6 of 7 in “test: rename $satisfied to $satisfied_prereq”
  1. 1/2 test: rename $satisfied to $satisfied_prereqJunio C Hamano, Jul 26, 2012
  2. 2/2 test: allow prerequisite to be evaluated lazilyJunio C Hamano, Jul 26, 2012
  3. 3/2 test-lib: provide case insensitivity as a prerequisiteJunio C Hamano, Jul 26, 2012
  4. 4/2 test-lib: provide UTF8 behaviour as a prerequisiteJunio C Hamano, Jul 26, 2012
  5. Jeff KingJul 27, 2012
  6. Jeff KingJul 27, 2012
  7. Junio C HamanoJul 27, 2012

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.