Closed pawamoy closed 5 years ago
@pawamoy -- this appears to be a bug in bats
itself; namely, the logic it uses for determining the location of its "library" scripts. The line in question (at least, in bats-core
release 1.1.0) is this:
The problem is that bats
does not properly handle cases in which $0
is not an absolute path. Compare:
$ bash -x bats
+ set -e
+ export BATS_READLINK=true
+ BATS_READLINK=true
+ command -v greadlink
+ command -v readlink
+ BATS_READLINK=readlink
+ export BATS_ROOT
+ bats_resolve_absolute_root_dir bats BATS_ROOT
+ local cwd=/home/matt/src/bash-bats-core
+ local path=bats
+ local result=BATS_ROOT
+ local target_dir
+ local target_name
+ local original_shell_options=ehxB
+ set -P
+ true
+ target_dir=bats
+ target_name=bats
+ [[ bats != \b\a\t\s ]]
+ [[ -L bats ]]
+ printf -v BATS_ROOT -- %s /home/matt/src
+ set +P -ehxB
+ cd /home/matt/src/bash-bats-core
+ return
+ exec /home/matt/src/lib/bats-core/bats
/usr/bin/bats: line 50: /home/matt/src/lib/bats-core/bats: No such file or directory
With:
$ bash -x /usr/bin/bats
+ set -e
+ export BATS_READLINK=true
+ BATS_READLINK=true
+ command -v greadlink
+ command -v readlink
+ BATS_READLINK=readlink
+ export BATS_ROOT
+ bats_resolve_absolute_root_dir /usr/bin/bats BATS_ROOT
+ local cwd=/home/matt/src/bash-bats-core
+ local path=/usr/bin/bats
+ local result=BATS_ROOT
+ local target_dir
+ local target_name
+ local original_shell_options=ehxB
+ set -P
+ true
+ target_dir=/usr/bin
+ target_name=bats
+ [[ /usr/bin != \/\u\s\r\/\b\i\n\/\b\a\t\s ]]
+ cd /usr/bin
+ [[ -L bats ]]
+ printf -v BATS_ROOT -- %s /usr
+ set +P -ehxB
+ cd /home/matt/src/bash-bats-core
+ return
+ exec /usr/lib/bats-core/bats
Error: Must specify at least one <test>
Bats 1.1.0
Usage: bats [-c] [-r] [-p | -t] <test> [<test> ...]
Unless and until this is fixed upstream, I'd suggested using the absolute path to bats
when invoking it with bashcov:
$ bashcov /home/pawamoy/.basher/cellar/bin/bats tests
Got it, thank you very much @tomeon for the explanation and workaround!
Sure thing, @pawamoy! Glad to see there's a fix pending over in the bats-core
repo.
Am I using bashcov correctly?
bashcov bats tests