Skip to main content

GitHub Release PyPI Version Python Versions CI GPLv3+

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

GPLv3+

Metadata

Release files for shtst 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shtst 0.1.1
File Size Uploaded
shtst-0.1.1.tar.gz 19.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for shtst 0.1.1
File Interpreter ABI Platform
shtst-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 36.8 kB

Release files / shtst-0.1.1.tar.gz

Download URL shtst-0.1.1.tar.gz
Size 19.3 kB
Tags Source
SHA-256 checksum
How to use checksums
aaa68e1684aed3c9e627a67d93cffcf742f7b88c048c897895d78abf61e7ccd9
BLAKE2b-256 checksum
How to use checksums
8353563d64d967a2e192f371c0132b8321accc73e51295ab50bbbfdd5e2ac8f0
Upload date
Uploaded using Trusted Publishing?
What is 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+

Release files / shtst-0.1.1-py3-none-any.whl

Download URL shtst-0.1.1-py3-none-any.whl
Size 17.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5a1edc50cf33b1eaf486b40238ca1a597618ab7871755392fcfa46f19b58299d
BLAKE2b-256 checksum
How to use checksums
ec847420b282563796fc2897d8ee8163d210711ba5841c88e2da8f6abb5590c2
Upload date
Uploaded using Trusted Publishing?
What is 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+

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page