Skip to content

Commit

Permalink
Merge pull request #873 from akinomyoga/check-bash-version
Browse files Browse the repository at this point in the history
Check Bash version
  • Loading branch information
martin-schulze-vireso committed Mar 1, 2024
2 parents 2d905aa + 7681ca7 commit ab2a86e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -8,8 +8,9 @@

[![Join the chat in bats-core/bats-core on gitter](https://badges.gitter.im/bats-core/bats-core.svg)][gitter]

Bats is a [TAP](https://testanything.org/)-compliant testing framework for Bash. It provides a simple
way to verify that the UNIX programs you write behave as expected.
Bats is a [TAP](https://testanything.org/)-compliant testing framework for Bash
3.2 or above. It provides a simple way to verify that the UNIX programs you
write behave as expected.

A Bats test file is a Bash script with special syntax for defining test cases.
Under the hood, each test case is just a function with a description.
Expand Down
13 changes: 13 additions & 0 deletions bin/bats
Expand Up @@ -2,6 +2,19 @@

set -euo pipefail

# Note: We first need to use POSIX's `[ ... ]' instead of Bash's `[[ ... ]]'
# because this is the check for Bash, where the shell may not be Bash. Once we
# confirm that we are in Bash, we can use [[ ... ]] and (( ... )). Note that
# these [[ ... ]] and (( ... )) do not cause syntax errors in POSIX shells,
# though they can be parsed differently.
if [ -z "${BASH_VERSION-}" ] ||
[[ -z "${BASH_VERSINFO-}" ]] ||
((BASH_VERSINFO[0] < 3 || (BASH_VERSINFO[0] == 3 && BASH_VERSINFO[1] < 2)))
then
printf 'bats: this program needs to be run by Bash >= 3.2\n' >&2
exit 1
fi

if command -v greadlink >/dev/null; then
bats_readlinkf() {
greadlink -f "$1"
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Expand Up @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog][kac] and this project adheres to
* add security.md (#762)
* add codespell CI checks (#720)
* dynamic test registration via `bats_test_function` (#349)
* add check that Bats is executed with Bash >= 3.2 (#873)

### Fixed

Expand Down

0 comments on commit ab2a86e

Please sign in to comment.