ddev / ddev-addon-template

Template for DDEV add-ons.
Apache License 2.0
20 stars 17 forks source link

bats-assert and bats-file libraries not actually loaded #33

Open rfay opened 1 year ago

rfay commented 1 year ago

Although we brew install bats-aassert bats-file we don't actually load them properly, so they're not available for use. brew info bats-assert for example tells us:

==> Caveats

To load the bats-assert lib in your bats test:

    load '/home/linuxbrew/.linuxbrew/lib/bats-support/load.bash'
    load '/home/linuxbrew/.linuxbrew/lib/bats-assert/load.bash'
==> Caveats

To load the bats-file lib in your bats test:

    load '/home/linuxbrew/.linuxbrew/lib/bats-support/load.bash'
    load '/home/linuxbrew/.linuxbrew/lib/bats-file/load.bash'
julienloizelet commented 1 year ago

Hi @rfay ,

After some search, I found that the "load" call must be made in the test.bats file itself ...

For example, I added :

TEST_BREW_PREFIX="$(brew --prefix)"
load "${TEST_BREW_PREFIX}/lib/bats-support/load.bash"
load "${TEST_BREW_PREFIX}/lib/bats-assert/load.bash"

at the beginning of a tests.bats file and the, the following test works :

@test 'assert_equal()' {
  assert_equal 'have' 'have'
}

Adding this these lines in a bats file is what is explained here: https://github.com/ztombol/bats-docs#loading

Maybe you know another way to load the files (I failed to try some source "/home/linuxbrew/.linuxbrew/lib/bats-support/load.bash" manually ) ?

If not, in my opinion, we should just update the ddev-addon-template README to speak about this.

rfay commented 1 year ago

Moved it over, thanks.