From bc239b3bd5023ed2da77ab03c581e56a4772f1d4 Mon Sep 17 00:00:00 2001 From: Nathan Vonnahme Date: Thu, 7 Sep 2006 00:53:51 +0000 Subject: adding example script and test for it, and fixing POD according to warnings from POD::Checker git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1476 f882894a-f735-0410-b71e-b25c423dba1c --- t/check_stuff.t | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100755 t/check_stuff.t (limited to 't/check_stuff.t') diff --git a/t/check_stuff.t b/t/check_stuff.t new file mode 100755 index 0000000..a748605 --- /dev/null +++ b/t/check_stuff.t @@ -0,0 +1,76 @@ +#!/usr/local/bin/perl +# +use strict; use warnings; +#use Test::More qw(no_plan); +use Test::More tests => 16; + +my ($r,$args); +my $s = 't/check_stuff.pl'; +$s = 'perl -Ilib '.$s; + +my $n = 'CHECK_STUFF'; + +# Nagios status strings and exit codes +my %e = qw( + OK 0 + WARNING 1 + CRITICAL 2 + UNKNOWN 3 + ); + +$r = `$s`; +is $?>>8 , $e{UNKNOWN}, "exits($e{UNKNOWN}) with no args"; +like $r, qr/^$n UNKNOWN/, "UNKNOWN with no args"; + + +#TODO: +SKIP: { + local $TODO = q~d'oh! we'll have to redirect STDERR and check it with like() here instead of checking `` which only gets STDIN. Maybe use IPC::Open3?~; + skip "too noisy, see TODO here", 6; + + $r = `$s -V`; + is $?>>8 , $e{UNKNOWN}, "exits($e{UNKNOWN}) with -V arg"; + like $r, qr/\d+\.\d/i, "looks like there's a version"; # broken + is $r, '', "prints nothing to STDOUT"; + + $r = `$s -h`; + is $?>>8 , $e{UNKNOWN}, "exits($e{UNKNOWN}) with -h arg"; + like $r, qr/usage/i, "looks like there's something helpful"; # broken + is $r, '', "prints nothing to STDOUT"; +} + + +$args = " -r 99 "; +diag "running `$s $args`" if $ENV{TEST_VERBOSE}; +$r = `$s $args`; +diag "output: '$r'" if $ENV{TEST_VERBOSE}; +is $?>>8 , $e{UNKNOWN}, "exits($e{UNKNOWN}) with $args"; +like $r, qr/UNKNOWN.+invalid/i, "UNKNOWN (warning: invalid -r) with $args"; + + +my $expected = { + " -w 10:15 -c~:15 -r 0" => 'WARNING', + " -w 10:15 -c~:15 -r 11" => 'OK', + " -w 10:15 -c~:15 -r 15.8" => 'CRITICAL', +}; + +test_expected( $s, $expected ); + + +sub test_expected { + my $s = shift; + my $expected = shift; + foreach ( keys %$expected ) { + diag "running `$s $_`" if $ENV{TEST_VERBOSE}; + $r = `$s $_`; + diag "output: '$r'" if $ENV{TEST_VERBOSE}; + is $?>>8 , $e{$expected->{$_}}, "exits($e{$expected->{$_}}) with $_"; + like $r, qr/^$n $expected->{$_}/i, "looks $expected->{$_} with $_"; + } +} + + + + + + -- cgit v1.2.3-74-g34f1