Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bas080/spat
Simple cli tool for writing quick tests for tools with stdout and stderr output
https://github.com/bas080/spat
Last synced: 21 days ago
JSON representation
Simple cli tool for writing quick tests for tools with stdout and stderr output
- Host: GitHub
- URL: https://github.com/bas080/spat
- Owner: bas080
- License: gpl-3.0
- Created: 2023-12-18T12:28:42.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2023-12-19T10:47:02.000Z (about 1 year ago)
- Last Synced: 2023-12-19T13:40:02.592Z (about 1 year ago)
- Language: Perl
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 💦 Spat
Tool for testing CLI tools and their outputs.
## Usage
```bash
spat spat.techo -e '\n# Or make test.sh executable and add the spat shebang.\n'
./spat.t
```
```
spat: sh spat.t > spat.t.new 2>&1
spat: All tests passed.# Or make test.sh executable and add the spat shebang.
spat: sh ./spat.t > ./spat.t.new 2>&1
spat: All tests passed.
```> You can change the shell with the `SPAT_SHELL` environment variable. If none is
> defined it will use `sh`.## Snapshot
The snapshot file (`.out`) is created by running the spat command while the output file
is not yet defined. You can re-create the snapshot file by removing the
snapshot and running the spat test again. You can also manually edit the
snapshot file while keeping your regular expressions.The snapshot is a file that can be edited to account for
variable output. An example would be the current date.```bash
head -n 7 spat.t
```
```
#!/usr/bin/env spatset -x
# A variable line where we use a regex.
date -I```
On every run the date can vary and the test can therefore fail for
the wrong reasons. This can be solved by replacing the line with a regex.```bash
head -n 3 spat.t.out
```
```
+ date -I
\d{4}-[\d{2}]{2}
+ tmp=/tmp/spat.test.sh
```Notice that we removed the 2 spaces and placed a regex accounts for the
variation while still checking if the output looks date like.## Tips & Tricks
- Turn on `set -x` when writing your commands in a `sh` or `bash` script. This
prints the command before it starts running it. This helps with debugging and
writting more expressive pattern files.