3 use Test::More tests => 15;
5 use Devel::Size qw(size total_size);
6 use Scalar::Util qw(weaken);
8 can_ok ('Devel::Size', qw/
13 die ("Uhoh, test uses an outdated version of Devel::Size")
14 unless is ($Devel::Size::VERSION, '0.73', 'VERSION MATCHES');
16 #############################################################################
19 use vars qw($foo @foo %foo);
22 %foo = (a => 1, b => 2);
25 my $y = "A much much longer string"; # need to be at least 7 bytes longer for 64 bit
26 cmp_ok(size($x), '<', size($y), 'size() of strings');
27 cmp_ok(total_size($x), '<', total_size($y), 'total_size() of strings');
32 my $size_1 = total_size(\@x);
33 my $size_2 = total_size(\@y);
35 cmp_ok($size_1, '<', $size_2, 'size() of array refs');
37 # the arrays alone shouldn't be the same size
41 isnt ( $size_1, $size_2, 'size() of array refs');
43 #############################################################################
44 # IV vs IV+PV (bug #17586)
52 cmp_ok($size_1, '<', $size_2, ' ."" makes string longer');
54 #############################################################################
55 # check that the tracking_hash is working
58 my @ary1 = (\$a, \$a);
59 my @ary2 = (\$a, \$b);
61 cmp_ok(total_size(\@ary1), '<', total_size(\@ary2),
62 'the tracking hash is working');
64 #############################################################################
65 # check that circular references don't mess things up
67 my($c1,$c2); $c2 = \$c1; $c1 = \$c2;
69 is (total_size($c1), total_size($c2), 'circular references');
71 #############################################################################
74 cmp_ok(total_size(*foo), '>', 0, 'total_size(*foo) > 0');
76 #############################################################################
79 my $code = sub { '1' };
81 cmp_ok(total_size($code), '>', 0, 'total_size($code) > 0');
83 ##########################################################
84 # RT#14849 (& RT#26781 and possibly RT#29238?)
85 cmp_ok( total_size( sub{ do{ my $t=0 }; } ), '>', 0,
86 'total_size( sub{ my $t=0 } ) > 0' );
88 # CPAN RT #58484 and #58485
89 cmp_ok(total_size(\&total_size), '>', 0, 'total_size(\&total_size) > 0');
91 use constant LARGE => 'N' x 8192;
93 cmp_ok (total_size(\&LARGE), '>', 8192,
94 'total_size for a constant includes the constant');
100 cmp_ok(total_size($a), '>', total_size([]),
101 'making a weakref upgrades the target to PVMG and adds magic');