Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 265 lines (196 sloc) 7.121 kb
#!/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.30";
use Devel::Cover::DB 0.30;
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
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;
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";
next unless -d $del;
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 ($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";
$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};
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
-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
-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.30 - 22nd December 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
Jump to Line
Something went wrong with that request. Please try again.