Commit | Line | Data |
---|---|---|
aa7facf2 | 1 | #!./perl |
f8d9d21f RGS |
2 | |
3 | BEGIN { | |
74517a3a | 4 | unshift @INC, 't'; |
9cd8f857 NC |
5 | require Config; |
6 | if (($Config::Config{'extensions'} !~ /\bB\b/) ){ | |
7 | print "1..0 # Skip -- Perl configured without B module\n"; | |
8 | exit 0; | |
9 | } | |
f8d9d21f RGS |
10 | } |
11 | ||
12 | use strict; | |
aa7facf2 RGS |
13 | use warnings; |
14 | no warnings 'once'; | |
f8d9d21f RGS |
15 | use Test::More tests => 14; |
16 | ||
17 | # line 50 | |
18 | use_ok( 'B::Xref' ); | |
19 | ||
20 | my $file = 'xreftest.out'; | |
21 | ||
aa7facf2 RGS |
22 | open SAVEOUT, ">&STDOUT" or diag $!; |
23 | close STDOUT; | |
f8d9d21f RGS |
24 | # line 100 |
25 | our $compilesub = B::Xref::compile("-o$file"); | |
5cc8528c | 26 | ok( ref $compilesub eq 'CODE', "compile() returns a coderef" ); |
f8d9d21f | 27 | $compilesub->(); # Compile this test script |
aa7facf2 RGS |
28 | close STDOUT; |
29 | open STDOUT, ">&SAVEOUT" or diag $!; | |
f8d9d21f RGS |
30 | |
31 | # Now parse the output | |
32 | # line 200 | |
33 | my ($curfile, $cursub, $curpack) = ('') x 3; | |
34 | our %xreftable = (); | |
35 | open XREF, $file or die "# Can't open $file: $!\n"; | |
36 | while (<XREF>) { | |
5cc8528c | 37 | print STDERR $_ if $ENV{PERL_DEBUG}; |
f8d9d21f RGS |
38 | chomp; |
39 | if (/^File (.*)/) { | |
40 | $curfile = $1; | |
41 | } elsif (/^ Subroutine (.*)/) { | |
42 | $cursub = $1; | |
43 | } elsif (/^ Package (.*)/) { | |
44 | $curpack = $1; | |
45 | } elsif ($curpack eq '?' && /^ (".*") +(.*)/ | |
46 | or /^ (\S+)\s+(.*)/) { | |
47 | $xreftable{$curfile}{$cursub}{$curpack}{$1} = $2; | |
48 | } | |
49 | } | |
50 | close XREF; | |
51 | my $thisfile = __FILE__; | |
52 | ||
53 | ok( | |
54 | defined $xreftable{$thisfile}{'(main)'}{main}{'$compilesub'}, | |
55 | '$compilesub present in main program' | |
56 | ); | |
57 | like( | |
58 | $xreftable{$thisfile}{'(main)'}{main}{'$compilesub'}, | |
59 | qr/\bi100\b/, | |
60 | '$compilesub introduced at line 100' | |
61 | ); | |
62 | like( | |
63 | $xreftable{$thisfile}{'(main)'}{main}{'$compilesub'}, | |
64 | qr/&102\b/, | |
65 | '$compilesub coderef called at line 102' | |
66 | ); | |
67 | ok( | |
68 | defined $xreftable{$thisfile}{'(main)'}{'(lexical)'}{'$curfile'}, | |
69 | '$curfile present in main program' | |
70 | ); | |
71 | like( | |
72 | $xreftable{$thisfile}{'(main)'}{'(lexical)'}{'$curfile'}, | |
73 | qr/\bi200\b/, | |
74 | '$curfile introduced at line 200' | |
75 | ); | |
76 | ok( | |
77 | defined $xreftable{$thisfile}{'(main)'}{main}{'%xreftable'}, | |
78 | '$xreftable present in main program' | |
79 | ); | |
80 | ok( | |
81 | defined $xreftable{$thisfile}{'Testing::Xref::foo'}{main}{'%xreftable'}, | |
82 | '$xreftable used in subroutine bar' | |
83 | ); | |
84 | is( | |
85 | $xreftable{$thisfile}{'(main)'}{main}{'&use_ok'}, '&50', | |
86 | 'use_ok called at line 50' | |
87 | ); | |
88 | is( | |
89 | $xreftable{$thisfile}{'(definitions)'}{'Testing::Xref'}{'&foo'}, 's1001', | |
90 | 'subroutine foo defined at line 1001' | |
91 | ); | |
92 | is( | |
93 | $xreftable{$thisfile}{'(definitions)'}{'Testing::Xref'}{'&bar'}, 's1002', | |
94 | 'subroutine bar defined at line 1002' | |
95 | ); | |
96 | is( | |
97 | $xreftable{$thisfile}{'Testing::Xref::bar'}{'Testing::Xref'}{'&foo'}, | |
98 | '&1002', 'subroutine foo called at line 1002 by bar' | |
99 | ); | |
100 | is( | |
101 | $xreftable{$thisfile}{'Testing::Xref::foo'}{'Testing::Xref'}{'*FOO'}, | |
102 | '1001', 'glob FOO used in subroutine foo' | |
103 | ); | |
104 | ||
886f8b0c JH |
105 | END { |
106 | 1 while unlink $file; | |
107 | } | |
108 | ||
f8d9d21f RGS |
109 | # End of tests. |
110 | # Now some stuff to feed B::Xref | |
111 | ||
112 | # line 1000 | |
113 | package Testing::Xref; | |
114 | sub foo { print FOO %::xreftable; } | |
115 | sub bar { print FOO foo; } | |
886f8b0c | 116 |