Skip to content

Commit ab2a86e

Browse files
Merge pull request #873 from akinomyoga/check-bash-version
Check Bash version
2 parents 2d905aa + 7681ca7 commit ab2a86e

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88

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

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

1415
A Bats test file is a Bash script with special syntax for defining test cases.
1516
Under the hood, each test case is just a function with a description.

bin/bats

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
set -euo pipefail
44

5+
# Note: We first need to use POSIX's `[ ... ]' instead of Bash's `[[ ... ]]'
6+
# because this is the check for Bash, where the shell may not be Bash. Once we
7+
# confirm that we are in Bash, we can use [[ ... ]] and (( ... )). Note that
8+
# these [[ ... ]] and (( ... )) do not cause syntax errors in POSIX shells,
9+
# though they can be parsed differently.
10+
if [ -z "${BASH_VERSION-}" ] ||
11+
[[ -z "${BASH_VERSINFO-}" ]] ||
12+
((BASH_VERSINFO[0] < 3 || (BASH_VERSINFO[0] == 3 && BASH_VERSINFO[1] < 2)))
13+
then
14+
printf 'bats: this program needs to be run by Bash >= 3.2\n' >&2
15+
exit 1
16+
fi
17+
518
if command -v greadlink >/dev/null; then
619
bats_readlinkf() {
720
greadlink -f "$1"

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The format is based on [Keep a Changelog][kac] and this project adheres to
1717
* add security.md (#762)
1818
* add codespell CI checks (#720)
1919
* dynamic test registration via `bats_test_function` (#349)
20+
* add check that Bats is executed with Bash >= 3.2 (#873)
2021

2122
### Fixed
2223

0 commit comments

Comments
 (0)