Re: [PATCH v5 10/12] tests: when run in Bash, annotate test failures with file name/line number
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- May 6, 2020, 12:54 UTC
- Message-ID
- <nycvar.QRO.7.76.6.2005061447010.56@tvgsbejvaqbjf.bet>
- In-Reply-To
- <20200506073045.GA52959@Carlos-MBP>
Hi Carlo,
On Wed, 6 May 2020, Carlo Marcelo Arenas Belón wrote:
Show 20 quoted lines
> 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.
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`.
Even worse, as `$0` does _not_ contain `test-lib.sh` at this point, the printed information is totally bogus.
So we will have to use that `eval` unless we find a better solution.
Ciao, Dscho