Shest: A Test Runner for Bash Scripts
Shest
is an intuitive test runner for Bash scripts, inspired by Node.js Jest. The name Shest stands for [Sh]ell T[est], and it simplifies testing by providing a clear structure for writing, organizing, and executing shell script tests. With built-in support for assertions, Shest
empowers developers to write reliable and maintainable Bash scripts effortlessly.
π Installation
You can install shest
using a single command. The installation script checks if shest
is already installed, downloads the latest version if not, and sets it up for global use.
Installation Command:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/aagamezl/shest/master/tools/install.sh)"
What the Command Does:
-
Checks if
shest
Exists:- Verifies if
shest
is already present in/home/$USER
. - Skips installation if already installed.
- Verifies if
-
Downloads the Script:
- Fetches the latest version from the GitHub repository using
curl
.
- Fetches the latest version from the GitHub repository using
-
Places the Script in
/home/$USER
:- Saves the script to
/home/$USER/shest.sh
for global access.
- Saves the script to
-
Displays Installation Status:
- Notifies whether the installation was successful or failed.
π Usage
To use shest
in your shell scripts, include it using the source
command. Hereβs an example test suite:
#!/bin/bash
# Include the shest framework
source /home/$USER/shest.sh
# Define a test suite
describe "Example Test Suite" <<'TEST'
test "Simple equality check" <<'SUITE'
toBeEqual "1 + 1 equals 2" "$(echo $((1 + 1)))" "2"
SUITE
test "String contains check" <<'SUITE'
toContain "Check substring" "Hello, World!" "World"
SUITE
TEST
# Run the tests
pluralize_test
π Syntax Overview
Shestβs syntax is designed to be intuitive:
-
describe
Block: Groups related test cases. -
test
Block: Defines individual test cases. -
Assertions: Built-in functions like
toBeEqual
,toBeNotEqual
,toBeTrue
,toBeFalse
, andtoContain
to validate outcomes. - Heredoc Syntax: Encapsulates multi-line strings without interpreting variables or special characters.
Example:
describe "Nouns ending in -ss, -sh, -ch, -x, -o" <<'TEST'
test "Testing toBeEqual" <<'SUITE'
toBeEqual "hello" "hello"
toBeEqual 1 1
SUITE
test "Testing toBeNotEqual" <<'SUITE'
toBeNotEqual "hello" "world"
SUITE
test "Testing toBeTrue" <<'SUITE'
toBeTrue true
SUITE
test "Testing toBeFalse" <<'SUITE'
toBeFalse false
SUITE
test "Testing toContain" <<'SUITE'
toContain "hello world" "world"
toContain 123 2
SUITE
TEST
π Test Results
Shest provides a detailed report for each test run:
- Pass/Fail Marks: Tests are marked as β (Pass) or β (Fail).
- Summary: Shows the total number of test suites and individual tests that passed/failed.
- Time Taken: Displays execution time for all tests.
Example:
β’ Testing Assertions
Testing toBeEqual
β toBeEqual: Passed
β toBeEqual: Passed
Testing toBeNotEqual
β toBeNotEqual: Passed
Testing toBeTrue
β toBeTrue: Passed
Testing toBeFalse
β toBeFalse: Passed
Testing toContain
β toContain: Passed
β toContain: Passed
Test Suites: 0 failed, 5 passed, 5 total
Tests: 0 failed, 7 passed, 7 total
Time: 0.01 s
π Why Use Shest?
- Intuitive Syntax: Simplifies writing and organizing Bash script tests.
- Comprehensive Assertions: Offers built-in functions to validate various conditions.
- Improved Productivity: Saves time by identifying issues early.
Start testing your Bash scripts with Shest
today and experience the simplicity of reliable shell scripting! π
Explore Shest on GitHub for more details.
Top comments (2)
Another tool to run tests in Bash: github.com/kward/shunit2
Thanks for the comment, yes, I saw the library while developing my library, have some good features.
I'm planning to add before, beforeEach, after, afterEach, and a better test report. Also, if I can, the line number where an error occurs, but this last is a big maybe.
@d-x can you please try my library and give me some feedback, I would appreciate it.