sstephenson / bats

Bash Automated Testing System
MIT License
7.12k stars 518 forks source link

set -o pipefail #202

Open philtay opened 7 years ago

philtay commented 7 years ago

Is there any way to set -o pipefail in a test function, test file or helper function?

The test below should fail, but I can't find a way to do so:

@test "foobar" {
  false | true
}
mislav commented 7 years ago

I wouldn't recommend doing so, since that flag would affect the operation of bats itself.

I suggest you find a way to write tests that are not dependent on pipefail.

aojea commented 7 years ago

What about running it this way?

@test "foobar" {
  bash -o pipefail  -c "false | true"
}

it works for me

✗ foobar
   (in test file test/pipefail.bats, line 8)
     `bash -o pipefail  -c "false | true"' failed

1 test, 1 failure
philtay commented 7 years ago

Yep, this is what I have resorted to. It's ugly. IMO bats should support the Unofficial Bash Strict Mode by default.