Subject: | Moving tests of Getopt::Long from Perl 5 lib/Getopt/Std.t |
In the Perl 5 core distribution, there are certain unit tests found in lib/Getopt/Std.t which are actually tests for Getopt::Long functionality:
#####
# Then try the Getopt::Long module
use Getopt::Long;
@ARGV = qw(--help --file foo --foo --nobar --num=5 -- file);
our ($HELP, $FILE, $FOO, $BAR, $NO);
ok( GetOptions(
'help' => \$HELP,
'file:s' => \$FILE,
'foo!' => \$FOO,
'bar!' => \$BAR,
'num:i' => \$NO,
),
'Getopt::Long::GetOptions succeeded'
);
is( "@ARGV", 'file', 'options removed from @ARGV (5)' );
ok( $HELP && $FOO && !$BAR && $FILE eq 'foo' && $NO == 5, 'options set' );
#####
Per Dave Mitchell (on p5p, July 12 2013), this is leftover from the days when Getopt::Std and Getopt::Long were jointly tested in a single program.
In order to provide for better maintenance of Getopt::Std (perhaps by ultimately moving it to maintenance on CPAN), we would like to remove these tests for Getopt::Long from lib/Getopt/Std.t.
I was advised, however, to make sure that this functionality is tested in Getopt::Long's test suite.
Accordingly, I have prepared a patch which rewrites those unit tests in the style of Getopt::Long's unit tests and added them to t/gol-basic.t. (I couldn't find any mention of a github or similar site for Getopt::Long's development, so I prepared the patch against 2.41 from CPAN.)
Please review. If the additional tests are duplicative, feel free to reject. Otherwise, I hope you can apply it.
Subject: | getopt-long-t-gol-basic.diff |
18c18
< print "1..9\n";
---
> print "1..12\n";
31a32,44
>
> @ARGV = qw(--help --file foo --foo --nobar --num=5 -- file);
> $rv = GetOptions(
> 'help' => \$HELP,
> 'file:s' => \$FILE,
> 'foo!' => \$FOO,
> 'bar!' => \$BAR,
> 'num:i' => \$NO,
> );
> print ($rv ? "" : "not "); print "ok 10\n";
> print ("@ARGV" eq 'file' ? "" : "not ", "ok 11\n");
> ( $HELP && $FOO && !$BAR && $FILE eq 'foo' && $NO == 5 )
> ? print "" : print "not "; print "ok 12\n";