Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Allow for set -e in run #719

@andras-tim

Description

@andras-tim

Describe the bug
The run changed resets the set -e that change the behaviors of the function.

To Reproduce

  1. Here is an example script that should fail without print anything to console:
set -e

function main() {
    my_command
}

function my_command() {
    false # failing command
    echo 'FOOBAR'
}

if [ "${BASH_SOURCE[0]}" == "$0" ]; then
    main
fi
  1. But this test will fail, because the set -e is not set as the source :
setup() {
    source my_script.sh
}

@test "test my_command" {
    run my_command
    [ "$output" != '' ]
}

Expected behavior
The sourced set flags have to be set under testing too.

Environment (please complete the following information):

  • Bats version: 1.8.2
  • OS: Linux (nixos)
  • Bash version: 5.1.16

Additional context
I use run to have $status and $output.

I have read the https://bats-core.readthedocs.io/en/stable/writing-tests.html#when-not-to-use-run part of the documentation, that mentions the code will run with set -e in a subshell. This would be right for me, but my function works differently.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: Bash CodeEverything regarding the bash codePriority: HighBroken behavior in specific environments like in parallel mode or only on some operating systemsSize: MediumChanges in the same fileStatus: ConfirmedThe reproducer worked as describedType: BugType: Enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions