1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-04-28 05:45:10 +02:00

Merge branch 'ps/t7800-variable-interpolation-fix' into next

Fix the way recently added tests interpolate variables defined
outside them, and document the best practice to help future
developers.

* ps/t7800-variable-interpolation-fix:
  t/README: document how to loop around test cases
  t7800: use single quotes for test bodies
  t7800: improve test descriptions with empty arguments
This commit is contained in:
Junio C Hamano 2024-03-25 16:26:51 -07:00
commit e7b1ec4df4
2 changed files with 40 additions and 20 deletions

View File

@ -724,6 +724,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:"

View File

@ -93,42 +93,42 @@ test_expect_success 'difftool forwards arguments to diff' '
for opt in '' '--dir-diff'
do
test_expect_success "difftool ${opt} ignores exit code" "
test_expect_success "difftool ${opt:-without options} ignores exit code" '
test_config difftool.error.cmd false &&
git difftool ${opt} -y -t error branch
"
'
test_expect_success "difftool ${opt} forwards exit code with --trust-exit-code" "
test_expect_success "difftool ${opt:-without options} forwards exit code with --trust-exit-code" '
test_config difftool.error.cmd false &&
test_must_fail git difftool ${opt} -y --trust-exit-code -t error branch
"
'
test_expect_success "difftool ${opt} forwards exit code with --trust-exit-code for built-ins" "
test_expect_success "difftool ${opt:-without options} forwards exit code with --trust-exit-code for built-ins" '
test_config difftool.vimdiff.path false &&
test_must_fail git difftool ${opt} -y --trust-exit-code -t vimdiff branch
"
'
test_expect_success "difftool ${opt} honors difftool.trustExitCode = true" "
test_expect_success "difftool ${opt:-without options} honors difftool.trustExitCode = true" '
test_config difftool.error.cmd false &&
test_config difftool.trustExitCode true &&
test_must_fail git difftool ${opt} -y -t error branch
"
'
test_expect_success "difftool ${opt} honors difftool.trustExitCode = false" "
test_expect_success "difftool ${opt:-without options} honors difftool.trustExitCode = false" '
test_config difftool.error.cmd false &&
test_config difftool.trustExitCode false &&
git difftool ${opt} -y -t error branch
"
'
test_expect_success "difftool ${opt} ignores exit code with --no-trust-exit-code" "
test_expect_success "difftool ${opt:-without options} ignores exit code with --no-trust-exit-code" '
test_config difftool.error.cmd false &&
test_config difftool.trustExitCode true &&
git difftool ${opt} -y --no-trust-exit-code -t error branch
"
'
test_expect_success "difftool ${opt} stops on error with --trust-exit-code" "
test_when_finished 'rm -f for-diff .git/fail-right-file' &&
test_when_finished 'git reset -- for-diff' &&
test_expect_success "difftool ${opt:-without options} stops on error with --trust-exit-code" '
test_when_finished "rm -f for-diff .git/fail-right-file" &&
test_when_finished "git reset -- for-diff" &&
write_script .git/fail-right-file <<-\EOF &&
echo failed
exit 1
@ -138,19 +138,19 @@ do
test_must_fail git difftool ${opt} -y --trust-exit-code \
--extcmd .git/fail-right-file branch >actual &&
test_line_count = 1 actual
"
'
test_expect_success "difftool ${opt} honors exit status if command not found" "
test_expect_success "difftool ${opt:-without options} honors exit status if command not found" '
test_config difftool.nonexistent.cmd i-dont-exist &&
test_config difftool.trustExitCode false &&
if test "${opt}" = '--dir-diff'
if test "${opt}" = --dir-diff
then
expected_code=127
else
expected_code=128
fi &&
test_expect_code \${expected_code} git difftool ${opt} -y -t nonexistent branch
"
test_expect_code ${expected_code} git difftool ${opt} -y -t nonexistent branch
'
done
test_expect_success 'difftool honors --gui' '