Pipetest is a simple and lightweight set of shell functions useful to implement assertions with I/O Redirection.
Thanks to the use of Piping it will be possible to create scripts that are easy to read and able to be understood by a wide audience. This makes Pipetest suitable for the following scenarios
- CI/CD Pipelines
- Ansible Playbooks
- Automated Testing
- Data Processing
In other words, everything that can refer to this
./build-something.sh | assert_equals "done."`
We try to do everything possible to ensure maximum compatibility with these platforms
Pipetest is just one file, put the file pipetest.sh
into your project then load as source into your script.
$ curl -o pipetest.sh https://github.com/javanile/pipetest/releases/download/v0.1.0/pipetest.sh
#!/usr/bin/env bash
set -e
source pipetest.sh
echo "Hello World!" | assert_equals "Hello World!"
There are the lists of supported functions
- assert_empty - Fails if piped output is not empty
- assert_not_empty - Fails if piped output is empty
- assert_equals - Fails if piped output not match with the argument
- assert_not_equals - Fails if piped output match with the argument
- assert_starts_with - Fails if piped output match with the argument
- assert_each_line_starts_with - Fails if piped output match with the argument
- assert_ends_with - Fails if piped output match with the argument
- assert_each_line_ends_with - Fails if piped output match with the argument
- assert_match - Fails if piped output match with the argument
- assert_file_exists - Fails if piped file name as text not exists
- assert_file_not_exists - Fails if piped file name as text exists
- assert_directory_exists -
- assert_directory_not_exists
Fails if piped output is not empty.
Usage
... | assert_empty [FAIL_MESSAGE] [SUCCESS_MESSAGE]
Examples
echo "" | assert_empty
ls | assert_empty "Current directory is not empty"
cat apache2.log | assert_empty "Log file is not empty"
Usage
... | assert_empty [FAIL_MESSAGE] [SUCCESS_MESSAGE]
Examples
echo "" | assert_empty
ls | assert_empty
cat apache2.log | assert_empty
Usage
assert_file_exists [FAIL_MESSAGE] [SUCCESS_MESSAGE]
Examples
touch sample_file.txt
assert_file_exists sample_file.txt
mv old_file_name.txt new_file_name.txt
assert_file_exists new_file_name.txt "Moving file goes wrong."
mv old_file_name.txt new_file_name.txt
assert_file_exists new_file_name.txt "Moving file goes wrong." "Ok! it working."
Usage
assert_file_exists [FAIL_MESSAGE] [SUCCESS_MESSAGE]
Examples
touch sample_file.txt
assert_file_exists sample_file.txt
mv old_file_name.txt new_file_name.txt
assert_file_exists new_file_name.txt "Moving file goes wrong."
mv old_file_name.txt new_file_name.txt
assert_file_exists new_file_name.txt "Moving file goes wrong." "Ok! it working."
Usage
assert_file_exists [FAIL_MESSAGE] [SUCCESS_MESSAGE]
Examples
touch sample_file.txt
assert_file_exists sample_file.txt
mv old_file_name.txt new_file_name.txt
assert_file_exists new_file_name.txt "Moving file goes wrong."
mv old_file_name.txt new_file_name.txt
assert_file_exists new_file_name.txt "Moving file goes wrong." "Ok! it working."
Usage
assert_file_exists [FAIL_MESSAGE] [SUCCESS_MESSAGE]
Examples
touch sample_file.txt
assert_file_exists sample_file.txt
mv old_file_name.txt new_file_name.txt
assert_file_exists new_file_name.txt "Moving file goes wrong."
mv old_file_name.txt new_file_name.txt
assert_file_exists new_file_name.txt "Moving file goes wrong." "Ok! it working."
See CONTRIBUTING.md in the repo, obviously pull-request are welcome.
- GitHub Issues: report a bug or raise a feature request to the Pipetest core team
- StackOverflow Tag: see existing Q&A for
BASH
andUnit Testing
. We look at them often
Pipetest is open-sourced software licensed under the MIT license.