Skip to main content

Doctests for your shell

Project description

Build Status


Doctests for your shell. Run an executable, check the output.


With pip:

pip install doctest-cli

By hand:

curl -O ~/bin
chmod +x ~/bin/doctest-cli


Create a test script, say

# Command
>>> echo hello
# Expected output

# Another command
>>> echo 'Good bye!'
Good bye!

# Failing
>>> echo banana

Test it:


Check output:

doctest-cli: test/
Error while running:
  echo banana

Expected STDOUT:
Tests ran: 3
Tests passed: 2
Tests failed: 1


The program depends on python - both 2.7 and 3.4 and above should work


See test/ for more examples.

Return code

Check return code by adding $?=<RET> to the beginning of the line. Default return code is 0:

>>> false
>>> true

Standard error

Check stderr output by adding ! to the beginning of the line:

>>> echo error > /dev/stderr
! error

By default, the stderr stream is assumed to be empty.

Custom shell

You can use a custom shell with a shebang line:

>>> echo hello; and echo this is fish
this is fish


doctest-cli uses python's subprocess module to spawn a new shell for each command and checks the output against the lines provided. All the environment variables are inherited from the parent session.

Whitespace (including intervening newlines) is ignored. For example, the following test should pass, since all the newlines in the middle are removed:

>>>printf 'hello\n\n\n\n\n\nworld'

This is done so that you can have an arbitrary amount of whitespace delineating the test blocks.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for doctest-cli, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size doctest_cli-0.0.3-py3-none-any.whl (3.8 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size doctest-cli-0.0.3.tar.gz (3.5 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page