Skip to main content

Turnt is a simple expect-style testing tool for command-line

Project description

Tiny Unified Runner N' Tester (Turnt)

Turnt is a simple testing tool inspired by Cram and LLVM's lit. The idea is that each test consists a single input file and one or more output files. You want to run a command on the input file and check that the output is equal to the expected output files.

To use it:

  1. Create a test file.
  2. Decide what command you need to run on this input. There are two options: You can put this in a turnt.toml config file alongside your test: use command = "mycmd {filename}" to pass the test file as an argument to mycmd. Or you can embed it in a comment in the test file itself: use CMD: mycmd {filename}.
  3. Get the initial output. Run turnt --save foo.t to generate the expected output in foo.out. You'll want to check these output files into version control along with your test.
  4. Run the tests. Use turnt foo.t to check a test output. If a test fails, add --diff to compare the actual and expected outputs.

Install

This is a Python 3 tool. Install it with pip:

$ pip install --user turnt

Or, if you want to work on Turnt, you can install Flit, clone this repository, and type this to get a "live" installation with a symlink:

$ flit install --symlink --user

Details

These options are available in turnt.toml:

  • command. This is a shell command to run for each test input.
  • output. This is a mapping from extensions to output files to collect from each test. For example, use output.txt = "my_output.txt" to collect my_output.txt after each text extension and save it in <test-name>.txt. Use - to indicate the command's standard output and 2 to indicate its standard error. The default is like output.out = "-", i.e., capture stdout and save it in <test-name>.out. You can include this yourself or omit if if you want to ignore the standard output.
  • return_code. The expected exit status for the command. By default, 0.
  • diff. The command to use for turnt --diff output. The default is diff --new-file --unified. Try git --no-pager diff --no-index to get colorful output.

Equivalently, you can embed options in test files themselves:

  • CMD: <command> overrides command from the configuration.
  • OUT: <ext> <filename> overrides output from the configuration. You can specify multiple files this way: one line per file.
  • ARGS: <arguments>. Add arguments to a configured command (see below).
  • RETURN: <code>. The expected exit status.

In commands and filenames, you can use certain patterns that get substituted with details about the tests:

  • {filename}: The name of the test file (without the directory part).
  • {base}: Just the basename of the test file (no extension).
  • {args}: Extra arguments specified using ARGS: in the test file.

If you need multiple files for a test, you can use a directory instead of a file. Outputs will be placed inside the test directory instead of adjacent to it. Output filenames will be like out.ext inside that directory. There are two configurations just for dealing with directory tests:

  • out_base. The basename for output files in directory tests: by default, out.
  • opts_file. The filename to read inside of a directory test to parse inline options.

Command Line

These are the command-line options:

  • --save: Bless the current output from each test as the "correct" output, saving it to the output file that you'll want to check into version control.
  • --diff: Show diffs between the actual and expected output for each test.
  • --verbose or -v: Disable Turnt's default behavior where it will suppress test commands' stderr output. The result is more helpful but harder to read.
  • --print or -p: Instead of checking test results, just run the command and show the output directly. This can be useful (especially in combination with -v) when iterating on a test interactively.
  • --args or -a: Override the args string that gets interpolated into commands, which normally comes from in-file comments.
  • --config or -c: Look for this config filename instead of the default turnt.toml.

TAP

Turnt outputs TAP results by default. To make the output more pleasant to read, you can pipe it into a tool like tap-difflet:

$ npm install -g tap-difflet
$ turnt *.t | tap-difflet

Authors

Turnt is by Adrian Sampson and Alexa VanHattum. We made it to test various research compilers in Capra. The license is MIT.

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

turnt-1.6.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

turnt-1.6.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file turnt-1.6.0.tar.gz.

File metadata

  • Download URL: turnt-1.6.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.27.1

File hashes

Hashes for turnt-1.6.0.tar.gz
Algorithm Hash digest
SHA256 5cfb87deffe2aab86fd3aee48cd44d966fbc15c5bd79344b72e3c5d38dd5e862
MD5 3116340b4711486511586b6094fe861e
BLAKE2b-256 7c9e2c6c865af3fe4258e5d37756f77af4ada79af13786e4be6c446398c6cc8f

See more details on using hashes here.

File details

Details for the file turnt-1.6.0-py3-none-any.whl.

File metadata

  • Download URL: turnt-1.6.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.27.1

File hashes

Hashes for turnt-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 38fc9c513c39ef1d368d5adb00fc22eb4794b8ad104f288ef4833aebf0b0a4f9
MD5 66dad5b69915628a3b16d5e0119ece6e
BLAKE2b-256 0ec601c6128b7a7d6776984dbb2dd845ef6ae89ff1190d9366fe3917d78ca581

See more details on using hashes here.

Supported by

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