git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 21/25] t9001: use test_when_finished

From
SZEDER Gábor <szeder@ira.uka.de>
Date
Mar 25, 2015, 02:00 UTC
Message-ID
<20150325030022.Horde.yvJScxCdU4w4HDIV_xUwrw1@webmail.informatik.kit.edu>
In-Reply-To
<20150320101321.GU12543@peff.net>
Quoting Jeff King <peff@peff.net>:
Show 9 quoted lines
> 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.
I think that saving the value of 'sendemail.confirm' is not necessary.

There are two blocks of confirmation tests, this patch concerns only tests of the second block. The first block of confirmation tests is nearly at the beginning of the file in order to check the "no confirm" cases early. If any of those fails the remainig tests in the file are skipped because they might hang. The last of those tests sets 'sendemail.confirm' to 'never' and leaves it so to avoid unintentional prompting in the remaining tests and then its value is not modified until that second block of confirm tests are reached. This means that when those tests save the value of 'sendemail.confirm' they always save 'never'. Then why save it, just use test_when_finished to restore it to 'never' and all is well.

Show 100 quoted 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>
> ---
> t/t9001-send-email.sh | 30 ++++++++++--------------------
> 1 file changed, 10 insertions(+), 20 deletions(-)
>
> diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
> index 37caa18..c9f54d5 100755
> --- a/t/t9001-send-email.sh
> +++ b/t/t9001-send-email.sh
> @@ -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' '
> --
> 2.3.3.520.g3cfbb5d
Previous: Jeff KingNext: Jeff King
Message 45 of 68 in “detecting &&-chain breakage”
  1. 0/25 detecting &&-chain breakageJeff King, Mar 20, 2015
  2. 01/25 t/test-lib: introduce --chain-lint optionJeff King, Mar 20, 2015
  3. SZEDER GáborMar 25, 2015
  4. Jeff KingMar 25, 2015
  5. 02/25 t: fix severe &&-chain breakageJeff King, Mar 20, 2015
  6. 03/25 t: fix moderate &&-chain breakageJeff King, Mar 20, 2015
  7. 04/25 t: fix trivial &&-chain breakageJeff King, Mar 20, 2015
  8. 05/25 t: assume test_cmp produces verbose outputJeff King, Mar 20, 2015
  9. 06/25 t: use verbose instead of hand-rolled errorsJeff King, Mar 20, 2015
  10. 07/25 t: use test_must_fail instead of hand-rolled blocksJeff King, Mar 20, 2015
  11. 08/25 t: fix &&-chaining issues around setup which might failJeff King, Mar 20, 2015
  12. 09/25 t: use test_might_fail for diff and grepJeff King, Mar 20, 2015
  13. 10/25 t: use test_expect_code instead of hand-rolled comparisonJeff King, Mar 20, 2015
  14. 11/25 t: wrap complicated expect_code users in a blockJeff King, Mar 20, 2015
  15. 12/25 t: avoid using ":" for commentsJeff King, Mar 20, 2015
  16. 13/25 t3600: fix &&-chain breakage for setup commandsJeff King, Mar 20, 2015
  17. 14/25 t7201: fix &&-chain breakageJeff King, Mar 20, 2015
  18. 15/25 t9502: fix &&-chain breakageJeff King, Mar 20, 2015
  19. Johannes SixtMar 20, 2015
  20. Jeff KingMar 20, 2015
  21. 16/25 t6030: use modern test_* helpersJeff King, Mar 20, 2015
  22. 17/25 t0020: use modern test_* helpersJeff King, Mar 20, 2015
  23. SZEDER GáborMar 25, 2015
  24. Jeff KingMar 25, 2015
  25. 0/8 more &&-chaining test fixupsJeff King, Mar 25, 2015
  26. 1/8 perf-lib: fix ignored exit code inside loopJeff King, Mar 25, 2015
  27. 2/8 t0020: fix ignored exit code inside loopsJeff King, Mar 25, 2015
  28. 3/8 t3305: fix ignored exit code inside loopJeff King, Mar 25, 2015
  29. Johan HerlandMar 25, 2015
  30. 4/8 t7701: fix ignored exit code inside loopJeff King, Mar 25, 2015
  31. 5/8 t: fix some trivial cases of ignored exit codes in loopsJeff King, Mar 25, 2015
  32. 6/8 t: simplify loop exit-code status variablesJeff King, Mar 25, 2015
  33. Junio C HamanoMar 25, 2015
  34. Jeff KingMar 25, 2015
  35. 7/8 t0020: use test_* helpers instead of hand-rolled messagesJeff King, Mar 25, 2015
  36. 8/8 t9001: drop save_confirm helperJeff King, Mar 25, 2015
  37. Junio C HamanoMar 25, 2015
  38. 18/25 t1301: use modern test_* helpersJeff King, Mar 20, 2015
  39. SZEDER GáborMar 24, 2015
  40. Jeff KingMar 25, 2015
  41. 19/25 t6034: use modern test_* helpersJeff King, Mar 20, 2015
  42. SZEDER GáborMar 24, 2015
  43. 20/25 t4117: use modern test_* helpersJeff King, Mar 20, 2015
  44. 21/25 t9001: use test_when_finishedJeff King, Mar 20, 2015
  45. SZEDER GáborMar 25, 2015
  46. Jeff KingMar 25, 2015
  47. 22/25 t0050: appease --chain-lintJeff King, Mar 20, 2015
  48. 23/25 t7004: fix embedded single-quotesJeff King, Mar 20, 2015
  49. 24/25 t0005: fix broken &&-chainsJeff King, Mar 20, 2015
  50. 25/25 t4104: drop hand-rolled error reportingJeff King, Mar 20, 2015
  51. Jeff KingMar 20, 2015
  52. Michael J GruberMar 20, 2015
  53. 26/27 t/*svn*: fix moderate &&-chain breakageMichael J Gruber, Mar 20, 2015
  54. Junio C HamanoMar 20, 2015
  55. Junio C HamanoMar 20, 2015
  56. Jeff KingMar 20, 2015
  57. Jeff KingMar 20, 2015
  58. Michael J GruberMar 23, 2015
  59. 27/27 t9104: fix test for following larger parentsMichael J Gruber, Mar 20, 2015
  60. Jeff KingMar 20, 2015
  61. Junio C HamanoMar 20, 2015
  62. Junio C HamanoMar 20, 2015
  63. Jeff KingMar 20, 2015
  64. Junio C HamanoMar 20, 2015
  65. Eric SunshineMar 20, 2015
  66. Jeff KingMar 21, 2015
  67. Junio C HamanoMar 21, 2015
  68. Jeff KingMar 21, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.