7 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
8 print "1..0 # Skip -- Perl configured without B module\n";
16 use Test::More tests => 14;
21 my $file = 'xreftest.out';
23 open SAVEOUT, ">&STDOUT" or diag $!;
26 our $compilesub = B::Xref::compile("-o$file");
27 ok( ref $compilesub eq 'CODE', "compile() returns a coderef ($compilesub)" );
28 $compilesub->(); # Compile this test script
30 open STDOUT, ">&SAVEOUT" or diag $!;
32 # Now parse the output
34 my ($curfile, $cursub, $curpack) = ('') x 3;
36 open XREF, $file or die "# Can't open $file: $!\n";
41 } elsif (/^ Subroutine (.*)/) {
43 } elsif (/^ Package (.*)/) {
45 } elsif ($curpack eq '?' && /^ (".*") +(.*)/
46 or /^ (\S+)\s+(.*)/) {
47 $xreftable{$curfile}{$cursub}{$curpack}{$1} = $2;
51 my $thisfile = __FILE__;
54 defined $xreftable{$thisfile}{'(main)'}{main}{'$compilesub'},
55 '$compilesub present in main program'
58 $xreftable{$thisfile}{'(main)'}{main}{'$compilesub'},
60 '$compilesub introduced at line 100'
63 $xreftable{$thisfile}{'(main)'}{main}{'$compilesub'},
65 '$compilesub coderef called at line 102'
68 defined $xreftable{$thisfile}{'(main)'}{'(lexical)'}{'$curfile'},
69 '$curfile present in main program'
72 $xreftable{$thisfile}{'(main)'}{'(lexical)'}{'$curfile'},
74 '$curfile introduced at line 200'
77 defined $xreftable{$thisfile}{'(main)'}{main}{'%xreftable'},
78 '$xreftable present in main program'
81 defined $xreftable{$thisfile}{'Testing::Xref::foo'}{main}{'%xreftable'},
82 '$xreftable used in subroutine bar'
85 $xreftable{$thisfile}{'(main)'}{main}{'&use_ok'}, '&50',
86 'use_ok called at line 50'
89 $xreftable{$thisfile}{'(definitions)'}{'Testing::Xref'}{'&foo'}, 's1001',
90 'subroutine foo defined at line 1001'
93 $xreftable{$thisfile}{'(definitions)'}{'Testing::Xref'}{'&bar'}, 's1002',
94 'subroutine bar defined at line 1002'
97 $xreftable{$thisfile}{'Testing::Xref::bar'}{'Testing::Xref'}{'&foo'},
98 '&1002', 'subroutine foo called at line 1002 by bar'
101 $xreftable{$thisfile}{'Testing::Xref::foo'}{'Testing::Xref'}{'*FOO'},
102 '1001', 'glob FOO used in subroutine foo'
106 1 while unlink $file;
110 # Now some stuff to feed B::Xref
113 package Testing::Xref;
114 sub foo { print FOO %::xreftable; }
115 sub bar { print FOO foo; }