X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fcode.t;h=8b32e375543db2f49943d4b9c0805fb9ed99d3cb;hb=e7d68377a1b22679251b1906740296455bb0f8c6;hp=3ac711ade3da8598c317af2c031dca3500978e4b;hpb=219b7d3497fb2c1bca6e63f521f61b725e5afc7d;p=p5sagit%2FDevel-Size.git diff --git a/t/code.t b/t/code.t index 3ac711a..8b32e37 100644 --- a/t/code.t +++ b/t/code.t @@ -1,7 +1,7 @@ #!/usr/bin/perl -w use strict; -use Test::More tests => 12; +use Test::More tests => 14; use Devel::Size ':all'; sub zwapp; @@ -15,8 +15,13 @@ 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)'); +if("$]" >= 5.017) { + cmp_ok($zwapp_size, '==', $whack_size, + 'CV stubbed at compiletime is the same size'); +} else { + 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'); @@ -30,13 +35,16 @@ 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'); -{ +SKIP: { use vars '@b'; my $aelemfast_lex = total_size(sub {my @a; $a[0]}); my $aelemfast = total_size(sub {my @a; $b[0]}); + # This one is sane even before Dave's lexical aelemfast changes: cmp_ok($aelemfast_lex, '>', $anon_size, 'aelemfast for a lexical is handled correctly'); + skip('alemfast was extended to lexicals after this perl was released', 1) + if $] < 5.008004; cmp_ok($aelemfast, '>', $aelemfast_lex, 'aelemfast for a package variable is larger'); } @@ -45,3 +53,39 @@ my $short_pvop = total_size(sub {goto GLIT}); my $long_pvop = total_size(sub {goto KREEK_KREEK_CLANK_CLANK}); cmp_ok($short_pvop, '>', $anon_size, 'OPc_PVOP can be measured'); is($long_pvop, $short_pvop + 19, 'the only size difference is the label length'); + +sub bloop { + my $clunk = shift; + if (--$clunk > 0) { + bloop($clunk); + } +} + +my $before_size = total_size(\&bloop); +bloop(42); +my $after_size = total_size(\&bloop); + +cmp_ok($after_size, '>', $before_size, 'Recursion increases the PADLIST'); + +sub closure_with_eval { + my $a; + return sub { eval ""; $a }; +} + +sub closure_without_eval { + my $a; + return sub { require ""; $a }; +} + +if ($] > 5.017001) { + # Again relying too much on the core's implementation, but while that holds, + # this does test that CvOUTSIDE() is being followed. + cmp_ok(total_size(closure_with_eval()), '>', + total_size(closure_without_eval()) + 256, + 'CvOUTSIDE is now NULL on cloned closures, unless they have eval'); +} else { + # Seems that they differ by a few bytes on 5.8.x + cmp_ok(total_size(closure_with_eval()), '<=', + total_size(closure_without_eval()) + 256, + "CvOUTSIDE is set on all cloned closures, so these won't differ by much"); +}