Skip to main content

Write snippets of code in C++, Python, Ruby, and others as documentation and execute them as regression tests.

Project description

byexample is a literate programming engine where you mix ordinary text and snippets of code in the same file and then you execute them as regression tests.

It lets you to execute the examples written in Python, Ruby or whatever in your documentation and validate them.

You can always be sure that the examples are correct and your documentation is up to date!

Currently byexample supports:

Usage

How do I get started?

First, you need to install it:

$ pip install byexample                # install it # byexample: +skip

Or if you prefer, you can install it inside a virtual env.

If you don’t have pip or python installed, check the download page.

That’s it! Now, write a tutorial, a blog or a how-to and put some examples in between (like this README.md that you are reading); All the snippets and examples will be collected, executed and checked.

$ byexample -l python,ruby,shell README.md      # run it    # byexample: +skip
[PASS] Pass: <...> Fail: <...> Skip: <...>

You can select which languages to run, over which files, how to display the differences and much more.

The usage document goes through almost all the flags that byexample program has, full of examples of course.

What an example looks like?

It is just a snippet of code followed by the expected result:

>>> 1 + 2
3

>>> for i in range(3):
...     print(i)
0
1
2

The expression 1 + 2 is executed and the output compared with 3 to see if the test passes or not.

Where should I write the examples?

byexample really doesn’t care where you write the examples: you can write them in a Markdown, HTML, Latex, or plain text file.

Even you can write them in your own source code to document and test it.

Anything that it is between ```<language> and ``` is considered an example: this the Markdown fenced block syntax.

But byexample detects examples in other contexts as well.

For example in Python you can use the prompts >>> and ... to write an interpreter session like example.

>>> def add(a, b):
...   return a + b

>>> add(1, 2)
3

Take a look to the documentation of each language docs/languages.

Check out where should I write the examples section, it has a more in deep description.

And also check the usage page for more examples.

Languages supported

Currently we support:

  • Python (compatible with doctest) -> stable

  • Ruby -> experimental

  • Javascript -> experimental

  • Shell (sh and bash) -> stable

  • GDB -> experimental

  • C/C++ (using cling) -> experimental

More languages will be supported in the future. Stay tuned.

Contributing

First off, thanks for using and considering contributing to byexample.

We love to receive contributions from our community. There are tons of ways you can contribute

  • add support to new languages (Javascript, Julia, just listen to you heart). Check this how to.

  • misspelling? Improve to the documentation is more than welcome.

  • add more examples. How do you use byexample? Give us your feedback!

  • is byexample producing a hard-to-debug diff or you found a bug? Create an issue in github.

But don’t be limited to those options. We keep our mind open to other useful contributions: write a tutorial or a blog, feature requests, social media…

Check out our CONTRIBUTING guidelines and welcome!

Extend byexample

It is possible to extend byexample adding new ways to find examples in a document and/or to parse and run/interpret a new language or adding hooks to be called regardless of the language/interpreter.

Check out how to support new finders and languages and how to hook to events with concerns for a quick tutorials that shows exactly how to do that.

You could also share your work and contribute to byexample with your extensions.

Versioning

We use semantic version for the core or engine.

For each module we have the following categorization:

  • experimental: non backward compatibility changes are possible or even removal between versions (even patch versions).

  • unstable: low impact non backward compatibility changes may occur between versions; but in general a change like that will happen only between major versions.

  • stable: non backward compatibility changes, if happen, they will between major versions.

  • deprecated: it will disappear in a future version.

See the latest releases and tags

Current version:

$ byexample -V
byexample 8.0.0-a2 (Python <...>) - GNU GPLv3
<...>
Copyright (C) Di Paola Martin - https://github.com/byexamples/byexample
<...>

License

This project is licensed under GPLv3

$ head -n 2 LICENSE     # byexample: +norm-ws
          GNU GENERAL PUBLIC LICENSE
           Version 3, 29 June 2007

See LICENSE for more details.

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

byexample-8.0.0a2.tar.gz (64.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

byexample-8.0.0a2-py2.py3-none-any.whl (75.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file byexample-8.0.0a2.tar.gz.

File metadata

  • Download URL: byexample-8.0.0a2.tar.gz
  • Upload date:
  • Size: 64.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/32.3.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.3

File hashes

Hashes for byexample-8.0.0a2.tar.gz
Algorithm Hash digest
SHA256 b775a8a3ac2918ae4a28fef6a476934ebb67db5f158f1e89b91efb1e9d90296a
MD5 f0eace98cf1f4374ba3a40abbb8bd14c
BLAKE2b-256 f5caa21621896cb2732d8cb69a76c7ec7a7c8212715de1290a27400f44c5dddf

See more details on using hashes here.

File details

Details for the file byexample-8.0.0a2-py2.py3-none-any.whl.

File metadata

  • Download URL: byexample-8.0.0a2-py2.py3-none-any.whl
  • Upload date:
  • Size: 75.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/32.3.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.3

File hashes

Hashes for byexample-8.0.0a2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 03b9d98a12c19090dfb95d421607b234cc94dcf1e5ba2533418317d01c36c951
MD5 69f1afedb03e4d6681d411aa278008a6
BLAKE2b-256 178847630c170f0d1efc638ccacc73ba206b4b7da0c46a93f406bbda0ce6bde3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page