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

Re: [PATCH 06/12] t: prepare execution of potentially failing commands for `set -e`

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 13, 2026, 17:09 UTC
Message-ID
<xmqqtsteiy7s.fsf@gitster.g>
In-Reply-To
<20260413-b4-pks-tests-with-set-e-v1-6-5b83763a0e84@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 8 quoted lines
> Several of our tests verify whether a certain binary can be executed,
> potentially skipping tests in case we cannot, for example because the
> binary doesn't exist. In those cases we often run the binary outside of
> any conditionally.
>
> This will start to fail once we enable `set -e`, as that will cause us
> to bail out the test immediately. Improve these tests by executing them
> inside of a conditional instead.

OK. "svn help" and "cvs version" do exit with status 0 and the rewrites that use them make sense. I wonder if we can do something similar to "git" instead of relying on "git<RETURN>" to exit with 1, perhaps ...

    $ git version >/dev/null; echo $?
    0
... by using "git version" in the test-lib.sh change?
Other than that looking very good.
Show 130 quoted lines
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  t/lib-git-svn.sh                | 3 +--
>  t/lib-httpd.sh                  | 3 +--
>  t/t9200-git-cvsexportcommit.sh  | 3 +--
>  t/t9400-git-cvsserver-server.sh | 5 +++--
>  t/t9401-git-cvsserver-crlf.sh   | 4 ++--
>  t/t9402-git-cvsserver-refs.sh   | 4 ++--
>  t/test-lib.sh                   | 4 ++--
>  7 files changed, 12 insertions(+), 14 deletions(-)
>
> diff --git a/t/lib-git-svn.sh b/t/lib-git-svn.sh
> index 2fde2353fd..07d86ea244 100644
> --- a/t/lib-git-svn.sh
> +++ b/t/lib-git-svn.sh
> @@ -15,8 +15,7 @@ GIT_SVN_DIR=$GIT_DIR/svn/refs/remotes/git-svn
>  SVN_TREE=$GIT_SVN_DIR/svn-tree
>  test_set_port SVNSERVE_PORT
>  
> -svn >/dev/null 2>&1
> -if test $? -ne 1
> +if ! svn help >/dev/null 2>&1
>  then
>  	skip_all='skipping git svn tests, svn not found'
>  	test_done
> diff --git a/t/lib-httpd.sh b/t/lib-httpd.sh
> index 4c76e813e3..fc646447d5 100644
> --- a/t/lib-httpd.sh
> +++ b/t/lib-httpd.sh
> @@ -235,11 +235,10 @@ start_httpd() {
>  
>  	test_atexit stop_httpd
>  
> -	"$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
> +	if ! "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
>  		-f "$TEST_PATH/apache.conf" $HTTPD_PARA \
>  		-c "Listen 127.0.0.1:$LIB_HTTPD_PORT" -k start \
>  		>&3 2>&4
> -	if test $? -ne 0
>  	then
>  		cat "$HTTPD_ROOT_PATH"/error.log >&4 2>/dev/null
>  		test_skip_or_die GIT_TEST_HTTPD "web server setup failed"
> diff --git a/t/t9200-git-cvsexportcommit.sh b/t/t9200-git-cvsexportcommit.sh
> index 14cbe96527..581cf3d28f 100755
> --- a/t/t9200-git-cvsexportcommit.sh
> +++ b/t/t9200-git-cvsexportcommit.sh
> @@ -11,8 +11,7 @@ if ! test_have_prereq PERL; then
>  	test_done
>  fi
>  
> -cvs >/dev/null 2>&1
> -if test $? -ne 1
> +if ! cvs version >/dev/null 2>&1
>  then
>      skip_all='skipping git cvsexportcommit tests, cvs not found'
>      test_done
> diff --git a/t/t9400-git-cvsserver-server.sh b/t/t9400-git-cvsserver-server.sh
> index e499c7f955..4b45398bab 100755
> --- a/t/t9400-git-cvsserver-server.sh
> +++ b/t/t9400-git-cvsserver-server.sh
> @@ -17,12 +17,13 @@ if ! test_have_prereq PERL; then
>  	skip_all='skipping git cvsserver tests, perl not available'
>  	test_done
>  fi
> -cvs >/dev/null 2>&1
> -if test $? -ne 1
> +
> +if ! cvs version >/dev/null 2>&1
>  then
>      skip_all='skipping git-cvsserver tests, cvs not found'
>      test_done
>  fi
> +
>  perl -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || {
>      skip_all='skipping git-cvsserver tests, Perl SQLite interface unavailable'
>      test_done
> diff --git a/t/t9401-git-cvsserver-crlf.sh b/t/t9401-git-cvsserver-crlf.sh
> index a34805acdc..6b4cbb1651 100755
> --- a/t/t9401-git-cvsserver-crlf.sh
> +++ b/t/t9401-git-cvsserver-crlf.sh
> @@ -60,12 +60,12 @@ check_status_options() {
>      return $stat
>  }
>  
> -cvs >/dev/null 2>&1
> -if test $? -ne 1
> +if ! cvs version >/dev/null 2>&1
>  then
>      skip_all='skipping git-cvsserver tests, cvs not found'
>      test_done
>  fi
> +
>  if ! test_have_prereq PERL
>  then
>      skip_all='skipping git-cvsserver tests, perl not available'
> diff --git a/t/t9402-git-cvsserver-refs.sh b/t/t9402-git-cvsserver-refs.sh
> index 2ee41f9443..65f2ceedec 100755
> --- a/t/t9402-git-cvsserver-refs.sh
> +++ b/t/t9402-git-cvsserver-refs.sh
> @@ -68,12 +68,12 @@ check_diff() {
>  
>  #########
>  
> -cvs >/dev/null 2>&1
> -if test $? -ne 1
> +if ! cvs version >/dev/null 2>&1
>  then
>  	skip_all='skipping git-cvsserver tests, cvs not found'
>  	test_done
>  fi
> +
>  if ! test_have_prereq PERL
>  then
>  	skip_all='skipping git-cvsserver tests, perl not available'
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index 70fd3e9baf..81380fe978 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -143,8 +143,8 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
>  ################################################################
>  # It appears that people try to run tests without building...
>  GIT_BINARY="${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X"
> -"$GIT_BINARY" >/dev/null
> -if test $? != 1
> +
> +if ! "$GIT_BINARY" version >/dev/null
>  then
>  	if test -n "$GIT_TEST_INSTALLED"
>  	then
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 20 of 95 in “t: detect errors outside of test cases”
  1. 00/12 t: detect errors outside of test casesPatrick Steinhardt, Apr 13, 2026
  2. 01/12 t: prepare `test_match_signal ()` calls for `set -e`Patrick Steinhardt, Apr 13, 2026
  3. Junio C HamanoApr 13, 2026
  4. Patrick SteinhardtApr 14, 2026
  5. Junio C HamanoApr 14, 2026
  6. 02/12 t: prepare `test_must_fail ()` for `set -e`Patrick Steinhardt, Apr 13, 2026
  7. Junio C HamanoApr 13, 2026
  8. Patrick SteinhardtApr 14, 2026
  9. Jeff KingApr 14, 2026
  10. Junio C HamanoApr 14, 2026
  11. Patrick SteinhardtApr 15, 2026
  12. Jeff KingApr 16, 2026
  13. 03/12 t: prepare `stop_git_daemon ()` for `set -e`Patrick Steinhardt, Apr 13, 2026
  14. Junio C HamanoApr 13, 2026
  15. 04/12 t: prepare `git config --unset` calls for `set -e`Patrick Steinhardt, Apr 13, 2026
  16. Junio C HamanoApr 13, 2026
  17. 05/12 t: prepare conditional test execution for `set -e`Patrick Steinhardt, Apr 13, 2026
  18. Junio C HamanoApr 13, 2026
  19. 06/12 t: prepare execution of potentially failing commands for `set -e`Patrick Steinhardt, Apr 13, 2026
  20. Junio C HamanoApr 13, 2026
  21. Patrick SteinhardtApr 14, 2026
  22. Junio C HamanoApr 14, 2026
  23. Junio C HamanoApr 13, 2026
  24. Junio C HamanoApr 14, 2026
  25. Patrick SteinhardtApr 14, 2026
  26. Patrick SteinhardtApr 14, 2026
  27. Junio C HamanoApr 14, 2026
  28. Jeff KingApr 14, 2026
  29. Jeff KingApr 14, 2026
  30. Jeff KingApr 14, 2026
  31. Patrick SteinhardtApr 15, 2026
  32. Jeff KingApr 16, 2026
  33. Patrick SteinhardtApr 16, 2026
  34. Junio C HamanoApr 16, 2026
  35. Jeff KingApr 18, 2026
  36. Junio C HamanoApr 15, 2026
  37. 07/12 t: prepare `test_when_finished ()`/`test_atexit()` for `set -e`Patrick Steinhardt, Apr 13, 2026
  38. Junio C HamanoApr 13, 2026
  39. Patrick SteinhardtApr 14, 2026
  40. 08/12 t0008: silence error in subshell when using `grep -v`Patrick Steinhardt, Apr 13, 2026
  41. Junio C HamanoApr 13, 2026
  42. Patrick SteinhardtApr 14, 2026
  43. 09/12 t1301: don't fail in case setfacl(1) doesn't exist or failsPatrick Steinhardt, Apr 13, 2026
  44. 10/12 t6002: fix use of `expr` with `set -e`Patrick Steinhardt, Apr 13, 2026
  45. 11/12 t9902: fix use of `read` with `set -e`Patrick Steinhardt, Apr 13, 2026
  46. 12/12 t: detect errors outside of test casesPatrick Steinhardt, Apr 13, 2026
  47. Junio C HamanoApr 13, 2026
  48. Junio C HamanoApr 13, 2026
  49. Junio C HamanoApr 13, 2026
  50. 00/12 t: detect errors outside of test casesPatrick Steinhardt, Apr 16, 2026
  51. 01/12 t: prepare `test_match_signal ()` calls for `set -e`Patrick Steinhardt, Apr 16, 2026
  52. 02/12 t: prepare `test_must_fail ()` for `set -e`Patrick Steinhardt, Apr 16, 2026
  53. 03/12 t: prepare `stop_git_daemon ()` for `set -e`Patrick Steinhardt, Apr 16, 2026
  54. 04/12 t: prepare `git config --unset` calls for `set -e`Patrick Steinhardt, Apr 16, 2026
  55. 05/12 t: prepare conditional test execution for `set -e`Patrick Steinhardt, Apr 16, 2026
  56. 06/12 t: prepare execution of potentially failing commands for `set -e`Patrick Steinhardt, Apr 16, 2026
  57. 07/12 t: prepare `test_when_finished ()`/`test_atexit()` for `set -e`Patrick Steinhardt, Apr 16, 2026
  58. 08/12 t0008: silence error in subshell when using `grep -v`Patrick Steinhardt, Apr 16, 2026
  59. 09/12 t1301: don't fail in case setfacl(1) doesn't exist or failsPatrick Steinhardt, Apr 16, 2026
  60. 10/12 t6002: fix use of `expr` with `set -e`Patrick Steinhardt, Apr 16, 2026
  61. 11/12 t9902: fix use of `read` with `set -e`Patrick Steinhardt, Apr 16, 2026
  62. SZEDER GáborApr 16, 2026
  63. Junio C HamanoApr 16, 2026
  64. Patrick SteinhardtApr 17, 2026
  65. 12/12 t: detect errors outside of test casesPatrick Steinhardt, Apr 16, 2026
  66. Junio C HamanoApr 16, 2026
  67. 00/12 t: detect errors outside of test casesPatrick Steinhardt, Apr 20, 2026
  68. 01/12 t: prepare `test_match_signal ()` calls for `set -e`Patrick Steinhardt, Apr 20, 2026
  69. 02/12 t: prepare `test_must_fail ()` for `set -e`Patrick Steinhardt, Apr 20, 2026
  70. 03/12 t: prepare `stop_git_daemon ()` for `set -e`Patrick Steinhardt, Apr 20, 2026
  71. 04/12 t: prepare `git config --unset` calls for `set -e`Patrick Steinhardt, Apr 20, 2026
  72. 05/12 t: prepare conditional test execution for `set -e`Patrick Steinhardt, Apr 20, 2026
  73. 06/12 t: prepare execution of potentially failing commands for `set -e`Patrick Steinhardt, Apr 20, 2026
  74. 07/12 t: prepare `test_when_finished ()`/`test_atexit()` for `set -e`Patrick Steinhardt, Apr 20, 2026
  75. 08/12 t0008: silence error in subshell when using `grep -v`Patrick Steinhardt, Apr 20, 2026
  76. 09/12 t1301: don't fail in case setfacl(1) doesn't exist or failsPatrick Steinhardt, Apr 20, 2026
  77. 10/12 t6002: fix use of `expr` with `set -e`Patrick Steinhardt, Apr 20, 2026
  78. 11/12 t9902: fix use of `read` with `set -e`Patrick Steinhardt, Apr 20, 2026
  79. 12/12 t: detect errors outside of test casesPatrick Steinhardt, Apr 20, 2026
  80. Junio C HamanoApr 20, 2026
  81. Jeff KingApr 21, 2026
  82. Patrick SteinhardtApr 21, 2026
  83. 00/12 t: detect errors outside of test casesPatrick Steinhardt, Apr 21, 2026
  84. 01/12 t: prepare `test_match_signal ()` calls for `set -e`Patrick Steinhardt, Apr 21, 2026
  85. 02/12 t: prepare `test_must_fail ()` for `set -e`Patrick Steinhardt, Apr 21, 2026
  86. 03/12 t: prepare `stop_git_daemon ()` for `set -e`Patrick Steinhardt, Apr 21, 2026
  87. 04/12 t: prepare `git config --unset` calls for `set -e`Patrick Steinhardt, Apr 21, 2026
  88. 05/12 t: prepare conditional test execution for `set -e`Patrick Steinhardt, Apr 21, 2026
  89. 06/12 t: prepare execution of potentially failing commands for `set -e`Patrick Steinhardt, Apr 21, 2026
  90. 07/12 t: prepare `test_when_finished ()`/`test_atexit()` for `set -e`Patrick Steinhardt, Apr 21, 2026
  91. 08/12 t0008: silence error in subshell when using `grep -v`Patrick Steinhardt, Apr 21, 2026
  92. 09/12 t1301: don't fail in case setfacl(1) doesn't exist or failsPatrick Steinhardt, Apr 21, 2026
  93. 10/12 t6002: fix use of `expr` with `set -e`Patrick Steinhardt, Apr 21, 2026
  94. 11/12 t9902: fix use of `read` with `set -e`Patrick Steinhardt, Apr 21, 2026
  95. 12/12 t: detect errors outside of test casesPatrick Steinhardt, Apr 21, 2026

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.