Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/javanile/pipetest
⛲ A minimal set of shell functions useful to implement assertions through pipe chaining. Loved by developer
https://github.com/javanile/pipetest
assert assertions bash pipe script stderr stdout testing
Last synced: 24 days ago
JSON representation
⛲ A minimal set of shell functions useful to implement assertions through pipe chaining. Loved by developer
- Host: GitHub
- URL: https://github.com/javanile/pipetest
- Owner: javanile
- License: mit
- Created: 2019-09-23T15:52:15.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-02-27T09:54:29.000Z (10 months ago)
- Last Synced: 2024-02-28T10:18:05.970Z (10 months ago)
- Topics: assert, assertions, bash, pipe, script, stderr, stdout, testing
- Language: Shell
- Homepage:
- Size: 64.5 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# ⛲ Pipetest
[![Build Status](https://travis-ci.com/javanile/pipetest.svg?branch=main)](https://travis-ci.com/javanile/pipetest)
[![License](https://img.shields.io/github/license/shellspec/shellspec.svg)](https://github.com/shellspec/shellspec/blob/master/LICENSE)Pipetest is a [simple and lightweight](#-pipetest "(but powerful)") set of shell functions useful
to implement assertions with [I/O Redirection](https://tldp.org/LDP/abs/html/io-redirection.html).## Why Pipetest?
Thanks to the use of [Piping](https://en.wikipedia.org/wiki/Pipeline_(Unix)) 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 ProcessingIn other words, everything that can refer to this
```bash
./build-something.sh | assert_equals "done."`
```## Suppoerted Shells
We try to do everything possible to ensure maximum compatibility with these platforms
[![bash](https://img.shields.io/badge/bash-≥2.03-lightgrey.svg?style=flat)](https://www.gnu.org/software/bash/)
[![bosh](https://img.shields.io/badge/bosh-≥2018%2F10%2F07-lightgrey.svg?style=flat)](http://schilytools.sourceforge.net/bosh.html)
[![busybox](https://img.shields.io/badge/busybox-≥1.20.0-lightgrey.svg?style=flat)](https://www.busybox.net/)
[![dash](https://img.shields.io/badge/dash-≥0.5.4-lightgrey.svg?style=flat)](http://gondor.apana.org.au/~herbert/dash/)
[![ksh](https://img.shields.io/badge/ksh-≥93s-lightgrey.svg?style=flat)](http://kornshell.org)
[![mksh](https://img.shields.io/badge/mksh-≥R28-lightgrey.svg?style=flat)](http://www.mirbsd.org/mksh.htm)
[![posh](https://img.shields.io/badge/posh-≥0.3.14-lightgrey.svg?style=flat)](https://salsa.debian.org/clint/posh)
[![yash](https://img.shields.io/badge/yash-≥2.29-lightgrey.svg?style=flat)](https://yash.osdn.jp/)
[![zsh](https://img.shields.io/badge/zsh-≥3.1.9-lightgrey.svg?style=flat)](https://www.zsh.org/)## Get Started
Pipetest is just one file, put the file `pipetest.sh` into your project then load as source into your script.
## Installation
```bash
$ curl -o pipetest.sh https://github.com/javanile/pipetest/releases/download/v0.1.0/pipetest.sh
``````bash
#!/usr/bin/env bash
set -esource pipetest.sh
echo "Hello World!" | assert_equals "Hello World!"
```## Documentation
There are the lists of supported functions
- [**assert_empty**](#assert_empty) - Fails if piped output is not empty
- [**assert_not_empty**](#assert_not_empty) - Fails if piped output is empty
- [**assert_equals**](#assert_equals) - Fails if piped output not match with the argument
- [**assert_not_equals**](#assert_not_equals) - Fails if piped output match with the argument
- [**assert_starts_with**](#assert_starts_with) - Fails if piped output match with the argument
- [**assert_each_line_starts_with**](#assert_each_line_starts_with) - Fails if piped output match with the argument
- [**assert_ends_with**](#assert_ends_with) - Fails if piped output match with the argument
- [**assert_each_line_ends_with**](#assert_ends_with) - Fails if piped output match with the argument
- [**assert_match**](#assert_match) - Fails if piped output match with the argument
- [**assert_file_exists**](#assert_file_exists) - Fails if piped file name as text not exists
- [**assert_file_not_exists**](#assert_file_not_exists) - Fails if piped file name as text exists
- [**assert_directory_exists**](#assert_directory_exists) -
- [**assert_directory_not_exists**](#assert_directory_not_exists)
### `assert_empty`
Fails if piped output is not empty.
**Usage**
```bash
... | assert_empty [FAIL_MESSAGE] [SUCCESS_MESSAGE]
```**Examples**
```bash
echo "" | assert_empty
``````bash
ls | assert_empty "Current directory is not empty"
``````bash
cat apache2.log | assert_empty "Log file is not empty"
```
### ➡ | `assert_empty`
**Usage**
```bash
... | assert_empty [FAIL_MESSAGE] [SUCCESS_MESSAGE]
```**Examples**
```bash
echo "" | assert_empty
``````bash
ls | assert_empty
``````bash
cat apache2.log | assert_empty
```
### ➡ | `assert_file_exists`
**Usage**
```bash
assert_file_exists [FAIL_MESSAGE] [SUCCESS_MESSAGE]
```**Examples**
```bash
touch sample_file.txt
assert_file_exists sample_file.txt
``````bash
mv old_file_name.txt new_file_name.txt
assert_file_exists new_file_name.txt "Moving file goes wrong."
``````bash
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**
```bash
assert_file_exists [FAIL_MESSAGE] [SUCCESS_MESSAGE]
```**Examples**
```bash
touch sample_file.txt
assert_file_exists sample_file.txt
``````bash
mv old_file_name.txt new_file_name.txt
assert_file_exists new_file_name.txt "Moving file goes wrong."
``````bash
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**
```bash
assert_file_exists [FAIL_MESSAGE] [SUCCESS_MESSAGE]
```**Examples**
```bash
touch sample_file.txt
assert_file_exists sample_file.txt
``````bash
mv old_file_name.txt new_file_name.txt
assert_file_exists new_file_name.txt "Moving file goes wrong."
``````bash
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**
```bash
assert_file_exists [FAIL_MESSAGE] [SUCCESS_MESSAGE]
```**Examples**
```bash
touch sample_file.txt
assert_file_exists sample_file.txt
``````bash
mv old_file_name.txt new_file_name.txt
assert_file_exists new_file_name.txt "Moving file goes wrong."
``````bash
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](https://github.com/javanile/pipetest/blob/main/CONTRIBUTING.md), obviously pull-request are welcome.
## Community & Questions
- [GitHub Issues](https://github.com/javanile/pipetest/issues): report a bug or raise a feature request to the Pipetest core team
- [StackOverflow Tag](https://stackoverflow.com/questions/tagged/bash+unit-testing): 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](LICENSE.md).