Skip to content

Define consistent behavior for ERREXIT in teardown #616

@martin-schulze-vireso

Description

@martin-schulze-vireso

Describe the bug
Currently, the behavior of Bats w.r.t. an error in teardown varies depending on the location of the failure, whether its the last command or in the middle.

To Reproduce
Run the following scripts and compare their output:

@test "test to make bats run this file" { :; }

teardown() {
    false
}

will trigger an error:

$ ./bin/bats test.bats 
test.bats
 ✗ test to make bats run this file
   (from function `teardown' in test file test.bats, line 4)
     `false' failed

1 test, 1 failure

while

@test "test to make bats run this file" { :; }

teardown() {
    false
    true
}

does not:

$ ./bin/bats test.bats 
test.bats
 ✓ test to make bats run this file

1 test, 0 failures

Expected behavior
Both files should generate the same output.

Environment (please complete the following information):
Seems to be present from bats version 1.0.0 onwards (earlier not tested)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: Bash CodeEverything regarding the bash codePriority: CriticalBroken behavior in nearly all environments, e.g. wrong test results, internal bats errorSize: MediumChanges in the same fileType: Bug

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions