12 use lib '../blib/arch';
13 use_ok('Devel::Size');
16 can_ok ('Devel::Size', qw/
21 Devel::Size->import( qw(size total_size) );
23 die ("Uhoh, test uses an outdated version of Devel::Size")
24 unless is ($Devel::Size::VERSION, '0.72_50', 'VERSION MATCHES');
26 #############################################################################
29 use vars qw($foo @foo %foo);
32 %foo = (a => 1, b => 2);
35 my $y = "A much much longer string"; # need to be at least 7 bytes longer for 64 bit
36 cmp_ok(size($x), '<', size($y), 'size() of strings');
37 cmp_ok(total_size($x), '<', total_size($y), 'total_size() of strings');
42 my $size_1 = total_size(\@x);
43 my $size_2 = total_size(\@y);
45 cmp_ok($size_1, '<', $size_2, 'size() of array refs');
47 # the arrays alone shouldn't be the same size
51 isnt ( $size_1, $size_2, 'size() of array refs');
53 #############################################################################
54 # IV vs IV+PV (bug #17586)
62 cmp_ok($size_1, '<', $size_2, ' ."" makes string longer');
64 #############################################################################
65 # check that the tracking_hash is working
68 my @ary1 = (\$a, \$a);
69 my @ary2 = (\$a, \$b);
71 isnt ( total_size(\@ary2) - total_size(\@ary1), 0,
72 'total_size(\@ary1) < total_size(\@ary2)');
74 #############################################################################
75 # check that circular references don't mess things up
77 my($c1,$c2); $c2 = \$c1; $c1 = \$c2;
79 is (total_size($c1), total_size($c2), 'circular references');
81 #############################################################################
84 isnt (total_size(*foo), 0, 'total_size(*foo) > 0');
86 #############################################################################
89 my $code = sub { '1' };
91 isnt (total_size($code), 0, 'total_size($code) > 0');
93 ##########################################################
94 # RT#14849 (& RT#26781 and possibly RT#29238?)
95 isnt( total_size( sub{ do{ my $t=0 }; } ), 0, 'total_size( sub{ my $t=0 } ) > 0' );
97 # CPAN RT #58484 and #58485
98 isnt (total_size(\&total_size), 0, 'total_size(\&total_size) > 0');
100 use constant LARGE => 'N' x 8192;
102 cmp_ok (total_size(\&LARGE), '>', 8192,
103 'total_size for a constant includes the constant');