-
Notifications
You must be signed in to change notification settings - Fork 36
Description
OS: MacOS 11.6.1
Bash: 5.1.12(1) (from MacPorts)
Bats: da56a30 (2022-01-05)
Bats-File: 17fa557 (2020-04-29)
This one took me hours to come up with a reproducible example; I didn't also have the fortitude to dig into the code and figure out the cause or a fix, too -- sorry!
If my program calls assert_file_exist
and fails, instead of reporting a failure it will report the test as not being executed, but only when there's a teardown
function with a load
call in it. Here's a test case; commentary follows:
setup() {
load 'test_helper/bats-support/load'
load 'test_helper/bats-assert/load'
load 'test_helper/bats-file/load'
}
teardown() {
load 'foofoo'
}
@test "[1] this one executes successfully" {
foo=/tmp/foo
touch $foo
assert_file_exist "$foo"
}
@test "[2] this one will execute and fail" {
foo=/tmp/foo
touch $foo
[[ -e "x$foo" ]]
}
@test "[3] this one will report as not executed" {
foo=/tmp/foo
touch $foo
assert_file_exist "x$foo"
}
@test "[4] this one works fine no matter what" {
foo=/tmp/foo
touch $foo
assert_file_not_exist "x$foo"
}
@test "[5] this one will also execute and fail" {
foo=/tmp/foo
touch $foo
run /bin/false
assert_success
}
The foofoo.bash
file is zero bytes; it just needs to exist.
When run, this produces the following output:
$ test/bats/bin/bats test/99*
✓ [1] this one executes successfully
✗ [2] this one will execute and fail
(in test file test/99-bats-issue.bats, line 24)
`[[ -e "x$foo" ]]' failed
✓ [4] this one works fine no matter what
✗ [5] this one will also execute and fail
(from function `assert_success' in file test/test_helper/bats-assert/src/assert_success.bash, line 42,
in test file test/99-bats-issue.bats, line 46)
`assert_success' failed
-- command failed --
status : 1
output :
--
bats warning: Executed 4 instead of expected 5 tests
5 tests, 2 failures, 1 not run
Notice that one of the tests is shown as not being run, and test #3 does in fact not show up in the output. If you watch the output closely, though, you'll see it is reported, it's just overwritten -- if you move test #3 to be the last test, its line won't get overwritten and you'll see it in the output:
$ test/bats/bin/bats test/99*
✓ [1] this one executes successfully
✗ [2] this one will execute and fail
(in test file test/99-bats-issue.bats, line 24)
`[[ -e "x$foo" ]]' failed
✓ [4] this one works fine no matter what
✗ [5] this one will also execute and fail
(from function `assert_success' in file test/test_helper/bats-assert/src/assert_success.bash, line 42,
in test file test/99-bats-issue.bats, line 39)
`assert_success' failed
-- command failed --
status : 1
output :
--
[3] this one will report as not executed 5/5
bats warning: Executed 4 instead of expected 5 tests
5 tests, 2 failures, 1 not run
If you remove the teardown
function (by either deleting it or renaming it), test #3 will properly show as executing and failing:
$ test/bats/bin/bats test/99*
✓ [1] this one executes successfully
✗ [2] this one will execute and fail
(in test file test/99-bats-issue.bats, line 24)
`[[ -e "x$foo" ]]' failed
✗ [3] this one will report as not executed
(from function `assert_file_exist' in file test/test_helper/bats-file/src/file.bash, line 72,
in test file test/99-bats-issue.bats, line 31)
`assert_file_exist "x$foo"' failed
-- file does not exist --
path : x/tmp/foo
--
✓ [4] this one works fine no matter what
✗ [5] this one will also execute and fail
(from function `assert_success' in file test/test_helper/bats-assert/src/assert_success.bash, line 42,
in test file test/99-bats-issue.bats, line 46)
`assert_success' failed
-- command failed --
status : 1
output :
--
5 tests, 3 failures
The same results can be achieved by removing the load
line, e.g.
teardown() {
: load 'foofoo'
}
I replicated this aberrant behavior with one or two other assert_*
commands from bats-file
, but I did not test each one.