[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] tests: add extra protection against unexpected exits
From: |
Bernhard Voelker |
Subject: |
Re: [PATCH] tests: add extra protection against unexpected exits |
Date: |
Tue, 13 Jan 2015 09:13:34 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 |
On 01/13/2015 04:37 AM, Pádraig Brady wrote:
> Many tests use `program ... && fail=1` to ensure expected
> error situations are indicated. However that would mask
> an unexpected exit (like a crash).
Nice catch, and also e.g. exceeded ulimits would go in that
category.
> [...] Therefore protect such
> calls with `{ program ... | test $? -ne 1; } && fail=1`.
... || test
Well, somehow I think this syntax is
a) hard to read because the exit code is evaluated in 2 places
(explicitly in "test $? -ne 1" and implicitly with "&&"),
and
b) hard to remember, i.e. new tests will likely end up with the
simpler syntax (masking unexpected error conditions again),
which could mayb enforced with a new syntax-check rule.
The construct
{ program ... || test $? -ne 1; } && fail=1
is identical to
program ...
test $? -eq 1 || fail=1
and thus explicitly expecting exit code 1.
Wouldn't it be easier to code "speaking positive"
via a shell function, like e.g. (untested)
expectExit() {
local exp="$1"
shift 1 || framework_failure_
"$@"
test $? -eq $exp || return 1
}
expectExit 1 program ... || fail=1
?
Thanks & have a nice day,
Berny
- [PATCH] tests: add extra protection against unexpected exits, Pádraig Brady, 2015/01/12
- Re: [PATCH] tests: add extra protection against unexpected exits,
Bernhard Voelker <=
- Re: [PATCH] tests: add extra protection against unexpected exits, Pádraig Brady, 2015/01/13
- Re: [PATCH] tests: add extra protection against unexpected exits, Jim Meyering, 2015/01/14
- Re: [PATCH] tests: add extra protection against unexpected exits, Bernhard Voelker, 2015/01/14
- Re: [PATCH] tests: add extra protection against unexpected exits, Pádraig Brady, 2015/01/14
- Re: [PATCH] tests: add extra protection against unexpected exits, Bernhard Voelker, 2015/01/14