Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
#! /usr/bin/perl -w # Perl coverage testing tool. # Ned Konz 3/10/2000 # ned@bike-nomad.com # $Revision: 1.1 $ # usage: run one script: # coverage script [ arg ... ] > listing.txt # or run multiple tests from a file of tests, one test per line. # coverage @file > listing.txt # output: annotated listing on STDOUT. use strict; my %coverage; my %functions; my $currentFile; my $currentFunction; my $tmpfile = `mktemp /tmp/coverageXXXXXX`; $ENV{PERLDB_OPTS} = "NonStop AutoTrace LineInfo=$tmpfile"; $| = 1; sub runOneTest { my $test = shift; system("perl -d $test") == 0 or die "can't open debugger: $!\n"; open(DBOUT, $tmpfile) or die "can't open $tmpfile: $!\n"; while (<DBOUT>) { if (/^(\D.*)\(([^(]+):(\d+)\):\s*(.*)$/) { $currentFunction = $1; $currentFile = $2; my $lineNumber = $3; my $otherStuff = $4; if (!exists($coverage{$currentFile})) { $coverage{$currentFile} = []; } if ($currentFunction !~ /CODE\(/) { $functions{$currentFunction} = $currentFile; } if ($otherStuff) { $coverage{$currentFile}->[$lineNumber] ++; } } elsif (/^(\d+):/) { $coverage{$currentFile}->[$1] ++; } } unlink $tmpfile; } sub printHeader { my $header = shift; $header = "$header " if length($header) % 2; my $dashLength = (78 - length($header)) / 2; $dashLength = 2 if $dashLength < 2; print '=' x $dashLength . " $header " . '=' x $dashLength . "\n"; } sub printSummary { printHeader("FUNCTIONS"); foreach my $function (sort(keys(%functions))) { printf "$function\t$functions{$function}\n"; } printHeader("FILE COVERAGE"); foreach my $file (sort(keys(%coverage))) { next if ! -r $file; next if ($file =~ qr{^/usr/.*/perl}); # skip system paths. printHeader($file); open(FILE, $file) or die "can't open $file: $!\n"; for (my $lineNumber = 1; <FILE>; $lineNumber++) { my $prefix = ($coverage{$file}->[$lineNumber]) ? ' ' : '- '; $prefix = ' ' if (/^\s*#.*/); $prefix = ' ' if (/^sub\s+\w+\s*$/); $prefix = ' ' if (/^\s*[{};]*$/); $prefix = ' ' if (/^\s*package\s+[\w:]+\s*;\s*$/); print $prefix, $_; } close(FILE); } } # main program. if ($ARGV[0] =~ /^@(.*)/) { open(TESTS, $1); foreach my $test (<TESTS>) { chomp($test); print STDERR "Running $test\n"; printHeader("Running $test"); runOneTest($test); } } else { runOneTest("@ARGV"); } printSummary();

In reply to Quick Perl coverage analyzer by bikeNomad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (5)
    As of 2014-08-30 21:45 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (294 votes), past polls