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

Re: [PATCH v5 10/12] tests: when run in Bash, annotate test failures with file name/line number

From
Carlo Marcelo Arenas Belón <carenas@gmail.com>
Date
May 7, 2020, 06:10 UTC
Message-ID
<20200507061029.GA83231@Carlos-MBP>
In-Reply-To
<nycvar.QRO.7.76.6.2005061624050.56@tvgsbejvaqbjf.bet>
On Wed, May 06, 2020 at 04:33:47PM +0200, Johannes Schindelin wrote:
Show 36 quoted lines
> On Wed, 6 May 2020, Carlo Marcelo Arenas Belón wrote:
> > On Wed, May 06, 2020 at 02:54:38PM +0200, Johannes Schindelin wrote:
> > > On Wed, 6 May 2020, Carlo Marcelo Arenas Belón wrote:
> > > > diff --git a/t/test-lib.sh b/t/test-lib.sh
> > > > index 1b221951a8..a8f8e4106b 100644
> > > > --- a/t/test-lib.sh
> > > > +++ b/t/test-lib.sh
> > > > @@ -676,15 +676,9 @@ die () {
> > > >  }
> > > >
> > > >  file_lineno () {
> > > > -	test -z "$GIT_TEST_FRAMEWORK_SELFTEST" && test -n "$BASH" || return 0
> > > > -	local i
> > > > -	for i in ${!BASH_SOURCE[*]}
> > > > -	do
> > > > -		case $i,"${BASH_SOURCE[$i]##*/}" in
> > > > -		0,t[0-9]*.sh) echo "t/${BASH_SOURCE[$i]}:$LINENO: ${1+$1: }"; return;;
> > > > -		*,t[0-9]*.sh) echo "t/${BASH_SOURCE[$i]}:${BASH_LINENO[$(($i-1))]}: ${1+$1: }"; return;;
> > > > -		esac
> > > > -	done
> > > > +	test -z "$GIT_TEST_FRAMEWORK_SELFTEST" || return 0
> > > > +
> > > > +	echo "$0:$LINENO: ${1+$1: }"
> > >
> > > That suppresses the error all right.
> > >
> > > Unfortunately, it completely breaks the feature. At that point, `$LINENO`
> > > is either unset (e.g. in `dash`) or it contains the number of the line
> > > _containing the `echo`. That is totally useless information at this point,
> > > we want the line number of the caller.
> >
> > that seems like a bug in dash, which NetBSD sh doesn't have, as LINENO
> > wouldn't be unset.
> 
> And your patch makes this a real problem as you no longer skip the `echo`
> in the non-Bash case.
FWIW, at least NetBSD's dash (0.5.10.2) always sets LINENO
Show 30 quoted lines
> > > Try this, for example:
> > >
> > > ```
> > > #!/bin/sh
> > >
> > > file_lineno () {
> > > 	echo "$0:$LINENO: hello"
> > > }
> > >
> > > file_lineno
> > > ```
> > >
> > > When you run this, it will print `4`. What we want is `7`.
> >
> > so you need instead :
> >
> > ```
> > #!/bin/sh
> >
> > file_lineno () {
> > 	echo "$0:$1: hello"
> > }
> >
> > file_lineno $LINENO
> 
> No.
> 
> Please understand what the intention of the current (Bash-specific) code
> is: in case that there is a failure, it needs to print out the file and
> line number of the actual statement that caused that problem.

that is what I got from the commmit message but then I was puzzled not to find the line inside the test case that faile but instead the one where the last test function was located.

eitherway, I was careless to send the previous version without checking more deeply; indeed the use of LINENO in the original code was part of that confusion and is therefore gone in this new one.

Show 51 quoted lines
> Take this example:
> 
> 	test_expect_success 'For Carlo' '
> 		false
> 	'
> 
> Obviously, this will fail, and it will print out an error message. What we
> want here is that the file that contains that `test_expect_success` and
> the actual line number of this call are printed.
> 
> Your suggestion would be to clutter each and every such call with
> `$LINENO`, like so:
> 
> 	test_expect_success $LINENO 'For Carlo' '
> 
> I don't think that is sensible an idea.
> 
> Besides, it would _still_ not work, for parameterized functions that call
> `test_expect_success` and that are defined in `lib-<whatever>.sh`.
> 
> Example:
> 
> 	# in t/lib-whatever.sh
> 	super_repetitive_test () {
> 		test_expect_success "first $1" '
> 			...
> 		'
> 
> 		test_expect_success "second $1" '
> 			...
> 		'
> 
> 		...
> 
> 		test_expect_success "gazillionth $1" '
> 			...
> 		'
> 	}
> 
> 	# in t/t1234-actual-caller.sh
> 	. lib-whatever.sh
> 
> 	super_repetitive_test hello
> 	super_repetitive_test world
> 	super_repetitive_test good-bye
> 	super_repetitive_test dreams
> 
> We will not want to print out the line number of the call in
> t/lib-whatever.sh. That is what your proposal would amount to, unless you
> want to clutter even the `super_repetitive_test` calles, which would fly
> even less.

that was very useful to understand better the constrain that was referred in the commit message and that forced to build a bash specific solution.

I have to admit too, I was confused by the code, but with the clear guidance you provided I think the new proposed[1] version is also clearer, and goes away with the problem that triggered this whole discussion.

Carlo
[1] https://lore.kernel.org/git/20200507055118.69971-1-carenas@gmail.com/
Previous: Johannes SchindelinNext: Junio C Hamano
Message 87 of 110 in “ci: replace our Azure Pipeline by GitHub Actions”
  1. 0/5 ci: replace our Azure Pipeline by GitHub ActionsJohannes Schindelin via GitGitGadget, Mar 31, 2020
  2. 1/5 ci/lib: if CI type is unknown, show the environment variablesJohannes Schindelin via GitGitGadget, Mar 31, 2020
  3. 4/5 README: add a build badge for the GitHub Actions runsJohannes Schindelin via GitGitGadget, Mar 31, 2020
  4. 2/5 ci/lib: allow running in GitHub ActionsJohannes Schindelin via GitGitGadget, Mar 31, 2020
  5. SZEDER GáborApr 3, 2020
  6. Johannes SchindelinApr 4, 2020
  7. Danh DoanApr 5, 2020
  8. Johannes SchindelinApr 7, 2020
  9. SZEDER GáborApr 10, 2020
  10. Junio C HamanoApr 10, 2020
  11. Johannes SchindelinApr 12, 2020
  12. Junio C HamanoApr 12, 2020
  13. Junio C HamanoApr 12, 2020
  14. 5/5 ci: retire the Azure Pipelines definitionJohannes Schindelin via GitGitGadget, Mar 31, 2020
  15. 3/5 ci: configure GitHub Actions for CI/PRJohannes Schindelin via GitGitGadget, Mar 31, 2020
  16. SZEDER GáborApr 3, 2020
  17. Johannes SchindelinApr 4, 2020
  18. Danh DoanApr 4, 2020
  19. Danh DoanMar 31, 2020
  20. Junio C HamanoMar 31, 2020
  21. 0/6 ci: replace our Azure Pipeline by GitHub ActionsĐoàn Trần Công Danh, Apr 1, 2020
  22. 1/6 ci/lib: if CI type is unknown, show the environment variablesĐoàn Trần Công Danh, Apr 1, 2020
  23. 2/6 ci/lib: allow running in GitHub ActionsĐoàn Trần Công Danh, Apr 1, 2020
  24. 3/6 ci/lib: set TERM environment variable if not existĐoàn Trần Công Danh, Apr 1, 2020
  25. 5/6 README: add a build badge for the GitHub Actions runsĐoàn Trần Công Danh, Apr 1, 2020
  26. 4/6 ci: configure GitHub Actions for CI/PRĐoàn Trần Công Danh, Apr 1, 2020
  27. 6/6 ci: retire the Azure Pipelines definitionĐoàn Trần Công Danh, Apr 1, 2020
  28. Junio C HamanoApr 1, 2020
  29. Danh DoanApr 2, 2020
  30. 0/6 ci: replace our Azure Pipeline by GitHub ActionsĐoàn Trần Công Danh, Apr 2, 2020
  31. 1/6 ci/lib: if CI type is unknown, show the environment variablesĐoàn Trần Công Danh, Apr 2, 2020
  32. 3/6 ci/lib: set TERM environment variable if not existĐoàn Trần Công Danh, Apr 2, 2020
  33. 2/6 ci/lib: allow running in GitHub ActionsĐoàn Trần Công Danh, Apr 2, 2020
  34. 5/6 README: add a build badge for the GitHub Actions runsĐoàn Trần Công Danh, Apr 2, 2020
  35. 4/6 ci: configure GitHub Actions for CI/PRĐoàn Trần Công Danh, Apr 2, 2020
  36. 6/6 ci: retire the Azure Pipelines definitionĐoàn Trần Công Danh, Apr 2, 2020
  37. 00/12 ci: replace our Azure Pipeline by GitHub ActionsĐoàn Trần Công Danh, Apr 8, 2020
  38. 01/12 ci/lib: if CI type is unknown, show the environment variablesĐoàn Trần Công Danh, Apr 8, 2020
  39. 03/12 ci/lib: set TERM environment variable if not existĐoàn Trần Công Danh, Apr 8, 2020
  40. 02/12 ci/lib: allow running in GitHub ActionsĐoàn Trần Công Danh, Apr 8, 2020
  41. 04/12 ci: fix the `jobname` of the `GETTEXT_POISON` jobĐoàn Trần Công Danh, Apr 8, 2020
  42. 05/12 ci: explicit install all required packagesĐoàn Trần Công Danh, Apr 8, 2020
  43. SZEDER GáborApr 10, 2020
  44. Danh DoanApr 10, 2020
  45. Junio C HamanoApr 10, 2020
  46. 06/12 ci: run gem with sudo to install asciidoctorĐoàn Trần Công Danh, Apr 8, 2020
  47. 07/12 ci: configure GitHub Actions for CI/PRĐoàn Trần Công Danh, Apr 8, 2020
  48. 08/12 README: add a build badge for the GitHub Actions runsĐoàn Trần Công Danh, Apr 8, 2020
  49. 09/12 ci: retire the Azure Pipelines definitionĐoàn Trần Công Danh, Apr 8, 2020
  50. 10/12 tests: when run in Bash, annotate test failures with file name/line numberĐoàn Trần Công Danh, Apr 8, 2020
  51. 12/12 ci: let GitHub Actions upload failed tests' directoriesĐoàn Trần Công Danh, Apr 8, 2020
  52. 11/12 ci: add a problem matcher for GitHub ActionsĐoàn Trần Công Danh, Apr 8, 2020
  53. Junio C HamanoApr 9, 2020
  54. Johannes SchindelinApr 10, 2020
  55. Johannes SchindelinApr 10, 2020
  56. Danh DoanApr 10, 2020
  57. Junio C HamanoApr 10, 2020
  58. Danh DoanApr 10, 2020
  59. Junio C HamanoApr 16, 2020
  60. fixing ci failure of 'pu' with the es/bugreport topicJunio C Hamano, Apr 16, 2020
  61. Emily ShafferApr 16, 2020
  62. Junio C HamanoApr 16, 2020
  63. Elijah NewrenApr 16, 2020
  64. Emily ShafferApr 16, 2020
  65. Junio C HamanoApr 16, 2020
  66. Danh DoanApr 16, 2020
  67. Johannes SchindelinApr 16, 2020
  68. Johannes SchindelinApr 16, 2020
  69. Junio C HamanoApr 16, 2020
  70. 00/12 ci: replace our Azure Pipeline by GitHub ActionsĐoàn Trần Công Danh, Apr 10, 2020
  71. 01/12 ci/lib: if CI type is unknown, show the environment variablesĐoàn Trần Công Danh, Apr 10, 2020
  72. 03/12 ci/lib: set TERM environment variable if not existĐoàn Trần Công Danh, Apr 10, 2020
  73. 02/12 ci/lib: allow running in GitHub ActionsĐoàn Trần Công Danh, Apr 10, 2020
  74. 05/12 ci: explicit install all required packagesĐoàn Trần Công Danh, Apr 10, 2020
  75. 04/12 ci: fix the `jobname` of the `GETTEXT_POISON` jobĐoàn Trần Công Danh, Apr 10, 2020
  76. 06/12 ci: run gem with sudo to install asciidoctorĐoàn Trần Công Danh, Apr 10, 2020
  77. 07/12 ci: configure GitHub Actions for CI/PRĐoàn Trần Công Danh, Apr 10, 2020
  78. 08/12 README: add a build badge for the GitHub Actions runsĐoàn Trần Công Danh, Apr 10, 2020
  79. 10/12 tests: when run in Bash, annotate test failures with file name/line numberĐoàn Trần Công Danh, Apr 10, 2020
  80. Carlo Marcelo Arenas BelónMay 4, 2020
  81. Danh DoanMay 4, 2020
  82. Junio C HamanoMay 5, 2020
  83. Carlo Marcelo Arenas BelónMay 6, 2020
  84. Johannes SchindelinMay 6, 2020
  85. Carlo Marcelo Arenas BelónMay 6, 2020
  86. Johannes SchindelinMay 6, 2020
  87. Carlo Marcelo Arenas BelónMay 7, 2020
  88. Junio C HamanoMay 6, 2020
  89. Carlo Marcelo Arenas BelónMay 5, 2020
  90. Alban GruinMay 15, 2020
  91. t: move metadata into TAP test descriptionCarlo Marcelo Arenas Belón, May 15, 2020
  92. Eric SunshineMay 15, 2020
  93. Alban GruinMay 15, 2020
  94. Carlo Marcelo Arenas BelónMay 15, 2020
  95. Junio C HamanoMay 15, 2020
  96. Carlo Marcelo Arenas BelónMay 15, 2020
  97. Junio C HamanoMay 15, 2020
  98. Johannes SchindelinMay 15, 2020
  99. Junio C HamanoMay 15, 2020
  100. 0/2 Unbreak TAP output under bashJunio C Hamano, May 15, 2020
  101. 1/2 Revert "t/test_lib: avoid naked bash arrays in file_lineno"Junio C Hamano, May 15, 2020
  102. 2/2 Revert "tests: when run in Bash, annotate test failures with file name/line number"Junio C Hamano, May 15, 2020
  103. Junio C HamanoMay 15, 2020
  104. Carlo Marcelo Arenas BelónMay 15, 2020
  105. Alban GruinMay 15, 2020
  106. Carlo Marcelo Arenas BelónMay 15, 2020
  107. Alban GruinMay 15, 2020
  108. 12/12 ci: let GitHub Actions upload failed tests' directoriesĐoàn Trần Công Danh, Apr 10, 2020
  109. 09/12 ci: retire the Azure Pipelines definitionĐoàn Trần Công Danh, Apr 10, 2020
  110. 11/12 ci: add a problem matcher for GitHub ActionsĐoàn Trần Công Danh, Apr 10, 2020

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.