From: Adam Dinwoodie <adam@dinwoodie.org>
To: cygwin@cygwin.com
Subject: Re: Unexpected zero return code from `throw std::runtime_error`
Date: Sat, 2 Jul 2022 22:34:35 +0100 [thread overview]
Message-ID: <20220702213435.hkdcsjm7jzbc7im4@lucy.dinwoodie.org> (raw)
In-Reply-To: <CAEhDDbCDj9bKLoJUbi4eOdA+Rx-jnA1eyJkkA583OQqyi_702w@mail.gmail.com>
On Sat, Jul 02, 2022 at 10:19:44PM +0200, Csaba Raduly wrote:
> On Sat, 2 Jul 2022 at 15:22, Adam Dinwoodie wrote:
> >
> > I'm currently experimenting with compiling rdfind for Cygwin, and one of
> > the testcases is failing because std::runtime_error is expected to
> > result in the compiled program exiting with a non-zero return code,
> > but on Cygwin, it just seems to cause the program to terminate with a
> > zero return code.
> >
> > I've attached a simple test case. Compare the output on Cygwin...
> >
> > $ ./test.sh
> > + cat
> > + g++ test.cc
> > + [[ -x a.exe ]]
> > + ./a.exe
> > + rc=0
> > + (( rc == 0 ))
> > + echo 'Unexpected zero return code from execution'
> > Unexpected zero return code from execution
> > + exit 1
> >
> > ...with the output from one of my Debian boxes...
> >
> > $ ./test.sh
> > + cat
> > + g++ test.cc
> > + [[ -x a.exe ]]
> > + [[ -x a.out ]]
> > + ./a.out
> > terminate called after throwing an instance of 'std::runtime_error'
> > what(): Test error
> > ./test.sh: line 21: 566327 Aborted ./a.out
> > + rc=134
> > + (( rc == 0 ))
> > + echo 'Expected non-zero return code received: 134'
> > Expected non-zero return code received: 134
> > + exit 0
> >
> > I'm not massively familiar with C++, so I could well be missing
> > something obvious, but this seems like an unexpected difference between
> > Cygwin and other *nix platforms. Is this a Cygwin bug, or am I doing
> > something wrong?
>
>
> Works just fine for me, unless I misunderstood something.
>
> $ /cygdrive/c/Users/Csaba/Downloads/test.sh
> + cat
> + g++ test.cc
> + [[ -x a.exe ]]
> + ./a.exe
> terminate called after throwing an instance of 'std::runtime_error'
> what(): Test error
> /cygdrive/c/Users/Csaba/Downloads/test.sh: line 21: 641 Aborted
> (core dumped) ./a.exe
> + rc=134
> + (( rc == 0 ))
> + echo 'Expected non-zero return code received: 134'
> Expected non-zero return code received: 134
> + exit 0
That's definitely closer to the behaviour I'd expect! I don't think it
should be dumping a core, though, at least based on the behaviour I see
on Debian.
I'd like to have a look at what's different about your environment;
could you share the output from `cygcheck -srv >cygcheck.out` on your
system?
> The if goes in the "else" case because rc is not 0, as it should be.
> (shoudn't the condition be $rc == 0 ?)
> After
>
> $ diff -u /cygdrive/c/Users/Csaba/Downloads/test.sh test.sh
> --- /cygdrive/c/Users/Csaba/Downloads/test.sh 2022-07-02
> 22:09:21.506377100 +0200
> +++ test.sh 2022-07-02 22:15:08.670809700 +0200
> @@ -20,7 +20,8 @@
> exit 2
> fi
>
> -if (( rc == 0 )); then
> +if [[ $rc == 0 ]]
> +then
> echo 'Unexpected zero return code from execution'
> exit 1
> else
>
> I get
>
> $ ./test.sh
> + cat
> + g++ test.cc
> + [[ -x a.exe ]]
> + ./a.exe
> terminate called after throwing an instance of 'std::runtime_error'
> what(): Test error
> ./test.sh: line 21: 660 Aborted (core dumped) ./a.exe
> + rc=134
> + [[ 134 == 0 ]]
> + echo 'Expected non-zero return code received: 134'
> Expected non-zero return code received: 134
> + exit 0
`(( rc == 0 ))` is comparing the value of `$rc` against the number 0;
the `$` isn't necessary in `(( ... ))` tests. `(( rc == 0 ))` is
essentially identical to `[[ $rc -eq 0 ]]`.
Your change means the comparison is done as a string comparison rather
than a numeric comparison. That doesn't make any difference here: '0'
is '0' regardless of whether you're testing it as a number or as a
string.
next prev parent reply other threads:[~2022-07-02 21:34 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-02 13:21 Adam Dinwoodie
2022-07-02 14:14 ` Joost Kraaijeveld
2022-07-02 14:29 ` Adam Dinwoodie
2022-07-02 15:56 ` [EXTERNAL] " Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2022-07-02 20:19 ` Csaba Raduly
2022-07-02 21:34 ` Adam Dinwoodie [this message]
2022-07-02 22:37 ` Csaba Raduly
2022-07-03 14:35 ` Adam Dinwoodie
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=20220702213435.hkdcsjm7jzbc7im4@lucy.dinwoodie.org \
--to=adam@dinwoodie.org \
--cc=cygwin@cygwin.com \
/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.
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).