X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=NPTest.pm;h=54a535e77808b167741ba30ca744fcb3266acc5c;hb=0aa751937455c4af4e49ccf6ba469c0b4ca8a4d0;hp=106e8f12a43956b6b5b38ffddbb3ccab82993172;hpb=61cd9f525aa236250b6768e6db2977c836c57d96;p=nagiosplug.git diff --git a/NPTest.pm b/NPTest.pm index 106e8f1..54a535e 100644 --- a/NPTest.pm +++ b/NPTest.pm @@ -21,7 +21,7 @@ use Data::Dumper; use Test; use vars qw($VERSION); -$VERSION = do { my @r = (q$Revision$ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # must be all one line, for MakeMaker +$VERSION = "1556."; # must be all one line, for MakeMaker =head1 NAME @@ -54,13 +54,13 @@ user. The user can accept the developer's default value or reply "none" which will then be returned as "" for the test to skip if appropriate. If a parameter needs to be entered and the test is run without a tty -attached (such as a cronjob), this routine will die causing the test to -fail. +attached (such as a cronjob), the parameter will be assigned as if it +was "none". Tests can check for the parameter and skip if not set. -Responses are stored in an external, file-based -cache so subsequent test runs will use these values. The user is able -to change the values by amending the values in the file /var/tmp/NPTest.pm, -or by setting the appropriate environment variable before running the test. +Responses are stored in an external, file-based cache so subsequent test +runs will use these values. The user is able to change the values by +amending the values in the file /var/tmp/NPTest.cache, or by setting +the appropriate environment variable before running the test. The option exists to store parameters in a scoped means, allowing a test harness to a localise a parameter should the need arise. This @@ -346,7 +346,8 @@ sub getTestParameter return $default; } - die "Need to manually enter test parameter $param" unless (-t STDERR); + # Set "none" if no terminal attached (eg, tinderbox build servers when new variables set) + return "" unless (-t STDERR); my $userResponse = ""; @@ -599,8 +600,15 @@ sub output { sub perf_output { my $self = shift; $_ = $self->{output}; - s/[^|]*\|//; - return $_; + /\|(.*)$/; + return $1 || ""; +} + +sub only_output { + my $self = shift; + $_ = $self->{output}; + /(.*?)\|/; + return $1 || ""; } sub testCmd { @@ -609,15 +617,18 @@ sub testCmd { my $object = $class->new; my $output = `$command`; + $object->return_code($? >> 8); + $_ = $? & 127; + if ($_) { + die "Got signal $_ for command $command"; + } chomp $output; - $object->output($output); - $object->return_code($? >> 8); + my ($pkg, $file, $line) = caller(0); + print "Testing: $command", $/; if ($ENV{'NPTEST_DEBUG'}) { - my ($pkg, $file, $line) = caller(0); print "testCmd: Called from line $line in $file", $/; - print "Testing: $command", $/; print "Output: ", $object->output, $/; print "Return code: ", $object->return_code, $/; }