Skip to content

Commit 7c4449e

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c559677 commit 7c4449e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

t/README

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,26 @@ The "do's:"
721721
Note that we still &&-chain the loop to propagate failures from
722722
earlier commands.
723723

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+
724744

725745
And here are the "don'ts:"
726746

0 commit comments

Comments
 (0)