X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F002_custom_option_type.t;h=5c0eb90c44eed5f727b08cbda84eaf8fa956c50a;hb=aec092482d5b90b8279e4a5f92165868a78ddf32;hp=881b0f6ee5676f3665c15dcffcca436615cc4ade;hpb=8034a2324bcef31b91a45a83baec1508acee2763;p=gitmo%2FMooseX-Getopt.git diff --git a/t/002_custom_option_type.t b/t/002_custom_option_type.t index 881b0f6..5c0eb90 100644 --- a/t/002_custom_option_type.t +++ b/t/002_custom_option_type.t @@ -1,9 +1,9 @@ -#!/usr/bin/perl - use strict; -use warnings; +use warnings FATAL => 'all'; -use Test::More tests => 5; +use Test::More tests => 7; +use Test::NoWarnings 1.04 ':early'; +use Test::Fatal; BEGIN { use_ok('MooseX::Getopt'); @@ -13,25 +13,24 @@ BEGIN { package App; use Moose; use Moose::Util::TypeConstraints; - + use Scalar::Util 'looks_like_number'; - + with 'MooseX::Getopt'; subtype 'ArrayOfInts' => as 'ArrayRef' => where { scalar (grep { looks_like_number($_) } @$_) }; - + MooseX::Getopt::OptionTypeMap->add_option_type_to_map( 'ArrayOfInts' => '=i@' ); - + has 'nums' => ( is => 'ro', isa => 'ArrayOfInts', default => sub { [0] } - ); - + ); } { @@ -39,8 +38,8 @@ BEGIN { my $app = App->new_with_options; isa_ok($app, 'App'); - - is_deeply($app->nums, [0], '... nums is [0] as expected'); + + is_deeply($app->nums, [0], '... nums is [0] as expected'); } { @@ -48,7 +47,18 @@ BEGIN { my $app = App->new_with_options; isa_ok($app, 'App'); - - is_deeply($app->nums, [3, 5], '... nums is [3, 5] as expected'); + + is_deeply($app->nums, [3, 5], '... nums is [3, 5] as expected'); } +# Make sure it really used our =i@, instead of falling back +# to =s@ via the type system, and test that exceptions work +# while we're at it. +like( + exception { + local @ARGV = ('--nums', 3, '--nums', 'foo'); + my $app = App->new_with_options; + }, + qr/Value "foo" invalid/, + 'Numeric constraint enforced', +);