The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test::DiagRef - Detailed diagnostics for your reference tracking tests

VERSION

version 1.132080

SYNOPSIS

    use Test::More tests => 1;
    use Test::DiagRef;
    use Scalar::Util 'weaken';

    my $obj = MyClass->new();

    weaken(my $ref = $obj);

    # Delete $obj
    undef $obj; # Uncomment this line to show a leak

    is($ref, undef, 'no leak') or diag_ref $ref;

DESCRIPTION

Test::DiagRef is an utility module for writing tests for memory leaks. It will not check for memory leaks himself (that's your job as a test author), but at least provide an advanced report if your test found one.

The only sub exported is diag_ref($ref). It is expected to be used where Test::More's diag is used: to provide advanced diagnostics when a test failed. The given $ref will be explored.

Devel::FindRef is the module that provides the detailed report. But it is loaded on demand, only if $ref is defined. This saves ressources if your test did not detect a leak.

The runtime dependency on Devel::FindRef is optional. If it is not installed when the test found a leak, diag_ref will just report a message suggesting to install it. This ensures that using Test::DiagRef has low dependancy impact on your own CPAN (or DarkPAN) distribution. You can safely use Test::DiagRef for development, and still keep it in the test suite of the distribution.

SEE ALSO

AUTHOR

Olivier Mengué, mailto:dolmen@cpan.org

COPYRIGHT & LICENCE

Copyright © 2013 Olivier Mengué.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself.