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>
Patrick Steinhardt committed
Mar 22, 2024 at 03:23 UTC
7c4449eb31b60e9a39fa22ef8d18277f45610db2
1 file changed
+20
t/README
+20
@@ -721,6 +721,26 @@ The "do's:"
721
Note that we still &&-chain the loop to propagate failures from
722
earlier commands.
723
724
+ - Repeat tests with slightly different arguments in a loop.
725
+
726
+ In some cases it may make sense to re-run the same set of tests with
727
+ different options or commands to ensure that the command behaves
728
+ despite the different parameters. This can be achieved by looping
729
+ around a specific parameter:
730
+
731
+ for arg in '' "--foo"
732
+ do
733
+ test_expect_success "test command ${arg:-without arguments}" '
734
+ command $arg
735
+ '
736
+ done
737
+
738
+ Note that while the test title uses double quotes ("), the test body
739
+ should continue to use single quotes (') to avoid breakage in case the
740
+ values contain e.g. quoting characters. The loop variable will be
741
+ accessible regardless of the single quotes as the test body is passed
742
+ to `eval`.
743
+
744
745
And here are the "don'ts:"
746