aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-03-22 03:23:46 +0100
committerJunio C Hamano <gitster@pobox.com>2024-03-22 07:36:35 -0700
commit7c4449eb31b60e9a39fa22ef8d18277f45610db2 (patch)
treeeb0d9466499a881662101007ed6b3c1cb3987dc7 /t
parentc559677c1fc45494ae45adafb35995992740e836 (diff)
downloadgit-7c4449eb31b60e9a39fa22ef8d18277f45610db2.tar.gz
t/README: document how to loop around test cases
In some cases it makes sense to loop around test cases so that we can execute the same test with slightly different arguments. There are some gotchas around quoting here though that are easy to miss and that may lead to easy-to-miss errors and portability issues. Document the proper way to do this in "t/README". Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't')
-rw-r--r--t/README20
1 files changed, 20 insertions, 0 deletions
diff --git a/t/README b/t/README
index 36463d0742..4422ab9b98 100644
--- a/t/README
+++ b/t/README
@@ -721,6 +721,26 @@ The "do's:"
Note that we still &&-chain the loop to propagate failures from
earlier commands.
+ - Repeat tests with slightly different arguments in a loop.
+
+ In some cases it may make sense to re-run the same set of tests with
+ different options or commands to ensure that the command behaves
+ despite the different parameters. This can be achieved by looping
+ around a specific parameter:
+
+ for arg in '' "--foo"
+ do
+ test_expect_success "test command ${arg:-without arguments}" '
+ command $arg
+ '
+ done
+
+ Note that while the test title uses double quotes ("), the test body
+ should continue to use single quotes (') to avoid breakage in case the
+ values contain e.g. quoting characters. The loop variable will be
+ accessible regardless of the single quotes as the test body is passed
+ to `eval`.
+
And here are the "don'ts:"