From: Eric Bavier <bavier@posteo.net>
To: "Ludovic Courtès" <ludo@gnu.org>, 62406@debbugs.gnu.org
Subject: bug#62406: “! failing-command” pattern in shell tests is wrong
Date: Thu, 23 Mar 2023 18:53:47 +0000 [thread overview]
Message-ID: <75622c7ab52087a4266b7b48374013d0c76d3c53.camel@posteo.net> (raw)
In-Reply-To: <87y1nn790x.fsf@inria.fr>
[-- Attachment #1: Type: text/plain, Size: 1663 bytes --]
On Thu, 2023-03-23 at 17:00 +0100, Ludovic Courtès wrote:
> In <https://issues.guix.gnu.org/43616> (commit
> d8934360d2453a403b5433e71d09188e4ed23b57), we changed:
>
> if command that should fail; then false; else true; fi
>
> to:
>
> ! command that should fail
>
> I had reservations back then, and now I know why: :-)
>
> --8<---------------cut here---------------start------------->8---
> $ bash -xe -c '! true; true'
> + true
> + true
> $ echo $?
> 0
> $ bash -xe -c '! false; true'
> + false
> + true
> $ echo $?
> 0
> --8<---------------cut here---------------end--------------->8---
>
> Whether or not the command following the exclamation mark succeeds, the
> statement succeeds. Bummer.
I think it's maybe not that the statement succeeds regardless. But that 'set
-e' doesn't consider it a "failure". From "The Set Builtin":
'-e'
Exit immediately if a pipeline (*note Pipelines::)... returns a
non-zero status. The shell does not exit if the command that
fails is ..., or if the command's return status is being
inverted with '!'.
So in each of your examples, execution continues to the second 'true'
statement and the overall exit status is 0. This is not the behavior we want
in our tests.
The purpose of d89343 was to ease visual parsing of the tests. I mentioned
having used the '!' syntax in my own shell tests, but I realize now that I
was not relying on `set -e` like guix is.
I'll consider a few options. Do we have a known issue where this is causing
a test to not to catch a failure?
Thanks for bringing this up,
`~Eric
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 858 bytes --]
next prev parent reply other threads:[~2023-03-23 18:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-23 16:00 bug#62406: “! failing-command” pattern in shell tests is wrong Ludovic Courtès
2023-03-23 18:53 ` Eric Bavier [this message]
2023-03-28 16:21 ` Ludovic Courtès
2023-04-20 5:48 ` Eric Bavier
2023-03-26 18:16 ` Martin Castillo
2023-03-26 18:21 ` Martin Castillo
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=75622c7ab52087a4266b7b48374013d0c76d3c53.camel@posteo.net \
--to=bavier@posteo.net \
--cc=62406@debbugs.gnu.org \
--cc=ludo@gnu.org \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.