1Test::Identity(3)     User Contributed Perl Documentation    Test::Identity(3)
2
3
4

NAME

6       "Test::Identity" - assert the referential identity of a reference
7

SYNOPSIS

9        use Test::More tests => 2;
10        use Test::Identity;
11
12        use Thingy;
13
14        {
15           my $thingy;
16
17           sub get_thingy { return $thingy }
18           sub set_thingy { $thingy = shift; }
19        }
20
21        identical( get_thingy, undef, 'get_thingy is undef' );
22
23        my $test_thingy = Thingy->new;
24        set_thingy $test_thingy;
25
26        identical( get_thingy, $thingy, 'get_thingy is now $test_thingy' );
27

DESCRIPTION

29       This module provides a single testing function, "identical". It asserts
30       that a given reference is as expected; that is, it either refers to the
31       same object or is "undef". It is similar to "Test::More::is" except
32       that it uses "refaddr", ensuring that it behaves correctly even if the
33       references under test are objects that overload stringification or
34       numification.
35
36       It also provides better diagnostics if the test fails:
37
38        $ perl -MTest::More=tests,1 -MTest::Identity -e'identical [], {}'
39        1..1
40        not ok 1
41        #   Failed test at -e line 1.
42        # Expected an anonymous HASH ref, got an anonymous ARRAY ref
43        # Looks like you failed 1 test of 1.
44
45        $ perl -MTest::More=tests,1 -MTest::Identity -e'identical [], []'
46        1..1
47        not ok 1
48        #   Failed test at -e line 1.
49        # Expected an anonymous ARRAY ref to the correct object
50        # Looks like you failed 1 test of 1.
51

FUNCTIONS

53   identical( $got, $expected, $name )
54       Asserts that $got refers to the same object as $expected.
55

AUTHOR

57       Paul Evans <leonerd@leonerd.org.uk>
58
59
60
61perl v5.34.0                      2021-07-23                 Test::Identity(3)
Impressum