File: 14-subinfo.t

package info (click to toggle)
libdevel-nytprof-perl 6.12%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,552 kB
  • sloc: perl: 5,616; javascript: 4,033; ansic: 107; makefile: 23
file content (93 lines) | stat: -rw-r--r-- 3,236 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use strict;
use warnings;
use Carp;
use Config qw(%Config);
use Devel::NYTProf::Reader;
use Test::More;
use Devel::NYTProf::Constants qw(
    NYTP_DEFAULT_COMPRESSION
    NYTP_ZLIB_VERSION
);

plan skip_all => "needs different profile data for testing on longdouble builds"
    if (defined $Config{uselongdouble} and $Config{uselongdouble} eq 'define');

plan skip_all => "needs different profile data for testing on quadmath builds"
    if (defined $Config{usequadmath} and $Config{usequadmath} eq 'define');

my $file = "./t/nytprof_14-subinfo.out.txt";
croak "No $file" unless -f $file;

plan skip_all => "$file doesn't work unless NYTP_ZLIB_VERSION is set" unless NYTP_ZLIB_VERSION();

# General setup

my $reporter = Devel::NYTProf::Reader->new($file, { quiet => 1 });
ok(defined $reporter, "Devel::NYTProf::Reader->new returned defined entity");
isa_ok($reporter, 'Devel::NYTProf::Reader');

my $profile = $reporter->{profile};
isa_ok($profile, 'Devel::NYTProf::Data');

my ($pkgref, $subinfo_obj, @keys, $expect);

$pkgref = $profile->package_subinfo_map(0,1);
is(ref($pkgref), 'HASH',
    "Devel::NYTProf::Data->package_subinfo_map(0,1) returned hashref");
@keys = keys %{$pkgref};
is(@keys, 1, "1-element hash");
$expect = 'main';
is($keys[0], $expect, "Sole element is '$expect'");
isa_ok($pkgref->{$expect}{""}[0], 'Devel::NYTProf::SubInfo');
$subinfo_obj = $pkgref->{$expect}{""}[0];
isa_ok($subinfo_obj, 'Devel::NYTProf::SubInfo');

## Covered, but not explicitly:
## recur_max_depth
## recur_incl_time
## cache

$expect = 1;
is($subinfo_obj->fid, $expect, "Got expected fid");

my ($fl,
    $ll, $calls);

$fl = $subinfo_obj->first_line;
ok(($fl =~ m/^\d+/ and $fl >= 0), "first_line() returned non-negative integer");
$ll = $subinfo_obj->last_line;
ok(($ll =~ m/^\d+/ and $fl >= 0), "last_line() returned non-negative integer");
$calls = $subinfo_obj->calls;
ok(($calls =~ m/^\d+/ and $fl >= 0), "calls() returned non-negative integer");

my ($subname, $package, $without);
$subname = $subinfo_obj->subname;
($package, $without) = split '::', $subname, 2;
is($package, 'main', "subname() returned expected package");
is($subinfo_obj->subname_without_package, $without,
    "subname_without_package() returned expected name");
is($subinfo_obj->package, $package,
    "package() returned expected package");

$profile = $subinfo_obj->profile;
is(ref($profile), 'Devel::NYTProf::Data',
    "profile() returns Devel::NYTProf::Data object");

ok(defined($subinfo_obj->incl_time), "incl_time() returned defined value");
ok(defined($subinfo_obj->excl_time), "excl_time() returned defined value");
ok(defined($subinfo_obj->recur_max_depth), "recur_max_depth() returned defined value");
ok(defined($subinfo_obj->recur_incl_time), "recur_incl_time() returned defined value");
is(ref($subinfo_obj->cache), 'HASH', "cache() returned hash ref");

my @caller_places = $subinfo_obj->caller_places;
for my $c (@caller_places) {
    is(ref($c), 'ARRAY',
        "each element of any returned by caller_places() is an array ref");
}
is($subinfo_obj->caller_count, scalar(@caller_places),
    "caller_count() returned expected count");

my $fileinfo = $subinfo_obj->fileinfo;
isa_ok($fileinfo, 'Devel::NYTProf::FileInfo');

done_testing();