MooX-Options

 view release on metacpan or  search on metacpan

t/06-failure.t  view on Meta::CPAN

{
    eval "#line ${\(__LINE__+1 . ' ' . __FILE__)}\n" . <<__EOF__
    {
        package MissingHas;
        sub with {};
        sub around {};
        use MooX::Options;
        1;
    }
__EOF__
        ;
    like $@, qr/^\QCan't find the method <has> in <MissingHas>!
Ensure to load a Role::Tiny compatible module like Moo or Moose before using MooX::Options.\E/,
        'missing with';
}

{
    eval "#line ${\(__LINE__+1 . ' ' . __FILE__)}\n" . <<__EOF__
    {
        package IllegalShortEnding;
        use Moo;
        use MooX::Options;
        option 'legal' => (is => 'rw', short => 'l!');
        1;
    }
    IllegalShortEnding->new_with_options;
__EOF__
        ;
    like $@,
        qr/^cmdline\sargument\s'legal|l!'\sshould\send\swith\sa\sword\scharacter/x,
        'illegal short trailing char causes reasonable failure';
}

{
    eval "#line ${\(__LINE__+1 . ' ' . __FILE__)}\n" . <<__EOF__
    {
        package ShortOptionConflict;
        use Moo;
        use MooX::Options;
	option 'l' => (is => 'rw');
        option 'legal' => (is => 'rw', short => 'l');
        1;
    }
    ShortOptionConflict->new_with_options;
__EOF__
        ;
    like $@,
        qr/^There\sis\salready\san\soption\s'l'\s\-\scan't\suse\sit\sto\sshorten\s'legal'/x,
        'short conflict with existing option';
}

trap {
    eval "#line ${\(__LINE__+1 . ' ' . __FILE__)}\n" . <<__EOF__
    {
        package NonNegatableNegated;
        use Moo;
        use MooX::Options;
        option 'legal' => (is => 'rw');
        1;
    }
    local \@ARGV = ('--no-legal');
    NonNegatableNegated->new_with_options;
__EOF__
        ;
};
like $trap->stderr, qr/^Unknown\soption:\sno_legal/x, 'Unexisting negation';

done_testing;



( run in 1.144 second using v1.01-cache-2.11-cpan-364913b4093 )