Skip to main content

Write brainf*ck programs with your unit tests.

Project description

BrainTest

This project makes it possible to write brainf*ck programs by running python unit tests.

Who knows what exciting programs you could be unwittingly writing while running your unit tests?!

Well wonder no longer!

Braintest is designed to be a drop in replacement for python's unittest module. It will run your tests (mostly) as normal, while also outputing a brainf*ck program. Exceptions being: unittest's verbosity option is overwritten, so you can't alter the verbosity of tests while running this.

Demo

demo gif of hello world

Usage

First install braintest:

python -m pip install braintest

Write your tests as you usually would with when using python's unittest and then replace unittest with braintest in your test command e.g.:

python -m braintest | tee my_program.bf

This will print out the results of the unit test, as well as write a brainf*ck program to my_program.bf.

Then you can use a locally installed brainf*ck interpreter to run your newly created program!

Running a program

A simple brainf*ck interpreter can be found in this repo. To run a program, pipe the program into the interpreter:

cat my_program.bf | python brainfuck-simple.py

Note: credit to Pablo Jorge where this brainf*ck interpreter is from (with a slight modification to make it work with newer python versions)

Writing programs

To write a . - write a successful unit test

To write a + - write a test that throws an exception

To write a - - write a test that throws a KeyError (admittedly this is a bit hacky)

To write a > - write a test that fails

To write a [ - skip a test

To write a ] - write a test that fails that you expect to fail

To write a < - write a test that succeeds when it shouldn't

To write a , - write a test that throws an IOError

You can see examples of all of these in action in the sample program.py provided in this repo. Be careful though! Tests are ran in order based on their alphabetical sorting of their function names.

Why?

For fun.

But seriously, why?

While I was waiting for my tests to complete I was staring at the python unittest output and thought it looked kind of like brainf*ck. So I thought it would be fun to override the default test runner to output valid brainf*ck characters.

Project details


Download files

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

Source Distribution

braintest-0.0.1.tar.gz (38.7 kB view details)

Uploaded Source

Built Distribution

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

braintest-0.0.1-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file braintest-0.0.1.tar.gz.

File metadata

  • Download URL: braintest-0.0.1.tar.gz
  • Upload date:
  • Size: 38.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.0

File hashes

Hashes for braintest-0.0.1.tar.gz
Algorithm Hash digest
SHA256 bb40add452f38aa15ddf3f17deea32493d650d2353df70c7b46e04311d1b7f08
MD5 3a82478dac4558352dbecce3d5e00f66
BLAKE2b-256 936b6cc466bff39e3f39f57a161d78e35880d94be1b7989e78bd9765e7f69ecb

See more details on using hashes here.

File details

Details for the file braintest-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: braintest-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.0

File hashes

Hashes for braintest-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dfa98a940896c1f98d632194cc7fed60e4a94680bf9638e42de4b1929d9da977
MD5 40481548613d760d550ecd3160e96d04
BLAKE2b-256 c617a1a252c1f07569a3e18d50997594f3bcf2b32a23c92fdbdd0ab7f490df34

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