Getopt-Kingpin

 view release on metacpan or  search on metacpan

t/03_int.t  view on Meta::CPAN

use strict;
use Test::More 0.98;
use Test::Exception;
use Capture::Tiny ':all';
use Getopt::Kingpin;


subtest 'int normal with overload' => sub {
    local @ARGV;
    push @ARGV, qw(--x 0);

    my $kingpin = Getopt::Kingpin->new;
    my $x = $kingpin->flag('x', 'set x')->int();
    $kingpin->parse;

    is $x, 0;
    ok $x == 0;
};


subtest 'int error with overload' => sub {
    local @ARGV;
    push @ARGV, qw(--x ZERO);

    my $kingpin = Getopt::Kingpin->new;
    $kingpin->terminate(sub {return @_});
    my $x = $kingpin->flag('x', 'set x')->int();
    my ($stdout, $stderr, $ret, $exit) = capture {
        $kingpin->parse;
    };

    like $stderr, qr/int parse error/, 'int parse error';
    is $exit, 1;

};

done_testing;



( run in 1.186 second using v1.01-cache-2.11-cpan-54e63673c56 )