9 use Test::More tests => 14;
14 my $file = 'xreftest.out';
17 our $compilesub = B::Xref::compile("-o$file");
18 ok( ref $compilesub eq 'CODE', "compile() returns a coderef ($compilesub)" );
19 $compilesub->(); # Compile this test script
21 #END { unlink $file or diag "END block failed: $!" }
23 # Now parse the output
25 my ($curfile, $cursub, $curpack) = ('') x 3;
27 open XREF, $file or die "# Can't open $file: $!\n";
32 } elsif (/^ Subroutine (.*)/) {
34 } elsif (/^ Package (.*)/) {
36 } elsif ($curpack eq '?' && /^ (".*") +(.*)/
37 or /^ (\S+)\s+(.*)/) {
38 $xreftable{$curfile}{$cursub}{$curpack}{$1} = $2;
42 my $thisfile = __FILE__;
45 defined $xreftable{$thisfile}{'(main)'}{main}{'$compilesub'},
46 '$compilesub present in main program'
49 $xreftable{$thisfile}{'(main)'}{main}{'$compilesub'},
51 '$compilesub introduced at line 100'
54 $xreftable{$thisfile}{'(main)'}{main}{'$compilesub'},
56 '$compilesub coderef called at line 102'
59 defined $xreftable{$thisfile}{'(main)'}{'(lexical)'}{'$curfile'},
60 '$curfile present in main program'
63 $xreftable{$thisfile}{'(main)'}{'(lexical)'}{'$curfile'},
65 '$curfile introduced at line 200'
68 defined $xreftable{$thisfile}{'(main)'}{main}{'%xreftable'},
69 '$xreftable present in main program'
72 defined $xreftable{$thisfile}{'Testing::Xref::foo'}{main}{'%xreftable'},
73 '$xreftable used in subroutine bar'
76 $xreftable{$thisfile}{'(main)'}{main}{'&use_ok'}, '&50',
77 'use_ok called at line 50'
80 $xreftable{$thisfile}{'(definitions)'}{'Testing::Xref'}{'&foo'}, 's1001',
81 'subroutine foo defined at line 1001'
84 $xreftable{$thisfile}{'(definitions)'}{'Testing::Xref'}{'&bar'}, 's1002',
85 'subroutine bar defined at line 1002'
88 $xreftable{$thisfile}{'Testing::Xref::bar'}{'Testing::Xref'}{'&foo'},
89 '&1002', 'subroutine foo called at line 1002 by bar'
92 $xreftable{$thisfile}{'Testing::Xref::foo'}{'Testing::Xref'}{'*FOO'},
93 '1001', 'glob FOO used in subroutine foo'
97 # Now some stuff to feed B::Xref
100 package Testing::Xref;
101 sub foo { print FOO %::xreftable; }
102 sub bar { print FOO foo; }