Installation
bashunit ships as a single-file executable. Pick the option that fits your project: install.sh (universal), npm (Node.js projects), Brew (macOS/Linux global), MacPorts, or bashdep.
Requirements
bashunit requires Bash 3.0 or newer. On Windows use WSL.
install.sh
There is a tool that will generate an executable with the whole library in a single file:
curl -s https://bashunit.typeddevs.com/install.sh | bash# IMPORTANT: You need WSL (Windows Subsystem for Linux) to run bashunit
#
# Step 1: Install WSL if you haven't already
# - Open PowerShell as Administrator
# - Run: wsl --install
# - Restart your computer
#
# Step 2: Open your WSL terminal and run:
curl -s https://bashunit.typeddevs.com/install.sh | bashThis will create a file inside a lib folder, such as lib/bashunit.
Verify
# Verify the sha256sum for latest stable: 0.35.0
DIR="lib"; KNOWN_HASH="bfe9f69bda77034234a38f26182cc34e1f7648d846dab57a513a14cf91977544"; FILE="$DIR/bashunit"; [ "$(shasum -a 256 "$FILE" | awk '{ print $1 }')" = "$KNOWN_HASH" ] && echo -e "✓ \033[1mbashunit\033[0m verified." || { echo -e "✗ \033[1mbashunit\033[0m corrupt"; rm "$FILE"; }TIP
You can find the checksum for each version inside GitHub's releases. E.g.:
https://github.com/TypedDevs/bashunit/releases/download/0.35.0/checksumDefine custom tag and folder
The installation script can receive arguments (in any order):
curl -s https://bashunit.typeddevs.com/install.sh | bash -s [dir] [version]# IMPORTANT: You need WSL (Windows Subsystem for Linux) to run bashunit
#
# Step 1: Install WSL if you haven't already
# - Open PowerShell as Administrator
# - Run: wsl --install
# - Restart your computer
#
# Step 2: Open your WSL terminal and run:
curl -s https://bashunit.typeddevs.com/install.sh | bash -s [dir] [version][dir]: the destiny directory to save the executable bashunit;libby default[version]: the release to download, for instance0.35.0;latestby default.
TIP
You can use beta as [version] to get the next non-stable preview release. We try to keep it stable, but there is no promise that we won't change functions or their signatures without prior notice.
TIP
Committing (or not) this file to your project it's up to you. In the end, it is a dev dependency.
npm
bashunit on npm is the recommended option for Node.js projects.
# Install as dev dependency
npm install --save-dev bashunit
# Run via npx (resolves node_modules/.bin/bashunit)
npx bashunit tests/# Install on PATH
npm install -g bashunit
# Run directly, no npx needed
bashunit tests/# No install, runs the latest release
npx bashunit@latest tests/Per-project: package.json script
Only relevant for the per-project install (global and one-shot don't touch package.json). Define a script so contributors and CI share one command:
{
"scripts": {
"test": "bashunit tests/"
},
"devDependencies": {
"bashunit": "^0.35.0"
}
}Then run:
npm test
# or any custom script name
npm run <script-name>Windows (native) not supported
The npm package declares "os": ["darwin", "linux"], so npm install bashunit on native Windows (PowerShell / cmd) fails with EBADPLATFORM:
npm error code EBADPLATFORM
npm error notsup Unsupported platform for bashunit@x.y.z: wanted {"os":"darwin,linux"} (current: {"os":"win32"})Fix: install WSL and run npm install --save-dev bashunit inside the WSL shell. Alternatively use the install.sh route from WSL.
WARNING
The npm package only ships the prebuilt single-file binary (no src/ tree). You cannot source internals from node_modules/bashunit/ - use the bashunit command. To vendor or extend the framework, use install.sh or clone the repository.
Brew
You can install bashunit globally on macOS or Linux using brew.
brew install bashunitMacPorts
On macOS, you can also install bashunit via MacPorts:
sudo port install bashunitbashdep
You can manage your dependencies using bashdep, a simple dependency manager for bash.
# Ensure bashdep is installed
[ ! -f lib/bashdep ] && {
mkdir -p lib
curl -sLo lib/bashdep \
https://github.com/Chemaclass/bashdep/releases/download/0.1/bashdep
chmod +x lib/bashdep
}
# Add latest bashunit release to your dependencies
DEPENDENCIES=(
"https://github.com/TypedDevs/bashunit/releases/download/0.35.0/bashunit"
)
# Load, configure and run bashdep
source lib/bashdep
bashdep::setup dir="lib" silent=false
bashdep::install "${DEPENDENCIES[@]}"# IMPORTANT: You need WSL (Windows Subsystem for Linux) to run bashunit
#
# Step 1: Install WSL if you haven't already
# - Open PowerShell as Administrator
# - Run: wsl --install
# - Restart your computer
#
# Step 2: Open your WSL terminal and run:
# Ensure bashdep is installed
[ ! -f lib/bashdep ] && {
mkdir -p lib
curl -sLo lib/bashdep \
https://github.com/Chemaclass/bashdep/releases/download/0.1/bashdep
chmod +x lib/bashdep
}
# Add latest bashunit release to your dependencies
DEPENDENCIES=(
"https://github.com/TypedDevs/bashunit/releases/download/0.35.0/bashunit"
)
# Load, configure and run bashdep
source lib/bashdep
bashdep::setup dir="lib" silent=false
bashdep::install "${DEPENDENCIES[@]}"Downloading 'bashunit' to 'lib'...
> bashunit installed successfully in 'lib'GitHub Actions
# .github/workflows/bashunit-tests.yml
name: Tests
on: [pull_request, push]
jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: curl -s https://bashunit.typeddevs.com/install.sh | bash
- run: ./lib/bashunit tests# .github/workflows/bashunit-tests.yml
name: Tests
on: [pull_request, push]
jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: 20 }
- run: npm ci
- run: npx bashunit tests/TIP
See bashunit's own pipeline for a real example: https://github.com/TypedDevs/bashunit/blob/main/.github/workflows/tests.yml