forked from pjcj/Devel--Cover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cover
executable file
·216 lines (152 loc) · 5.33 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
#!/usr/local/bin/perl
# Copyright 2001-2003, 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.24";
use Devel::Cover::DB 0.24;
use Getopt::Long;
use Pod::Usage;
my $Options =
{
coverage => [],
delete => 0,
file => [],
option => [],
report => "",
summary => 1,
};
sub get_options
{
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!
help|h!
file=s
info|i!
option=s
report=s
summary!
version|v!
));
}
sub main
{
get_options;
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;
}
}
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 = shift @ARGV || "cover_db";
if ($Options->{delete})
{
for my $del ($dbname, @ARGV)
{
print "Deleting database $del\n";
my $db = Devel::Cover::DB->new(db => $del);
$db->delete;
}
exit 0;
}
print "Reading database from $dbname\n";
my $db = Devel::Cover::DB->new(db => $dbname);
for my $merge (@ARGV)
{
print "Merging database from $merge\n";
my $mdb = Devel::Cover::DB->new(db => $merge);
$db->merge($mdb);
}
if (exists $Options->{write})
{
$dbname = $Options->{write} if length $Options->{write};
print "Writing database to $dbname\n";
$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";
$db->print_summary(@{$Options->{coverage}}) if $Options->{summary};
return unless length $Options->{report};
@{$Options->{file}} = sort $db->cover->items unless @{$Options->{file}};
$format->report($db, $Options)
}
main
__END__
=head1 NAME
cover - report coverage statistics
=head1 SYNOPSIS
cover -help -info -version -summary
-report report_format -option option
-file filename -coverage criterion -write [db]
-delete
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:
-summary - give summary report (default on)
-report report_format - report format required (default none)
-option - options for report
-file filename - only report on the file (default all)
-write [db] - write the merged database (default off)
-delete - drop database(s) (default off)
-coverage criterion - report on criterion (default all available)
-h -help - show help
-i -info - show documentation
-v -version - show version
=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.24 - 10th October 2003
=head1 LICENCE
Copyright 2001-2003, 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