t9001: use test_when_finished
The confirmation tests in t9001 all save the value of sendemail.confirm, do something to it, then restore it at the end, in a way that breaks the &&-chain (they are not wrong, because they save the $? value, but it fools --chain-lint). Instead, they can all use test_when_finished, and we can even make the code simpler by factoring out the shared lines. Note that we can _almost_ use test_config here, except that: 1. We do not restore the config with test_unconfig, but by setting it back to some prior value. 2. We are not always setting a config variable. Sometimes the change to be undone is unsetting it entirely. We could teach test_config to handle these cases, but it's not worth the complexity for a single call-site. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
e7d053ddb9
commit
545871bf77
@ -817,26 +817,25 @@ test_expect_success $PREREQ '--confirm=compose' '
|
||||
test_confirm --confirm=compose --compose
|
||||
'
|
||||
|
||||
test_expect_success $PREREQ 'confirm by default (due to cc)' '
|
||||
save_confirm () {
|
||||
CONFIRM=$(git config --get sendemail.confirm) &&
|
||||
test_when_finished "git config sendemail.confirm ${CONFIRM:-never}"
|
||||
}
|
||||
|
||||
test_expect_success $PREREQ 'confirm by default (due to cc)' '
|
||||
save_confirm &&
|
||||
git config --unset sendemail.confirm &&
|
||||
test_confirm
|
||||
ret="$?"
|
||||
git config sendemail.confirm ${CONFIRM:-never}
|
||||
test $ret = "0"
|
||||
'
|
||||
|
||||
test_expect_success $PREREQ 'confirm by default (due to --compose)' '
|
||||
CONFIRM=$(git config --get sendemail.confirm) &&
|
||||
save_confirm &&
|
||||
git config --unset sendemail.confirm &&
|
||||
test_confirm --suppress-cc=all --compose
|
||||
ret="$?"
|
||||
git config sendemail.confirm ${CONFIRM:-never}
|
||||
test $ret = "0"
|
||||
'
|
||||
|
||||
test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
|
||||
CONFIRM=$(git config --get sendemail.confirm) &&
|
||||
save_confirm &&
|
||||
git config --unset sendemail.confirm &&
|
||||
rm -fr outdir &&
|
||||
git format-patch -2 -o outdir &&
|
||||
@ -846,13 +845,10 @@ test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
|
||||
--to=nobody@example.com \
|
||||
--smtp-server="$(pwd)/fake.sendmail" \
|
||||
outdir/*.patch </dev/null
|
||||
ret="$?"
|
||||
git config sendemail.confirm ${CONFIRM:-never}
|
||||
test $ret = "0"
|
||||
'
|
||||
|
||||
test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
|
||||
CONFIRM=$(git config --get sendemail.confirm) &&
|
||||
save_confirm &&
|
||||
git config sendemail.confirm auto &&
|
||||
GIT_SEND_EMAIL_NOTTY=1 &&
|
||||
export GIT_SEND_EMAIL_NOTTY &&
|
||||
@ -861,13 +857,10 @@ test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
|
||||
--to=nobody@example.com \
|
||||
--smtp-server="$(pwd)/fake.sendmail" \
|
||||
$patches </dev/null
|
||||
ret="$?"
|
||||
git config sendemail.confirm ${CONFIRM:-never}
|
||||
test $ret = "0"
|
||||
'
|
||||
|
||||
test_expect_success $PREREQ 'confirm does not loop forever' '
|
||||
CONFIRM=$(git config --get sendemail.confirm) &&
|
||||
save_confirm &&
|
||||
git config sendemail.confirm auto &&
|
||||
GIT_SEND_EMAIL_NOTTY=1 &&
|
||||
export GIT_SEND_EMAIL_NOTTY &&
|
||||
@ -876,9 +869,6 @@ test_expect_success $PREREQ 'confirm does not loop forever' '
|
||||
--to=nobody@example.com \
|
||||
--smtp-server="$(pwd)/fake.sendmail" \
|
||||
$patches
|
||||
ret="$?"
|
||||
git config sendemail.confirm ${CONFIRM:-never}
|
||||
test $ret = "0"
|
||||
'
|
||||
|
||||
test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
|
||||
|
Loading…
Reference in New Issue
Block a user