simple cli testing
Project description
shtst - simple cli testing
shtst
is a command-line tool for testing command-line programs
against a simple specification of their expected output and exit code
given certain options and input.
It is inspired by (and similar to) shelltestrunner.
Test Specification Format
# '#' starts a comment line; blank lines are ignored
# '$' starts a command line
$ true
# '?' specifies the expected return code [default: 0]
$ false
? 1
# '>' starts a stdout specification (which ends at the first line that
# is either blank or starts with a '#', '$', '?', '<', or '>')
$ echo foo
>
foo
# '<' starts an input specification (which ends the same way)
$ cat
<
foo
bar
>
foo
bar
# input from the previous command (if any) is reused if not specified
$ wc -l
2
# prefixing the input/output lines with '|' allows blank lines and
# other input/output that would otherwise end the specification (and
# lines that start with '|')
$ printf "foo\n\n<>\n"
>
|foo
|
|<>
# instead of literal lines of output, you can provide a regex
# (delimited by '/' and optionally followed by flags: 'i' for case
# insensitive, 'm' for multiline, and 's' for dotall) immediately
# after '>' or '>2'
$ printf "Line 1 foo\nLine 2 bar\nLine 3 baz\n"
> /^line 1.*^line 2/ims
# use '>2' instead of '>' to specify stderr instead of stdout
$ cat --oops
>2 /unrecognized option/
? 1
# use a '!' before the exit code to negate the test
$ echo 'does not return 42'
? !42
# no stdout/stderr specification means anything is accepted;
# explicitly use an empty specification if necessary
$ echo OK
>2
A test case always starts with a command line. All input/output/exit code specifications belong to the preceding command line. With one exception: you can specify input before the first command, which will then be used for all subsequent commands until the next input specification.
<
foo
bar
baz
$ cat
>
foo
bar
baz
$ wc -l
> 3
Help
$ shtst --help
Tab Completion
For Bash, add this to ~/.bashrc
:
eval "$(_SHTST_COMPLETE=source_bash shtst)"
For Zsh, add this to ~/.zshrc
:
eval "$(_SHTST_COMPLETE=source_zsh shtst)"
For Fish, add this to ~/.config/fish/completions/shtst.fish
:
eval (env _SHTST_COMPLETE=source_fish shtst)
Requirements
- Python >= 3.7 + click.
Debian/Ubuntu
$ apt install python3-click
Installing
Using pip
$ pip install shtst
NB: depending on your system you may need to use e.g. pip3 --user
instead of just pip
.
From git
NB: this installs the latest development version, not the latest release.
$ git clone https://github.com/obfusk/shtst.git
$ cd shtst
$ pip install -e .
NB: you may need to add e.g. ~/.local/bin
to your $PATH
in order
to run shtst
.
To update to the latest development version:
$ cd shtst
$ git pull --rebase
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file shtst-0.1.1.tar.gz
.
File metadata
- Download URL: shtst-0.1.1.tar.gz
- Upload date:
- Size: 19.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.1+
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aaa68e1684aed3c9e627a67d93cffcf742f7b88c048c897895d78abf61e7ccd9 |
|
MD5 | aeaa61c2ee110030f841f1f348cc4da8 |
|
BLAKE2b-256 | 8353563d64d967a2e192f371c0132b8321accc73e51295ab50bbbfdd5e2ac8f0 |
File details
Details for the file shtst-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: shtst-0.1.1-py3-none-any.whl
- Upload date:
- Size: 17.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.1+
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a1edc50cf33b1eaf486b40238ca1a597618ab7871755392fcfa46f19b58299d |
|
MD5 | 8e1e68444500fad656d9861c53ef31f3 |
|
BLAKE2b-256 | ec847420b282563796fc2897d8ee8163d210711ba5841c88e2da8f6abb5590c2 |