bats-docs
bats-docs copied to clipboard
Taking advantage of the PATH
Apologies if this isn't the right repo to report this issue in, it's not clear whether it belongs here (as the "proposal describing how a Bats helper library should look and behave") or in bats-core.
One issue I run into with the BATS library model is that the load paths need to be qualified. For example running brew install bats-assert prints:
To load the bats-assert lib in your bats test:
load '/Users/dimo414/homebrew/lib/bats-support/load.bash'
load '/Users/dimo414/homebrew/lib/bats-assert/load.bash'
This isn't portable; if I use these commands in a project I have to ensure the same directory structure exists on every system (e.g. a Docker CI image), which is brittle and tedious. It's really not clear to me how to portably include bats-assert into a project now without either cloning the library into the project or adding some custom location-resolving logic to support different systems. By contrast bats itself is expected to simply be on the system PATH; scripts don't need to know where or how it's installed.
BATS libraries would be much easier to work with if they didn't require fully-qualified paths. I see @ntnn has proposed https://github.com/bats-core/bats-core/pull/27, but it's been years with no movement. More to the point, though, bash itself already supports source-ing files that are on the PATH, which can be configured by system owners however they'd like.
One blocker is the existing idiom of using load.bash as the entry point for each library. That means it's not possible to add (for example) both bats-support/load.sh and bats-assert/load.bash to the PATH at the same time. If the entry-point files were named after each library (bats-support.sh and bats-assert.bash) users could add these libraries to the PATH and then they could be included in tests by simply writing:
source bats-support.sh
source bats-assert.bash
Is this at all feasible? Are there other approaches in this vein that might be workable?
@sublimino FYI, since you're helping me with https://github.com/bats-core/bats-core/pull/282
At the time I made the PR load didn't even support full qualified paths.
For some reason the PR that added fully qualified paths was merged before mine - although mine added more functionality: https://github.com/bats-core/bats-core/pull/282
Apologies, that was an oversight rather than malice! If there's further functionality we're still open to it, please tag me where needed 🙏
On Fri, 29 May 2020, 12:56 Nelo-T. Wallus, [email protected] wrote:
At the time I made the PR load didn't even support full qualified paths. For some reason the PR that added fully qualified paths was merged before mine - although added more functionality: bats-core/bats-core#282 https://github.com/bats-core/bats-core/pull/282
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ztombol/bats-docs/issues/15#issuecomment-635932511, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABAXZOP76DIASZVNGZSQT3RT6PIVANCNFSM4MOYKKKA .