1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-11-29 22:28:02 +02:00

Added integration for testing coverage with Devel::Cover.

This commit is contained in:
David Steele
2017-01-09 20:49:04 -05:00
parent 39744a4f1d
commit 0e4f51c271
14 changed files with 188 additions and 25 deletions

View File

@@ -13,6 +13,7 @@ use English '-no_match_vars';
use Exporter qw(import);
our @EXPORT = qw();
use File::Basename qw(dirname);
use pgBackRest::Common::Exception;
use pgBackRest::Common::Log;
@@ -26,7 +27,6 @@ use pgBackRestTest::Common::DefineTest;
use constant BOGUS => 'bogus';
push @EXPORT, qw(BOGUS);
####################################################################################################################################
# The current test run that is executung. Only a single run should ever occur in a process to prevent various cleanup issues from
# affecting the next run. Of course multiple subtests can be executed in a single run.
@@ -86,7 +86,7 @@ sub process
$self->{iVmId},
$self->{strBasePath},
$self->{strTestPath},
$self->{strBackRestExe},
$self->{strBackRestExeOriginal},
$self->{strPgBinPath},
$self->{strPgVersion},
$self->{strModule},
@@ -97,6 +97,7 @@ sub process
$self->{bDryRun},
$self->{bCleanup},
$self->{bLogForce},
$self->{bCoverage},
$self->{strPgUser},
$self->{strBackRestUser},
$self->{strGroup},
@@ -108,7 +109,7 @@ sub process
{name => 'iVmId'},
{name => 'strBasePath'},
{name => 'strTestPath'},
{name => 'strBackRestExe'},
{name => 'strBackRestExeOriginal'},
{name => 'strPgBinPath', required => false},
{name => 'strPgVersion', required => false},
{name => 'strModule'},
@@ -119,6 +120,7 @@ sub process
{name => 'bDryRun'},
{name => 'bCleanup'},
{name => 'bLogForce'},
{name => 'bCoverage'},
{name => 'strPgUser'},
{name => 'strBackRestUser'},
{name => 'strGroup'},
@@ -206,16 +208,27 @@ sub begin
return false;
}
# If the module is defined then create a ExpectTest object
if ($self->doExpect())
my $strExe = $self->backrestExeOriginal();
# If coverage is requested then prepend the coverage code
if ($self->coverage())
{
$strExe = testRunExe(
$strExe, dirname($self->testPath()), $self->basePath(), $self->module(), $self->moduleTest(), $self->runCurrent(),
true);
}
# Else if the module is defined then create a ExpectTest object
elsif ($self->doExpect())
{
$self->{oExpect} = new pgBackRestTest::Common::LogTest(
$self->module(), $self->moduleTest(), $self->runCurrent(), $self->doLogForce(), $strDescription, $self->backrestExe(),
$self->module(), $self->moduleTest(), $self->runCurrent(), $self->doLogForce(), $strDescription, $strExe,
$self->pgBinPath(), $self->testPath());
&log(INFO, ' expect log: ' . $self->{oExpect}->{strFileName});
}
$self->{strBackRestExe} = $strExe;
return true;
}
@@ -365,12 +378,80 @@ sub testRunGet
push @EXPORT, qw(testRunGet);
####################################################################################################################################
# testExe
####################################################################################################################################
sub testRunExe
{
my $strExe = shift;
my $strCoveragePath = shift;
my $strBackRestBasePath = shift;
my $strModule = shift;
my $strTest = shift;
my $iRun = shift;
my $bLog = shift;
# Limit Perl modules tested to what is defined in the test coverage (if it exists)
my $strPerlModule;
my $strPerlModuleLog;
my $hTestCoverage;
my $hTestDef = testDefGet();
foreach my $hTestModule (@{$hTestDef->{&TESTDEF_MODULE}})
{
if ($hTestModule->{&TESTDEF_MODULE_NAME} eq $strModule)
{
$hTestCoverage = $hTestModule->{&TESTDEF_TEST_COVERAGE};
foreach my $hTest (@{$hTestModule->{&TESTDEF_TEST}})
{
if (defined($strTest) && $hTest->{&TESTDEF_TEST_NAME} eq $strTest)
{
$hTestCoverage =
defined($hTest->{&TESTDEF_TEST_COVERAGE}{$iRun}) ? $hTest->{&TESTDEF_TEST_COVERAGE}{$iRun}: $hTestCoverage;
}
}
}
}
if (defined($hTestCoverage))
{
foreach my $strCoverageModule (sort(keys(%{$hTestCoverage})))
{
$strPerlModule .= ',.*/' . $strCoverageModule . '\.p.$';
$strPerlModuleLog .= (defined($strPerlModuleLog) ? ', ' : '') . $strCoverageModule;
}
}
# Build the exe
if (defined($strPerlModule))
{
$strExe =
'perl -MDevel::Cover=-silent,1,-dir,' . $strCoveragePath . ',-subs_only,1' .
",-select${strPerlModule},+inc," . $strBackRestBasePath .
',-coverage,statement,branch,condition,path,subroutine' . " ${strExe}";
if (defined($bLog) && $bLog)
{
&log(INFO, " coverage: ${strPerlModuleLog}");
}
}
return $strExe;
}
push(@EXPORT, qw(testRunExe));
####################################################################################################################################
####################################################################################################################################
# Getters
####################################################################################################################################
sub backrestExe {return shift->{strBackRestExe}}
sub backrestExeOriginal {return shift->{strBackRestExeOriginal}}
sub backrestUser {return shift->{strBackRestUser}}
sub basePath {return shift->{strBasePath}}
sub coverage {return shift->{bCoverage}}
sub dataPath {return shift->basePath() . '/test/data'}
sub doCleanup {return shift->{bCleanup}}
sub doExpect {return shift->{bExpect}}