#!perl use lib 'lib'; use strict; use warnings; no warnings qw(once); use Test::More tests => 24; BEGIN { use_ok( 'Getopt::Declare' ); } my $spec = q{ [pvtype: bool /0|1/] [pvtype: one /asdf/ { $_VAL_ = 1; } ] -a option 1 -b option 2 bee [ditto] (again) option 3 +d ... option 4 [repeatable] -1 option 5 --out ... option 6 -y option 8 -z option 9 -e option 10 -f * @ option 11 -g option 12 -p option 13 { $::use_percentage = 'on'; } Decorations using brackets need to be escaped with '\\\[', e.g. \[ditto], \[repeatable] }; my $usage = quotemeta( q{ Options: -a option 1 -b option 2 bee " " (again) option 3 +d ... option 4 -1 option 5 --out ... option 6 -y option 8 -z option 9 -e option 10 -f * @ option 11 -g option 12 -p option 13 Decorations using brackets need to be escaped with '\[', e.g. [ditto], [repeatable] } ); @ARGV = ( '-g', 'asdf', 'bee', 'BB BB', '--out', 'dummy.txt', 'fake.csv', '-aA', 's e e', 'remainder', '-yz', '+d', '8', '1.2345', '0.99', '1000123', '.3', 'a', '-e', '0', '-p', '0.452', '-f', '1', '*', '10', '@', '0.1', '+d', '9', '1.2345', '1e3', '2.1E-01', '.3', '-1', ); ok my $args = Getopt::Declare->new($spec), 'new'; isa_ok $args, 'Getopt::Declare'; ok $args->version, 'version'; ok $args->usage, 'usage'; ok $args->usage_string =~ m/$usage/; is $args->{'-a'}, 'A', 'argument parsing'; is $args->{'bee'}, 'BB BB'; is $args->{''}, 's e e'; is join(',',@{$args->{'+d'}}), '8,1.2345,0.99,1000123,.3,9,1.2345,1e3,2.1E-01,.3'; is $args->{''}, undef; is $args->{'-1'}, -1; is $args->{'--out'}->[0], 'dummy.txt'; is $args->{'--out'}->[1], 'fake.csv'; is $args->{'-f'}->{''}, 1; is $args->{'-f'}->{''}, 10; is $args->{'-f'}->{''}, 0.1; is $args->{'-g'}, 1; is $args->{'-e'}, 0; is $args->{'-p'}, 0.452; is $::use_percentage, 'on'; is scalar @ARGV, 2; is $ARGV[0], 'remainder'; is $ARGV[1], 'a';