javanile / pipetest

⛲ A minimal set of shell functions useful to implement assertions through pipe chaining. Loved by developer
MIT License
2 stars 0 forks source link
assert assertions bash pipe script stderr stdout testing

⛲ Pipetest

Build Status License

Pipetest is a simple and lightweight set of shell functions useful to implement assertions with I/O Redirection.

Why Pipetest?

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."`

Suppoerted Shells

We try to do everything possible to ensure maximum compatibility with these platforms

bash bosh busybox dash ksh mksh posh yash zsh

Get Started

Pipetest is just one file, put the file pipetest.sh into your project then load as source into your script.

Installation

$ 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!"

Documentation

There are the lists of supported functions


### `assert_empty`

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"
[back to top]

➡ | assert_empty

Usage

... | assert_empty [FAIL_MESSAGE] [SUCCESS_MESSAGE]

Examples

echo "" | assert_empty
ls | assert_empty
cat apache2.log | assert_empty
[back to top]

➡ | 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."
[back to top]

➡ | 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."
[back to top]

➡ | 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."
[back to top]

➡ | 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."
[back to top]

Contributing

See CONTRIBUTING.md in the repo, obviously pull-request are welcome.

Community & Questions

License

Pipetest is open-sourced software licensed under the MIT license.