skip to navigation
skip to content

exactly 0.8.1

Tests a command line program by executing it in a temporary sandbox directory and inspecting its result.

Package Documentation

Tests a command line program by executing it in a temporary sandbox directory and inspecting its result.

Supports individual test cases and test suites.

Exactly has a Wiki, and an introduction by examples.

It also has a Reference manual.


A test case is written as a plain text file. The following checks that your new addressbook program reads an address book from stdin, and is able to find an address:


stdin a-test-address-book.txt


addressbook --get-email-of --name 'Test Testingson'


exitcode 0

stdout equals <<EOF

If the file ‘’ contains this test case, then Exactly can execute it:

> exactly

“PASS” means that the two assertions were satisfied.

This test assumes that

  • the system under test - the addressbook program - is is found in the same directory as the test case file
  • the file “an-address-book.txt” (that is referenced from the test case) is found in the same directory as the test case file

The home instruction can be used to change the directory where Exactly looks for files referenced from the test case.

Using shell commands

Shell commands can be used both in the “act” phase (the system under test), and in other phases, using “$”.


$ touch file


$ echo ${PATH}


$ tr ':' '\n' < ../result/stdout | grep '^/usr/local/bin$'

A shell command in the “assert” phase becomes an assertion that depends on the exit code of the command.

Testing source code files

The actor instruction can specify an interpreter to test a source code file:


actor --file python

[act] 'an argument'


stdout equals <<EOF
Arguments: an argument

Experimenting with source code

The “source interpreter” actor treats the contents of the “act” phase as source code. It’s probably most useful as a tool for experimenting:


actor --source bash


var='hello world'
echo ${var:5}


stdout equals <<EOF

or for running a source file in a sandbox:

> exactly --actor bash

This is more useful combined with --act (see below).

[act] is the default phase

[act] is not needed to indicate what is being checked, since the “act” phase is the default phase.

The following is a valid test case, and if run by Exactly, it won’t remove anything, since it is executed inside a temporary sandbox directory:

$ rm -rf *

Keeping the sandbox directory for later inspection

If --keep is used, the sandbox directory will not be deleted, and its name will be printed.

This can be used to inspect the outcome of the “setup” phase, e.g:


dir  my-dir
file my-file.txt


my-prog my-file.txt


exitcode 0
> exactly --keep

> find /tmp/exactly-1strbro1

The act/ directory is the current directory when the test starts. The file instruction has put the file my-file.txt there.

The result of the “act” phase is saved in the result/ directory.

tmp/user/ is a directory where the test can put temporary files.


Tests can be grouped in suites:





If the file mysuite.suite contains this text, then Exactly can run it:

> exactly suite mysuite.suite

The result of a suite can also be reported as JUnit XML, by using --reporter junit.


Exactly has a built in help system.

Use exactly --help or exactly help to get brief help.

exactly help help displays a summary of help options.

exactly help instructions lists the instructions that are available in each “phase”.

exactly help htmldoc outputs all built in help as html, which serves as Exactly’s reference manual.


The examples/ directory of the source distribution contains examples.

A complex example

The following test case displays a potpurri of features. (Beware that this test case does not make sense! - it just displays some of Exactly’s features.)


mode SKIP
# This will cause the test case to not be executed.


install this-is-an-existing-file-in-same-dir-as-test-case.txt

dir first/second/third

file in/a/dir/file-name.txt <<EOF
contents of the file

dir root-dir-for-act-phase

cd root-dir-for-act-phase
# This will be current directory for the "act" phase.

stdin <<EOF
this will be stdin for the program in the "act" phase
# (It is also possible to have stdin redirected to an existing file.)

env MY_VAR = 'value of my environment variable'

env PATH = '${PATH}:/my-dir'


run my-prog--located-in-same-dir-as-test-case--that-does-some-more-setup 'with an argument'

run --python --interpret 'with an argument'

run ( --python -c ) --source print('Setting up things...')




cd ..
# Moves back to the original current directory.

$ sort root-dir-for-act-phase/output-from-sut.txt > sorted.txt


exitcode != 0

stdout equals <<EOF
This is the expected output from the-system-under-test

stdout --with-replaced-env-vars contains 'EXACTLY_ACT:[0-9]+'

stderr empty

contents a-file.txt empty

contents a-second-file.txt ! empty

contents another-file.txt --with-replaced-env-vars equals expected-content.txt

contents file.txt contains 'my .* reg ex'

type actual-file directory

cd this-dir-is-where-we-should-be-for-the-following-assertions

run my-prog--located-in-same-dir-as-test-case--that-does-some-assertions

run --python --interpret

cd --rel-result
# Changes to the directory where the result of the act phase is stored (exitcode, stdout, stderr)

$ sed '1,10d' stdout > modified-stdout.txt
contents modified-stdout.txt equals <<EOF
this should be the single line of modified-stdout.txt


$ umount my-test-mount-point

run my-prog-that-removes-database 'my test database'


Exactly is written entirely in Python and does not require any external libraries.

Exactly requires Python >= 3.5 (not tested on earlier version of Python 3).

Use pip or pip3 to install:

> pip install exactly


> pip3 install exactly

The program can also be run from a source distribution:

> python3 src/


Current version is fully functional, but syntax and semantics are experimental.

Comments are welcome!


Aron Karlén

Tommy Karlsson

Götabergsgatan 10, lägenhet 4

File Type Py Version Uploaded on Size
exactly-0.8.1-py3-none-any.whl (md5) Python Wheel py3 2017-02-27 944KB
exactly-0.8.1.tar.gz (md5) Source 2017-02-27 211KB