2
"Test::Identity" - assert the referential identity of a reference
5
use Test::More tests => 2;
13
sub get_thingy { return $thingy }
14
sub set_thingy { $thingy = shift; }
17
identical( get_thingy, undef, 'get_thingy is undef' );
19
my $test_thingy = Thingy->new;
20
set_thingy $test_thingy;
22
identical( get_thingy, $thingy, 'get_thingy is now $test_thingy' );
25
This module provides a single testing function, "identical". It asserts
26
that a given reference is as expected; that is, it either refers to the
27
same object or is "undef". It is similar to "Test::More::is" except that
28
it uses "refaddr", ensuring that it behaves correctly even if the
29
references under test are objects that overload stringification or
32
It also provides better diagnostics if the test fails:
34
$ perl -MTest::More=tests,1 -MTest::Identity -e'identical [], {}'
37
# Failed test at -e line 1.
38
# Expected an anonymous HASH ref, got an anonymous ARRAY ref
39
# Looks like you failed 1 test of 1.
41
$ perl -MTest::More=tests,1 -MTest::Identity -e'identical [], []'
44
# Failed test at -e line 1.
45
# Expected an anonymous ARRAY ref to the correct object
46
# Looks like you failed 1 test of 1.
49
identical( $got, $expected, $name )
50
Asserts that $got refers to the same object as $expected.
53
Paul Evans <leonerd@leonerd.org.uk>