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