summaryrefslogtreecommitdiffstats
path: root/t/check_stuff.t
diff options
context:
space:
mode:
authorNathan Vonnahme <n8v@users.sourceforge.net>2006-09-07 00:53:51 +0000
committerNathan Vonnahme <n8v@users.sourceforge.net>2006-09-07 00:53:51 +0000
commitbc239b3bd5023ed2da77ab03c581e56a4772f1d4 (patch)
tree655747da3db99a6e8ed0aab03f3036827c221748 /t/check_stuff.t
parent31336ec620bec84d5d4db1ba69deac2157611c12 (diff)
downloadmonitoring-plugin-perl-bc239b3bd5023ed2da77ab03c581e56a4772f1d4.tar.gz
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
Diffstat (limited to 't/check_stuff.t')
-rwxr-xr-xt/check_stuff.t76
1 files changed, 76 insertions, 0 deletions
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 @@
1#!/usr/local/bin/perl
2#
3use strict; use warnings;
4#use Test::More qw(no_plan);
5use Test::More tests => 16;
6
7my ($r,$args);
8my $s = 't/check_stuff.pl';
9$s = 'perl -Ilib '.$s;
10
11my $n = 'CHECK_STUFF';
12
13# Nagios status strings and exit codes
14my %e = qw(
15 OK 0
16 WARNING 1
17 CRITICAL 2
18 UNKNOWN 3
19 );
20
21$r = `$s`;
22is $?>>8 , $e{UNKNOWN}, "exits($e{UNKNOWN}) with no args";
23like $r, qr/^$n UNKNOWN/, "UNKNOWN with no args";
24
25
26#TODO:
27SKIP: {
28 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?~;
29 skip "too noisy, see TODO here", 6;
30
31 $r = `$s -V`;
32 is $?>>8 , $e{UNKNOWN}, "exits($e{UNKNOWN}) with -V arg";
33 like $r, qr/\d+\.\d/i, "looks like there's a version"; # broken
34 is $r, '', "prints nothing to STDOUT";
35
36 $r = `$s -h`;
37 is $?>>8 , $e{UNKNOWN}, "exits($e{UNKNOWN}) with -h arg";
38 like $r, qr/usage/i, "looks like there's something helpful"; # broken
39 is $r, '', "prints nothing to STDOUT";
40}
41
42
43$args = " -r 99 ";
44diag "running `$s $args`" if $ENV{TEST_VERBOSE};
45$r = `$s $args`;
46diag "output: '$r'" if $ENV{TEST_VERBOSE};
47is $?>>8 , $e{UNKNOWN}, "exits($e{UNKNOWN}) with $args";
48like $r, qr/UNKNOWN.+invalid/i, "UNKNOWN (warning: invalid -r) with $args";
49
50
51my $expected = {
52 " -w 10:15 -c~:15 -r 0" => 'WARNING',
53 " -w 10:15 -c~:15 -r 11" => 'OK',
54 " -w 10:15 -c~:15 -r 15.8" => 'CRITICAL',
55};
56
57test_expected( $s, $expected );
58
59
60sub test_expected {
61 my $s = shift;
62 my $expected = shift;
63 foreach ( keys %$expected ) {
64 diag "running `$s $_`" if $ENV{TEST_VERBOSE};
65 $r = `$s $_`;
66 diag "output: '$r'" if $ENV{TEST_VERBOSE};
67 is $?>>8 , $e{$expected->{$_}}, "exits($e{$expected->{$_}}) with $_";
68 like $r, qr/^$n $expected->{$_}/i, "looks $expected->{$_} with $_";
69 }
70}
71
72
73
74
75
76