Debian Codegraph @

README

raw
1 NAME
2 "Test::Identity" - assert the referential identity of a reference
3
4 SYNOPSIS
5 use Test::More tests => 2;
6 use Test::Identity;
7
8 use Thingy;
9
10 {
11 my $thingy;
12
13 sub get_thingy { return $thingy }
14 sub set_thingy { $thingy = shift; }
15 }
16
17 identical( get_thingy, undef, 'get_thingy is undef' );
18
19 my $test_thingy = Thingy->new;
20 set_thingy $test_thingy;
21
22 identical( get_thingy, $thingy, 'get_thingy is now $test_thingy' );
23
24 DESCRIPTION
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
30 numification.
31
32 It also provides better diagnostics if the test fails:
33
34 $ perl -MTest::More=tests,1 -MTest::Identity -e'identical [], {}'
35 1..1
36 not ok 1
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.
40
41 $ perl -MTest::More=tests,1 -MTest::Identity -e'identical [], []'
42 1..1
43 not ok 1
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.
47
48 FUNCTIONS
49 identical( $got, $expected, $name )
50 Asserts that $got refers to the same object as $expected.
51
52 AUTHOR
53 Paul Evans <[email protected]>
54