|
From: <jgr...@us...> - 2003-07-13 05:21:25
|
Update of /cvsroot/popfile/engine
In directory sc8-pr-cvs1:/tmp/cvs-serv5644
Modified Files:
tests.pl
Added Files:
coverage.pl
Log Message:
Make test runner merge data from forked subprocesses to give one set of output data on coverage
--- NEW FILE: coverage.pl ---
#!/usr/bin/perl
# ---------------------------------------------------------------------------------------------
#
# coverage.pl - Calculate coverage data from LNE files
#
# Copyright (c) 2001-2003 John Graham-Cumming
#
# ---------------------------------------------------------------------------------------------
use strict;
# This hash will store a count of the number of times each line is executed # in each file,
# it is in fact a hash of hashes used as
# $count{filename}{linenumber}
my %count;
# This hash will map file names of POPFile modules to coverage
my %files;
# Now look for LNE files containing code coverage information
my @line_files = glob '*.lne';
foreach my $file (@line_files) {
# Each LNE has a file name of ModuleName.PID.lne and the ModuleName has had
# / or :: converted to -
$file =~ /^(.+)\.pm\.(-?\d+)\.lne$/;
my $module = $1;
my $pid = $2;
$module =~ s/-/\//g;
open SOURCE_FILE, "<../$module.pm";
open LINE_DATA, "<$file";
my $current_line = 0;
while ( <SOURCE_FILE> ) {
# Keep count of the total number of lines in this file
$current_line += 1;
$count{$module}{total_lines} += 1;
my $state = <LINE_DATA>;
if ( $state =~ /1/ ) {
$count{$module}{total_executable_lines} += 1;
$count{$module}{total_executed} += 1;
} else {
if ( $state =~ /0/ ) {
$count{$module}{total_executable_lines} += 1;
} else {
}
}
}
close LINE_DATA;
close SOURCE_FILE;
$files{$module} = int(100 * $count{$module}{total_executed} / $count{$module}{total_executable_lines}) unless ( $count{$module}{total_executable_lines} == 0 );
unlink $file;
}
foreach my $file (sort {$files{$b} <=> $files{$a}} keys %files) {
my $clean = $file;
$clean =~ s/^\.\.\/\///;
print sprintf( "Coverage of %-32s %d%%\n", "$clean...", $files{$file});
}
Index: tests.pl
===================================================================
RCS file: /cvsroot/popfile/engine/tests.pl,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** tests.pl 13 Jul 2003 02:40:35 -0000 1.20
--- tests.pl 13 Jul 2003 05:21:21 -0000 1.21
***************
*** 149,153 ****
if ( $test =~ /$pattern/ ) {
! # This works by reading the entire suite into the $suite variable
# and then changing calls to test_assert_equal so that they include
# the line number and the file they are from, then the $suite is
--- 149,153 ----
if ( $test =~ /$pattern/ ) {
! # This works by reading the entire suite into the $suite variable
# and then changing calls to test_assert_equal so that they include
# the line number and the file they are from, then the $suite is
|