Test::Identity(3pm)
π Test::Identity π
okay bestie, so this is Test::Identity β and it does exactly one thing, but it does it flawlessly. It asserts the referential identity of a reference. that's it. that's the whole vibe. β¨
πΈ NAME πΈ
Test::Identity β assert the referential identity of a reference π
β¨ SYNOPSIS β¨
use Test::More tests => 2;
use Test::Identity;
use Thingy;
{
my $thingy;
sub get_thingy { return $thingy }
sub set_thingy { $thingy = shift; }
}
identical( get_thingy, undef, 'get_thingy is undef' );
my $test_thingy = Thingy->new;
set_thingy $test_thingy;
identical( get_thingy, $thingy, 'get_thingy is now $test_thingy' );
π¦ DESCRIPTION π¦
so this module literally gives you one single testing function, identical. it asserts that a given reference is as expected β meaning it either refers to the same object or it's undef. no in-between, no crumbs. π
it's similar to Test::More::is, except it uses refaddr, which means it behaves correctly even if the references you're testing are objects that overload stringification or numification. the way that matters so much fr fr β those overloaded objects would lowkey lie to a plain old string comparison. π
and bestie, the diagnostics? iconic. it gives you better ones when a test fails:
$ perl -MTest::More=tests,1 -MTest::Identity -e'identical [], {}'
1..1
not ok 1
# Failed test at -e line 1.
# Expected an anonymous HASH ref, got an anonymous ARRAY ref
# Looks like you failed 1 test of 1.
$ perl -MTest::More=tests,1 -MTest::Identity -e'identical [], []'
1..1
not ok 1
# Failed test at -e line 1.
# Expected an anonymous ARRAY ref to the correct object
# Looks like you failed 1 test of 1.
see how it tells you what went wrong instead of leaving you guessing? main character energy. π
π FUNCTIONS π
π identical( $got, $expected, $name )
Asserts that $got refers to the same object as $expected. that's the whole assignment. slay. β¨
π AUTHOR π
Paul Evans <leonerd@leonerd.org.uk>
and that's a wrap, bestie π«Ά this whole page is from perl v5.36.0, dated 2022-10-22, straight outta the User Contributed Perl Documentation. go forth and test your references with confidence πππ¦
π¦ where this page comes from
- ubuntu noble: libtest-identity-perl 0.01-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtest-identity-perl 0.01-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtest-identity-perl 0.01-4 Β· Artistic-1.0-Perl OR 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