-
Notifications
You must be signed in to change notification settings - Fork 4
BATS
robnagler edited this page May 21, 2024
·
1 revision
BATS is a test suite framework for Bash built on the Test Anything Protcol (TAP).
BATS is built on a git clone model that basically works something like this:
mkdir -p ~/tmp
cd ~/tmp
git clone https://github.com/bats-core/bats-core
cd tmp/bats-core
./install.sh "$HOME"/.local
cd ..
rm -rf bats-core
cd "$HOME"/.local/lib
git clone https://github.com/bats-core/bats-support
git clone https://github.com/bats-core/bats-assert
git clone https://github.com/bats-core/bats-file
A test with plugins then looks like:
setup() {
load "$BATS_ROOT"/lib/bats-support/load
load "$BATS_ROOT"/lib/bats-assert/load
}
@test "echo" {
run echo hello
assert_output hello
}
The output is hardwired colorized. Patch this file:
$HOME/.local/libexec/bats-core/bats-format-pretty
with this diff:
--- bats-core/bats-format-pretty~ 2024-05-21 15:34:14.948241627 +0000
+++ bats-core/bats-format-pretty 2024-05-21 15:49:55.209524269 +0000
@@ -88,7 +88,7 @@
pass() {
local TIMING="${1:-}"
- finish_test ' ✓ %s' "$name"
+ finish_test ' pass %s' "$name"
test_result=pass
}
@@ -104,14 +104,14 @@
fail() {
local TIMING="${1:-}"
set_color 1 bold
- finish_test ' ✗ %s' "$name"
+ finish_test ' FAIL %s' "$name"
test_result=fail
}
timeout() {
local TIMING="${1:-}"
set_color 3 bold
- TIMEOUT="${2:-}" finish_test ' ✗ %s' "$name"
+ TIMEOUT="${2:-}" finish_test ' FAIL %s' "$name"
test_result=timeout
}
@@ -228,6 +228,9 @@
_buffer=
buffer() {
+ if [[ ${1:-} =~ ^\\x1B ]]; then
+ return
+ fi
local content
# shellcheck disable=SC2059
printf -v content -- "$@"