Pattern: Test with !
never fails
Issue: -
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.
This means that tests which use !
can never fail.
Example of incorrect code:
#!/usr/bin/env bats
@test "test" {
# ... code
! [ $status == 0 ]
# ... more code
}
Example of correct code:
#!/usr/bin/env bats
@test "test" {
# ... code
[ $status != 0 ]
# ... more code
}