X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F100_gld_default_bug.t;fp=t%2F100_gld_default_bug.t;h=4a2b42a0e1689186ffc5e0398c930efbe74a15ae;hb=630657d529277b7fb600febf001d8667d8e85184;hp=0000000000000000000000000000000000000000;hpb=84f85ea4261f96ab86bde19610658bba98588500;p=gitmo%2FMooseX-Getopt.git diff --git a/t/100_gld_default_bug.t b/t/100_gld_default_bug.t new file mode 100644 index 0000000..4a2b42a --- /dev/null +++ b/t/100_gld_default_bug.t @@ -0,0 +1,48 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More; +use Test::Exception; + +BEGIN { + eval 'use Getopt::Long::Descriptive;'; + plan skip_all => "Getopt::Long::Descriptive required for this test" if $@; + plan tests => 5; + use_ok('MooseX::Getopt'); +} + +{ + package Engine::Foo; + use Moose; + + with 'MooseX::Getopt'; + + has 'nproc' => ( + metaclass => 'Getopt', + is => 'ro', + isa => 'Int', + default => sub { 1 }, + cmd_aliases => 'n', + ); +} + +@ARGV = (); + +{ + my $foo = Engine::Foo->new_with_options(nproc => 10); + isa_ok($foo, 'Engine::Foo'); + + is($foo->nproc, 10, '... got the right value (10), not the default (1)'); +} + +{ + my $foo = Engine::Foo->new_with_options(); + isa_ok($foo, 'Engine::Foo'); + + is($foo->nproc, 1, '... got the right value (1), without GLD needing to handle defaults'); +} + + +