Assertions
ZUnit’s powerful assertion library provides a series of methods enabling you to compare values within your tests. Here is a full list of all the methods available to you.
equals
Compares two integers to ensure that they are equal, and fails the test if they are not.
assert 1 equals 1
not_equal_to
Compares two integers to ensure that they are not equal, and fails the test if they are.
assert 1 not_equal_to 0
is_positive
Checks an integer to ensure that it is positive, and fails the test if it is not.
assert 1 is_positive
is_negative
Checks an integer to ensure that it is negative, and fails the test if it is not.
assert -1 is_negative
is_greater_than
Compares two integers to ensure one is greater, and fails the test if it is not.
assert 2 is_greater_than 1
is_less_than
Compares two integers to ensure one is lesser, and fails the test if it is not.
assert 1 is_less_than 2
same_as
Compares two strings to ensure that they are equal, and fails the test if they are not
assert 'Rainbows!' same_as 'Rainbows!'
different_to
Compares two strings to ensure that they are different, and fails the test if they are not
assert 'Rainbows' different_to 'Unicorns!'
is_empty
Checks that the value passed is empty or undefined, and fails the test if it contains a value.
assert '' is_empty
is_not_empty
Checks that the value passed contains something, and fails the test if it is empty or undefined.
assert 'Rainbows!' is_not_empty
is_substring_of
Searches for the value within a defined string, and fails if it is not found.
assert 'unicorns' is_substring_of 'I love unicorns!'
is_not_substring_of
Searches for the value within a defined string, and fails if it is found.
assert 'unicorns' is_not_substring_of 'I love rainbows!'
contains
Checks if the value contains a defined string, and fails if it is not found.
assert 'I love unicorns!' contains 'unicorns'
does_not_contain
Checks if the value contains a defined string, and fails if it is found.
assert 'I love rainbows!' does_not_contain 'unicorns'
matches
Compares the value against a PCRE-compliant regular expression, and fails the test if it does not match.
assert 'unicorns' matches '[a-z]{8}'
does_not_match
Compares the value against a PCRE-compliant regular expression, and fails the test if it matches.
assert 'unicorns' does_not_match '[0-9]+'
in
Search for the value in a list or array of values, and fails the test if it is not found.
assert 'a' in 'a' 'b' 'c'
not_in
Search for the value in a list or array of values, and fails the test if it is found.
assert 'a' not_in 'x' 'y' 'z'
is_key_in
Searches for the value within the keys of the provided hash, and fails the test if it is not found.
typeset -A hash; hash=(
'a' 1
'b' 2
'c' 3
)
assert 'a' is_key_in ${(@kv)hash}
is_not_key_in
Searches for the value within the keys of the provided hash, and fails the test if it is found.
typeset -A hash; hash=(
'x' 1
'y' 2
'z' 3
)
assert 'a' is_not_key_in ${(@kv)hash}
is_value_in
Searches for the value within the values of the provided hash, and fails the test if it is not found.
typeset -A hash; hash=(
'a' 1
'b' 2
'c' 3
)
assert 1 is_value_in ${(@kv)hash}
is_not_value_in
Searches for the value within the values of the provided hash, and fails the test if it is found.
typeset -A hash; hash=(
'x' 1
'y' 2
'z' 3
)
assert 4 is_not_value_in ${(@kv)hash}
exists
Searches the filesystem for the given path, and fails the test if it does not exist.
assert /path/to/a/file exists
is_file
Searches the filesystem for the given path, and fails the test if it does not exist, or is not a file.
assert /path/to/a/file is_file
is_dir
Searches the filesystem for the given path, and fails the test if it does not exist, or is not a directory.
assert /path/to/a/directory is_dir
is_link
Searches the filesystem for the given path, and fails the test if it does not exist, or is not a symbolic link.
assert /path/to/a/symlink is_link
is_readable
Searches the filesystem for the given path, and fails the test if it does not exist, or is not readable.
assert /path/to/a/file is_readable
is_writable
Searches the filesystem for the given path, and fails the test if it does not exist, or is not writable.
assert /path/to/a/file is_writable
is_executable
Searches the filesystem for the given path, and fails the test if it does not exist, or is not executable.
assert /path/to/a/file is_executable