From: "Carlo Marcelo Arenas Belón" <carenas@gmail.com> To: Johannes Schindelin <Johannes.Schindelin@gmx.de> Cc: Junio C Hamano <gitster@pobox.com>, Danh Doan <congdanhqx@gmail.com>, git@vger.kernel.org Subject: Re: [PATCH v5 10/12] tests: when run in Bash, annotate test failures with file name/line number Date: Wed, 6 May 2020 23:10:29 -0700 [thread overview] Message-ID: <20200507061029.GA83231@Carlos-MBP> (raw) 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: > 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 > > > 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. > 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/
next prev parent reply other threads:[~2020-05-07 6:10 UTC|newest] Thread overview: 110+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-03-31 12:48 [PATCH 0/5] ci: replace our Azure Pipeline by GitHub Actions Johannes Schindelin via GitGitGadget 2020-03-31 12:48 ` [PATCH 1/5] ci/lib: if CI type is unknown, show the environment variables Johannes Schindelin via GitGitGadget 2020-03-31 12:48 ` [PATCH 2/5] ci/lib: allow running in GitHub Actions Johannes Schindelin via GitGitGadget 2020-04-03 8:46 ` SZEDER Gábor 2020-04-04 20:08 ` Johannes Schindelin 2020-04-05 0:01 ` Danh Doan 2020-04-07 22:41 ` Johannes Schindelin 2020-04-10 15:31 ` SZEDER Gábor 2020-04-10 19:10 ` Junio C Hamano 2020-04-12 21:42 ` Johannes Schindelin 2020-04-12 22:12 ` Junio C Hamano 2020-04-12 22:25 ` Junio C Hamano 2020-03-31 12:48 ` [PATCH 3/5] ci: configure GitHub Actions for CI/PR Johannes Schindelin via GitGitGadget 2020-04-03 22:07 ` SZEDER Gábor 2020-04-04 17:59 ` Johannes Schindelin 2020-04-04 23:55 ` Danh Doan 2020-03-31 12:48 ` [PATCH 4/5] README: add a build badge for the GitHub Actions runs Johannes Schindelin via GitGitGadget 2020-03-31 12:48 ` [PATCH 5/5] ci: retire the Azure Pipelines definition Johannes Schindelin via GitGitGadget 2020-03-31 14:46 ` [PATCH 0/5] ci: replace our Azure Pipeline by GitHub Actions Danh Doan 2020-03-31 18:47 ` Junio C Hamano 2020-04-01 15:55 ` [PATCH v2 0/6] " Đoàn Trần Công Danh 2020-04-01 15:55 ` [PATCH v2 1/6] ci/lib: if CI type is unknown, show the environment variables Đoàn Trần Công Danh 2020-04-01 15:55 ` [PATCH v2 2/6] ci/lib: allow running in GitHub Actions Đoàn Trần Công Danh 2020-04-01 15:55 ` [PATCH v2 3/6] ci/lib: set TERM environment variable if not exist Đoàn Trần Công Danh 2020-04-01 15:55 ` [PATCH v2 4/6] ci: configure GitHub Actions for CI/PR Đoàn Trần Công Danh 2020-04-01 15:55 ` [PATCH v2 5/6] README: add a build badge for the GitHub Actions runs Đoàn Trần Công Danh 2020-04-01 15:55 ` [PATCH v2 6/6] ci: retire the Azure Pipelines definition Đoàn Trần Công Danh 2020-04-01 21:23 ` [PATCH v2 0/6] ci: replace our Azure Pipeline by GitHub Actions Junio C Hamano 2020-04-02 0:14 ` Danh Doan 2020-04-02 13:16 ` [PATCH v3 " Đoàn Trần Công Danh 2020-04-02 13:16 ` [PATCH v3 1/6] ci/lib: if CI type is unknown, show the environment variables Đoàn Trần Công Danh 2020-04-02 13:16 ` [PATCH v3 2/6] ci/lib: allow running in GitHub Actions Đoàn Trần Công Danh 2020-04-02 13:16 ` [PATCH v3 3/6] ci/lib: set TERM environment variable if not exist Đoàn Trần Công Danh 2020-04-02 13:16 ` [PATCH v3 4/6] ci: configure GitHub Actions for CI/PR Đoàn Trần Công Danh 2020-04-02 13:16 ` [PATCH v3 5/6] README: add a build badge for the GitHub Actions runs Đoàn Trần Công Danh 2020-04-02 13:17 ` [PATCH v3 6/6] ci: retire the Azure Pipelines definition Đoàn Trần Công Danh 2020-04-08 4:05 ` [PATCH v4 00/12] ci: replace our Azure Pipeline by GitHub Actions Đoàn Trần Công Danh 2020-04-08 4:05 ` [PATCH v4 01/12] ci/lib: if CI type is unknown, show the environment variables Đoàn Trần Công Danh 2020-04-08 4:05 ` [PATCH v4 02/12] ci/lib: allow running in GitHub Actions Đoàn Trần Công Danh 2020-04-08 4:05 ` [PATCH v4 03/12] ci/lib: set TERM environment variable if not exist Đoàn Trần Công Danh 2020-04-08 4:05 ` [PATCH v4 04/12] ci: fix the `jobname` of the `GETTEXT_POISON` job Đoàn Trần Công Danh 2020-04-08 4:05 ` [PATCH v4 05/12] ci: explicit install all required packages Đoàn Trần Công Danh 2020-04-10 15:53 ` SZEDER Gábor 2020-04-10 16:07 ` Danh Doan 2020-04-10 16:21 ` Junio C Hamano 2020-04-08 4:05 ` [PATCH v4 06/12] ci: run gem with sudo to install asciidoctor Đoàn Trần Công Danh 2020-04-08 4:05 ` [PATCH v4 07/12] ci: configure GitHub Actions for CI/PR Đoàn Trần Công Danh 2020-04-08 4:05 ` [PATCH v4 08/12] README: add a build badge for the GitHub Actions runs Đoàn Trần Công Danh 2020-04-08 4:05 ` [PATCH v4 09/12] ci: retire the Azure Pipelines definition Đoàn Trần Công Danh 2020-04-08 4:05 ` [PATCH v4 10/12] tests: when run in Bash, annotate test failures with file name/line number Đoàn Trần Công Danh 2020-04-08 4:05 ` [PATCH v4 11/12] ci: add a problem matcher for GitHub Actions Đoàn Trần Công Danh 2020-04-08 4:05 ` [PATCH v4 12/12] ci: let GitHub Actions upload failed tests' directories Đoàn Trần Công Danh 2020-04-09 21:19 ` [PATCH v4 00/12] ci: replace our Azure Pipeline by GitHub Actions Junio C Hamano 2020-04-10 14:34 ` Johannes Schindelin 2020-04-10 14:37 ` Johannes Schindelin 2020-04-10 17:35 ` Danh Doan 2020-04-10 15:42 ` Junio C Hamano 2020-04-10 17:41 ` Danh Doan 2020-04-16 0:49 ` Junio C Hamano 2020-04-16 1:28 ` fixing ci failure of 'pu' with the es/bugreport topic Junio C Hamano 2020-04-16 1:55 ` Emily Shaffer 2020-04-16 3:20 ` Junio C Hamano 2020-04-16 3:45 ` Elijah Newren 2020-04-16 4:10 ` Emily Shaffer 2020-04-16 4:57 ` Junio C Hamano 2020-04-16 11:26 ` Danh Doan 2020-04-16 12:05 ` Johannes Schindelin 2020-04-16 12:08 ` [PATCH v4 00/12] ci: replace our Azure Pipeline by GitHub Actions Johannes Schindelin 2020-04-16 15:55 ` Junio C Hamano 2020-04-10 17:18 ` [PATCH v5 " Đoàn Trần Công Danh 2020-04-10 17:18 ` [PATCH v5 01/12] ci/lib: if CI type is unknown, show the environment variables Đoàn Trần Công Danh 2020-04-10 17:18 ` [PATCH v5 02/12] ci/lib: allow running in GitHub Actions Đoàn Trần Công Danh 2020-04-10 17:18 ` [PATCH v5 03/12] ci/lib: set TERM environment variable if not exist Đoàn Trần Công Danh 2020-04-10 17:18 ` [PATCH v5 04/12] ci: fix the `jobname` of the `GETTEXT_POISON` job Đoàn Trần Công Danh 2020-04-10 17:18 ` [PATCH v5 05/12] ci: explicit install all required packages Đoàn Trần Công Danh 2020-04-10 17:18 ` [PATCH v5 06/12] ci: run gem with sudo to install asciidoctor Đoàn Trần Công Danh 2020-04-10 17:18 ` [PATCH v5 07/12] ci: configure GitHub Actions for CI/PR Đoàn Trần Công Danh 2020-04-10 17:18 ` [PATCH v5 08/12] README: add a build badge for the GitHub Actions runs Đoàn Trần Công Danh 2020-04-10 17:18 ` [PATCH v5 09/12] ci: retire the Azure Pipelines definition Đoàn Trần Công Danh 2020-04-10 17:18 ` [PATCH v5 10/12] tests: when run in Bash, annotate test failures with file name/line number Đoàn Trần Công Danh 2020-05-04 17:46 ` Carlo Marcelo Arenas Belón 2020-05-04 23:25 ` Danh Doan 2020-05-05 0:35 ` Junio C Hamano 2020-05-06 7:30 ` Carlo Marcelo Arenas Belón 2020-05-06 12:54 ` Johannes Schindelin 2020-05-06 13:46 ` Carlo Marcelo Arenas Belón 2020-05-06 14:33 ` Johannes Schindelin 2020-05-07 6:10 ` Carlo Marcelo Arenas Belón [this message] 2020-05-06 16:33 ` Junio C Hamano 2020-05-05 0:54 ` Carlo Marcelo Arenas Belón 2020-05-15 13:16 ` Alban Gruin 2020-05-15 15:00 ` [RFC PATCH] t: move metadata into TAP test description Carlo Marcelo Arenas Belón 2020-05-15 15:08 ` Eric Sunshine 2020-05-15 15:38 ` Alban Gruin 2020-05-15 15:45 ` Carlo Marcelo Arenas Belón 2020-05-15 16:50 ` Junio C Hamano 2020-05-15 17:14 ` Carlo Marcelo Arenas Belón 2020-05-15 17:23 ` Junio C Hamano 2020-05-15 22:42 ` Johannes Schindelin 2020-05-15 22:57 ` Junio C Hamano 2020-05-15 17:21 ` [PATCH 0/2] Unbreak TAP output under bash Junio C Hamano 2020-05-15 17:21 ` [PATCH 1/2] Revert "t/test_lib: avoid naked bash arrays in file_lineno" Junio C Hamano 2020-05-15 17:21 ` [PATCH 2/2] Revert "tests: when run in Bash, annotate test failures with file name/line number" Junio C Hamano 2020-05-15 16:38 ` [RFC PATCH] t: move metadata into TAP test description Junio C Hamano 2020-05-15 17:22 ` Carlo Marcelo Arenas Belón 2020-05-15 19:04 ` Alban Gruin 2020-05-15 15:28 ` [PATCH v5 10/12] tests: when run in Bash, annotate test failures with file name/line number Carlo Marcelo Arenas Belón 2020-05-15 15:33 ` Alban Gruin 2020-04-10 17:18 ` [PATCH v5 11/12] ci: add a problem matcher for GitHub Actions Đoàn Trần Công Danh 2020-04-10 17:18 ` [PATCH v5 12/12] ci: let GitHub Actions upload failed tests' directories Đoàn Trần Công Danh
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style List information: http://vger.kernel.org/majordomo-info.html * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200507061029.GA83231@Carlos-MBP \ --to=carenas@gmail.com \ --cc=Johannes.Schindelin@gmx.de \ --cc=congdanhqx@gmail.com \ --cc=git@vger.kernel.org \ --cc=gitster@pobox.com \ --subject='Re: [PATCH v5 10/12] tests: when run in Bash, annotate test failures with file name/line number' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Code repositories for project(s) associated with this inbox: https://80x24.org/mirrors/git.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).