Skip to content

Files

Latest commit

 

History

History
37 lines (26 loc) · 730 Bytes

SC2315.md

File metadata and controls

37 lines (26 loc) · 730 Bytes

Pattern: Test with ! never fails

Issue: -

Description

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
}

Further Reading