22
33use strict;
44
5- use Test::More tests => 76 ;
5+ use Test::More tests => 81 ;
66BEGIN { use_ok(' Monitoring::Plugin::Getopt' ) };
77
88# Needed to get evals to work in testing
@@ -35,6 +35,13 @@ sub setup
3535 required => 1,
3636 );
3737
38+ # Add argument - boolean, supporting --no-prefix
39+ $ng -> arg(
40+ spec => ' perfdata!' ,
41+ help => qq( Provide performance data) ,
42+ default => 1,
43+ );
44+
3845 return $ng ;
3946}
4047
@@ -47,6 +54,13 @@ $ng->getopts;
4754is($ng -> warning, 3, ' warning set to 3' );
4855is($ng -> critical, 10, ' critical set to 10' );
4956is($ng -> timeout, 12, ' timeout set to 12' );
57+ is($ng -> perfdata, 1, ' perfdata set to default of 1' );
58+
59+ # Disable perfdata
60+ @ARGV = qw( --critical 10 --no-perfdata) ;
61+ $ng = setup;
62+ $ng -> getopts;
63+ is($ng -> perfdata, 0, ' perfdata set to 0' );
5064
5165# Check multiple verbose flags
5266@ARGV = qw( -w 3 --critical 10 -v -v -v) ;
@@ -131,6 +145,7 @@ like($@, qr/--version/, 'help includes default options 1');
131145like($@ , qr / --verbose/ , ' help includes default options 2' );
132146like($@ , qr / --warning/ , ' help includes custom option 1' );
133147like($@ , qr / --critical/ , ' help includes custom option 2' );
148+ like($@ , qr / --\[ no-\] perfdata\n / , ' help includes custom option 3' );
134149unlike($@ , qr / Missing arg/ , ' no missing arguments' );
135150
136151@ARGV = ( ' --help' );
@@ -146,4 +161,5 @@ like($@, qr/--version/, 'help includes default options 1');
146161like($@ , qr / --verbose/ , ' help includes default options 2' );
147162like($@ , qr / --warning/ , ' help includes custom option 1' );
148163like($@ , qr / -c, --critical=INTEGER/ , ' help includes custom option 2, with expanded args' );
164+ like($@ , qr / --\[ no-\] perfdata\n / , ' help includes custom option 3' );
149165unlike($@ , qr / Missing arg/ , ' no missing arguments' );
0 commit comments