public
Created

A Gentle Reminder about Test Coverage

  • Download Gist
ch.pl
Perl
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
#!perl
 
sub nn
{
%characters = (
acute => sub { qq|\\'| . shift },
grave => sub { qq|\\`| . shift },
uml => sub { qq|\\"| . shift },
cedilla => sub { '\c' }, # ccedilla
opy => sub { '\copyright' }, # copy
dash => sub { '---' }, # mdash
lusmn => sub { '\pm' }, # plusmn
mp => sub { '\&' }, # amp
rademark => sub { '\texttrademark' }
);
}
 
sub emit_character
{
my ($class, $char) = @_;
 
print $characters{$class}->($char) if exists $characters{$class};
}
 
sub r
{
nn;
emit_character acute, a;
emit_character dash;
emit_character cedilla;
}
 
r
gistfile1.txt
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
$ perl -MDevel::Cover ch.pl
 
Devel::Cover 0.79: Collecting coverage data for branch, condition, statement, subroutine and time.
Pod coverage is unavailable. Please install Pod::Coverage from CPAN.
Selecting packages matching:
Ignoring packages matching:
/Devel/Cover[./]
Ignoring packages in:
.
/home/pjcj/g/perl5/perlbrew/perls/perl-5.14.1/lib/5.14.1
/home/pjcj/g/perl5/perlbrew/perls/perl-5.14.1/lib/5.14.1/x86_64-linux
/home/pjcj/g/perl5/perlbrew/perls/perl-5.14.1/lib/site_perl/5.14.1
/home/pjcj/g/perl5/perlbrew/perls/perl-5.14.1/lib/site_perl/5.14.1/x86_64-linux
\'a---\cDevel::Cover: Writing coverage database to /home/pjcj/g/perl/tmp/cover_db/runs/1320394831.20166.09097
----------------------------------- ------ ------ ------ ------ ------ ------
File stmt bran cond sub time total
----------------------------------- ------ ------ ------ ------ ------ ------
ch.pl 64.7 50.0 n/a 50.0 100.0 58.1
Total 64.7 50.0 n/a 50.0 100.0 58.1
----------------------------------- ------ ------ ------ ------ ------ ------
 
 
$ cover -report text
 
Reading database from /home/pjcj/g/perl/tmp/cover_db
 
 
----------------------------------- ------ ------ ------ ------ ------ ------
File stmt bran cond sub time total
----------------------------------- ------ ------ ------ ------ ------ ------
ch.pl 64.7 50.0 n/a 50.0 100.0 58.1
Total 64.7 50.0 n/a 50.0 100.0 58.1
----------------------------------- ------ ------ ------ ------ ------ ------
 
 
Run: ch.pl
Perl version: 118.53.46.49.52.46.49
OS: linux
Start: Fri Nov 4 08:20:31 2011
Finish: Fri Nov 4 08:20:31 2011
 
ch.pl
 
line err stmt bran cond sub time code
1 #!perl
2
3 sub nn
4 {
5 %characters = (
6 1 1 8 acute => sub { qq|\\'| . shift },
7 *** 0 0 0 grave => sub { qq|\\`| . shift },
8 *** 0 0 0 uml => sub { qq|\\"| . shift },
9 1 1 0 cedilla => sub { '\c' }, # ccedilla
10 *** 0 0 0 opy => sub { '\copyright' }, # copy
11 1 1 7 dash => sub { '---' }, # mdash
12 *** 0 0 0 lusmn => sub { '\pm' }, # plusmn
13 *** 0 0 0 mp => sub { '\&' }, # amp
14 *** 0 0 0 rademark => sub { '\texttrademark' }
15 1 1 19 );
16 }
17
18 sub emit_character
19 {
20 3 3 18 my ($class, $char) = @_;
21
22 *** 3 50 25 print $characters{$class}->($char) if exists $characters{$class};
23 }
24
25 sub r
26 {
27 1 1 7 nn;
28 1 8 emit_character acute, a;
29 1 7 emit_character dash;
30 1 6 emit_character cedilla;
31 }
32
33 1 53329 r
Branches
--------
 
line err % true false branch
----- --- ------ ------ ------ ------
22 *** 50 3 0 if exists $characters{$class}
 
 
Covered Subroutines
-------------------
 
Subroutine Count Location
-------------- ----- --------
__ANON__ 1 ch.pl:11
__ANON__ 1 ch.pl:6
__ANON__ 1 ch.pl:9
emit_character 3 ch.pl:20
nn 1 ch.pl:15
r 1 ch.pl:27
 
Uncovered Subroutines
---------------------
 
Subroutine Count Location
-------------- ----- --------
__ANON__ 0 ch.pl:10
__ANON__ 0 ch.pl:12
__ANON__ 0 ch.pl:13
__ANON__ 0 ch.pl:14
__ANON__ 0 ch.pl:7
__ANON__ 0 ch.pl:8

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.