Commit | Line | Data |
0430b7f7 |
1 | #!/usr/bin/perl -w |
e98cedbf |
2 | |
0430b7f7 |
3 | use Test::More; |
4 | use strict; |
5 | |
6 | my $tests; |
e98cedbf |
7 | |
0430b7f7 |
8 | BEGIN |
9 | { |
10 | chdir 't' if -d 't'; |
11 | plan tests => 13; |
e98cedbf |
12 | |
0430b7f7 |
13 | use lib '../lib'; |
14 | use lib '../blib/arch'; |
15 | use_ok('Devel::Size'); |
16 | } |
e98cedbf |
17 | |
0430b7f7 |
18 | can_ok ('Devel::Size', qw/ |
19 | size |
20 | total_size |
21 | /); |
e98cedbf |
22 | |
0430b7f7 |
23 | Devel::Size->import( qw(size total_size) ); |
24 | |
25 | die ("Uhoh, test uses outdated version of Devel::Size") |
b1e5ad85 |
26 | unless is ($Devel::Size::VERSION, '0.67', 'VERSION MATCHES'); |
0430b7f7 |
27 | |
28 | ############################################################################# |
29 | # some basic checks: |
e98cedbf |
30 | |
5073b933 |
31 | use vars qw($foo @foo %foo); |
32 | $foo = "12"; |
33 | @foo = (1,2,3); |
34 | %foo = (a => 1, b => 2); |
b98fcdb9 |
35 | |
36 | my $x = "A string"; |
0430b7f7 |
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'); |
b98fcdb9 |
40 | |
41 | my @x = (1..4); |
0430b7f7 |
42 | my @y = (1..200); |
43 | |
44 | my $size_1 = total_size(\@x); |
45 | my $size_2 = total_size(\@y); |
46 | |
47 | ok ( $size_1 < $size_2, 'size() of array refs'); |
48 | ok (total_size(\@x) < total_size(\@y), 'total_size() of array refs'); |
49 | |
50f7a785 |
50 | # the arrays alone shouldn't be the same size |
0430b7f7 |
51 | $size_1 = size(\@x); |
52 | $size_2 = size(\@y); |
53 | |
50f7a785 |
54 | isnt ( $size_1, $size_2, 'size() of array refs'); |
0430b7f7 |
55 | |
56 | ############################################################################# |
57 | # IV vs IV+PV (bug #17586) |
b98fcdb9 |
58 | |
0430b7f7 |
59 | $x = 12; |
60 | $y = 12; $y .= ''; |
b98fcdb9 |
61 | |
0430b7f7 |
62 | $size_1 = size($x); |
63 | $size_2 = size($y); |
b98fcdb9 |
64 | |
0430b7f7 |
65 | ok ($size_1 < $size_2, ' ."" makes string longer'); |
66 | |
67 | ############################################################################# |
78dfb4e7 |
68 | # check that the tracking_hash is working |
69 | |
70 | my($a,$b) = (1,2); |
71 | my @ary1 = (\$a, \$a); |
72 | my @ary2 = (\$a, \$b); |
73 | |
0430b7f7 |
74 | isnt ( total_size(\@ary2) - total_size(\@ary1), 0, |
75 | 'total_size(\@ary1) < total_size(\@ary2)'); |
78dfb4e7 |
76 | |
0430b7f7 |
77 | ############################################################################# |
78dfb4e7 |
78 | # check that circular references don't mess things up |
79 | |
80 | my($c1,$c2); $c2 = \$c1; $c1 = \$c2; |
81 | |
0430b7f7 |
82 | is (total_size($c1), total_size($c2), 'circular references'); |
83 | |
84 | ############################################################################# |
85 | # GLOBS |
86 | |
87 | isnt (total_size(*foo), 0, 'total_size(*foo) > 0'); |
88 | |
89 | ############################################################################# |
90 | # CODE ref |
91 | |
92 | my $code = sub { '1' }; |
93 | |
94 | isnt (total_size($code), 0, 'total_size($code) > 0'); |