Skip to main content

Doctests for your shell

Project description

Build Status

doctest-cli

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

Installation

With pip:

pip install doctest-cli

By hand:

curl -O https://github.com/ivan-krukov/doctest-cli/blob/master/bin/doctest-cli ~/bin
chmod +x ~/bin/doctest-cli

Usage

Create a test script, say test.sh:

# Command
>>> echo hello
# Expected output
hello

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

# Failing
>>> echo banana
apple

Test it:

doctest-cli test.sh

Check output:

doctest-cli: test/simple.sh
------------------------------------------------------------
Error while running:
  echo banana
With STDERR:

Expected STDOUT:
  apple
Got:
  banana
------------------------------------------------------------
Tests ran: 3
Tests passed: 2
Tests failed: 1

Dependencies

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

Extra

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
$?=1
>>> true
$?=0

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:

#!/usr/local/bin/fish
>>> echo hello; and echo this is fish
hello
this is fish

Details

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'
hello
world

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.

Filename, size & hash SHA256 hash help File type Python version Upload date
doctest_cli-0.0.3-py3-none-any.whl (3.8 kB) Copy SHA256 hash SHA256 Wheel py3
doctest-cli-0.0.3.tar.gz (3.5 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page