From: Nicholas Clark Date: Sat, 23 Apr 2011 17:48:36 +0000 (+0100) Subject: Add tests for subroutines and subroutine references. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=57fcdb5b2135b53c38a100282adcf8a239eb918c;p=p5sagit%2FDevel-Size.git Add tests for subroutines and subroutine references. --- diff --git a/MANIFEST b/MANIFEST index b30e339..7efbd38 100644 --- a/MANIFEST +++ b/MANIFEST @@ -8,6 +8,7 @@ README Size.xs ppport.h t/basic.t +t/code.t t/globs.t t/pod.t t/pod_cov.t diff --git a/t/basic.t b/t/basic.t index e9e5bd7..8bbfa3e 100644 --- a/t/basic.t +++ b/t/basic.t @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -use Test::More tests => 17; +use Test::More tests => 16; use strict; use Devel::Size qw(size total_size); use Scalar::Util qw(weaken); @@ -68,13 +68,6 @@ my($c1,$c2); $c2 = \$c1; $c1 = \$c2; is (total_size($c1), total_size($c2), 'circular references'); -############################################################################# -# CODE ref - -my $code = sub { '1' }; - -cmp_ok(total_size($code), '>', 0, 'total_size($code) > 0'); - ########################################################## # RT#14849 (& RT#26781 and possibly RT#29238?) cmp_ok( total_size( sub{ do{ my $t=0 }; } ), '>', 0, diff --git a/t/code.t b/t/code.t new file mode 100644 index 0000000..65aca0e --- /dev/null +++ b/t/code.t @@ -0,0 +1,31 @@ +#!/usr/bin/perl -w + +use strict; +use Test::More tests => 8; +use Devel::Size ':all'; + +sub zwapp; +sub swoosh($$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$); +sub crunch { +} + +my $whack_size = total_size(\&whack); +my $zwapp_size = total_size(\&zwapp); +my $swoosh_size = total_size(\&swoosh); +my $crunch_size = total_size(\&crunch); + +cmp_ok($whack_size, '>', 0, 'CV generated at runtime has a size'); +cmp_ok($zwapp_size, '>', $whack_size, + 'CV stubbed at compiletime is larger (CvOUTSIDE is set and followed)'); +cmp_ok(length prototype \&swoosh, '>', 0, 'prototype has a length'); +cmp_ok($swoosh_size, '>', $zwapp_size + length prototype \&swoosh, + 'prototypes add to the size'); +cmp_ok($crunch_size, '>', $zwapp_size, 'sub bodies add to the size'); + +my $anon_proto = sub ($$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$) {}; +my $anon_size = total_size(sub {}); +my $anon_proto_size = total_size($anon_proto); +cmp_ok($anon_size, '>', 0, 'anonymous subroutines have a size'); +cmp_ok(length prototype $anon_proto, '>', 0, 'prototype has a length'); +cmp_ok($anon_proto_size, '>', $anon_size + length prototype $anon_proto, + 'prototypes add to the size');