Skip to content

Commit 545871b

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e7d053d commit 545871b

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

t/t9001-send-email.sh

+10-20
Original file line numberDiff line numberDiff line change
@@ -817,26 +817,25 @@ test_expect_success $PREREQ '--confirm=compose' '
817817
test_confirm --confirm=compose --compose
818818
'
819819

820-
test_expect_success $PREREQ 'confirm by default (due to cc)' '
820+
save_confirm () {
821821
CONFIRM=$(git config --get sendemail.confirm) &&
822+
test_when_finished "git config sendemail.confirm ${CONFIRM:-never}"
823+
}
824+
825+
test_expect_success $PREREQ 'confirm by default (due to cc)' '
826+
save_confirm &&
822827
git config --unset sendemail.confirm &&
823828
test_confirm
824-
ret="$?"
825-
git config sendemail.confirm ${CONFIRM:-never}
826-
test $ret = "0"
827829
'
828830

829831
test_expect_success $PREREQ 'confirm by default (due to --compose)' '
830-
CONFIRM=$(git config --get sendemail.confirm) &&
832+
save_confirm &&
831833
git config --unset sendemail.confirm &&
832834
test_confirm --suppress-cc=all --compose
833-
ret="$?"
834-
git config sendemail.confirm ${CONFIRM:-never}
835-
test $ret = "0"
836835
'
837836

838837
test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
839-
CONFIRM=$(git config --get sendemail.confirm) &&
838+
save_confirm &&
840839
git config --unset sendemail.confirm &&
841840
rm -fr outdir &&
842841
git format-patch -2 -o outdir &&
@@ -846,13 +845,10 @@ test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
846845
847846
--smtp-server="$(pwd)/fake.sendmail" \
848847
outdir/*.patch </dev/null
849-
ret="$?"
850-
git config sendemail.confirm ${CONFIRM:-never}
851-
test $ret = "0"
852848
'
853849

854850
test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
855-
CONFIRM=$(git config --get sendemail.confirm) &&
851+
save_confirm &&
856852
git config sendemail.confirm auto &&
857853
GIT_SEND_EMAIL_NOTTY=1 &&
858854
export GIT_SEND_EMAIL_NOTTY &&
@@ -861,13 +857,10 @@ test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
861857
862858
--smtp-server="$(pwd)/fake.sendmail" \
863859
$patches </dev/null
864-
ret="$?"
865-
git config sendemail.confirm ${CONFIRM:-never}
866-
test $ret = "0"
867860
'
868861

869862
test_expect_success $PREREQ 'confirm does not loop forever' '
870-
CONFIRM=$(git config --get sendemail.confirm) &&
863+
save_confirm &&
871864
git config sendemail.confirm auto &&
872865
GIT_SEND_EMAIL_NOTTY=1 &&
873866
export GIT_SEND_EMAIL_NOTTY &&
@@ -876,9 +869,6 @@ test_expect_success $PREREQ 'confirm does not loop forever' '
876869
877870
--smtp-server="$(pwd)/fake.sendmail" \
878871
$patches
879-
ret="$?"
880-
git config sendemail.confirm ${CONFIRM:-never}
881-
test $ret = "0"
882872
'
883873

884874
test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '

0 commit comments

Comments
 (0)