1 # Nagios::Monitoring::Plugin::Getopt spec-to-help generation tests
5 use Test::More tests => 11;
6 BEGIN { use_ok('Nagios::Monitoring::Plugin::Getopt') };
8 # Needed to get evals to work in testing
9 Nagios::Monitoring::Plugin::Functions::_use_die(1);
13 usage => "Don't use this plugin!",
19 my $ng = Nagios::Monitoring::Plugin::Getopt->new(%PARAM);
20 ok($ng, 'constructor ok');
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),
27 # Named args, long + short arguments, INTEGER
29 spec => 'critical|c=i',
30 help => qq(Exit with CRITICAL status if less than INTEGER foobars are free),
34 # Named args, multiple short arguments, STRING, default expansion
37 help => qq(Foobar. Default: %s),
41 # Named args, multiple mixed, no label
43 spec => 'long|longer|longest|l',
44 help => qq(Long format),
47 # Named args, long + short, explicit label
49 spec => 'hostname|H=s',
54 # Positional args, long only, explicit label
55 $ng->arg('avatar=s', 'Avatar', undef, undef, 'AVATAR');
57 # Multiline help test, named args
60 label => [ qw(BYTES PERCENT%), undef ],
62 qq(Disk limit in BYTES),
63 qq(Disk limit in PERCENT),
64 qq(Disk limit in FOOBARS (Default: %s)),
69 # Multiline help test, positional args
78 [ undef, 'PERCENT%' ],
88 ok(! defined eval { $ng->getopts }, 'getopts died on help');
89 like($@, qr/\n --warning=INTEGER/, 'warning ok');
90 like($@, qr/\n -c, --critical=INTEGER/, 'critical ok');
91 like($@, qr/\n -x, -y, -z=STRING\n Foobar. Default: XYZ\n/, 'x|y|z ok');
92 like($@, qr/\n -l, --long, --longer, --longest\n Long format\n/, 'long ok');
93 like($@, qr/\n -H, --hostname=ADDRESS\n Hostname\n/, 'hostname ok');
94 like($@, qr/\n --avatar=AVATAR\n Avatar\n/, 'avatar ok');
95 like($@, 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');
96 like($@, qr/\n --limit=STRING\n Limit in BYTES\n --limit=PERCENT%\n Limit in PERCENT\n/, 'limit multiline ok');