Commit | Line | Data |
4ee48f8e |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
b10dde3a |
5 | use Test::Fatal; |
4ee48f8e |
6 | use 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 | |
21 | with_immutable { |
b10dde3a |
22 | is( exception { Foo->new( x => {} ) }, undef, 'Setting coerce => 1 without a coercion on the type does not cause an error in the constructor' ); |
4ee48f8e |
23 | |
b10dde3a |
24 | is( exception { Foo->new->x( {} ) }, undef, 'Setting coerce => 1 without a coercion on the type does not cause an error when setting the attribut' ); |
4ee48f8e |
25 | |
b10dde3a |
26 | like( exception { Foo->new( x => 42 ) }, qr/\QAttribute (x) does not pass the type constraint because/, 'Attempting to provide an invalid value to the constructor for this attr still fails' ); |
5d9b0b88 |
27 | |
b10dde3a |
28 | like( exception { Foo->new->x(42) }, qr/\QAttribute (x) does not pass the type constraint because/, 'Attempting to provide an invalid value to the accessor for this attr still fails' ); |
4ee48f8e |
29 | } |
30 | 'Foo'; |
31 | |
32 | done_testing; |