Compare commits

..

42 commits

Author SHA1 Message Date
Timothée Mazzucotelli b86c006f62 Add zplug installation method to README 2020-06-25 08:39:45 +01:00
Sebastian Gniazdowski 8048638571 helpers.zsh: Fix quoting issues by quoting the "-special characters 2019-12-17 12:37:00 +01:00
Sebastian Gniazdowski 2fbbf7c8a8 helpers.zsh: evl: include other special-constructs like |, ||, etc. 2019-08-13 23:21:32 +02:00
Sebastian Gniazdowski 4721a662cd helpers.zsh: A new helper `evl' <-> eval of the supplied code 2019-08-13 23:21:32 +02:00
Sebastian Gniazdowski 6db3c59142 helpers.zsh/run: Allow running of complex commands containing ;, |, etc.
Basically, instead of:

     output=$("${cmd[@]}" 2>&1)

it is done:

     eval "output=$( ${cmd[@]} 2>&1)"

because this allows the command to include e.g. redirections or command
separators like ; or ||, etc., or pipes, etc.

Actually, the eval looks more terrifying:

  IFS=$'\n' eval "output=\$( function run {
        ${cmd[@]/(#m)*/${${${${${(M)MATCH:#(${(j:|:)~dont_quote})}:+$MATCH}}:-\"$MATCH\"}}} 2>&1 }; run )";

But the substitution is (as always..) simple: it quotes the command's arguments
by using double quotes, so that when eval sees it, it will not skip empty
strings (and also that it will not split strings). The dont_quote array holds
things that are not to be quoted – currently the semicolon and redirections
('[[:digit:]]>&[[:digit:]]). The run function is to make the error messages
look the same, i.e.:

run:1: command not found: a-non-existent-command

instead of (eval):1: command .... I've checked that zunit's tests pass normally
with this change.
2019-08-13 22:45:51 +02:00
Sebastian Gniazdowski 2c66e7a9fe helpers.zsh: Codify the coding style into a vim modeline 2019-08-13 22:45:51 +02:00
Sebastian Gniazdowski 089a5bb103 zunit.zsh: Set option extendedglob and typesetsilent 2019-08-13 22:45:51 +02:00
James Dinsdale f2857b74c6
Enable travis slack notifications 2019-02-20 12:11:50 +00:00
James Dinsdale e58c49a7b2
Enable building on OSX 2018-01-06 21:04:54 +00:00
James Dinsdale bce183c39a Version number changed 2018-01-04 23:32:33 +00:00
James Dinsdale fab582c403 Add tests for assertion false-positives with empty values 2018-01-04 23:32:33 +00:00
James Dinsdale 6ed43da303 Quote command arguments passed to run helper
Prevents argument lists from being shifted left if one of the arguments
is an empty string
2018-01-04 23:32:33 +00:00
James Dinsdale c3d0f2f2c8 Ensure assertion value is double quoted
Internally, the `assert` helper does not quote the value to be asserted
against when cascading the call to the relevant assertion function,
resulting in an implicit pass if the value is empty, since the
comparisons are shifted forward a step. Double quoting the vaue when
cascading prevents these false-positives from occurring.

- [ ] Write tests to capture these false-positives

Fix #84
2018-01-04 23:32:33 +00:00
James Dinsdale 344ab57e78 Make zunit init idempotent
Currently, running `zunit init` fails if either `.zunit.yml` or the
directory `tests` exists within the repository, meaning the default
`.travis.yml` cannot be generated. This commit checks for the existence
of `.zunit.yml`, `tests` and `.travis.yml` as before, but instead of
exiting with an error, raises a warning and continues.

Fixes #88
2018-01-04 23:32:33 +00:00
James Dinsdale 75ba193af0 Bump Version 2018-01-04 23:32:33 +00:00
James Dinsdale 99ef8bc07a Bump version 2017-07-12 12:49:19 +01:00
James Dinsdale 83103bdbd0 Add contains and does_not_contain assertion methods 2017-07-12 12:49:19 +01:00
James Dinsdale 7677348758 Stop output from @setup and @teardown from being suppressed 2017-07-12 12:49:19 +01:00
James Dinsdale 31efe8bffa Rename tests with incorrect extension 2017-07-12 12:49:19 +01:00
Michael Aquilina a37ecdb1ba Allow optional space in shebang 2017-07-12 12:49:19 +01:00
James Dinsdale 7d9d5cdb50 Implement travis build stages 2017-07-10 19:12:14 +01:00
James Dinsdale 598f46e22c Add new integer assertion methods
* `is_positive`
* `is_negative`
* `is_greater_than`
* `is_less_than`
2017-07-10 19:12:14 +01:00
James Dinsdale 6f297fbcc7 Add new pass, fail and error helper methods 2017-07-10 19:12:14 +01:00
James Dinsdale 8ccc47e697 Remove mention of color from README 2017-07-10 19:12:14 +01:00
James Dinsdale 8fd2175a37 Remove color dependency 2017-07-10 19:12:14 +01:00
James Dinsdale fff5f15b1b Rename substring tests for consistency 2017-07-10 19:12:14 +01:00
James Dinsdale be24118a9c Update repository URLs 2017-07-10 19:12:14 +01:00
James Dinsdale aeba33e18f Don't install zvm shell integration 2017-07-10 19:12:14 +01:00
James Dinsdale 405bb22496 Cache ZVM version between test runs 2017-07-10 19:12:14 +01:00
James Dinsdale 4dc33eda3f Use language:generic in .travis.yml 2017-07-10 19:12:14 +01:00
James Dinsdale 72a5d4e419 Fix readable time output
Previously printed an incorrect value for the `ms` portion of the
running time when it is reported at the end of the test run.
2017-07-10 19:12:14 +01:00
James Dinsdale 8767b70601 Update completion 2017-07-10 19:12:14 +01:00
James Dinsdale 55820243d0 Add --verbose option
Prints the full command output for each test, as well as any processes
launched using the `run` helper.

Also includes a `verbose` option in `.zunit.yml`
2017-07-10 19:12:14 +01:00
James Dinsdale 0db9420260 Bump version 2017-07-10 19:12:14 +01:00
Michael Aquilina 0e6eaa9519 Add substring assertion functions (#64)
* Add is_substring_of assert function

* Add is_not_substring_of
2017-07-10 19:12:14 +01:00
James Dinsdale 62f1951b3c
Add release badge to README 2017-07-06 20:15:51 +01:00
James Dinsdale c2bc8b4f93
Remove tap from homebrew instructions 2017-07-06 15:16:39 +01:00
James Dinsdale ddcf697280 Add homebrew installation instructions
Fix #72
2017-07-06 00:51:55 +01:00
James Dinsdale e3f867677c Add branch information to contribution guidelines 2017-07-03 21:24:30 +01:00
James Dinsdale 6e3e03a968 Fix logo URL in README 2017-06-02 21:41:43 +01:00
James Dinsdale dfb04e0d10 Merge pull request #62 from MichaelAquilina/fix_readme_docs
Fix link to Zunit docs on README
2017-06-02 21:40:20 +01:00
Michael Aquilina d81645ba00
Fix link to Zunit docs on README 2017-06-02 20:31:23 +01:00
33 changed files with 718 additions and 70 deletions

View file

@ -7,20 +7,53 @@ addons:
- yodl
- man
dist: trusty
matrix:
language: generic
cache:
apt: true
directories:
- "$HOME/.zvm"
jobs:
include:
- env: ZVM_VERSION='4.3.12'
- env: ZVM_VERSION='4.3.17'
- env: ZVM_VERSION='5.0.8'
- env: ZVM_VERSION='5.1.1'
- env: ZVM_VERSION='5.2'
- env: ZVM_VERSION='5.3.1'
- stage: linux
os: linux
env: ZVM_VERSION='4.3.12'
- os: linux
env: ZVM_VERSION='4.3.17'
- os: linux
env: ZVM_VERSION='5.0.8'
- os: linux
env: ZVM_VERSION='5.1.1'
- os: linux
env: ZVM_VERSION='5.2'
- os: linux
env: ZVM_VERSION='5.3.1'
- stage: mac os
os: osx
env: ZVM_VERSION='5.0.8'
- os: osx
env: ZVM_VERSION='5.1.1'
- os: osx
env: ZVM_VERSION='5.2'
- os: osx
env: ZVM_VERSION='5.3.1'
- stage: deploy
script: skip
deploy:
provider: releases
api_key:
secure: JudjZ9Ou15GKmgOga6qpcxtCKITpq+EnGCUvNAGefuuG/etxSAEdXQfjmC4VBzCAC9Pn1gkABFAASUtZdZ5xxXhxkuU/lTopJxWG2tdxNuvW/wflZNGdnxgWA1PcYptKrLoDRLzUpDtsnnvD75mMvAR8+YjRJk76gWVM02we2JR8WKcD1bchQiqzc7CK2X4kDL6zRayYpwFnFKhA8bTlIEJ36k92liTeW8VNwg+9CAsM2zjWpCKmLXrecNl3e5sO+4ssGU+J4gnWYSC112oEzLJzm3cYsEj8dTuFtVHby1DrLrpW1fPQdF1h1cwjHtQkbKTF5vrNKcCmSGcFxA2YbMu8aMdkEZmwN8JvShFamyyYHi90UTyv8PQ/WYER143zGZinZ2VeSaIlFEvH7R/sbS6t4DjbXV7rHF9Zbg0d3D7p71kNDpbtH1dkX6KXxtqCOOVRwAMhwRJ6c7VCXwj0AZEr6YrqZucPjbLTn9NVtI0WPZPOIL/HhyB6vzB1zunmjQERmcwNcC3gR47mmOPWfh1XaCpIurrZKjF+SfH/mDN6Tr24a9oeae6+subI5LW9G1qP2/GmibDVmlX+F1jE4xxKr6sIrzB/DLdYVtiSnzAmquZnGNunUCOMB6DN4nCajh9X3O/e2DzKImHSHZyYIThytSNyMs885ZBbev6F850=
file:
- zunit
- zunit.zsh-completion
skip_cleanup: true
on:
tags: true
before_script:
- if [[ $(ls "$HOME/.zvm" | wc -l) -eq 0 ]]; then rm -rf "$HOME/.zvm"; fi
- mkdir .bin
- curl -L https://raw.githubusercontent.com/molovo/revolver/master/revolver > .bin/revolver
- curl -L https://raw.githubusercontent.com/molovo/color/master/color.zsh > .bin/color
- curl -L https://raw.githubusercontent.com/molovo/zvm/master/zvm > .bin/zvm
- curl -L https://raw.githubusercontent.com/molovo/zvm/master/zvm-shell-integration.zsh > zvm-shell-integration.zsh
- chmod u+x .bin/{color,revolver,zvm}
- export PATH="$HOME/.zvm/bin:$PWD/.bin:$PATH"
- zvm use ${ZVM_VERSION}
@ -28,13 +61,5 @@ before_script:
script: "./zunit"
notifications:
email: false
deploy:
provider: releases
api_key:
secure: JudjZ9Ou15GKmgOga6qpcxtCKITpq+EnGCUvNAGefuuG/etxSAEdXQfjmC4VBzCAC9Pn1gkABFAASUtZdZ5xxXhxkuU/lTopJxWG2tdxNuvW/wflZNGdnxgWA1PcYptKrLoDRLzUpDtsnnvD75mMvAR8+YjRJk76gWVM02we2JR8WKcD1bchQiqzc7CK2X4kDL6zRayYpwFnFKhA8bTlIEJ36k92liTeW8VNwg+9CAsM2zjWpCKmLXrecNl3e5sO+4ssGU+J4gnWYSC112oEzLJzm3cYsEj8dTuFtVHby1DrLrpW1fPQdF1h1cwjHtQkbKTF5vrNKcCmSGcFxA2YbMu8aMdkEZmwN8JvShFamyyYHi90UTyv8PQ/WYER143zGZinZ2VeSaIlFEvH7R/sbS6t4DjbXV7rHF9Zbg0d3D7p71kNDpbtH1dkX6KXxtqCOOVRwAMhwRJ6c7VCXwj0AZEr6YrqZucPjbLTn9NVtI0WPZPOIL/HhyB6vzB1zunmjQERmcwNcC3gR47mmOPWfh1XaCpIurrZKjF+SfH/mDN6Tr24a9oeae6+subI5LW9G1qP2/GmibDVmlX+F1jE4xxKr6sIrzB/DLdYVtiSnzAmquZnGNunUCOMB6DN4nCajh9X3O/e2DzKImHSHZyYIThytSNyMs885ZBbev6F850=
file:
- zunit
- zunit.zsh-completion
skip_cleanup: true
on:
tags: true
slack:
secure: gYbqJKOiko4AKjIY+68CxDPCyRQl22rdodRq55Wj745/ljyY5AQ8i3/Pvds19z2waX2ti232hWOczG09huYloTIDuiKNCqeedKVQQvThSqLW/8zYo1ETbOb09OPu6e68u8EAoPiwXeY56AqFEa5J3RBXP0cXl6EI9m1aL+LvGzV6AI149vh35Fib3a6Cr1JMspjf/iXf5LO9JI3YvdPI5xWGfjuqf7BWoJuQXsAIWtrpy9rHV1jfCFQNMuefwJruU0DbGEhW1er0HVWw4Sm8xP2BnIGoPDpqHUALaGs6RYBdsHTMUq9TjXVYNiYymvlpU4KpfUxOBQx8vIzzBwWjGua9YZsUMPxRw+ShVBnfVzMG/sGqG9zLSDMbMNiy5NXi9JxZi87/s9/7gUMWZqVXBucJ7L/xRr6xv/UTKe1Ur+Tb2FkZewWxkW3w8VU1uW5TgD1e72aeMHm+hXuBnKORIUB/BrNIYvfiUuKTMNZ6P78TgwGwe8BWA1NmqTwsyQip6OU7+OW5VYmB6Kv8YMZ87RtLTS6kPn2W5T+5wEYqTAMH4a1nbFglmM5Qu6i6Vf6Fhr05+YJtUToBQsB929VIqKVOlDYK8mMuS7K/B3dMSA/BjAgFQWDKaacGbM65PDhOZZTB6uTht9qvbxX0hLc7aU3Bj8Y7TRenv+BJwA26fnU=

View file

@ -6,3 +6,4 @@ directories:
time_limit: 15
fail_fast: true
allow_risky: false
verbose: false

View file

@ -1,12 +1,12 @@
![ZUnit](https://molovo.co/zunit/img/logo.png)
![ZUnit](https://zunit.xyz/img/logo.png)
[![Build Status](https://travis-ci.org/molovo/zunit.svg?branch=master)](https://travis-ci.org/molovo/zunit) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/molovo/zunit?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![GitHub release](https://img.shields.io/github/release/zunit-zsh/zunit.svg)](https://github.com/zunit-zsh/zunit/releases/latest) [![Build Status](https://travis-ci.org/zunit-zsh/zunit.svg?branch=master)](https://travis-ci.org/zunit-zsh/zunit) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/zunit-zsh/zunit?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
ZUnit is a powerful unit testing framework for ZSH
## Installation
> **WARNING**: Although the majority of ZUnit's functionality works as expected, it is in the early stages of development, and as such bugs are likely to be present. Please continue with caution, and [report any issues](https://github.com/molovo/zunit/issues/new) you may have.
> **WARNING**: Although the majority of ZUnit's functionality works as expected, it is in the early stages of development, and as such bugs are likely to be present. Please continue with caution, and [report any issues](https://github.com/zunit-zsh/zunit/issues/new) you may have.
### [Zulu](https://github.com/zulu-zsh/zulu)
@ -21,18 +21,39 @@ zulu install zunit
./build.zsh
zulu link zunit
```
### [zplug](https://github.com/zplug/zplug)
ZUnit and its dependencies can all be installed with zplug.
```sh
zplug 'molovo/revolver', \
as:command, \
use:revolver
zplug 'zunit-zsh/zunit', \
as:command, \
use:zunit, \
hook-build:'./build.zsh'
```
### Homebrew
```sh
brew install zunit-zsh/zunit/zunit
```
### Manual
```sh
git clone https://github.com/molovo/zunit
git clone https://github.com/zunit-zsh/zunit
cd ./zunit
./build.zsh
chmod u+x ./zunit
cp ./zunit /usr/local/bin
```
> ZUnit requires the utilities [Color](https://github.com/molovo/color) and [Revolver](https://github.com/molovo/revolver) to be installed, and in your `$PATH`. The zulu installation method will install these dependencies for you.
> ZUnit requires [Revolver](https://github.com/molovo/revolver) to be installed, and in your `$PATH`. The zulu or homebrew installation methods will install this dependency for you.
## Writing Tests
@ -52,7 +73,7 @@ The body of each test can contain any valid ZSH code. The zunit shebang `#!/usr/
## Documentation
For a full breakdown of ZUnit's syntax and functionality, check out the [official documentation](https://molovo.co/zunit/docs).
For a full breakdown of ZUnit's syntax and functionality, check out the [official documentation](https://zunit.xyz/docs/).
## Contributing

View file

@ -10,7 +10,7 @@ Please note that this project is released with a [Contributor Code of Conduct](c
As a user of ZUnit you're the perfect candidate to help us improve our documentation. Typo corrections, error fixes, better explanations, more examples, etc. Open issues for things that could be improved. Anything. Even improvements to this document.
Use the [`docs` label](https://github.com/molovo/zunit/labels/docs) to find suggestions for what we'd love to see more documentation on.
Use the [`docs` label](https://github.com/zunit-zsh/zunit/labels/docs) to find suggestions for what we'd love to see more documentation on.
### Improve issues
@ -20,30 +20,30 @@ Some issues are created with missing information, not reproducible, or plain inv
We're always looking for more opinions on discussions in the issue tracker. It's a good opportunity to influence the future direction of ZUnit.
The [`question` label](https://github.com/molovo/zunit/labels/question) is a good place to find ongoing discussions.
The [`question` label](https://github.com/zunit-zsh/zunit/labels/question) is a good place to find ongoing discussions.
### Write code
You can use issue labels to discover issues you could help out with:
* [`blocked` issues](https://github.com/molovo/zunit/labels/blocked) need help getting unstuck
* [`bug` issues](https://github.com/molovo/zunit/labels/bug) are known bugs we'd like to fix
* [`enhancement` issues](https://github.com/molovo/zunit/labels/enhancement) are features we're open to including
* [`performance` issues](https://github.com/molovo/zunit/labels/performance) track ideas on how to improve ZUnits performance
* [`blocked` issues](https://github.com/zunit-zsh/zunit/labels/blocked) need help getting unstuck
* [`bug` issues](https://github.com/zunit-zsh/zunit/labels/bug) are known bugs we'd like to fix
* [`enhancement` issues](https://github.com/zunit-zsh/zunit/labels/enhancement) are features we're open to including
* [`performance` issues](https://github.com/zunit-zsh/zunit/labels/performance) track ideas on how to improve ZUnits performance
The [`help wanted`](https://github.com/molovo/zunit/labels/help%20wanted) and [`good for beginner`](https://github.com/molovo/zunit/labels/good%20for%20beginner) labels are especially useful.
The [`help wanted`](https://github.com/zunit-zsh/zunit/labels/help%20wanted) and [`good for beginner`](https://github.com/zunit-zsh/zunit/labels/good%20for%20beginner) labels are especially useful.
You may find an issue is assigned, or has the [`assigned` label](https://github.com/molovo/zunit/labels/assigned). Please double-check before starting on this issue because somebody else is likely already working on it.
You may find an issue is assigned, or has the [`assigned` label](https://github.com/zunit-zsh/zunit/labels/assigned). Please double-check before starting on this issue because somebody else is likely already working on it.
We'd like to fix [`priority` issues](https://github.com/molovo/zunit/labels/priority) first. We'd love to see progress on [`low-priority` issues](https://github.com/molovo/zunit/labels/low%20priority) too. [`future` issues](https://github.com/molovo/zunit/labels/future) are those that we'd like to get to, but not anytime soon. Please check before working on these since we may not yet want to take on the burden of supporting those features.
We'd like to fix [`priority` issues](https://github.com/zunit-zsh/zunit/labels/priority) first. We'd love to see progress on [`low-priority` issues](https://github.com/zunit-zsh/zunit/labels/low%20priority) too. [`future` issues](https://github.com/zunit-zsh/zunit/labels/future) are those that we'd like to get to, but not anytime soon. Please check before working on these since we may not yet want to take on the burden of supporting those features.
### Hang out in our chat
We have a [chat](https://gitter.im/molovo/zunit). Jump in there and lurk, talk to us, and help others.
We have a [chat](https://gitter.im/zunit-zsh/zunit). Jump in there and lurk, talk to us, and help others.
## Submitting an issue
- The issue tracker is for issues. Use our [chat](https://gitter.im/molovo/zunit) for support.
- The issue tracker is for issues. Use our [chat](https://gitter.im/zunit-zsh/zunit) for support.
- Search the issue tracker before opening an issue.
- Ensure you're using the latest version of ZUnit.
- Use a clear and descriptive title.
@ -53,6 +53,8 @@ We have a [chat](https://gitter.im/molovo/zunit). Jump in there and lurk, talk t
## Submitting a pull request
- Most pull requests should target the `next` branch, so they can be included in the next release.
- Urgent bug fixes may be targeted to the `master` branch, and a new patch release will be created immediately after they are merged. If in doubt, ask.
- Non-trivial changes are often best discussed in an issue first, to prevent you from doing unnecessary work.
- For ambitious tasks, you should try to get your work in front of the community for feedback as soon as possible. Open a pull request as soon as you have done the minimum needed to demonstrate your idea. At this early stage, don't worry about making things perfect, or 100% complete. Add a [WIP] prefix to the title, and describe what you still need to do. This lets reviewers know not to nit-pick small details or point out improvements you already know you need to make.
- New features should be accompanied with tests and documentation.

View file

@ -2,6 +2,54 @@
# Internal assertion functions #
################################
###
# Assert one string is a substring of another
###
function _zunit_assert_is_substring_of() {
local value=$1 comparison=$2
[[ "$comparison" = *"$value"* ]] && return 0
echo "'$value' is not a substring of '$comparison'"
exit 1
}
###
# Assert one string is not a substring of another
###
function _zunit_assert_is_not_substring_of() {
local value=$1 comparison=$2
[[ "$comparison" != *"$value"* ]] && return 0
echo "'$value' is a substring of '$comparison'"
exit 1
}
###
# Assert one string contains another
###
function _zunit_assert_contains() {
local value=$1 comparison=$2
[[ "$value" = *"$comparison"* ]] && return 0
echo "'$value' does not contain '$comparison'"
exit 1
}
###
# Assert one string does not contain another
###
function _zunit_assert_does_not_contain() {
local value=$1 comparison=$2
[[ "$value" != *"$comparison"* ]] && return 0
echo "'$value' contains '$comparison'"
exit 1
}
###
# Assert that two integers are equal
###
@ -26,6 +74,54 @@ function _zunit_assert_not_equal_to() {
exit 1
}
###
# Assert that an integer is positive
###
function _zunit_assert_is_positive() {
local value=$1 comparison=$2
[[ $value -gt 0 ]] && return 0
echo "'$value' is not positive"
exit 1
}
###
# Assert that an integer is negative
###
function _zunit_assert_is_negative() {
local value=$1 comparison=$2
[[ $value -lt 0 ]] && return 0
echo "'$value' is not negative"
exit 1
}
###
# Assert that an integer is greater than the comparison
###
function _zunit_assert_is_greater_than() {
local value=$1 comparison=$2
[[ $value -gt $comparison ]] && return 0
echo "'$value' is not greater than '$comparison'"
exit 1
}
###
# Assert that an integer is less than the comparison
###
function _zunit_assert_is_less_than() {
local value=$1 comparison=$2
[[ $value -lt $comparison ]] && return 0
echo "'$value' is not less than '$comparison'"
exit 1
}
###
# Assert that two string are the same
###

View file

@ -71,7 +71,7 @@ allow_risky: false"
zsh
install:
- mkdir .bin
- curl -L https://github.com/molovo/zunit/releases/download/v$(_zunit_version)/zunit > .bin/zunit
- curl -L https://github.com/zunit-zsh/zunit/releases/download/v$(_zunit_version)/zunit > .bin/zunit
- curl -L https://raw.githubusercontent.com/molovo/revolver/master/revolver > .bin/revolver
- curl -L https://raw.githubusercontent.com/molovo/color/master/color.zsh > .bin/color
before_script:
@ -82,19 +82,19 @@ script: zunit"
# Check that a config file doesn't already exist so that
# we don't overwrite it
if [[ -f "$PWD/.zunit.yml" ]]; then
echo $(color red "Zunit config file already exists at $PWD/.zunit.yml") >&2
exit 1
echo $(color yellow "ZUnit config file already exists at $PWD/.zunit.yml. Skipping...")
else
# Write the contents to the config file
echo "Writing ZUnit config file to $PWD/.zunit.yml"
echo "$yaml" > "$PWD/.zunit.yml"
fi
# Check that the tests directory doesn't already exist so that
# we don't overwrite it
if [[ -d "$PWD/tests" ]]; then
echo $(color red "Directory already exists at $PWD/tests") >&2
exit 1
echo $(color yellow "Test directory already exists at $PWD/tests. Skipping...")
else
echo "Creating test directory at $PWD/tests"
# Create the directory structure for tests
mkdir -p tests/_{output,support}
touch tests/_{output,support}/.gitkeep
@ -109,9 +109,9 @@ script: zunit"
# Check that a travis config doesn't already exist so that
# we don't overwrite it
if [[ -f "$PWD/.travis.yml" ]]; then
echo $(color red "Travis config already exists at $PWD/.travis.yml") >&2
exit 1
echo $(color yellow "Travis config already exists at $PWD/.travis.yml. Skipping...")
else
echo "Writing Travis CI config to $PWD/.travis.yml"
# Write the contents to the config file
echo "$travis_yml" > "$PWD/.travis.yml"
fi

View file

@ -14,6 +14,7 @@ function _zunit_run_usage() {
echo " -v, --version Output version information and exit"
echo " -f, --fail-fast Stop the test runner immediately after the first failure"
echo " -t, --tap Output results in a TAP compatible format"
echo " --verbose Prints full output from each test"
echo " --output-text Print results to a text log, in TAP compatible format"
echo " --output-html Print results to a HTML page"
echo " --allow-risky Supress warnings generated for risky tests"
@ -24,18 +25,18 @@ function _zunit_run_usage() {
# Format a ms timestamp in a human-readable format
###
function _zunit_human_time() {
local ms=$1
local tmp=$(( $1 / 1000 ))
local days=$(( tmp / 60 / 60 / 24 ))
local hours=$(( tmp / 60 / 60 % 24 ))
local minutes=$(( tmp / 60 % 60 ))
local seconds=$(( tmp % 60 ))
local ms=$(( $1 % 1000 ))
(( $days > 0 )) && print -n "${days}d "
(( $hours > 0 )) && print -n "${hours}h "
(( $minutes > 0 )) && print -n "${minutes}m "
(( $seconds > 5 )) && print -n "${seconds}s "
(( $seconds < 30 )) && (( $seconds > 5 )) && print -n "$(( ms - $((seconds*1000)) ))ms"
(( $tmp <= 5 )) && print -n "${1}ms"
(( $seconds < 30 )) && (( $seconds > 5 )) && print -n "${ms}ms"
(( $seconds <= 5 )) && print -n "${1}ms"
}
###
@ -82,7 +83,7 @@ function _zunit_execute_test() {
# defined and the test exits early
if (( \$+functions[__zunit_test_teardown] )); then
zshexit() {
__zunit_test_teardown >/dev/null 2>&1
__zunit_test_teardown 2>&1
}
fi
@ -94,7 +95,7 @@ function _zunit_execute_test() {
# If a setup function is defined, run it now
if (( \$+functions[__zunit_test_setup] )); then
__zunit_test_setup >/dev/null 2>&1
__zunit_test_setup 2>&1
fi
# The test body is printed here, so when we eval the wrapper
@ -103,7 +104,7 @@ function _zunit_execute_test() {
# If a teardown function is defined, run it now
if (( \$+functions[__zunit_test_teardown] )); then
__zunit_test_teardown >/dev/null 2>&1
__zunit_test_teardown 2>&1
fi
# Remove the error handler
@ -166,6 +167,7 @@ function _zunit_execute_test() {
# The kill time has been reached, kill the child process,
# and exit the wrapper function
kill -9 $pid >/dev/null 2>&1
echo "Test took too long to run. Terminated after $time_limit seconds"
exit 78
fi
done
@ -190,14 +192,20 @@ function _zunit_execute_test() {
return
elif [[ $state -eq 78 ]]; then
_zunit_error "Test took too long to run. Terminated after $time_limit seconds" $output
_zunit_error $output
return
elif [[ -z $allow_risky && $state -eq 248 ]]; then
# If --verbose is specified, print test output to screen
[[ -n $verbose && -n $output ]] && echo $output
_zunit_warn 'No assertions were run, test is risky'
return
elif [[ -n $allow_risky && $state -eq 248 ]] || [[ $state -eq 0 ]]; then
# If --verbose is specified, print test output to screen
[[ -n $verbose && -n $output ]] && echo $output
_zunit_success
return
@ -401,7 +409,7 @@ function _zunit_parse_argument() {
line=$(cat $argument | head -n 1)
# Check for the zunit shebang
if [[ $line = "#!/usr/bin/env zunit" ]]; then
if [[ $line =~ "#! ?/usr/bin/env zunit" ]]; then
# Add it to the array
testfiles[(( ${#testfiles} + 1 ))]=("$argument${test_name+"@$test_name"}")
return
@ -426,7 +434,7 @@ function _zunit_parse_argument() {
###
function _zunit_run() {
local -a arguments testfiles
local fail_fast tap allow_risky
local fail_fast tap allow_risky verbose
local output_text logfile_text output_html logfile_html
# Load the datetime module, and record the start time
@ -438,6 +446,7 @@ function _zunit_run() {
v=version -version=version \
f=fail_fast -fail-fast=fail_fast \
t=tap -tap=tap \
-verbose=verbose \
-output-text=output_text \
-output-html=output_html \
-allow-risky=allow_risky \
@ -520,6 +529,11 @@ function _zunit_run() {
allow_risky=1
fi
# Check if verbose is specified in the config or as an option
if [[ -z $verbose ]] && [[ "$zunit_config_verbose" = "true" ]]; then
verbose=1
fi
# Check if time_limit is specified in the config or as an option
if [[ -n $time_limit ]]; then
shift time_limit

View file

@ -2,6 +2,35 @@
# Helpers for use within tests #
################################
###
# Colorise and style a string
###
function color() {
local color=$1 style=$2 b=0
shift
case $style in
bold|b) b=1; shift ;;
italic|i) b=2; shift ;;
underline|u) b=4; shift ;;
inverse|in) b=7; shift ;;
strikethrough|s) b=9; shift ;;
esac
case $color in
black|b) echo "\033[${b};30m${@}\033[0;m" ;;
red|r) echo "\033[${b};31m${@}\033[0;m" ;;
green|g) echo "\033[${b};32m${@}\033[0;m" ;;
yellow|y) echo "\033[${b};33m${@}\033[0;m" ;;
blue|bl) echo "\033[${b};34m${@}\033[0;m" ;;
magenta|m) echo "\033[${b};35m${@}\033[0;m" ;;
cyan|c) echo "\033[${b};36m${@}\033[0;m" ;;
white|w) echo "\033[${b};37m${@}\033[0;m" ;;
*) echo "\033[${b};38;5;$(( ${color} ))m${@}\033[0;m" ;;
esac
}
###
# Find a file, and load it into the environment
###
@ -52,18 +81,36 @@ function run() {
# Store each word of the command in an array, and grab the first
# argument which is the command name
cmd=(${@[@]})
cmd=("${@[@]}")
name="${cmd[1]}"
# If the command is not an existing command or file,
# then prepend the test directory to the path
type $name > /dev/null
type -- $name > /dev/null
if [[ $? -ne 0 && ! -f $name && -f "$testdir/${name}" ]]; then
cmd[1]="$testdir/${name}"
fi
# Store full output in a variable
output=$("${cmd[@]}" 2>&1)
local -a dont_quote
dont_quote=(
# Allow redirections and running multiple commands
"[[:digit:]]#(>|>>)(&|)[[:digit:]]#"
"[[:digit:]]#(<|<<)(&|)[[:digit:]]#"
"<<<" ";" "\\|" "\\|\\|" "&" "&&"
# Skip quoting of var=... -like strings and also of a single
# `)' as it might follow var=( ... array assignment
"([0-9]#|[a-zA-Z_][a-zA-Z0-9_]#)=*" "\\)"
)
# The new line is important, it makes the error messages include the line
# number, i.e. e.g.:
# run:1: command not found: a-non-existent-command
# It would be skipped otherwise, i.e. "run: command ..." would be printed
IFS=$'\n' eval "output=\$( function run {
${cmd[@]/(#m)*/${${${${${(M)MATCH:#(${(j:|:)~dont_quote})}:+$MATCH}}:-\"${MATCH//(#b)([\"\`\\])/\\${match[1]}}\"}}} 2>&1 }; run )";
# Get the process exit state
state="$?"
@ -75,10 +122,92 @@ function run() {
# Restore $IFS
IFS=$oldIFS
# Print the command output if --verbose is specified
if [[ -n $verbose && -n $output ]]; then
echo $output
fi
# Restore the exit on error state
setopt ERR_EXIT
}
###
# Eval given code and capture its output and exit status
###
function evl() {
# Separation of the main zunit option scope
setopt localoptions
# Within tests, the shell is set to exit immediately when errors
# occur. Since we want to capture the exit code of the command
# we're running, we stop the shell from exiting on error temporarily
unsetopt ERR_EXIT
# Preserve current $IFS
local ___oldIFS=$IFS ___name
local -a ___cmd
# Store each word of the command in an array, and grab the first
# argument which is the command ___name
___cmd=("${@[@]}")
___name="${___cmd[1]}"
# If the command is not an existing command or file,
# then prepend the test directory to the path
type -- $___name > /dev/null
if [[ $? -ne 0 && ! -f $___name && -f "$testdir/${___name}" ]]; then
___cmd[1]="$testdir/${___name}"
fi
# Store full output in a variable
local -a ___dont_quote
___dont_quote=(
# Allow redirections and running multiple commands
"[[:digit:]]#(>|>>)(&|)[[:digit:]]#"
"[[:digit:]]#(<|<<)(&|)[[:digit:]]#"
"<<<" ";" "\\|" "\\|\\|" "&" "&&"
# Skip quoting of var=... -like strings and also of a single
# `)' as it might follow var=( ... array assignment
"([0-9]#|[a-zA-Z_][a-zA-Z0-9_]#)=*" "\\)"
)
# Prepare the output file
local ___OUTFILE=$(mktemp)
# The new line is important, it makes the error messages include the line
# number, i.e. e.g.:
# eval:1: command not found: a-non-existent-command
# It would be skipped otherwise, i.e. "eval: command ..." would be printed.
# This is to maintain consistency with the messages printed from run().
IFS=$'\n' builtin eval "function __eval {
${___cmd[@]/(#m)*/${${${${${(M)MATCH:#(${(j:|:)~___dont_quote})}:+$MATCH}}:-\"${MATCH//(#b)([\"\`\\])/\\${match[1]}}\"}}} \
}; __eval >!$___OUTFILE 2>&1";
# Get the process exit state
state="$?"
# $(<...) trims all trailing \n-s, therefore cat is being used
output="$(cat "$___OUTFILE")"
# Cleanup
unset -f __eval;
command rm -f "$___OUTFILE"
# Store individual lines of output in an array
IFS=$'\n'
lines=("${(@f)output}")
# Restore $IFS
IFS=$___oldIFS
# Print the command output if --verbose is specified
if [[ -n $verbose && -n $output ]]; then
echo $output
fi
}
###
# Redirect the assertion shorthand to the correct function
###
@ -110,7 +239,7 @@ function assert() {
_zunit_assertion_count=$(( _zunit_assertion_count + 1 ))
# Run the assertion
"_zunit_assert_${assertion}" $value ${(@f)comparisons[@]}
"_zunit_assert_${assertion}" "$value" ${(@f)comparisons[@]}
local state=$?
@ -124,6 +253,37 @@ function assert() {
IFS=$oldIFS
}
###
# Mark the current test as passed
###
function pass() {
# Exit code 0 will end the test, and mark is as passed. The reason for
# skipping is echoed to stdout first, so that it can be picked up by the
# error handler
exit 0
}
###
# Mark the current test as failed
###
function fail() {
# Any non-zero exit code without special meaning will mark the test as failed.
# The failure message is echoed to stdout first, so that it can be picked up
# by the error handler
echo "$@"
exit 1
}
###
# Mark the current test as skipped
###
function error() {
# Exit code 78 will end the test, and report an error. The error message
# is echoed to stdout first, so that it can be picked up by the error handler
echo "$@"
exit 78
}
###
# Mark the current test as skipped
###
@ -135,3 +295,5 @@ function skip() {
echo "$@"
exit 48
}
# vim:ft=zsh:et:sts=2:sw=2

File diff suppressed because one or more lines are too long

View file

@ -1,5 +1,7 @@
#!/usr/bin/env zsh
setopt extendedglob typesetsilent
######################
# Main zunit process #
######################
@ -20,6 +22,7 @@ function _zunit_usage() {
echo " -v, --version Output version information and exit"
echo " -f, --fail-fast Stop the test runner immediately after the first failure"
echo " -t, --tap Output results in a TAP compatible format"
echo " --verbose Prints full output from each test"
echo " --output-text Print results to a text log, in TAP compatible format"
echo " --output-html Print results to a HTML page"
echo " --allow-risky Supress warnings generated for risky tests"
@ -30,7 +33,7 @@ function _zunit_usage() {
# Output the version number
###
function _zunit_version() {
echo '0.7.0'
echo '0.8.2'
}
###
@ -56,25 +59,14 @@ function _zunit() {
fi
fi
# Check for the 'color' dependency
$(type color >/dev/null 2>&1)
if [[ $? -ne 0 ]]; then
# 'color' could not be found, so print an error message
missing_dependencies=$(( missing_dependencies + 1 ))
echo "\033[0;31mMissing required dependency: Color - https://github.com/molovo/color\033[0;m" >&2
fi
# Check for the 'revolver' dependency
$(type revolver >/dev/null 2>&1)
if [[ $? -ne 0 ]]; then
# 'revolver' could not be found, so print an error message
missing_dependencies=$(( missing_dependencies + 1 ))
echo "\033[0;31mMissing required dependency: Revolver - https://github.com/molovo/revolver\033[0;m" >&2
exit 1
fi
# If any missing dependencies have been found, we can't run tests, so we exit
[[ $missing_dependencies -gt 0 ]] && exit 1
zparseopts -D -E \
h=help -help=help \
v=version -version=version

View file

@ -0,0 +1,43 @@
#!/usr/bin/env zunit
@test 'Test _zunit_assert_contains match' {
run assert 'hello world' contains 'lo wo'
assert "$output" is_empty
assert $state equals 0
}
@test 'Test _zunit_assert_contains suffix match' {
run assert 'hello world' contains 'world'
assert "$output" is_empty
assert $state equals 0
}
@test 'Test _zunit_assert_contains prefix match' {
run assert 'hello world' contains 'hello'
assert "$output" is_empty
assert $state equals 0
}
@test 'Test _zunit_assert_contains whole word matches' {
run assert 'red blue green' contains 'red blue green'
assert "$output" is_empty
assert $state equals 0
}
@test 'Test _zunit_assert_contains match failure' {
run assert 'elephants' contains 'foo'
assert "$output" same_as "'elephants' does not contain 'foo'"
assert $state equals 1
}
@test 'Test _zunit_assert_contains match failure with empty value' {
run assert '' contains 'foo'
assert "$output" same_as "'' does not contain 'foo'"
assert $state equals 1
}

View file

@ -11,3 +11,9 @@
assert $state equals 1
assert $output same_as "'test' is the same as 'test'"
}
@test 'Test _zunit_assert_different_to passes with empty value' {
run assert '' different_to 'test'
assert $state equals 0
assert $output is_empty
}

View file

@ -0,0 +1,22 @@
#!/usr/bin/env zunit
@test 'Test _zunit_assert_does_not_contain success' {
run assert 'yellow' does_not_contain 'foo'
assert "$output" is_empty
assert $state equals 0
}
@test 'Test _zunit_assert_does_not_contain success with empty value' {
run assert '' does_not_contain 'foo'
assert "$output" is_empty
assert $state equals 0
}
@test 'Test _zunit_assert_does_not_contain failure' {
run assert 'foobar' does_not_contain 'foo'
assert "$output" same_as "'foobar' contains 'foo'"
assert $state equals 1
}

View file

@ -10,6 +10,12 @@
assert $output is_empty
}
@test 'Test _zunit_assert_does_not_match success with empty value' {
run assert '' does_not_match '[0-9]+'
assert $state equals 0
assert $output is_empty
}
@test 'Test _zunit_assert_does_not_match failure' {
run assert 'test' does_not_match '[a-z]{4}'
assert $state equals 1

View file

@ -11,3 +11,9 @@
assert $state equals 1
assert $output same_as "'1' is not equal to '0'"
}
@test 'Test _zunit_assert_equals failure with empty value' {
run assert '' equals 1
assert $state equals 1
assert $output same_as "'' is not equal to '1'"
}

View file

@ -1,4 +1,4 @@
#!/usr/bin/env zunit
#! /usr/bin/env zunit
@test 'Test _zunit_assert_exists success' {
run assert './exists.zunit' exists

View file

@ -11,3 +11,9 @@
assert $state equals 1
assert "$output" same_as "'a' is not in (x y z)"
}
@test 'Test _zunit_assert_in failure with empty value' {
run assert '' in 'x' 'y' 'z'
assert $state equals 1
assert "$output" same_as "'' is not in (x y z)"
}

View file

@ -0,0 +1,19 @@
#!/usr/bin/env zunit
@test 'Test _zunit_assert_is_greater_than success' {
run assert 2 is_greater_than 1
assert $state equals 0
assert $output is_empty
}
@test 'Test _zunit_assert_is_greater_than failure' {
run assert -1 is_greater_than 1
assert $state equals 1
assert $output same_as "'-1' is not greater than '1'"
}
@test 'Test _zunit_assert_is_greater_than failure with empty value' {
run assert '' is_greater_than 1
assert $state equals 1
assert $output same_as "'' is not greater than '1'"
}

View file

@ -21,3 +21,14 @@
assert $state equals 1
assert "$output" same_as "'a' is not a key in (x 1 y 2 z 3)"
}
@test 'Test _zunit_assert_is_key_in failure with empty value' {
typeset -A hash; hash=(
'x' 1
'y' 2
'z' 3
)
run assert '' is_key_in ${(@kv)hash}
assert $state equals 1
assert "$output" same_as "'' is not a key in (x 1 y 2 z 3)"
}

View file

@ -0,0 +1,19 @@
#!/usr/bin/env zunit
@test 'Test _zunit_assert_is_less_than success' {
run assert -1 is_less_than 1
assert $state equals 0
assert $output is_empty
}
@test 'Test _zunit_assert_is_less_than failure' {
run assert 2 is_less_than 1
assert $state equals 1
assert $output same_as "'2' is not less than '1'"
}
@test 'Test _zunit_assert_is_less_than failure' {
run assert '' is_less_than -1
assert $state equals 1
assert $output same_as "'' is not less than '-1'"
}

View file

@ -0,0 +1,19 @@
#!/usr/bin/env zunit
@test 'Test _zunit_assert_is_negative success' {
run assert -1 is_negative
assert $state equals 0
assert $output is_empty
}
@test 'Test _zunit_assert_is_negative failure' {
run assert 1 is_negative
assert $state equals 1
assert $output same_as "'1' is not negative"
}
@test 'Test _zunit_assert_is_negative failure with empty value' {
run assert '' is_negative
assert $state equals 1
assert $output same_as "'' is not negative"
}

View file

@ -11,6 +11,17 @@
assert "$output" is_empty
}
@test 'Test _zunit_assert_is_not_key_in success with empty value' {
typeset -A assoc; assoc=(
'x' 1
'y' 2
'z' 3
)
run assert '' is_not_key_in ${(@kv)assoc}
assert $state equals 0
assert "$output" is_empty
}
@test 'Test _zunit_assert_is_not_key_in failure' {
typeset -A assoc; assoc=(
'a' 1

View file

@ -0,0 +1,22 @@
#!/usr/bin/env zunit
@test 'Test _zunit_assert_is_substring_of success' {
run assert 'foo' is_not_substring_of 'yellow'
assert "$output" is_empty
assert $state equals 0
}
@test 'Test _zunit_assert_is_substring_of failure' {
run assert 'foo' is_not_substring_of 'foobar'
assert "$output" same_as "'foo' is a substring of 'foobar'"
assert $state equals 1
}
@test 'Test _zunit_assert_is_substring_of failure with empty value' {
run assert '' is_not_substring_of 'foobar'
assert "$output" same_as "'' is a substring of 'foobar'"
assert $state equals 1
}

View file

@ -11,6 +11,17 @@
assert "$output" is_empty
}
@test 'Test _zunit_assert_is_not_value_in success with empty value' {
typeset -A hash; hash=(
'x' 7
'y' 8
'z' 9
)
run assert '' is_not_value_in ${(@kv)hash}
assert $state equals 0
assert "$output" is_empty
}
@test 'Test _zunit_assert_is_not_value_in failure' {
typeset -A hash; hash=(
'a' 1

View file

@ -0,0 +1,19 @@
#!/usr/bin/env zunit
@test 'Test _zunit_assert_is_positive success' {
run assert 1 is_positive
assert $state equals 0
assert $output is_empty
}
@test 'Test _zunit_assert_is_positive failure' {
run assert -1 is_positive
assert $state equals 1
assert $output same_as "'-1' is not positive"
}
@test 'Test _zunit_assert_is_positive failure with empty value' {
run assert '' is_positive
assert $state equals 1
assert $output same_as "'' is not positive"
}

View file

@ -0,0 +1,43 @@
#!/usr/bin/env zunit
@test 'Test _zunit_assert_is_substring_of match' {
run assert 'lo wo' is_substring_of 'hello world'
assert "$output" is_empty
assert $state equals 0
}
@test 'Test _zunit_assert_is_substring_of match with empty value' {
run assert '' is_substring_of 'hello world'
assert "$output" is_empty
assert $state equals 0
}
@test 'Test _zunit_assert_is_substring_of suffix match' {
run assert 'world' is_substring_of 'hello world'
assert "$output" is_empty
assert $state equals 0
}
@test 'Test _zunit_assert_is_substring_of prefix match' {
run assert 'hello' is_substring_of 'hello world'
assert "$output" is_empty
assert $state equals 0
}
@test 'Test _zunit_assert_is_substring_of whole word matches' {
run assert 'red blue green' is_substring_of 'red blue green'
assert "$output" is_empty
assert $state equals 0
}
@test 'Test _zunit_assert_is_substring_of match failure' {
run assert 'foo' is_substring_of 'elephants'
assert "$output" same_as "'foo' is not a substring of 'elephants'"
assert $state equals 1
}

View file

@ -21,3 +21,14 @@
assert $state equals 1
assert "$output" same_as "'4' is not a value in (x 1 y 2 z 3)"
}
@test 'Test _zunit_assert_is_value_in failure with empty value' {
typeset -A hash; hash=(
'x' 1
'y' 2
'z' 3
)
run assert '' is_value_in ${(@kv)hash}
assert $state equals 1
assert "$output" same_as "'' is not a value in (x 1 y 2 z 3)"
}

View file

@ -19,3 +19,9 @@
assert $state equals 1
assert $output same_as "'123' does not match /[a-z]+/"
}
@test 'Test _zunit_assert_matches failure with empty value' {
run assert '' matches '[a-z]+'
assert $state equals 1
assert $output same_as "'' does not match /[a-z]+/"
}

View file

@ -6,6 +6,18 @@
assert $output is_empty
}
@test 'Test _zunit_assert_not_equal_to success with empty value' {
run assert '' not_equal_to 1
assert $state equals 0
assert $output is_empty
}
@test 'Test _zunit_assert_not_equal_to success with empty comparison' {
run assert 1 not_equal_to ''
assert $state equals 0
assert $output is_empty
}
@test 'Test _zunit_assert_not_equal_to failure' {
run assert 1 not_equal_to 1
assert $state equals 1

View file

@ -6,6 +6,12 @@
assert $output is_empty
}
@test 'Test _zunit_assert_not_in success with empty value' {
run assert '' not_in 'x' 'y' 'z'
assert $state equals 0
assert $output is_empty
}
@test 'Test _zunit_assert_not_in failure' {
run assert 'a' not_in 'a' 'b' 'c'
assert $state equals 1

View file

@ -11,3 +11,9 @@
assert $state equals 1
assert $output same_as "'test' is not the same as 'wrong'"
}
@test 'Test _zunit_assert_same_as failure with empty value' {
run assert '' same_as 'wrong'
assert $state equals 1
assert $output same_as "'' is not the same as 'wrong'"
}

29
tests/helpers.zunit Normal file
View file

@ -0,0 +1,29 @@
#!/usr/bin/env zunit
@test 'Test pass helper' {
run pass
assert $state equals 0
assert "$output" is_empty
}
@test 'Test fail helper' {
run fail 'The failure message'
assert $state equals 1
assert "$output" same_as 'The failure message'
}
@test 'Test error helper' {
run error 'The error message'
assert $state equals 78
assert "$output" same_as 'The error message'
}
@test 'Test skip helper' {
run skip 'The skip message'
assert $state equals 48
assert "$output" same_as 'The skip message'
}

View file

@ -21,6 +21,7 @@ _zunit() {
'(-v --version)'{-v,--version}'[show version information and exit]' \
'(-f --fail-fast)'{-f,--fail-fast}'[stop execution after the first failure]' \
'(-t --tap)'{-t,--tap}'[output results in a TAP compatible format]' \
'--verbose[prints full output from each test]' \
'--output-text[print results to a text log, in TAP compatible format]' \
'--output-html[print results to a HTML page]' \
'--allow-risky[supress warnings generated for risky tests]' \
@ -42,6 +43,7 @@ _zunit() {
'(-h --help)'{-h,--help}'[show help text and exit]' \
'(-f --fail-fast)'{-f,--fail-fast}'[stop execution after the first failure]' \
'(-t --tap)'{-t,--tap}'[output results in a TAP compatible format]' \
'--verbose[prints full output from each test]' \
'--output-text[print results to a text log, in TAP compatible format]' \
'--output-html[print results to a HTML page]' \
'--allow-risky[supress warnings generated for risky tests]' \