Skip to content
zsh-test-runner
GitHub

zsh-test-runner (ztr)

splash card: the text '% ztr' as green neon lettering

Straight-forward tests and coverage reports for zsh and —under zsh’s emulation— csh, ksh, and sh

What it features: everything you need for testing zsh scripts.

  • test zsh and, to a degree, csh, ksh, and sh thanks to zsh’s emulate builtin
    • optionally give tests descriptive names and additional notes
  • run one or more tests on the command line
  • run one or more tests saved in a test suite file
  • optionally run a setup function before each test
  • optionally run a teardown function after each test
  • skip tests
  • queue tests to run in a batch
    • optionally run a bootstrap function before each batch
    • optionally run a clean function after each batch
  • access cumulative failure, pass, and skip counts as shell variables
  • print coverage summaries with total count, failure count and rate, pass count and rate, and skip count
  • short and gentle learning curve

What it does not feature: its own human language-like declarative test syntax.

There’s no “describe”, “expect”, etc. Downside is the tests don’t read like a story. Upside is —because the shell already has rich support for tests— there is nothing idiomatic to learn, there are no artificial limits on what can be tested, the cost to migrating to zsh-test-runner (or from it, if you must) is very low, and there is no risk that assertions were incorrectly implemented. Just write your [[ ]]s, (( ))s, even your tests and [ ]s.