-
Notifications
You must be signed in to change notification settings - Fork 1.8k
SC2315
Joachim Ansorg edited this page Nov 15, 2021
·
3 revisions
#!/usr/bin/env bats
@test "test" {
# ... code
! [ $status == 0 ]
# ... more code
}
#!/usr/bin/env bats
@test "test" {
# ... code
[ $status != 0 ]
# ... more code
}
Bats uses set -e
and trap ERR
to catch test failures as early as possible.
Although the return code of a !
negated command is inverted, they will never trigger errexit
, due to a bash design decision (see Related Resources).
This means that tests which use !
can never fail.
The return code of the last command in the test will be the exit code of the test function.
This means that you can use ! <command>
on the last line of the test and it will still fail appropriately.
However, you are encouraged to still transform the code in this case for consistency.
- SC2314: In bats, ! does not cause a test failure (for non-conditionals)
- SC2251: This ! is not on a condition and skips errexit
- Stackoverflow: Why do I need parenthesis In bash
set -e
and negated return code -
bash manpage (look at
trap [-lp] [[arg] sigspec ...]
):The ERR trap is not executed [...] if the command's return value is being inverted via !