Closed thorstenkampe closed 2 years ago
false is just a string in bash. A non-empty string is true. Therefore, this is working properly. You need to manage boolean logic differently in your bash.
Related discussion: https://unix.stackexchange.com/questions/105935/understanding-boolean-operators-in-bash-script
@flickerfly quoting from the documentation... | assert - Fail if the given expression evaluates to false. ...that means the false string is evaluated (to boolean false).
But that was just an example of a failing assertion. The issue is that it reports the true
statement as failing while it's the assertion that is failing.
I just ran the same example, and everything seems to work properly. I didn't see any code changes, so it was possible there was a fix within Bats. You might be also using an older version of Bash, it may be useful to know what it is
✗ core
(in test file 32.sh, line 8)
`false' failed
✗ assert
(from function `assert' in file ../bats-assert/src/assert.bash, line 40,
in test file 32.sh, line 13)
`assert false' failed
-- assertion failed --
expression : false
--
I would suspect that the error boiled down to accessing the wrong line number (off by one indexing error), or something along those lines. At least with the current code, the "false being a string" isn't particularly relevant, because all parameters are passed as strings - the actual execution occurs after being passed into assert.
@hyperupcall can't confirm your observation. The result is still the same for me with Bats 1.3.0.
Which version of Bats are you using and how did you install it?
Hmmm, I'm using Bats version 1.4.1
and Bash version 5.0.17(1)-release (x86_64-pc-linux-gnu)
. I installed it with my Bash package manager, which effectively is the downloaded tarball of release v1.4.1
on the Bats release page
@thorstenkampe I can't reproduce this, even with Bats 1.3.0. Please try to provide more detail about your environment and post this at bats-core, since error line reporting comes from over there.
see below example: bats-core reports that
false
failed (correct) whileassert
reportstrue
failed (incorrect).I suspect that
assert
always reports the previous command as failing while a test can include more than just onerun
and oneassert
.