| 1 | # Before `make install' is performed this script should be runnable with | ||
| 2 | # `make test'. After `make install' it should work as `perl 1.t' | ||
| 3 | |||
| 4 | ######################### | ||
| 5 | |||
| 6 | # change 'tests => 1' to 'tests => last_test_to_print'; | ||
| 7 | |||
| 8 | 1 | ▶ | use Test::More tests => 1; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 1 | ▶ | BEGIN { use_ok('Getopt::ExPar') }; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | ######################### | ||
| 12 | |||
| 13 | # Insert your test code below, the Test::More module is use()ed here so read | ||
| 14 | # its man page ( perldoc Test::More ) for help writing this test script. | ||
| 15 | |||
| 16 | 1 | my($opt) = _new Getopt::ExPar( {'development_check' => 1, | |
| 17 | 'switchglomming' => 1, | ||
| 18 | 'ignorecase' => 1, | ||
| 19 | } ); | ||
| 20 | 1 | foreach ( qw/a b c d e f g h i j k l m n o p/ ) { | |
| 21 | 16 | $opt->_parameter( $_ ); | |
| 22 | 16 | $opt->_help( $_, 'Just a switch.' ); | |
| 23 | } | ||
| 24 | 1 | $opt->_parameter( 'switch01' ); | |
| 25 | 1 | $opt->_help( 'switch01', 'Just a switch.' ); | |
| 26 | 1 | $opt->_multi_parameter( 'multiparam01', { 'mp01op01' => 'string', }, { 'mp01op02' => 'string', }, ); | |
| 27 | 1 | $opt->_keys( 'multiparam01', { 'mp01op02' => [ 'a', 'b', 'aa', 'bb', 'aaa', 'bbb', ], 'mp01op01' => [ 'a', 'b', 'cc', ], } ); | |
| 28 | 1 | $opt->_alias( 'multiparam01', 'mp01', ); | |
| 29 | 1 | $opt->_help( 'multiparam01', 'First parameter with multiple arguments.', ); | |
| 30 | 1 | $opt->_multi_parameter( 'multiparam02', { 'mp02op01' => 'file', }, { 'mp02op02' => 'file', }, { 'mp02op03' => 'integer', }, ); | |
| 31 | 1 | $opt->_unique( 'multiparam02', ); | |
| 32 | 1 | $opt->_help( 'multiparam02', 'Second parameter with multiple arguments.', ); | |
| 33 | 1 | $opt->_mp( 'multiparam03', { 'mp03op01' => 'string', }, { 'mp03op02' => 'file', }, ); | |
| 34 | 1 | $opt->_help( 'multiparam03', 'Third parameter with multiple arguments.', ); | |
| 35 | 1 | $opt->_p( 'param01', 'file', 'p01', ); | |
| 36 | 1 | $opt->_h( 'param01', 'First parameter, has alias of p01.' ); | |
| 37 | 1 | $opt->_p( 'param02', 'file' ); | |
| 38 | 1 | $opt->_h( 'param02', 'Second parameter.' ); | |
| 39 | 1 | $opt->_p( 'param03', 'file', 'p03' ); | |
| 40 | 1 | $opt->_h( 'param03', 'Third parameter, has alias of p03.' ); | |
| 41 | 1 | $opt->_req_grp( 'multiparam01', 'multiparam03', 'param01', 'param03', ); | |
| 42 | 1 | $opt->_p( 'param04', 'string', ); | |
| 43 | 1 | $opt->_default( 'param04', 'string04', ); | |
| 44 | 1 | $opt->_h( 'param04', 'Fourth parameter, has default of string04.' ); | |
| 45 | 1 | $opt->_p( 'PAram05', 'string', ); | |
| 46 | 1 | $opt->_required( 'PAram05', ); | |
| 47 | 1 | $opt->_h( 'PAram05', 'Fifth parameter, a required parameter.' ); | |
| 48 | 1 | $opt->_keys( 'PAram05', 'a', 'b', 'c', 'foo', 'bar' ); | |
| 49 | 1 | $opt->_p( 'param06', 'file', ); | |
| 50 | 1 | $opt->_unique( 'param06', ); | |
| 51 | 1 | $opt->_h( 'param06', 'Sixth parameter, requires unique values.' ); | |
| 52 | 1 | $opt->_help(<<End); | |
| 53 | This is the help description for the entire script $0. | ||
| 54 | This is printed whenever -help is requested. | ||
| 55 | End | ||
| 56 | |||
| 57 | 1 | $opt->_special( 'numOpt', '^\-\d+' ); | |
| 58 | 1 | $opt->_help_option( 'numOpt', '-#' ); | |
| 59 | 1 | $opt->_help( 'numOpt', 'Matches any -# option.' ); | |
| 60 | 1 | foreach my $cmd ( 'a' .. 'd' ) { | |
| 61 | 4 | $opt->_special( "${cmd}Switch", '\+'.$cmd.'Switch\+.+' ); | |
| 62 | 4 | $opt->_help_option( "${cmd}Switch", "+${cmd}Switch+<$cmd switch>" ); | |
| 63 | 4 | $opt->_help( "${cmd}Switch", "Specify switch for $cmd."); | |
| 64 | 4 | $opt->_s( "${cmd}Option", '\+'.$cmd.'Option\+.+', 'string' ); | |
| 65 | 4 | $opt->_help_option( "${cmd}Option", "+${cmd}Option+<$cmd option>" ); | |
| 66 | 4 | $opt->_help( "${cmd}Option", "Specify option for $cmd." ); | |
| 67 | 4 | $opt->_s( "${cmd}Default", '\+'.$cmd.'Default\+.+', 'string' ); | |
| 68 | 4 | $opt->_help_option( "${cmd}Default", "+${cmd}Default+<$cmd option>" ); | |
| 69 | 4 | $opt->_help( "${cmd}Default", "Specify default for $cmd." ); | |
| 70 | 4 | $opt->_s( "${cmd}RemoveSwitch", '\+'.$cmd.'RemoveSwitch\+.+' ); | |
| 71 | 4 | $opt->_help_option( "${cmd}RemoveSwitch", "+${cmd}RemoveSwitch+<$cmd switch>" ); | |
| 72 | 4 | $opt->_help( "${cmd}RemoveSwitch", "Remove switch for $cmd." ); | |
| 73 | 4 | $opt->_multi_special( "${cmd}RemoveOption", '\+'.$cmd.'RemoveOption\+.+', { 'arg1' => 'string', }, { 'arg2' => 'integer', }, { 'arg3' => 'string', } ); | |
| 74 | 4 | $opt->_help_option( "${cmd}RemoveOption", "+${cmd}RemoveOption+<$cmd option>" ); | |
| 75 | 4 | $opt->_help( "${cmd}RemoveOption", "Remove option for $cmd." ); | |
| 76 | } | ||
| 77 | |||
| 78 | 1 | $opt->_mutex( 'switch01', 'aSwitch' ); | |
| 79 | |||
| 80 | # $opt->_parse(); | ||
| 81 | # | ||
| 82 | # #Now test the actual methods to return data: _arg, _args, _arge, _argl, _argh | ||
| 83 | # | ||
| 84 | # #switches always return 0/1 | ||
| 85 | # foreach ( qw/a b c d e f g h i j k l m n o p/ ) { | ||
| 86 | # print "$_: ", $opt->_arg($_), "\n"; | ||
| 87 | # } | ||
| 88 | # print "switch01: ", $opt->switch01(), "\n"; | ||
| 89 | # | ||
| 90 | # #regular parameters will return undef() so check _arge first | ||
| 91 | # print "param01: ", $opt->param01(), " exists, ", $opt->param01_argc(), " arguments.\n" if $opt->param01_arge(); | ||
| 92 | # print "param02: ", $opt->param02(), " exists, ", $opt->param02_argc(), " arguments.\n" if $opt->param02_arge(); | ||
| 93 | # print "param03: ", $opt->param03(), " exists, ", $opt->param03_argc(), " arguments.\n" if $opt->param03_arge(); | ||
| 94 | # print "param04: ", $opt->param04(), " exists, ", $opt->param04_argc(), " arguments.\n" if $opt->param04_arge(); | ||
| 95 | # print "param05: ", $opt->PAram05(), " exists, ", $opt->PAram05_argc(), " arguments.\n" if $opt->PAram05_arge(); | ||
| 96 | # print "param06: ", $opt->param06(), " exists, ", $opt->param06_argc(), " arguments.\n" if $opt->param06_arge(); | ||
| 97 | # print "multiparam01: ", join(', ', @{$opt->multiparam01()}), " exists, ", $opt->multiparam01_argc(), " arguments.\n" if $opt->multiparam01_arge(); | ||
| 98 | # print "multiparam02: ", join(', ', @{$opt->multiparam02()}), " exists, ", $opt->multiparam02_argc(), " arguments.\n" if $opt->multiparam02_arge(); | ||
| 99 | # print "multiparam03: ", join(', ', @{$opt->multiparam03()}), " exists, ", $opt->multiparam03_argc(), " arguments.\n" if $opt->multiparam03_arge(); | ||
| 100 | # | ||
| 101 | # #special parameters always return array refs when accessing each element | ||
| 102 | # print "aSwitch: ", join(', ', @{$opt->aSwitch()}), " exists, ", $opt->aSwitch_argc(), " arguments.\n" if $opt->aSwitch_arge(); | ||
| 103 | # print "cOption: ", join(', ', @{$opt->cOption()}), " exists, ", $opt->cOption_argc(), " arguments.\n" if $opt->cOption_arge(); | ||
| 104 | # print "dRemoveOption: ", join(', ', @{$opt->dRemoveOption()}), " exists, ", $opt->dRemoveOption_argc(), " arguments.\n" if $opt->dRemoveOption_arge(); | ||
| 105 | # print "numOpt: ", join(', ', @{$opt->numOpt()}), " exists, ", $opt->numOpt_argc(), " arguments.\n" if $opt->numOpt_arge(); | ||
| 106 | # | ||
| 107 | # #argl loops through all arguments of specified parameter | ||
| 108 | # while ( my $v = $opt->param06_argl() ) { | ||
| 109 | # print "param06: $v\n"; | ||
| 110 | # } | ||
| 111 | # while ( my $v = $opt->multiparam02_argl() ) { | ||
| 112 | # print "multiparam06: @{$v}\n"; | ||
| 113 | # } | ||
| 114 | # | ||
| 115 | # #argh returns hashes with all arguments available | ||
| 116 | # my($h) = $opt->param02_argh(); | ||
| 117 | # foreach ( sort { $a<=>$b; } keys %{$h} ) { | ||
| 118 | # print "param02($_) => $h->{$_}\n"; | ||
| 119 | # } | ||
| 120 | # $h = $opt->multiparam02_argh(); | ||
| 121 | # foreach my $i ( sort { $a<=>$b; } keys %{$h} ) { | ||
| 122 | # foreach ( sort keys %{$h->{$i}} ) { | ||
| 123 | # print "multiparam02($i, $_) => $h->{$i}->{$_}\n"; | ||
| 124 | # } | ||
| 125 | # } | ||
| 126 | # print "multiparam02(2, 'mp02op02') => ", $opt->multiparam02_argh()->{2}->{'mp02op02'}, "\n"; | ||
| 127 | # $h = $opt->cOption_argh(); | ||
| 128 | # foreach my $i ( sort { $a<=>$b; } keys %{$h} ) { | ||
| 129 | # foreach ( sort keys %{$h->{$i}} ) { | ||
| 130 | # print "cOption($i, $_) => $h->{$i}->{$_}\n"; | ||
| 131 | # } | ||
| 132 | # } | ||
| 133 | # $h = $opt->dRemoveOption_argh(); | ||
| 134 | # foreach my $i ( sort { $a<=>$b; } keys %{$h} ) { | ||
| 135 | # foreach ( sort keys %{$h->{$i}} ) { | ||
| 136 | # print "dRemoveOption($i, $_) => $h->{$i}->{$_}\n"; | ||
| 137 | # } | ||
| 138 | # } | ||
| 139 | # | ||