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
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
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"
assert_empty
Usage
... | assert_empty [FAIL_MESSAGE] [SUCCESS_MESSAGE]
Examples
echo "" | assert_empty
ls | assert_empty
cat apache2.log | assert_empty
assert_file_exists
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."
assert_file_exists
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."
assert_file_exists
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."
assert_directory_exists
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.
BASH
and Unit Testing
. We look at them oftenPipetest is open-sourced software licensed under the MIT license.