or implied warranty. It may be used, redistributed and/or modified
under the same terms as the Nagios Plugins release.
=cut
#
# Package Scope Variables
#
my( %CACHE ) = ();
# I'm not really sure wether to house a site-specific cache inside
# or outside of the extracted source / build tree - lets default to outside
my( $CACHEFILENAME ) = ( exists( $ENV{'NPTEST_CACHE'} ) && $ENV{'NPTEST_CACHE'} )
? $ENV{'NPTEST_CACHE'} : "/var/tmp/NPTest.cache"; # "../Cache.pdd";
#
# Testing Functions
#
sub checkCmd
{
my( $command, $desiredExitStatus, $desiredOutput, %exceptions ) = @_;
my $result = NPTest->testCmd($command);
my $output = $result->output;
my $exitStatus = $result->return_code;
$output = "" unless defined( $output );
chomp( $output );
my $testStatus;
my $testOutput = "continue";
if ( defined( $desiredExitStatus ) )
{
if ( ref $desiredExitStatus eq "ARRAY" )
{
if ( scalar( grep { $_ == $exitStatus } @{$desiredExitStatus} ) )
{
$desiredExitStatus = $exitStatus;
}
else
{
$desiredExitStatus = -1;
}
}
elsif ( ref $desiredExitStatus eq "HASH" )
{
if ( exists( ${$desiredExitStatus}{$exitStatus} ) )
{
if ( defined( ${$desiredExitStatus}{$exitStatus} ) )
{
$testOutput = ${$desiredExitStatus}{$exitStatus};
}
$desiredExitStatus = $exitStatus;
}
else
{
$desiredExitStatus = -1;
}
}
if ( %exceptions && exists( $exceptions{$exitStatus} ) )
{
$testStatus += skip( $exceptions{$exitStatus}, $exitStatus, $desiredExitStatus );
$testOutput = "skip";
}
else
{
$testStatus += ok( $exitStatus, $desiredExitStatus );
}
}
if ( defined( $desiredOutput ) )
{
if ( $testOutput ne "skip" )
{
$testStatus += ok( $output, $desiredOutput );
}
else
{
$testStatus += skip( "Skipping output test as requested", $output, $desiredOutput );
}
}
return $testStatus;
}
sub skipMissingCmd
{
my( $command, $count ) = @_;
my $testStatus;
for ( 1 .. $count )
{
=3= |