Stubbed subs no longer have CvOUTSIDE set.
[p5sagit/Devel-Size.git] / t / code.t
CommitLineData
57fcdb5b 1#!/usr/bin/perl -w
2
3use strict;
219b7d34 4use Test::More tests => 12;
57fcdb5b 5use Devel::Size ':all';
6
7sub zwapp;
8sub swoosh($$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$);
9sub crunch {
10}
11
12my $whack_size = total_size(\&whack);
13my $zwapp_size = total_size(\&zwapp);
14my $swoosh_size = total_size(\&swoosh);
15my $crunch_size = total_size(\&crunch);
16
17cmp_ok($whack_size, '>', 0, 'CV generated at runtime has a size');
75510c88 18if("$]" >= 5.017) {
19 cmp_ok($zwapp_size, '==', $whack_size,
20 'CV stubbed at compiletime is the same size');
21} else {
22 cmp_ok($zwapp_size, '>', $whack_size,
23 'CV stubbed at compiletime is larger (CvOUTSIDE is set and followed)');
24}
57fcdb5b 25cmp_ok(length prototype \&swoosh, '>', 0, 'prototype has a length');
26cmp_ok($swoosh_size, '>', $zwapp_size + length prototype \&swoosh,
27 'prototypes add to the size');
28cmp_ok($crunch_size, '>', $zwapp_size, 'sub bodies add to the size');
29
30my $anon_proto = sub ($$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$) {};
31my $anon_size = total_size(sub {});
32my $anon_proto_size = total_size($anon_proto);
33cmp_ok($anon_size, '>', 0, 'anonymous subroutines have a size');
34cmp_ok(length prototype $anon_proto, '>', 0, 'prototype has a length');
35cmp_ok($anon_proto_size, '>', $anon_size + length prototype $anon_proto,
36 'prototypes add to the size');
574d9fd9 37
4c229154 38SKIP: {
574d9fd9 39 use vars '@b';
40 my $aelemfast_lex = total_size(sub {my @a; $a[0]});
41 my $aelemfast = total_size(sub {my @a; $b[0]});
42
4c229154 43 # This one is sane even before Dave's lexical aelemfast changes:
574d9fd9 44 cmp_ok($aelemfast_lex, '>', $anon_size,
45 'aelemfast for a lexical is handled correctly');
4c229154 46 skip('alemfast was extended to lexicals after this perl was released', 1)
47 if $] < 5.008004;
574d9fd9 48 cmp_ok($aelemfast, '>', $aelemfast_lex,
49 'aelemfast for a package variable is larger');
50}
219b7d34 51
52my $short_pvop = total_size(sub {goto GLIT});
53my $long_pvop = total_size(sub {goto KREEK_KREEK_CLANK_CLANK});
54cmp_ok($short_pvop, '>', $anon_size, 'OPc_PVOP can be measured');
55is($long_pvop, $short_pvop + 19, 'the only size difference is the label length');