11 use Test::More tests => 14;
16 my $file = 'xreftest.out';
18 open SAVEOUT, ">&STDOUT" or diag $!;
21 our $compilesub = B::Xref::compile("-o$file");
22 ok( ref $compilesub eq 'CODE', "compile() returns a coderef ($compilesub)" );
23 $compilesub->(); # Compile this test script
25 open STDOUT, ">&SAVEOUT" or diag $!;
27 # Now parse the output
29 my ($curfile, $cursub, $curpack) = ('') x 3;
31 open XREF, $file or die "# Can't open $file: $!\n";
36 } elsif (/^ Subroutine (.*)/) {
38 } elsif (/^ Package (.*)/) {
40 } elsif ($curpack eq '?' && /^ (".*") +(.*)/
41 or /^ (\S+)\s+(.*)/) {
42 $xreftable{$curfile}{$cursub}{$curpack}{$1} = $2;
46 my $thisfile = __FILE__;
49 defined $xreftable{$thisfile}{'(main)'}{main}{'$compilesub'},
50 '$compilesub present in main program'
53 $xreftable{$thisfile}{'(main)'}{main}{'$compilesub'},
55 '$compilesub introduced at line 100'
58 $xreftable{$thisfile}{'(main)'}{main}{'$compilesub'},
60 '$compilesub coderef called at line 102'
63 defined $xreftable{$thisfile}{'(main)'}{'(lexical)'}{'$curfile'},
64 '$curfile present in main program'
67 $xreftable{$thisfile}{'(main)'}{'(lexical)'}{'$curfile'},
69 '$curfile introduced at line 200'
72 defined $xreftable{$thisfile}{'(main)'}{main}{'%xreftable'},
73 '$xreftable present in main program'
76 defined $xreftable{$thisfile}{'Testing::Xref::foo'}{main}{'%xreftable'},
77 '$xreftable used in subroutine bar'
80 $xreftable{$thisfile}{'(main)'}{main}{'&use_ok'}, '&50',
81 'use_ok called at line 50'
84 $xreftable{$thisfile}{'(definitions)'}{'Testing::Xref'}{'&foo'}, 's1001',
85 'subroutine foo defined at line 1001'
88 $xreftable{$thisfile}{'(definitions)'}{'Testing::Xref'}{'&bar'}, 's1002',
89 'subroutine bar defined at line 1002'
92 $xreftable{$thisfile}{'Testing::Xref::bar'}{'Testing::Xref'}{'&foo'},
93 '&1002', 'subroutine foo called at line 1002 by bar'
96 $xreftable{$thisfile}{'Testing::Xref::foo'}{'Testing::Xref'}{'*FOO'},
97 '1001', 'glob FOO used in subroutine foo'
101 1 while unlink $file;
105 # Now some stuff to feed B::Xref
108 package Testing::Xref;
109 sub foo { print FOO %::xreftable; }
110 sub bar { print FOO foo; }