Skip to content

Latest commit

 

History

History
264 lines (180 loc) · 6.81 KB

README.md

File metadata and controls

264 lines (180 loc) · 6.81 KB

⛲ 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

  • CI/CD Pipelines
  • Ansible Playbooks
  • Automated Testing
  • Data Processing

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"

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

Contributing

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

Community & Questions

  • GitHub Issues: report a bug or raise a feature request to the Pipetest core team
  • StackOverflow Tag: see existing Q&A for BASH and Unit Testing. We look at them often

License

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