summaryrefslogtreecommitdiffstats
path: root/t/Monitoring-Plugin-Getopt-04.t
diff options
context:
space:
mode:
authorSven Nierlein <sven@nierlein.de>2014-01-19 23:54:34 (GMT)
committerSven Nierlein <sven@nierlein.de>2014-01-19 23:54:34 (GMT)
commitb418181dfe80dd75169b6e8a619ac1932155dea2 (patch)
treecad9c0ae0eae8e800cfff60555ead06ad33c6856 /t/Monitoring-Plugin-Getopt-04.t
parent1cd8d1c52cbd47121f344c4074aec84653f412ce (diff)
downloadmonitoring-plugin-perl-b418181dfe80dd75169b6e8a619ac1932155dea2.tar.gz
renamed module into Monitoring::Plugin
since the complete monitoring team has been renamed, we also rename this module. Signed-off-by: Sven Nierlein <sven@nierlein.de>
Diffstat (limited to 't/Monitoring-Plugin-Getopt-04.t')
-rw-r--r--t/Monitoring-Plugin-Getopt-04.t97
1 files changed, 97 insertions, 0 deletions
diff --git a/t/Monitoring-Plugin-Getopt-04.t b/t/Monitoring-Plugin-Getopt-04.t
new file mode 100644
index 0000000..b6345d0
--- /dev/null
+++ b/t/Monitoring-Plugin-Getopt-04.t
@@ -0,0 +1,97 @@
1# Monitoring::Plugin::Getopt spec-to-help generation tests
2
3use strict;
4
5use Test::More tests => 11;
6BEGIN { use_ok('Monitoring::Plugin::Getopt') };
7
8# Needed to get evals to work in testing
9Monitoring::Plugin::Functions::_use_die(1);
10
11my %PARAM = (
12 version => '0.01',
13 usage => "Don't use this plugin!",
14);
15
16sub setup
17{
18 # Instantiate object
19 my $ng = Monitoring::Plugin::Getopt->new(%PARAM);
20 ok($ng, 'constructor ok');
21
22 # Positional args, no short arguments, INTEGER
23 $ng->arg('warning=i' =>
24 qq(Exit with WARNING status if less than INTEGER foobars are free),
25 5);
26
27 # Named args, long + short arguments, INTEGER
28 $ng->arg(
29 spec => 'critical|c=i',
30 help => qq(Exit with CRITICAL status if less than INTEGER foobars are free),
31 required => 1,
32 );
33
34 # Named args, multiple short arguments, STRING, default expansion
35 $ng->arg(
36 spec => 'x|y|z=s',
37 help => qq(Foobar. Default: %s),
38 default => "XYZ",
39 );
40
41 # Named args, multiple mixed, no label
42 $ng->arg(
43 spec => 'long|longer|longest|l',
44 help => qq(Long format),
45 );
46
47 # Named args, long + short, explicit label
48 $ng->arg(
49 spec => 'hostname|H=s',
50 label => 'ADDRESS',
51 help => qq(Hostname),
52 );
53
54 # Positional args, long only, explicit label
55 $ng->arg('avatar=s', 'Avatar', undef, undef, 'AVATAR');
56
57 # Multiline help test, named args
58 $ng->arg(
59 spec => 'disk=s',
60 label => [ qw(BYTES PERCENT%), undef ],
61 help => [
62 qq(Disk limit in BYTES),
63 qq(Disk limit in PERCENT),
64 qq(Disk limit in FOOBARS (Default: %s)),
65 ],
66 default => 1024,
67 );
68
69 # Multiline help test, positional args
70 $ng->arg(
71 'limit=s',
72 [
73 qq(Limit in BYTES),
74 qq(Limit in PERCENT),
75 ],
76 undef,
77 undef,
78 [ undef, 'PERCENT%' ],
79 );
80
81 return $ng;
82}
83
84my $ng;
85
86@ARGV = ( '--help' );
87$ng = setup;
88ok(! defined eval { $ng->getopts }, 'getopts died on help');
89like($@, qr/\n --warning=INTEGER/, 'warning ok');
90like($@, qr/\n -c, --critical=INTEGER/, 'critical ok');
91like($@, qr/\n -x, -y, -z=STRING\n Foobar. Default: XYZ\n/, 'x|y|z ok');
92like($@, qr/\n -l, --long, --longer, --longest\n Long format\n/, 'long ok');
93like($@, qr/\n -H, --hostname=ADDRESS\n Hostname\n/, 'hostname ok');
94like($@, qr/\n --avatar=AVATAR\n Avatar\n/, 'avatar ok');
95like($@, qr/\n --disk=BYTES\n Disk limit in BYTES\n --disk=PERCENT%\n Disk limit in PERCENT\n --disk=STRING\n Disk limit in FOOBARS \(Default: 1024\)\n/, 'disk multiline ok');
96like($@, qr/\n --limit=STRING\n Limit in BYTES\n --limit=PERCENT%\n Limit in PERCENT\n/, 'limit multiline ok');
97#print $@;