Skip to content
zsh-test-runner
GitHub

Test suites

You can run a test suite from a file. The following examples suppose the file is in the current working directory; adjust the path to fit your situation.

Either source your test suite or run it in a subshell.

Running a test suite in the current shell

In this method

  • the ztr summary results are available in the parent shell
  • any side effects of your tests are not sandboxed
% cat ./suite.ztr.zsh
my_test=false

ztr clear-summary
ztr test true 'my first test'
ztr test my_test 'my second test'
ztr test 'my_test && true' 'my third test' 'depends on my second test'
ztr skip my_other_test 'my other test' '@TODO build the api for this!'

echo
ztr summary
% . ./suite.ztr.zsh # or the longhand `source ./suite.ztr.zsh`
PASS my first test
FAIL my second test
FAIL my third test
    depends on my second test
SKIP my other test
    @TODO build the api for this!

4 tests total
2 (40%) failed
1 was skipped
1 (20%) passed

% ztr summary # suite's summary is available
4 tests total
2 (50%) failed
1 was skipped
1 (25%) passed

% echo $my_test # suite's context is available
false

Running a test suite in a subshell

In this method

  • the ztr summary results are not available in the parent shell
  • any side effects of your tests are sandboxed
% cat ./suite.ztr.zsh
# run with `ztr_path=$ZTR_PATH zsh <path to this file>`
. $ztr_path

# from here on is the same as the "Sourcing the test suite" example
my_test=false

ztr clear-summary
ztr test true 'my first test'
ztr test my_test 'my second test'
ztr test 'my_test && true' 'my third test' 'depends on my second test'
ztr skip my_other_test 'my other test' '@TODO build the api for this!'

echo
ztr summary

To run the suite in a subshell pass the file to zsh, passing in the zsh-test-runner path as context, and then reload your user abbreviations:

% ztr_path=$ZTR_PATH zsh ./suite.ztr.zsh
PASS my first test
FAIL my second test
FAIL my third test
    depends on my second test
SKIP my other test
    @TODO build the api for this!

4 tests total
2 (40%) failed
1 was skipped
1 (20%) passed

% ztr summary # suite's summary is not available
0 tests total
0 failed
0 were skipped
0 passed

% echo $my_test # suite's context is not available

%