Add tests for subroutines and subroutine references.
[p5sagit/Devel-Size.git] / t / code.t
CommitLineData
57fcdb5b 1#!/usr/bin/perl -w
2
3use strict;
4use Test::More tests => 8;
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');
18cmp_ok($zwapp_size, '>', $whack_size,
19 'CV stubbed at compiletime is larger (CvOUTSIDE is set and followed)');
20cmp_ok(length prototype \&swoosh, '>', 0, 'prototype has a length');
21cmp_ok($swoosh_size, '>', $zwapp_size + length prototype \&swoosh,
22 'prototypes add to the size');
23cmp_ok($crunch_size, '>', $zwapp_size, 'sub bodies add to the size');
24
25my $anon_proto = sub ($$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$) {};
26my $anon_size = total_size(sub {});
27my $anon_proto_size = total_size($anon_proto);
28cmp_ok($anon_size, '>', 0, 'anonymous subroutines have a size');
29cmp_ok(length prototype $anon_proto, '>', 0, 'prototype has a length');
30cmp_ok($anon_proto_size, '>', $anon_size + length prototype $anon_proto,
31 'prototypes add to the size');