File Coverage

File:config/auto/coverage.pm
Coverage:85.7%

linestmtbrancondsubcode
1# Copyright (C) 2001-2008, Parrot Foundation.
2
3 - 21
=head1 NAME

config/auto/coverage- Check whether coverage analysis tools are present

=head1 DESCRIPTION

Coverage analysis is the measurement of the extent to which a program's source
code is exercised by its tests.

In Parrot, we can perform coverage analysis on our Parrot source code (well,
at least on F<.c> and F<.pmc> files) and on the Perl 5 components used in our
tools.

To conduct such analysis, we need the C coverage utility F<gcov> and two
utilities, F<cover> and F<gcov2perl>, which are included in the Devel-Cover
distribution from CPAN.  (Paul Johnson++).  This configuration step determines
whether those utilities are present.

=cut
22
23package auto::coverage;
24
25
2
2
2
use strict;
26
2
2
2
use warnings;
27
28
2
2
2
use File::Which;
29
2
2
2
use base qw(Parrot::Configure::Step);
30
2
2
2
use Parrot::Configure::Utils ':auto';
31
32
33sub _init {
34
2
    my $self = shift;
35
2
    my %data;
36
2
    $data{description} = q{Are coverage analysis tools installed};
37
2
    $data{result} = q{};
38
2
    return \%data;
39}
40
41sub runstep {
42
2
    my ( $self, $conf ) = @_;
43
44
2
6
    my %utils_needed = map { $_ => undef } qw( gcov gcov2perl cover );
45
2
    my @utils_lacking;
46
2
    foreach my $util (keys %utils_needed) {
47
6
        my $which_util = which($util);
48
6
        if ($which_util) {
49
6
            $utils_needed{$util} = which($util);
50        }
51        else {
52
0
            $utils_needed{$util} =
53                '$(PERL) -e "print \"'.$util.' needed but not found.\\n\"; exit 1;"';
54
0
            push @utils_lacking, $util;
55        }
56    }
57
2
    if (@utils_lacking) {
58
0
        $utils_needed{'have_cover'} =
59            '$(PERL) -e "print \"The following tools are needed for coverage testing: '.
60            join(', ',@utils_lacking).
61            '\\n\"; print \"Please install Devel::Cover.\\n\"; exit 1;"';
62
0
        $self->set_result("lacking @utils_lacking");
63
0
        $conf->data->set(
64            "has_coverage_tools" => 0,
65            %utils_needed,
66        );
67    }
68    else {
69
2
        $utils_needed{'have_cover'} = 'exit 0';
70
2
        $conf->data->set(
71            "has_coverage_tools" => 1,
72            %utils_needed,
73        );
74
2
        $self->set_result('yes');
75    }
76
2
    return 1;
77}
78
791;
80
81 - 85
=head1 REFERENCES

L<http://search.cpan.org/dist/Devel-Cover/>.

=cut
86
87# Local Variables:
88# mode: cperl
89# cperl-indent-level: 4
90# fill-column: 100
91# End:
92# vim: expandtab shiftwidth=4: