Skip to content

Instantly share code, notes, and snippets.

@pjcj
Created November 4, 2011 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjcj/1338915 to your computer and use it in GitHub Desktop.
Save pjcj/1338915 to your computer and use it in GitHub Desktop.
A Gentle Reminder about Test Coverage
#!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
$ 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment