meleu
May 13, 2026, 4:31pm
1
I like the way you guys solved the hassle of setting up BATS assertions (simply concatenating the contents of bats-support and bats-assert).
My question is: can someone share the automated way to generate the bats-extra file?
(I’m assuming you don’t do that manually).
cc @IsaacG / @glennj
(pinging some guys who I think are involved in the bash track)
It’s hand curated/written and copy pasted from exercise to exercise.
glennj
May 14, 2026, 12:10am
3
meleu
May 15, 2026, 12:33pm
4
I was looking for a way to automatically get something like the bats-extra in order to make it easier for people start writing tests for bash with less setup.
Sharing here what I did so far:
a script to dump to stdout all sourced files in bats-support/load.bash and in bats-assert/load.bash
pipe the output to shfmt --minify to remove all comments
then pipe the output to a regular shfmt to get a minimally reasonable formatting
Here’s the script:
#!/usr/bin/env bash
# bundle-bats-extra.sh
######################
source() {
cat "$1"
}
export -f source
.() {
source "$@"
}
export -f .
for target in "$@"; do
builtin source "$target"
done
How I run it:
./bundle-bats-extra.sh \
test_helper/bats-support/load.bash \
test_helper/bats-assert/load.bash \
| shfmt --minify \
| shfmt > bats-extra.sh
IMPORTANT! : This script only works as long as the load.bash files are composed only of source commands, which is currently the case.