Debian Codegraph @

t/42-global.t

raw symbols SCIP
1 use strictscip-perl cpan Devel-NYTProf 6.15 strict/;
2 use warningsscip-perl cpan Devel-NYTProf 6.15 warnings/;
3 # Tests CORE::GLOBAL::foo plus assorted data model methods
4
5 use Test::Morescip-perl cpan Devel-NYTProf 6.15 Test/More/;
6 use libscip-perl cpan Devel-NYTProf 6.15 lib/ '/home/travis/perl5'; # travis workaround https://travis-ci.org/timbunce/devel-nytprof/jobs/35285944
7 use Test::Differencesscip-perl cpan Devel-NYTProf 6.15 Test/Differences/;
8
9 use libscip-perl cpan Devel-NYTProf 6.15 lib/ qw(t/lib);
10 use NYTProfTestscip-perl cpan Devel-NYTProf 6.15 NYTProfTest/;
11
12 use Devel::NYTProf::Runscip-perl cpan Devel-NYTProf 6.15 Devel/NYTProf/Run/ qw(profile_this);
13
14 my $pre589 = ($]scip-perl cpan Devel-NYTProf 6.15 main/`$]`. < 5.008009 or $]scip-perl cpan Devel-NYTProf 6.15 main/`$]`. eq "5.010000");
15
16 my $src_code = joinscip-perl cpan Devel-NYTProf 6.15 main/join().("", <DATA>);
17
18 run_test_groupscip-perl cpan Devel-NYTProf 6.15 main/run_test_group().( {
19 extra_options => { start => 'begin' },
20 extra_test_count => 17,
21 extra_test_code => sub {
22 my ($profile, $env) = @_scip-perl cpan Devel-NYTProf 6.15 main/`@_`.;
23
24 $profile = profile_thisscip-perl cpan Devel-NYTProf 6.15 Devel/NYTProf/Run/profile_this().(
25 src_code => $src_code,
26 out_file => $env->{file},
27 skip_sitecustomize => 1,
28 );
29 isa_okscip-perl cpan Devel-NYTProf 6.15 main/isa_ok(). $profile, 'Devel::NYTProf::Data';
30
31 my $subs1 = $profile->subname_subinfo_mapscip-perl cpan Devel-NYTProf 6.15 main/subname_subinfo_map().;
32
33 my $begin = ($pre589) ? 'main::BEGIN' : 'main::BEGIN@4';
34 okscip-perl cpan Devel-NYTProf 6.15 main/ok(). $subs1->{$begin};
35 okscip-perl cpan Devel-NYTProf 6.15 main/ok(). $subs1->{'main::RUNTIME'};
36 okscip-perl cpan Devel-NYTProf 6.15 main/ok(). $subs1->{'main::foo'};
37
38 my @fi = $profile->all_fileinfosscip-perl cpan Devel-NYTProf 6.15 main/all_fileinfos().;
39 isscip-perl cpan Devel-NYTProf 6.15 main/is(). @fi, 1, 'should be 1 fileinfo';
40 my $fid = $fi[0]->fidscip-perl cpan Devel-NYTProf 6.15 main/fid().;
41
42 my @a; # ($file, $fid, $first, $last);
43 @a = $profile->file_line_range_of_subscip-perl cpan Devel-NYTProf 6.15 main/file_line_range_of_sub().($begin);
44 isscip-perl cpan Devel-NYTProf 6.15 main/is(). "$a[1] $a[2] $a[3]", "$fid 4 7", "details for $begin should match";
45 @a = $profile->file_line_range_of_subscip-perl cpan Devel-NYTProf 6.15 main/file_line_range_of_sub().('main::RUNTIME');
46 isscip-perl cpan Devel-NYTProf 6.15 main/is(). "$a[1] $a[2] $a[3]", "$fid 1 1", 'details for main::RUNTIME should match';
47 @a = $profile->file_line_range_of_subscip-perl cpan Devel-NYTProf 6.15 main/file_line_range_of_sub().('main::foo');
48 isscip-perl cpan Devel-NYTProf 6.15 main/is(). "$a[1] $a[2] $a[3]", "$fid 2 2", 'details for main::foo should match';
49
50 my $subs2 = $profile->subs_defined_in_filescip-perl cpan Devel-NYTProf 6.15 main/subs_defined_in_file().($fid);
51
52 eq_or_diff [ sortscip-perl cpan Devel-NYTProf 6.15 main/sort(). keysscip-perl cpan Devel-NYTProf 6.15 main/keys(). %$subs2 ], [ sortscip-perl cpan Devel-NYTProf 6.15 main/sort(). keysscip-perl cpan Devel-NYTProf 6.15 main/keys(). %$subs1 ],
53 'keys from subname_subinfo_map and subs_defined_in_file should match';
54
55 my @begins = grepscip-perl cpan Devel-NYTProf 6.15 main/grep(). { $_scip-perl cpan Devel-NYTProf 6.15 main/$_.->subnamescip-perl cpan Devel-NYTProf 6.15 main/subname(). =~ /\bBEGIN\b/ } valuesscip-perl cpan Devel-NYTProf 6.15 main/values(). %$subs2;
56 if ($pre589) { # we only see one sub and we don't see it called
57 isscip-perl cpan Devel-NYTProf 6.15 main/is(). @begins, 1, 'number of BEGIN subs';
58 isscip-perl cpan Devel-NYTProf 6.15 main/is(). grepscip-perl cpan Devel-NYTProf 6.15 main/grep().({ $_scip-perl cpan Devel-NYTProf 6.15 main/$_.->callsscip-perl cpan Devel-NYTProf 6.15 main/calls(). == 1 } @begins), 0, 'BEGIN has no calls';
59 }
60 else {
61 isscip-perl cpan Devel-NYTProf 6.15 main/is(). @begins, 3, 'number of BEGIN subs';
62 isscip-perl cpan Devel-NYTProf 6.15 main/is(). grepscip-perl cpan Devel-NYTProf 6.15 main/grep().({ $_scip-perl cpan Devel-NYTProf 6.15 main/$_.->callsscip-perl cpan Devel-NYTProf 6.15 main/calls(). == 1 } @begins), scalarscip-perl cpan Devel-NYTProf 6.15 main/scalar(). @begins,
63 'all BEGINs should be called just once';
64 }
65
66 my $sub;
67 ok $sub = $subs2->{'main::RUNTIME'};
68 isscip-perl cpan Devel-NYTProf 6.15 main/is(). $sub->callsscip-perl cpan Devel-NYTProf 6.15 main/calls()., 0, 'main::RUNTIME should be called 0 times';
69 ok $sub = $subs2->{'main::foo'};
70 isscip-perl cpan Devel-NYTProf 6.15 main/is(). $sub->callsscip-perl cpan Devel-NYTProf 6.15 main/calls()., 2, 'main::foo should be called 2 times';
71
72 okscip-perl cpan Devel-NYTProf 6.15 main/ok(). my $called_by_subnames = $sub->called_by_subnamesscip-perl cpan Devel-NYTProf 6.15 main/called_by_subnames().;
73 isscip-perl cpan Devel-NYTProf 6.15 main/is(). keysscip-perl cpan Devel-NYTProf 6.15 main/keys(). %$called_by_subnames, 2, 'should be called from 2 subs';
74
75 },
76 });
77
78 __DATA__
79 #!perl
80 sub foo { 42 }
81 BEGIN { 'b' } BEGIN { 'c' } # two on same line
82 BEGIN { # BEGIN@3
83 foo(2);
84 *CORE::GLOBAL::sleep = \&foo;
85 }
86 sleep 1;
87