"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Thomas Adam <thomas@xteddy.org>
Subject:
Re: [rfc] regress: add line number to failure output
To:
Omar Polo <op@omarpolo.com>
Cc:
Mark Jamsek <mark@jamsek.com>, Christian Weisgerber <naddy@mips.inka.de>, gameoftrees@openbsd.org
Date:
Tue, 14 Feb 2023 20:22:07 +0000

Download raw body.

Thread
On Tue, Feb 14, 2023 at 07:05:03PM +0100, Omar Polo wrote:
> FWIW dash 0.5.12 as in the alpine repo has $LINENO working

It does -- but you won't find it on other distributions or some older BSDs
whose $SHELL is of the ark.

Note that in dash's case, Debian were (not sure if they still are), compiling
dash with "--disable-lineno".

Turns out that despite my ~20 years of working with shell portability, the
situation hasn't changed at all.  I'm afraid, the lowest common denominator
still wins, which means sacrificing functionality to support a very small
proportion of unlikely use-cases.

It's 2023.  I bet we won't be switching to relying on $LINENO this time next
year by default.  :)

> what is actually the issue for -portable?  we're not running with set
> -u, so if the shell used doesn't know that $LINENO is special it will
> just replace it with the empty string.  Worst case scenario, $LINENO
> could be defined in the environment.  Am i missing something?

It's about the information it conveys, moreover the functionality.  I just
don't think it's worth adding.

That being said, we could look at what autotools does with $LINENO, which is
essentially a form of post-processing of $LINENO to reference it in-situ to
where it appears in the script:

  # Blame Lee E. McMahon (1931-1989) for sed's syntax.  :-)
  sed -n '
    p
    /[$]LINENO/=
  ' <$as_myself |
    sed '
      s/[$]LINENO.*/&-/
      t lineno
      b
      :lineno
      N
      :loop
      s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/
      t loop
      s/-\n.*//
    ' >$as_me.lineno &&
  chmod +x "$as_me.lineno" ||
    { printf "%s\n" "$as_me: error: cannot create $as_me.lineno; rerun with a \
    POSIX shell" >&2; as_fn_exit 1; }

Which we could probably distill to something like:

awk '{gsub(/[$]LINENO/, FNR);print}'

But there's always tradeoffs to this approach.  We'd have to do that
everytime we run tests.  I guess we could do this from the Makefiles, but that
now enforces using make to run tests, rather than developers running
individual tests.

> time to roll some m4 over the tests?  :P

;)

-- Thomas Adam