re: long double vs. Tru64 UNIX
[p5sagit/p5-mst-13.2.git] / ext / B / t / xref.t
CommitLineData
f8d9d21f 1#!./perl -w
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = qw(../lib);
6}
7
8use strict;
9use Test::More tests => 14;
10
11# line 50
12use_ok( 'B::Xref' );
13
14my $file = 'xreftest.out';
15
16# line 100
17our $compilesub = B::Xref::compile("-o$file");
18ok( ref $compilesub eq 'CODE', "compile() returns a coderef ($compilesub)" );
19$compilesub->(); # Compile this test script
20
21#END { unlink $file or diag "END block failed: $!" }
22
23# Now parse the output
24# line 200
25my ($curfile, $cursub, $curpack) = ('') x 3;
26our %xreftable = ();
27open XREF, $file or die "# Can't open $file: $!\n";
28while (<XREF>) {
29 chomp;
30 if (/^File (.*)/) {
31 $curfile = $1;
32 } elsif (/^ Subroutine (.*)/) {
33 $cursub = $1;
34 } elsif (/^ Package (.*)/) {
35 $curpack = $1;
36 } elsif ($curpack eq '?' && /^ (".*") +(.*)/
37 or /^ (\S+)\s+(.*)/) {
38 $xreftable{$curfile}{$cursub}{$curpack}{$1} = $2;
39 }
40}
41close XREF;
42my $thisfile = __FILE__;
43
44ok(
45 defined $xreftable{$thisfile}{'(main)'}{main}{'$compilesub'},
46 '$compilesub present in main program'
47);
48like(
49 $xreftable{$thisfile}{'(main)'}{main}{'$compilesub'},
50 qr/\bi100\b/,
51 '$compilesub introduced at line 100'
52);
53like(
54 $xreftable{$thisfile}{'(main)'}{main}{'$compilesub'},
55 qr/&102\b/,
56 '$compilesub coderef called at line 102'
57);
58ok(
59 defined $xreftable{$thisfile}{'(main)'}{'(lexical)'}{'$curfile'},
60 '$curfile present in main program'
61);
62like(
63 $xreftable{$thisfile}{'(main)'}{'(lexical)'}{'$curfile'},
64 qr/\bi200\b/,
65 '$curfile introduced at line 200'
66);
67ok(
68 defined $xreftable{$thisfile}{'(main)'}{main}{'%xreftable'},
69 '$xreftable present in main program'
70);
71ok(
72 defined $xreftable{$thisfile}{'Testing::Xref::foo'}{main}{'%xreftable'},
73 '$xreftable used in subroutine bar'
74);
75is(
76 $xreftable{$thisfile}{'(main)'}{main}{'&use_ok'}, '&50',
77 'use_ok called at line 50'
78);
79is(
80 $xreftable{$thisfile}{'(definitions)'}{'Testing::Xref'}{'&foo'}, 's1001',
81 'subroutine foo defined at line 1001'
82);
83is(
84 $xreftable{$thisfile}{'(definitions)'}{'Testing::Xref'}{'&bar'}, 's1002',
85 'subroutine bar defined at line 1002'
86);
87is(
88 $xreftable{$thisfile}{'Testing::Xref::bar'}{'Testing::Xref'}{'&foo'},
89 '&1002', 'subroutine foo called at line 1002 by bar'
90);
91is(
92 $xreftable{$thisfile}{'Testing::Xref::foo'}{'Testing::Xref'}{'*FOO'},
93 '1001', 'glob FOO used in subroutine foo'
94);
95
96# End of tests.
97# Now some stuff to feed B::Xref
98
99# line 1000
100package Testing::Xref;
101sub foo { print FOO %::xreftable; }
102sub bar { print FOO foo; }