$bool = is($got, $expect)
$bool = is($got, $expect, $name)
$bool = is($got, $expect, $name, @diag)
This does a string comparison of the two arguments. If the two arguments are the same after
stringification the test passes. The test will also pass if both arguments are undef.
The test $name is optional.
The test @diag is optional, it is extra diagnostics messages that will be displayed if the test
fails. The diagnostics are ignored if the test passes.
It is important to note that this tool considers "1" and "1.0" to not be equal as it uses a string
comparison.
See Test2::Tools::Compare if you want an is() function that tries to be smarter for you.
$bool = isnt($got, $dont_expect)
$bool = isnt($got, $dont_expect, $name)
$bool = isnt($got, $dont_expect, $name, @diag)
This is the inverse of is(), it passes when the strings are not the same.
$bool = like($got, $pattern)
$bool = like($got, $pattern, $name)
$bool = like($got, $pattern, $name, @diag)
Check if $got matches the specified pattern. Will fail if it does not match.
The test $name is optional.
The test @diag is optional. It contains extra diagnostics messages that will be displayed if the test
fails. The diagnostics are ignored if the test passes.
$bool = unlike($got, $pattern)
$bool = unlike($got, $pattern, $name)
$bool = unlike($got, $pattern, $name, @diag)
This is the inverse of like(). This will fail if $got matches $pattern.
$bool = is_deeply($got, $expect)
$bool = is_deeply($got, $expect, $name)
$bool = is_deeply($got, $expect, $name, @diag)
This does a deep check, comparing the structures in $got with those in $expect. It will recurse into
hashrefs, arrayrefs, and scalar refs. All other values will be stringified and compared as strings.
It is important to note that this tool considers "1" and "1.0" to not be equal as it uses a string
comparison.
This is the same as Test2::Tools::Compare::is().
cmp_ok($got, $op, $expect)
cmp_ok($got, $op, $expect, $name)
cmp_ok($got, $op, $expect, $name, @diag)
Compare $got to $expect using the operator specified in $op. This is effectively an "eval "\$got $op
\$expect"" with some other stuff to make it more sane. This is useful for comparing numbers,
overloaded objects, etc.
OverloadingNote: Your input is passed as-is to the comparison. If the comparison fails between two
overloaded objects, the diagnostics will try to show you the overload form that was used in
comparisons. It is possible that the diagnostics will be wrong, though attempts have been made to
improve them since Test::More.
Exceptions: If the comparison results in an exception then the test will fail and the exception will
be shown.
cmp_ok() has an internal list of operators it supports. If you provide an unsupported operator it
will issue a warning. You can add operators to the %Test2::Tools::ClassicCompare::OPS hash, the key
should be the operator, and the value should either be 'str' for string comparison operators, 'num'
for numeric operators, or any other true value for other operators.
Supported operators:
== (num)
!= (num)
>= (num)
<= (num)
> (num)
< (num)
<=> (num)
eq (str)
ne (str)
gt (str)
lt (str)
ge (str)
le (str)
cmp (str)
!~ (str)
=~ (str)
&&
||
xor
or
and
//
&
|
~~