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

Skip to content

Issue with using load in teardown #609

@colleeneb

Description

@colleeneb

Describe the bug
If we use load in the teardown, bats dies in the run and does not complete.

To Reproduce
Steps to reproduce the behavior:

Given this .bats file:

> cat t.bats 
teardown() {
      load ./common_functions.bash
 }

@test test2 {
     g++ test.cpp
    ./a.out
}

and this test.cpp:

> cat test.cpp 
int main() {
      return 1;
}

and this common_functions.bash:

> cat common_functions.bash 
function test_exit
{
        echo "Hi"
}

And then run bats. What I'm seeing is that it dies before printing what passed or failed:

> ./bin/bats -t t.bats 
1..1
# bats warning: Executed 0 instead of expected 1 tests

Expected behavior
Since test.cpp just returns 1, I expect bats to say that the test failed and exit cleanly. If we remove the teardown() function from t.bats it does work as expected:

> ./bin/bats -t t.bats 
1..1
not ok 1 test2
# (in test file t.bats, line 5)
#   `./a.out' failed

Environment (please complete the following information):

  • Bats Version: 61abd09
  • OS: Linux
  • Bash version: GNU bash, version 4.4.23(1)-release (x86_64-suse-linux-gnu)

Additional context
If I'm doing something wrong in the code, let me know! But I thought it should be ok.

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 fileStatus: ConfirmedThe reproducer worked as describedType: Bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions