Skip to content
zsh-test-runner
GitHub

Individual tests

The three essential zsh-test-runner commands are ztr test, ztr summary, and ztr clear-summary.

ztr test runs a test. ztr summary prints statistics about the ztr test tests run since the last ztr clear-summary.

You can also build up a queue of tests, and specify bootstrap and clean functions (run at the start and end of the queue, respectively) and setup and teardown functions (run before and after each test, respectively).

Minimal usage

  1. Clear the summary
    % ztr clear-summary
  2. Run some tests, using the format ztr test <expression to test>
    % x=2
    % ztr test '(( x == 2 ))'
    PASS (( x == 2 ))
    % ztr test '[[ $x == 1 ]]'
    FAIL [[ $x == 1 ]]
  3. Print the results
    % ztr summary
    4 tests total
    1 (25%) failed
    0 were skipped
    3 (75%) passed

Typical usage

zsh-test-runner tests are typically run as part of a test suite, with the ztr commands living in a <name>.ztr.zsh file. For more on that, see Running Test Suites.

Things to know

The ztr test expression argument is evaluated.

% x=2
% ztr test 'x=1'
PASS x=1
% echo $x
1 # side effect

That may cause unwanted side effects.

Make careful use of quotation levels.

Consider saving any context you’ll be manipulating, and restoring the saved values after testing.

Or run tests in a subshell.