Skip to content

Instantly share code, notes, and snippets.

@bdonlan
Created July 20, 2009 02:41
Show Gist options
  • Save bdonlan/150130 to your computer and use it in GitHub Desktop.
Save bdonlan/150130 to your computer and use it in GitHub Desktop.
use Test::More qw(no_plan); #tests => 32;
BEGIN { use_ok('Getopt::String', ":all"); }
my $gs = new Getopt::String(
option_switch($help, [qw/help h/]),
option_counter($verbose, [qw/verbose v/]),
option_stop(""),
option_arg($outfile, [qw/output o/]),
option_arg($foo, 'foo', optional_arg => 1)
);
my $remain = $gs->parse("");
is_deeply([$help, $verbose, $outfile, $foo], [0, 0, undef, undef], "defaulting");
my $remain = $gs->parse("-h");
is_deeply([$help, $verbose, $outfile, $foo], [1, 0, undef, undef], "switch args");
my $remain = $gs->parse("--help");
is_deeply([$help, $verbose, $outfile, $foo], [1, 0, undef, undef], "switch args");
my $remain = $gs->parse("--help -h");
is_deeply([$help, $verbose, $outfile, $foo], [1, 0, undef, undef], "switch args");
my $remain = $gs->parse("--help --help");
is_deeply([$help, $verbose, $outfile, $foo], [1, 0, undef, undef], "switch args");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment