import Devel-Size 0.64 from CPAN
[p5sagit/Devel-Size.git] / t / basic.t
CommitLineData
e98cedbf 1# Before `make install' is performed this script should be runnable with
2# `make test'. After `make install' it should work as `perl test.pl'
3
4######################### We start with some black magic to print on failure.
5
6# Change 1..1 below to 1..last_test_to_print .
7# (It may become useful if the test is moved to ./t subdirectory.)
8
5073b933 9BEGIN { $| = 1; print "1..8\n"; }
e98cedbf 10END {print "not ok 1\n" unless $loaded;}
b98fcdb9 11use Devel::Size qw(size total_size);
e98cedbf 12$loaded = 1;
13print "ok 1\n";
14
15######################### End of black magic.
16
17# Insert your test code below (better if it prints "ok 13"
18# (correspondingly "not ok 13") depending on the success of chunk 13
19# of the test code):
20
5073b933 21use vars qw($foo @foo %foo);
22$foo = "12";
23@foo = (1,2,3);
24%foo = (a => 1, b => 2);
b98fcdb9 25
26my $x = "A string";
27my $y = "A longer string";
28if (size($x) < size($y)) {
29 print "ok 2\n";
30} else {
31 print "not ok 2\n";
32}
33
34if (total_size($x) < total_size($y)) {
35 print "ok 3\n";
36} else {
37 print "not ok 3\n";
38}
39
40my @x = (1..4);
41my @y = (1..10);
42
43if (size(\@x) < size(\@y)) {
44 print "ok 4\n";
45} else {
46 print "not ok 4\n";
47}
48
49if (total_size(\@x) < total_size(\@y)) {
50 print "ok 5\n";
51} else {
52 print "not ok 5\n";
53}
54
78dfb4e7 55# check that the tracking_hash is working
56
57my($a,$b) = (1,2);
58my @ary1 = (\$a, \$a);
59my @ary2 = (\$a, \$b);
60
61if (total_size(\@ary1) < total_size(\@ary2)) {
62 print "ok 6\n";
63} else {
64 print "not ok 6\n";
65}
66
67# check that circular references don't mess things up
68
69my($c1,$c2); $c2 = \$c1; $c1 = \$c2;
70
71if( total_size($c1) == total_size($c2) ) {
72 print "ok 7\n";
73} else {
74 print "not ok 7\n";
75}
76
5073b933 77if (total_size(*foo)) {
78 print "ok 8\n";
79} else {
80 print "not ok 8\n";
81}