-
Notifications
You must be signed in to change notification settings - Fork 88
/
cover
executable file
·272 lines (202 loc) · 7.31 KB
/
cover
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#!/usr/bin/perl
# Copyright 2001-2004, Paul Johnson (pjcj@cpan.org)
# This software is free. It is licensed under the same terms as Perl itself.
# The latest version of this software should be available from my homepage:
# http://www.pjcj.net
require 5.6.1;
use strict;
use warnings;
our $VERSION = "0.43";
use Devel::Cover::DB 0.43;
use Cwd "abs_path";
use Data::Dumper;
use File::Path;
use Getopt::Long;
use Pod::Usage;
my $Options =
{
coverage => [],
delete => 0,
exclude => [],
file => [],
report => "",
summary => 1,
};
sub get_options
{
@ARGV = qw( -report html ) unless @ARGV;
Getopt::Long::Configure("pass_through");
die "Bad option" unless
GetOptions($Options, # Store the options in the Options hash.
"write:s" => sub
{
@$Options{qw( write summary )} = ($_[1], 0)
},
qw(
coverage=s
delete!
dump_db!
exclude=s
help|h!
file=s
info|i!
outputdir=s
report=s
silent!
summary!
version|v!
));
Getopt::Long::Configure("nopass_through");
}
sub main
{
if ($INC{"Devel/Cover.pm"})
{
my $err = "$0 shouldn't be run with coverage turned on.\n";
eval
{
require POSIX;
print STDERR $err;
POSIX::_exit(1);
};
die $err;
}
get_options;
$Devel::Cover::Silent = 1 if $Options->{silent};
my $format = "Devel::Cover::Report::\u$Options->{report}";
if (length $Options->{report})
{
eval ("use $format");
if ($@)
{
print "Error: $Options->{report} ",
"is not a recognised output format\n\n$@";
exit 1;
}
}
$format->get_options($Options) if $format->can("get_options");
print "$0 version $VERSION\n" and exit 0 if $Options->{version};
pod2usage(-exitval => 0, -verbose => 0) if $Options->{help};
pod2usage(-exitval => 0, -verbose => 2) if $Options->{info};
my $dbname = Cwd::abs_path(@ARGV ? shift @ARGV : "cover_db");
die "Can't open database $dbname\n"
if !$Options->{delete} && !-d $dbname;
$Options->{outputdir} = $dbname unless exists $Options->{outputdir};
my $od = Cwd::abs_path($Options->{outputdir});
$Options->{outputdir} = $od if defined $od;
mkpath($Options->{outputdir}) unless -d $Options->{outputdir};
if ($Options->{delete})
{
for my $del ($dbname, @ARGV)
{
print "Deleting database $del\n" unless $Options->{silent};
next unless -d $del;
my $db = Devel::Cover::DB->new(db => $del);
$db->delete;
}
exit 0
}
print "Reading database from $dbname\n" unless $Options->{silent};
my $db = Devel::Cover::DB->new(db => $dbname);
$db = $db->merge_runs;
for my $merge (@ARGV)
{
print "Merging database from $merge\n" unless $Options->{silent};
my $mdb = Devel::Cover::DB->new(db => $merge);
$mdb = $mdb->merge_runs;
$db->merge($mdb);
}
if ($Options->{dump_db})
{
my $d = Data::Dumper->new([$db], ["db"]);
$d->Indent(1);
$d->Sortkeys(1) if $] >= 5.008;
print $d->Dump;
exit 0
}
if (exists $Options->{write})
{
$dbname = $Options->{write} if length $Options->{write};
print "Writing database to $dbname\n" unless $Options->{silent};
$db->write($dbname);
}
return unless $Options->{summary} || $Options->{report};
$Options->{coverage} = [ $db->collected ] unless @{$Options->{coverage}};
$Options->{show} = { map { $_ => 1 } @{$Options->{coverage}} };
$Options->{show}{total} = 1 if keys %{$Options->{show}};
$db->calculate_summary(map { $_ => 1 } @{$Options->{coverage}});
print "\n\n" unless $Options->{silent};
$db->print_summary(@{$Options->{coverage}}) if $Options->{summary};
return unless length $Options->{report};
my %f = map { $_ => 1 } (@{$Options->{file}}
? map glob, @{$Options->{file}}
: $db->cover->items);
delete @f{map glob, @{$Options->{exclude}}};
@{$Options->{file}} = sort grep exists $db->{summary}{$_}, keys %f;
$format->report($db, $Options)
}
main
__END__
=head1 NAME
cover - report coverage statistics
=head1 SYNOPSIS
cover -help -info -version
-summary -report report_format -outputdir dir
-file filename -exclude filname
-write [db] -delete -dump_db
-silent
-coverage criterion
[report specific options]
coverage_database [coverage_database ...]
=head1 DESCRIPTION
Report coverage statistics in a variety of formats.
The summary option produces a short textual summary. Other reports are
available by using the report option.
The following reports are currently available:
text - detailed textual summary
html - detailed HTML reports
=head1 OPTIONS
The following command line options are supported:
-h -help - show help
-i -info - show documentation
-v -version - show version
-silent - don't print informational messages (default off)
-summary - give summary report (default on)
-report report_format - report format required (default html)
-outputdir - directory for output (default db)
-file filename - only report on the file (default all)
-exclude filename - don't report on the file (default none)
-write [db] - write the merged database (default off)
-delete - drop database(s) (default off)
-dump_db - dump database(s) (for debugging) (default off)
-coverage criterion - report on criterion (default all available)
other options specific to the report
=head1 DETAILS
Any number of coverage databases may be specified on the command line.
These databases will be merged and the reports will be based on the
merged information. If no databases are specified the default database
(cover_db) will be used.
The -write option will write out the merged database. If no name is
given for the new database, the first database read in will be
overwritten. When this option is used no reports are generated by
default.
Specify -file options to report on specific files. Specify -coverage
options to report on specific criteria. By default all available
information on all criteria in all files will be reported.
=head1 EXIT STATUS
The following exit values are returned:
0 All operaions were completed successfully.
>0 An error occurred.
=head1 SEE ALSO
Devel::Cover
=head1 BUGS
Did I mention that this is alpha code?
See the BUGS file.
=head1 VERSION
Version 0.43 - 2nd May 2004
=head1 LICENCE
Copyright 2001-2004, Paul Johnson (pjcj@cpan.org)
This software is free. It is licensed under the same terms as Perl itself.
The latest version of this software should be available from my homepage:
http://www.pjcj.net
=cut