Skip to content

Latest commit

 

History

History
40 lines (28 loc) · 888 Bytes

SC2314.md

File metadata and controls

40 lines (28 loc) · 888 Bytes

Pattern: Test 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.

Starting with bats 1.5.0 you can use ! inside run. If you are still using an older bats version, you can rewrite ! <command> to <command> && exit 1.

Example of incorrect code:

#!/usr/bin/env bats

@test "test" {
    # ... code
    ! test_file_exists
    # ... more code
}

Example of correct code:

#!/usr/bin/env bats

@test "test" {
    # ... code
    run ! test_file_exists
    # ... more code
}

Further Reading