Test2:...ompare(3perl)
π NAME π
Test2::Tools::ClassicCompare β Classic (Test::More style) comparison tools. π«Ά
It lives in the Perl Programmers Reference Guide as Test2:...ompare(3perl), so yeah, it's official Perl manual-section-3perl realness. β¨
π¦ DESCRIPTION π¦
Bestie. Listen. This module provides comparison functions that behave exactly like they did in Test::More β the old-school way, the way you remember, the way your heart wants. π
Unlike the Test2::Tools::Compare plugin, which has modified them (it went and changed the vibe, smh), this one keeps the classic behaviour. Periodt. π
β¨ SYNOPSIS β¨
use Test2::Tools::ClassicCompare qw/is is_deeply isnt like unlike cmp_ok/;
is($got, $expect, "These are the same when stringified");
isnt($got, $unexpected, "These are not the same when stringified");
like($got, qr/.../, "'got' matches the pattern");
unlike($got, qr/.../, "'got' does not match the pattern");
is_deeply($got, $expect, "These structures are same when checked deeply");
cmp_ok($GOT, $OP, $WANT, 'Compare these items using the specified operatr');
π EXPORTS π
is π
$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 they're the same after stringification, the test passes, slay. And it'll also pass if both arguments are undef. Iconic.
The test $name is optional. π¦
The test @diag is optional too β it's extra diagnostics messages that get displayed if the test fails. (If the test passes, the diagnostics are ignored. They don't get shown, they don't get acknowledged, they get nothing. π)
It is important to note that this tool considers"1"and"1.0"to not be equal, because it uses a string comparison. No cap. It's giving string equality and nothing else.
If you want an is() function that tries to be smarter for you, go see Test2::Tools::Compare. That's a different girl. πΈ
isnt π
$bool = isnt($got, $dont_expect)
$bool = isnt($got, $dont_expect, $name)
$bool = isnt($got, $dont_expect, $name, @diag)
This is the inverse of is(), bestie β it passes when the strings are not the same. The way that it just flips the whole energy. π₯
like π
$bool = like($got, $pattern)
$bool = like($got, $pattern, $name)
$bool = like($got, $pattern, $name, @diag)
Check if $got matches the specified pattern. It will fail if it does not match. Simple as that. β¨
The test $name is optional. π
The test @diag is optional. It contains extra diagnostics messages that get displayed if the test fails. The diagnostics are ignored if the test passes. (Yes, again. Rules are rules. π«Ά)
unlike π
$bool = unlike($got, $pattern)
$bool = unlike($got, $pattern, $name)
$bool = unlike($got, $pattern, $name, @diag)
This is the inverse of like(). It will fail if $got matches $pattern. Got it? Got it. π
is_deeply π§
$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, because it uses a string comparison. Same energy asis, fr fr.
This is the same as Test2::Tools::Compare::is(). π
cmp_ok π₯
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. Useful for comparing numbers, overloaded objects, etc. Iconic for math girlies. β
Overloading Note: 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. π (We tried.)
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. Customise away, bestie. π«Ά
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
//
&
|
~~
π SOURCE π
The source code repository for Test2-Suite can be found at:
https://github.com/Test-More/test-more/
Go look, it's giving open source royalty. π
π MAINTAINERS π
- Chad Granum
<exodist@cpan.org>
π AUTHORS π
- Chad Granum
<exodist@cpan.org>
π COPYRIGHT π
Copyright Chad Granum <exodist@cpan.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://dev.perl.org/licenses/
And that's the whole page, bestie β perl v5.44.0, dated 2026-10-17, from Test2:...ompare(3perl). Read it, love it, is() responsibly. ππ¦β¨
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms