14 use lib '../blib/arch';
15 use_ok('Devel::Size');
18 can_ok ('Devel::Size', qw/
23 Devel::Size->import( qw(size total_size) );
25 die ("Uhoh, test uses an outdated version of Devel::Size")
26 unless is ($Devel::Size::VERSION, '0.72_50', 'VERSION MATCHES');
28 #############################################################################
31 use vars qw($foo @foo %foo);
34 %foo = (a => 1, b => 2);
37 my $y = "A much much longer string"; # need to be at least 7 bytes longer for 64 bit
38 ok (size($x) < size($y), 'size() of strings');
39 ok (total_size($x) < total_size($y), 'total_size() of strings');
44 my $size_1 = total_size(\@x);
45 my $size_2 = total_size(\@y);
47 ok ( $size_1 < $size_2, 'size() of array refs');
49 # the arrays alone shouldn't be the same size
53 isnt ( $size_1, $size_2, 'size() of array refs');
55 #############################################################################
56 # IV vs IV+PV (bug #17586)
64 ok ($size_1 < $size_2, ' ."" makes string longer');
66 #############################################################################
67 # check that the tracking_hash is working
70 my @ary1 = (\$a, \$a);
71 my @ary2 = (\$a, \$b);
73 isnt ( total_size(\@ary2) - total_size(\@ary1), 0,
74 'total_size(\@ary1) < total_size(\@ary2)');
76 #############################################################################
77 # check that circular references don't mess things up
79 my($c1,$c2); $c2 = \$c1; $c1 = \$c2;
81 is (total_size($c1), total_size($c2), 'circular references');
83 #############################################################################
86 isnt (total_size(*foo), 0, 'total_size(*foo) > 0');
88 #############################################################################
91 my $code = sub { '1' };
93 isnt (total_size($code), 0, 'total_size($code) > 0');
95 ##########################################################
96 # RT#14849 (& RT#26781 and possibly RT#29238?)
97 isnt( total_size( sub{ do{ my $t=0 }; } ), 0, 'total_size( sub{ my $t=0 } ) > 0' );