[Nagiosplug-checkins] Nagios-Plugin/t Nagios-Plugin-Getopt-04.t, NONE, 1.1 Nagios-Plugin-04.t, 1.2, 1.3 Nagios-Plugin-Getopt-01.t, 1.2, 1.3 Nagios-Plugin-Getopt-03.t, 1.1, 1.2

Gavin Carr gonzai at users.sourceforge.net
Wed Mar 21 01:52:54 CET 2007


Update of /cvsroot/nagiosplug/Nagios-Plugin/t
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv11948/t

Modified Files:
	Nagios-Plugin-04.t Nagios-Plugin-Getopt-01.t 
	Nagios-Plugin-Getopt-03.t 
Added Files:
	Nagios-Plugin-Getopt-04.t 
Log Message:
Finished initial --extra-opts support; added Getopt spec-to-help and multiline help support.

Index: Nagios-Plugin-Getopt-03.t
===================================================================
RCS file: /cvsroot/nagiosplug/Nagios-Plugin/t/Nagios-Plugin-Getopt-03.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Nagios-Plugin-Getopt-03.t	8 Feb 2007 05:18:05 -0000	1.1
+++ Nagios-Plugin-Getopt-03.t	21 Mar 2007 00:52:52 -0000	1.2
@@ -1,4 +1,4 @@
-# Nagios::Plugin::Getopt --default-opts tests
+# Nagios::Plugin::Getopt --extra-opts tests
 
 use strict;
 use File::Spec;
@@ -27,7 +27,8 @@
   }
 }
 
-$Nagios::Plugin::Getopt::DEFAULT_CONFIG_FILE = File::Spec->catfile($tdir, 'plugins.cfg');
+# Override NAGIOS_CONFIG_PATH to use our test plugins.ini file
+$ENV{NAGIOS_CONFIG_PATH} = "/random/bogus/path:$tdir";
 
 my %PARAM = (
     version => '0.01',
@@ -56,14 +57,18 @@
   { spec => 'S',            help => '-S' },
   { spec => 'H=s',          help => '-H' },
   { spec => 'p=s@',         help => '-p' },
+  { spec => 'path=s@',      help => '--path' },
   { spec => 'username|u=s', help => '--username' },
   { spec => 'password=s',   help => '--password' },
-  { spec => 'critical=i',   help => '--critical' },
-  { spec => 'warning=i',    help => '--warning' },
+  { spec => 'critical=s',   help => '--critical' },
+  { spec => 'warning=s',    help => '--warning' },
   { spec => 'expect=s',     help => '--expect' },
+  { spec => 'units=s',      help => '--units' },
 ];
 
-my %SKIP = map { $_ => 1 } qw(05_singlechar1 07_singlechar3);
+#my %SKIP = map { $_ => 1 } qw(05_singlechar1 07_singlechar3);
+#my %SKIP = map { $_ => 1 } qw(06_singlechar2);
+my %SKIP = ();
 
 # Process all test cases in $tdir/input
 my $glob = $ARGV[0] || '*';
@@ -82,7 +87,7 @@
     
     # Parse the options
     SKIP: {
-      skip "Still discussing how overrides with multiple arguments should work ...", 1 if $SKIP{$infile};
+      skip "Skipping ..." if $SKIP{$infile};
 
       @ARGV = @args;
       eval { $ng->getopts };

Index: Nagios-Plugin-04.t
===================================================================
RCS file: /cvsroot/nagiosplug/Nagios-Plugin/t/Nagios-Plugin-04.t,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Nagios-Plugin-04.t	16 Mar 2007 11:25:15 -0000	1.2
+++ Nagios-Plugin-04.t	21 Mar 2007 00:52:52 -0000	1.3
@@ -1,6 +1,5 @@
 
 # tests for toplevel access to Threshold and GetOpts stuff
-# $Id$
 
 use strict;
 #use Test::More 'no_plan';

Index: Nagios-Plugin-Getopt-01.t
===================================================================
RCS file: /cvsroot/nagiosplug/Nagios-Plugin/t/Nagios-Plugin-Getopt-01.t,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Nagios-Plugin-Getopt-01.t	31 Aug 2006 08:34:24 -0000	1.2
+++ Nagios-Plugin-Getopt-01.t	21 Mar 2007 00:52:52 -0000	1.3
@@ -27,8 +27,8 @@
   
   # Add argument - named version
   $ng->arg(
-    spec => 'critical|c=s',
-    help => qq(-c, --critical=INTEGER\n   Exit with CRITICAL status if less than INTEGER foobars are free),
+    spec => 'critical|c=i',
+    help => qq(Exit with CRITICAL status if less than INTEGER foobars are free),
     required => 1,
   );
 
@@ -104,6 +104,7 @@
 like($@, qr/$PARAM{url}/, 'version info includes url');
 unlike($@, qr/Usage:/, 'no usage message');
 unlike($@, qr/Missing arg/, 'no missing arguments');
+
 @ARGV = ( '--version' );
 $ng = setup;
 ok(! defined eval { $ng->getopts }, 'getopts died on version');
@@ -128,6 +129,7 @@
 like($@, qr/--warning/, 'help includes custom option 1');
 like($@, qr/--critical/, 'help includes custom option 2');
 unlike($@, qr/Missing arg/, 'no missing arguments');
+
 @ARGV = ( '--help' );
 $ng = setup;
 ok(! defined eval { $ng->getopts }, 'getopts died on help');
@@ -140,6 +142,6 @@
 like($@, qr/--version/, 'help includes default options 1');
 like($@, qr/--verbose/, 'help includes default options 2');
 like($@, qr/--warning/, 'help includes custom option 1');
-like($@, qr/--critical/, 'help includes custom option 2');
+like($@, qr/-c, --critical=INTEGER/, 'help includes custom option 2, with expanded args');
 unlike($@, qr/Missing arg/, 'no missing arguments');
 

--- NEW FILE: Nagios-Plugin-Getopt-04.t ---
# Nagios::Plugin::Getopt spec-to-help generation tests

use strict;

use Test::More tests => 11;
BEGIN { use_ok('Nagios::Plugin::Getopt') };

my %PARAM = (
    version => '0.01',
    usage => "Don't use this plugin!",
);

sub setup 
{
  # Instantiate object
  my $ng = Nagios::Plugin::Getopt->new(%PARAM);
  ok($ng, 'constructor ok');

  # Positional args, no short arguments, INTEGER
  $ng->arg('warning=i' =>
    qq(Exit with WARNING status if less than INTEGER foobars are free),
    5);
  
  # Named args, long + short arguments, INTEGER
  $ng->arg(
    spec => 'critical|c=i',
    help => qq(Exit with CRITICAL status if less than INTEGER foobars are free),
    required => 1,
  );

  # Named args, multiple short arguments, STRING, default expansion
  $ng->arg(
    spec => 'x|y|z=s',
    help => qq(Foobar. Default: %s),
    default => "XYZ", 
  );

  # Named args, multiple mixed, no label
  $ng->arg(
    spec => 'long|longer|longest|l',
    help => qq(Long format),
  );

  # Named args, long + short, explicit label
  $ng->arg(
    spec => 'hostname|H=s',
    label => 'ADDRESS',
    help => qq(Hostname),
  );

  # Positional args, long only, explicit label
  $ng->arg('avatar=s', 'Avatar', undef, undef, 'AVATAR');

  # Multiline help test, named args
  $ng->arg(
    spec => 'disk=s',
    label => [ qw(BYTES PERCENT%), undef ],
    help => [
      qq(Disk limit in BYTES),
      qq(Disk limit in PERCENT),
      qq(Disk limit in FOOBARS (Default: %s)),
    ],
    default => 1024,
  );

  # Multiline help test, positional args
  $ng->arg(
    'limit=s',
    [
      qq(Limit in BYTES),
      qq(Limit in PERCENT),
    ],
    undef,
    undef,
    [ undef, 'PERCENT%' ],
  );

  return $ng;
}

my $ng;

@ARGV = ( '--help' );
$ng = setup;
ok(! defined eval { $ng->getopts }, 'getopts died on help');
like($@, qr/\n --warning=INTEGER/, 'warning ok');
like($@, qr/\n -c, --critical=INTEGER/, 'critical ok');
like($@, qr/\n -x, -y, -z=STRING\n   Foobar. Default: XYZ\n/, 'x|y|z ok');
like($@, qr/\n -l, --long, --longer, --longest\n   Long format\n/, 'long ok');
like($@, qr/\n -H, --hostname=ADDRESS\n   Hostname\n/, 'hostname ok');
like($@, qr/\n --avatar=AVATAR\n   Avatar\n/, 'avatar ok');
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');
like($@, qr/\n --limit=STRING\n   Limit in BYTES\n --limit=PERCENT%\n   Limit in PERCENT\n/, 'limit multiline ok');
#print $@;






More information about the Commits mailing list