File Coverage

inc/Test/Compile.pm
Criterion Covered Total %
statement 68 72 94.4
branch 19 30 63.3
condition n/a
subroutine 11 11 100.0
pod 3 3 100.0
total 101 116 87.0


line stmt bran cond sub pod time code
1             #line 1
2             package Test::Compile;
3 1     1   1614  
  1         2  
  1         41  
4 1     1   5 use warnings;
  1         2  
  1         38  
5 1     1   6 use strict;
  1         1  
  1         221  
6 1     1   6 use Test::Builder;
  1         2  
  1         22  
7 1     1   767 use File::Spec;
  1         3  
  1         189  
8             use UNIVERSAL::require;
9              
10              
11             our $VERSION = '0.06';
12              
13              
14             my $Test = Test::Builder->new;
15              
16              
17 1     1   10 sub import {
18 1         2 my $self = shift;
19             my $caller = caller;
20 1         2  
21 1     1   80 for my $func ( qw( pm_file_ok all_pm_files all_pm_files_ok ) ) {
  1         2  
  1         936  
22 3         7 no strict 'refs';
  3         13  
23             *{$caller."::".$func} = \&$func;
24             }
25 1         4  
26 1         10 $Test->exported_to($caller);
27             $Test->plan(@_);
28             }
29              
30              
31 1     1 1 3 sub pm_file_ok {
32 1 50       12 my $file = shift;
33             my $name = @_ ? shift : "Compile test for $file";
34 1 50       23  
35 0         0 if (!-f $file) {
36 0         0 $Test->ok(0, $name);
37 0         0 $Test->diag("$file does not exist");
38             return;
39             }
40 1         1  
41 1         10 my $module = $file;
42 1         3 $module =~ s!^(blib/)?lib/!!;
43 1         4 $module =~ s!/!::!g;
44             $module =~ s/\.pm$//;
45 1         2  
46 1         9 my $ok = 1;
47 1 50       5 $module->use;
48             $ok = 0 if $@;
49 1         2  
50 1 50       4 my $diag = '';
51 1         7 unless ($ok) {
52             $diag = "couldn't use $module ($file): $@";
53             }
54 1         10  
55 1 50       628 $Test->ok($ok, $name);
56 1         166 $Test->diag($diag) unless $ok;
57             $ok;
58             }
59              
60              
61 1 50   1 1 20 sub all_pm_files_ok {
62             my @files = @_ ? @_ : all_pm_files();
63 1         10  
64             $Test->plan(tests => scalar @files);
65 1         909  
66 1         3 my $ok = 1;
67 1 50       3 for (@files) {
68             pm_file_ok($_) or undef $ok;
69 1         1973 }
70             $ok;
71             }
72              
73              
74 1 50   1 1 3 sub all_pm_files {
75 1         2 my @queue = @_ ? @_ : _starting_points();
76             my @pm;
77 1         5  
78 26         38 while ( @queue ) {
79 26 100       327 my $file = shift @queue;
80 17         34 if ( -d $file ) {
81 17 50       599 local *DH;
82 17         9232 opendir DH, $file or next;
83 17         161 my @newfiles = readdir DH;
84             closedir DH;
85 17         205  
86 17 50       28 @newfiles = File::Spec->no_upwards(@newfiles);
  25         120  
87             @newfiles = grep { $_ ne "CVS" && $_ ne ".svn" } @newfiles;
88 17         31  
89 25         191 for my $newfile (@newfiles) {
90 25 100       611 my $filename = File::Spec->catfile($file, $newfile);
91 9         64 if (-f $filename) {
92             push @queue, $filename;
93 16         117 } else {
94             push @queue, File::Spec->catdir($file, $newfile);
95             }
96             }
97 26 100       863 }
98 9 100       41 if (-f $file) {
99             push @pm, $file if $file =~ /\.pm$/;
100             }
101 1         4 }
102             return @pm;
103             }
104              
105              
106 1 50   1   18 sub _starting_points {
107 0           return 'blib' if -e 'blib';
108             return 'lib';
109             }
110              
111              
112             1;
113              
114             __END__