Skip to content
Richard Bairwell edited this page Jul 2, 2022 · 8 revisions

🦇 Bats Installation Guides

Bats logo

📑: links to another wiki page

Install Bats from GitHub Release

Download and install a tagged release.

tag=1.1.0
batstmp="$(mktemp -d bats-core-"${tag}".XXXXX)"
pushd "${batstmp}" &> /dev/null || return 11
curl -sSLO https://github.com/bats-core/bats-core/archive/refs/tags/v"${tag}".tar.gz
tar -zxvf v"${tag}".tar.gz
sudo bash "${batstmp}"/bats-core-"${tag}"/install.sh /usr/local
popd &> /dev/null || return 12
command -v bats && rm -rf "${batstmp}"

Install Bats from GitHub branch archive

Download and install from the master branch zip archive

branch=master
batstmp="$(mktemp -d bats-core-"${branch}".XXXXX)"
pushd "${batstmp}" &> /dev/null || return 11
curl -sSLO https://github.com/bats-core/bats-core/archive/refs/heads/"${branch}".zip
unzip -qo "${branch}".zip
sudo bash "${batstmp}"/bats-core-"${branch}"/install.sh /usr/local
popd &> /dev/null || return 12
command -v bats && rm -rf "${batstmp}"

Travis CI - adding Bats dependency

If you use Bats for testing builds in 🔁Travis CI, start with this configuration.

ℹ️ Note
language: bash is a Travis CI alias for language: minimal

This installs the GitHub master branch from source and adds /usr/local/bin to the PATH.

Sample .travis.yml file
language: bash
dist: xenial
#addons:
#  apt:
#    update: true
#    packages:
#    - xz-utils
#    - pv

env:
  global:
  - export PATH="/usr/local/bin:$PATH"

before_install:
- |
  if [ "$TRAVIS_OS_NAME" = "linux" ]; then
    branch=master
    batstmp="$(mktemp -d bats-core-"${branch}".XXXXX)"
    pushd "${batstmp}" &> /dev/null || return 11
    curl -sSLO https://github.com/bats-core/bats-core/archive/refs/heads/"${branch}".zip
    unzip -qo "${branch}".zip
    sudo bash "${batstmp}"/bats-core-"${branch}"/install.sh /usr/local
    popd &> /dev/null || return 12
  fi

script:
  - bats test/test.bats

Uncomment the addons: apt section if you need to install other packages, not included in the default xenial environment.

Install Bats from Github Release to your own Dockerfile

If you have your own Docker based development environment in which you want Bats to be available, then the following works.

ℹ️ Note
Some "slim/thin/minimal" Docker images may need curl installing first. The below extract was tested with debian:bullseye-slim which did need curl installing via apt-get install

Sample Dockerfile extract
...
# Set tagged release version of Bats to use. This could be also set in docker-compose.
ARG BATS_VERSION="1.7.0"

# Install bats
RUN batstmp="$(mktemp -d bats-core-${BATS_VERSION}.XXXX)" \
    && echo ${batstmp} \
    && cd ${batstmp} \
    && curl -SLO https://github.com/bats-core/bats-core/archive/refs/tags/v${BATS_VERSION}.tar.gz \
    && tar -zxvf v${BATS_VERSION}.tar.gz \
    && bash bats-core-${BATS_VERSION}/install.sh /usr/local \
    && rm -rf "${batstmp}"