Revert most of the conversion to Test::Fatal so we can redo it
[gitmo/Moose.git] / t / 100_bugs / 030_coerce_without_coercion.t
CommitLineData
4ee48f8e 1use strict;
2use warnings;
3
4use Test::More;
53a4d826 5use Test::Exception;
4ee48f8e 6use Test::Moose;
7
8{
9 package Foo;
10
5d9b0b88 11 use Moose::Deprecated -api_version => '1.07';
4ee48f8e 12 use Moose;
13
14 has x => (
15 is => 'rw',
16 isa => 'HashRef',
17 coerce => 1,
18 );
19}
20
21with_immutable {
53a4d826 22 lives_ok { Foo->new( x => {} ) }
4ee48f8e 23 'Setting coerce => 1 without a coercion on the type does not cause an error in the constructor';
24
53a4d826 25 lives_ok { Foo->new->x( {} ) }
4ee48f8e 26 'Setting coerce => 1 without a coercion on the type does not cause an error when setting the attribut';
27
53a4d826 28 throws_ok { Foo->new( x => 42 ) }
5d9b0b88 29 qr/\QAttribute (x) does not pass the type constraint because/,
30 'Attempting to provide an invalid value to the constructor for this attr still fails';
31
53a4d826 32 throws_ok { Foo->new->x(42) }
5d9b0b88 33 qr/\QAttribute (x) does not pass the type constraint because/,
34 'Attempting to provide an invalid value to the accessor for this attr still fails';
4ee48f8e 35}
36'Foo';
37
38done_testing;