logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

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

Author

       Paul Evans <leonerd@leonerd.org.uk>

perl v5.36.0                                       2022-10-22                                Test::Identity(3pm)

Description

       This module provides a single testing function, "identical". It asserts that a given reference is as
       expected; that is, it either refers to the same object or is "undef". It is similar to "Test::More::is"
       except that it uses "refaddr", ensuring that it behaves correctly even if the references under test are
       objects that overload stringification or numification.

       It also provides better diagnostics if the 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.

Functions

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

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' );

See Also