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

[PATCH v2 1/6] t: document test_lazy_prereq

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 11, 2025, 21:25 UTC
Message-ID
<20250311212505.2920181-2-gitster@pobox.com>
In-Reply-To
<20250311212505.2920181-1-gitster@pobox.com>

The t/README file talked about test_set_prereq but lacked explanation on test_lazy_prereq, which is a more modern way to define prerequisites.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 t/README | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/t/README b/t/README
index 53e5b4a710..3ce9f5a393 100644
--- a/t/README
+++ b/t/README
@@ -818,7 +818,7 @@ Skipping tests
 --------------
 
 If you need to skip tests you should do so by using the three-arg form
-of the test_* functions (see the "Test harness library" section
+of the test_expect_* functions (see the "Test harness library" section
 below), e.g.:
 
     test_expect_success PERL 'I need Perl' '
@@ -965,6 +965,27 @@ see test-lib-functions.sh for the full list and their options.
 	    test_done
 	fi
 
+ - test_lazy_prereq <prereq> <script>
+
+   Declare the way to determine if a test prerequisite <prereq> is
+   satisified or not, but delay the actual determination until the
+   prerequisite is actually used by "test_have_prereq" or the
+   three-arg form of the test_expect_* functions.  For example, this
+   is how the SYMLINKS prerequisite is declared to see if the platform
+   supports symbolic links:
+
+	test_lazy_prereq SYMLINKS '
+		ln -s x y && test -h y
+	'
+
+   The script is lazily invoked when SYMLINKS prerequisite is first
+   queried by either "test_have_prereq SYMLINKS" or "test_expect_*
+   SYMLINKS ...".  The script is run in a temporary directory inside
+   a subshell, so you do not have to worry about removing temporary
+   files you create there.  When the script exits with status 0, the
+   prerequisite is set.  Exiting with non-zero status makes the
+   prerequisite unsatisified.
+
  - test_expect_code <exit-code> <command>
 
    Run a command and ensure that it exits with the given exit code.
-- 
2.49.0-rc2-181-g28e223d67e
Previous: Junio C HamanoNext: Junio C Hamano
Message 12 of 20 in “drop "name-rev --stdin" support”
  1. 0/4 drop "name-rev --stdin" supportJunio C Hamano, Mar 10, 2025
  2. 1/4 t: introduce WITH_BREAKING_CHANGES prerequisiteJunio C Hamano, Mar 10, 2025
  3. Eric SunshineMar 10, 2025
  4. Patrick SteinhardtMar 11, 2025
  5. Junio C HamanoMar 11, 2025
  6. 2/4 t6120: avoid hiding "git" exit statusJunio C Hamano, Mar 10, 2025
  7. 3/4 t6120: further modernizeJunio C Hamano, Mar 10, 2025
  8. 4/4 name-rev: remove "--stdin" supportJunio C Hamano, Mar 10, 2025
  9. Patrick SteinhardtMar 11, 2025
  10. Junio C HamanoMar 11, 2025
  11. 0/6 drop "name-rev --stdin" supportJunio C Hamano, Mar 11, 2025
  12. 1/6 t: document test_lazy_prereqJunio C Hamano, Mar 11, 2025
  13. 2/6 t: extend test_lazy_prereqJunio C Hamano, Mar 11, 2025
  14. Patrick SteinhardtMar 12, 2025
  15. Junio C HamanoMar 13, 2025
  16. 3/6 t: introduce WITH_BREAKING_CHANGES prerequisiteJunio C Hamano, Mar 11, 2025
  17. Patrick SteinhardtMar 12, 2025
  18. 4/6 t6120: avoid hiding "git" exit statusJunio C Hamano, Mar 11, 2025
  19. 5/6 t6120: further modernizeJunio C Hamano, Mar 11, 2025
  20. 6/6 name-rev: remove "--stdin" supportJunio C Hamano, Mar 11, 2025

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.