line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# (c) Copyright 2005 Neurogen Corporation, all rights reserved. |
2
|
|
|
|
|
|
|
package Test::AutoLoader; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
1038
|
use 5.006; # for 'warnings' |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
32
|
|
5
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
6
|
1
|
|
|
1
|
|
17
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
7
|
1
|
|
|
1
|
|
5
|
use Exporter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
54
|
|
8
|
1
|
|
|
1
|
|
22
|
BEGIN{*import = \&Exporter::import}; |
9
|
1
|
|
|
1
|
|
4
|
use File::Spec; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
10
|
1
|
|
|
1
|
|
4
|
use Test::Builder; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
104
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT = ('autoload_ok'); |
13
|
|
|
|
|
|
|
our $VERSION = 0.03; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Lifted fairly directly from AutoLoader.pm |
16
|
|
|
|
|
|
|
my ($is_dosish, $is_epoc,$is_vms, $is_macos); |
17
|
|
|
|
|
|
|
BEGIN { |
18
|
1
|
|
33
|
1
|
|
11
|
$is_dosish = $^O eq 'dos' || $^O eq 'os2' || $^O eq 'MSWin32'; |
19
|
1
|
|
|
|
|
1
|
$is_epoc = $^O eq 'epoc'; |
20
|
1
|
|
|
|
|
3
|
$is_vms = $^O eq 'VMS'; |
21
|
1
|
|
|
|
|
989
|
$is_macos = $^O eq 'MacOS'; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub autoload_ok { |
25
|
0
|
|
|
0
|
1
|
|
my ($package,@subnames) = @_; |
26
|
0
|
|
|
|
|
|
my $Test = Test::Builder->new; |
27
|
|
|
|
|
|
|
# initialize the special vars here? (if we make this part of Test::More) |
28
|
0
|
0
|
|
|
|
|
unless ($package) { |
29
|
0
|
|
|
|
|
|
return $Test->ok(0,"Can't test autoload of empty package") |
30
|
|
|
|
|
|
|
} |
31
|
0
|
0
|
|
|
|
|
my $test_label = "Autoload of $package" . |
32
|
|
|
|
|
|
|
(@subnames ? " (listed subroutines)" : " (all files)"); |
33
|
0
|
|
|
|
|
|
(my $pkg = $package) =~ s#::#/#g; |
34
|
0
|
|
|
|
|
|
my $dirname; |
35
|
0
|
|
|
|
|
|
my (@ok,@nok); |
36
|
|
|
|
|
|
|
|
37
|
0
|
0
|
|
|
|
|
if (defined($dirname = $INC{"$pkg.pm"})) { |
38
|
0
|
0
|
|
|
|
|
if ($is_macos) { |
39
|
0
|
|
|
|
|
|
$pkg =~ tr#/#:#; |
40
|
0
|
|
|
|
|
|
$dirname =~ s#^(.*)$pkg\.pm\z#$1auto:$pkg#s; |
41
|
|
|
|
|
|
|
} else { |
42
|
0
|
|
|
|
|
|
$dirname =~ s#^(.*)$pkg\.pm\z#$1auto/$pkg#s; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
0
|
0
|
0
|
|
|
|
unless (defined $dirname and -d $dirname && -r _ ) { |
|
|
|
0
|
|
|
|
|
46
|
0
|
|
|
|
|
|
$Test->ok(0,$test_label); |
47
|
0
|
|
|
|
|
|
my $diag = "Unable to find valid autoload directory for $package"; |
48
|
0
|
0
|
|
|
|
|
$diag .= " (perhaps you forgot to load '$package'?)" |
49
|
|
|
|
|
|
|
if !defined $dirname; |
50
|
0
|
|
|
|
|
|
$Test->diag($diag); |
51
|
0
|
|
|
|
|
|
return; |
52
|
|
|
|
|
|
|
} |
53
|
0
|
|
|
|
|
|
my @filenames = map "$_.al", @subnames; |
54
|
0
|
0
|
|
|
|
|
if (!@filenames ) { |
55
|
0
|
0
|
|
|
|
|
unless (opendir AUTOLOAD, $dirname) { |
56
|
0
|
|
|
|
|
|
$Test->ok(0,$test_label); |
57
|
0
|
|
|
|
|
|
$Test->diag("Can't open $dirname: $!"); |
58
|
0
|
|
|
|
|
|
return; |
59
|
|
|
|
|
|
|
} |
60
|
0
|
|
|
|
|
|
@filenames = grep /.+\.al\z/, readdir AUTOLOAD; |
61
|
0
|
0
|
|
|
|
|
closedir AUTOLOAD or $Test->diag("Unable to close $dirname: $!"); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
foreach my $filename (@filenames) { |
65
|
0
|
|
|
|
|
|
my $full_path = File::Spec->catfile($dirname,$filename); |
66
|
|
|
|
|
|
|
# also lifted directly from AutoLoader.pm, then tweaked |
67
|
0
|
0
|
|
|
|
|
unless ($full_path =~ m|^/|s) { |
68
|
0
|
0
|
0
|
|
|
|
if ($is_dosish && $full_path !~ m{^([a-z]:)?[\\/]}is) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$full_path = "./$full_path"; |
70
|
|
|
|
|
|
|
} elsif ($is_epoc && $full_path !~ m{^([a-z?]:)?[\\/]}is) { |
71
|
0
|
|
|
|
|
|
$full_path = "./$full_path"; |
72
|
|
|
|
|
|
|
} elsif ($is_vms) { |
73
|
|
|
|
|
|
|
# XXX todo by VMSmiths |
74
|
0
|
|
|
|
|
|
$full_path = "./$full_path"; |
75
|
|
|
|
|
|
|
} elsif (!$is_macos) { |
76
|
0
|
|
|
|
|
|
$full_path = "./$full_path"; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
0
|
|
|
|
|
|
local ($@,$!,$?); |
80
|
0
|
0
|
|
|
|
|
if (my $ret = do $full_path) { |
81
|
0
|
|
|
|
|
|
push @ok, $filename; |
82
|
|
|
|
|
|
|
} else { |
83
|
0
|
|
0
|
|
|
|
my $err = $! |
84
|
|
|
|
|
|
|
|| $@ && "Compile error" |
85
|
|
|
|
|
|
|
|| "false return value"; |
86
|
0
|
|
|
|
|
|
push @nok, [$filename,$err]; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
0
|
0
|
|
|
|
|
if (@nok) { |
|
|
0
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
$Test->ok(0,$test_label); |
91
|
0
|
|
|
|
|
|
$Test->diag(map " couldn't load $_->[0]: $_->[1]\n", @nok); |
92
|
0
|
|
|
|
|
|
return 0; |
93
|
|
|
|
|
|
|
} elsif(@ok) { |
94
|
0
|
|
|
|
|
|
return $Test->ok(1,$test_label); |
95
|
|
|
|
|
|
|
} else { |
96
|
0
|
|
|
|
|
|
$Test->ok(0,$test_label); |
97
|
0
|
|
|
|
|
|
$Test->diag("No autoloaded files found"); |
98
|
0
|
|
|
|
|
|
return 0; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
1
|
|
|
1
|
|
6
|
no warnings 'void'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
50
|
|
102
|
|
|
|
|
|
|
"I pass the test. I will diminish, and go into the West, and remain Galadriel" |
103
|
|
|
|
|
|
|
__END__ |