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:
- Create a test file.
- Decide what command you need to run on this input.
There are two options:
You can put this in a
turnt.tomlconfig file alongside your test: usecommand = "mycmd {filename}"to pass the test file as an argument tomycmd. Or you can embed it in a comment in the test file itself: useCMD: mycmd {filename}. - Get the initial output.
Run
turnt --save foo.tto generate the expected output infoo.out. You'll want to check these output files into version control along with your test. - Run the tests.
Use
turnt foo.tto check a test output. If a test fails, add--diffto 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, useoutput.txt = "my_output.txt"to collectmy_output.txtafter each text extension and save it in<test-name>.txt. Use-to indicate the command's standard output and2to indicate its standard error. The default is likeoutput.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 forturnt --diffoutput. The default isdiff --new-file --unified. Trygit --no-pager diff --no-indexto get colorful output.
Equivalently, you can embed options in test files themselves:
CMD: <command>overridescommandfrom the configuration.OUT: <ext> <filename>overridesoutputfrom 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 usingARGS: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.--verboseor-v: Disable Turnt's default behavior where it will suppress test commands' stderr output. The result is more helpful but harder to read.--printor-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.--argsor-a: Override theargsstring that gets interpolated into commands, which normally comes from in-file comments.--configor-c: Look for this config filename instead of the defaultturnt.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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5cfb87deffe2aab86fd3aee48cd44d966fbc15c5bd79344b72e3c5d38dd5e862
|
|
| MD5 |
3116340b4711486511586b6094fe861e
|
|
| BLAKE2b-256 |
7c9e2c6c865af3fe4258e5d37756f77af4ada79af13786e4be6c446398c6cc8f
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38fc9c513c39ef1d368d5adb00fc22eb4794b8ad104f288ef4833aebf0b0a4f9
|
|
| MD5 |
66dad5b69915628a3b16d5e0119ece6e
|
|
| BLAKE2b-256 |
0ec601c6128b7a7d6776984dbb2dd845ef6ae89ff1190d9366fe3917d78ca581
|