1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2026-05-22 10:15:16 +02:00

Refactor File module to improve test coverage.

This commit is contained in:
David Steele
2016-12-23 08:30:34 -05:00
parent 6b2666a9d7
commit 5d3473b52d
38 changed files with 1063 additions and 919 deletions
+59
View File
@@ -14,6 +14,7 @@ use English '-no_match_vars';
use Exporter qw(import);
our @EXPORT = qw();
use pgBackRest::Common::Exception;
use pgBackRest::Common::Log;
use pgBackRestTest::Common::LogTest;
@@ -227,6 +228,64 @@ sub end
}
}
####################################################################################################################################
# testResult
####################################################################################################################################
sub testResult
{
my $self = shift;
my $fnSub = shift;
my $strExpected = shift;
my $strActual = $fnSub->();
if ($strActual ne $strExpected)
{
confess
'expected ' . (defined($strExpected) ? "\"${strExpected}\"" : '[undef]') .
" but actual was " . (defined($strActual) ? "\"${strActual}\"" : '[undef]');
}
}
####################################################################################################################################
# testException
####################################################################################################################################
sub testException
{
my $self = shift;
my $fnSub = shift;
my $iCodeExpected = shift;
my $strMessageExpected = shift;
my $bError = false;
my $strError = "exception ${iCodeExpected}, \"${strMessageExpected}\" was expected";
eval
{
$fnSub->();
return true;
}
or do
{
if (!isException($EVAL_ERROR))
{
confess "${strError} but actual was standard Perl exception";
}
if (!($EVAL_ERROR->code() == $iCodeExpected && $EVAL_ERROR->message() eq $strMessageExpected))
{
confess "${strError} but actual was " . $EVAL_ERROR->code() . ", \"" . $EVAL_ERROR->message() . "\"";
}
$bError = true;
};
if (!$bError)
{
confess "${strError} but no exception was thrown";
}
}
####################################################################################################################################
# testRunName
#