3 use Test::More tests => 14;
5 use Devel::Size qw(size total_size);
7 can_ok ('Devel::Size', qw/
12 die ("Uhoh, test uses an outdated version of Devel::Size")
13 unless is ($Devel::Size::VERSION, '0.72_52', 'VERSION MATCHES');
15 #############################################################################
18 use vars qw($foo @foo %foo);
21 %foo = (a => 1, b => 2);
24 my $y = "A much much longer string"; # need to be at least 7 bytes longer for 64 bit
25 cmp_ok(size($x), '<', size($y), 'size() of strings');
26 cmp_ok(total_size($x), '<', total_size($y), 'total_size() of strings');
31 my $size_1 = total_size(\@x);
32 my $size_2 = total_size(\@y);
34 cmp_ok($size_1, '<', $size_2, 'size() of array refs');
36 # the arrays alone shouldn't be the same size
40 isnt ( $size_1, $size_2, 'size() of array refs');
42 #############################################################################
43 # IV vs IV+PV (bug #17586)
51 cmp_ok($size_1, '<', $size_2, ' ."" makes string longer');
53 #############################################################################
54 # check that the tracking_hash is working
57 my @ary1 = (\$a, \$a);
58 my @ary2 = (\$a, \$b);
60 cmp_ok(total_size(\@ary1), '<', total_size(\@ary2),
61 'the tracking hash is working');
63 #############################################################################
64 # check that circular references don't mess things up
66 my($c1,$c2); $c2 = \$c1; $c1 = \$c2;
68 is (total_size($c1), total_size($c2), 'circular references');
70 #############################################################################
73 cmp_ok(total_size(*foo), '>', 0, 'total_size(*foo) > 0');
75 #############################################################################
78 my $code = sub { '1' };
80 cmp_ok(total_size($code), '>', 0, 'total_size($code) > 0');
82 ##########################################################
83 # RT#14849 (& RT#26781 and possibly RT#29238?)
84 cmp_ok( total_size( sub{ do{ my $t=0 }; } ), '>', 0,
85 'total_size( sub{ my $t=0 } ) > 0' );
87 # CPAN RT #58484 and #58485
88 cmp_ok(total_size(\&total_size), '>', 0, 'total_size(\&total_size) > 0');
90 use constant LARGE => 'N' x 8192;
92 cmp_ok (total_size(\&LARGE), '>', 8192,
93 'total_size for a constant includes the constant');