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

[PATCH 2/1] test-lib: allow lazy prerequisite snippets as here-docs

From
Jeff King <peff@peff.net>
Date
Oct 6, 2026, 03:52 UTC
Message-ID
<20261006035239.GA1335881@coredump.intra.peff.net>
In-Reply-To
<20261006034331.GA1325722@coredump.intra.peff.net>
On Mon, Oct 05, 2026 at 11:43:32PM -0400, Jeff King wrote:
Show 8 quoted lines
>   2. Single-quote the snippet, then quote interior single-quotes as
>      '\''. Reasonably obvious, but ugly.
> 
>   3. Use the '<<\EOT' here-doc trick to specify the snippet. This would
>      look nice, but we don't yet support it for prereqs. ;)
> 
> This patch uses (2), and we can circle back to (3) to make it look nicer
> later.

Doing (3) turned out easier than I thought it would. Patch is below. I think it still makes sense to do the immediate fix with (2), and then this on top as cleanup (or as a separate topic, though obviously there is a textual dependency).

-- >8 --
Subject: test-lib: allow lazy prerequisite snippets as here-docs

Commit 1d133ae91f (test-lib: allow test snippets as here-docs, 2024-07-10) let test_expect_success and test_expect_failure read their snippets from stdin, making it easier to use single quotes within them. I mentioned there that we could extend this to lazy prerequisites, but left it for later.

Let's finish that off now. Since test_body_or_stdin() takes the name of the variable to fill, we can use it directly to populate the saved prereq snippet. We read the body when the prereq is declared, but still evaluate it only when the prereq is used.

Converting the curl version check in t5551 shows how this can reduce awkward quoting.

Signed-off-by: Jeff King <peff@peff.net>
---
 t/t5551-http-fetch-smart.sh | 8 ++++----
 t/test-lib-functions.sh     | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/t/t5551-http-fetch-smart.sh b/t/t5551-http-fetch-smart.sh
index cb681e644f..9dd20d1c65 100755
--- a/t/t5551-http-fetch-smart.sh
+++ b/t/t5551-http-fetch-smart.sh
@@ -21,14 +21,14 @@ start_httpd
 # authentication after an early HTTP/2 response. This bug was introduced
 # in cURL v7.88.0 (8c762f5998 (http2: minor buffer and error path fixes,
 # 2023-02-08)) and fixed in v8.3.0 (https://github.com/curl/curl/pull/11756).
-test_lazy_prereq HAVE_CURL_HTTP2_BUG '
+test_lazy_prereq HAVE_CURL_HTTP2_BUG - <<\EOT
 	test_have_prereq HTTP2 &&
 	build_option libcurl |
-	awk -F. '\''
+	awk -F. '
 		($1 == 7 && $2 >= 88) || ($1 == 8 && $2 < 3) { broken = 1 }
 		END { exit !broken }
-	'\''
-'
+	'
+EOT
 
 test_expect_success HTTP2 'enable client-side http/2' '
 	git config --global http.version HTTP/2
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 809c662124..de75ae842c 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -760,7 +760,7 @@ lazily_testable_prereq= lazily_tested_prereq=
 # Usage: test_lazy_prereq PREREQ 'script'
 test_lazy_prereq () {
 	lazily_testable_prereq="$lazily_testable_prereq$1 "
-	eval test_prereq_lazily_$1=\$2
+	test_body_or_stdin "test_prereq_lazily_$1" "$2"
 }
 
 test_run_lazy_prereq_ () {
-- 
2.56.0.399.g9e0ddc9b37
Previous: Jeff KingNext: Johannes Schindelin
Message 13 of 15 in “ci: work around Debian 12's HTTP/2 authentication failures”
  1. ci: work around Debian 12's HTTP/2 authentication failuresJohannes Schindelin via GitGitGadget, Sep 22, 2026
  2. Junio C HamanoSep 23, 2026
  3. Jeff KingSep 23, 2026
  4. Jeff KingSep 23, 2026
  5. Jeff KingSep 23, 2026
  6. Junio C HamanoSep 23, 2026
  7. Jeff KingSep 23, 2026
  8. Johannes SchindelinSep 24, 2026
  9. Junio C HamanoSep 24, 2026
  10. Jeff KingSep 24, 2026
  11. ci: work around Debian 12's HTTP/2 authentication failuresJohannes Schindelin via GitGitGadget, Sep 24, 2026
  12. t5551: fix quoting in curl version bug prereqJeff King, Oct 6, 2026
  13. 2/1 test-lib: allow lazy prerequisite snippets as here-docsJeff King, Oct 6, 2026
  14. Johannes SchindelinOct 6, 2026
  15. Junio C HamanoOct 6, 2026

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.