Commit | Line | Data |
238b424d |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
7ff56534 |
6 | use Test::More tests => 3; |
238b424d |
7 | use Test::Exception; |
8 | |
7ff56534 |
9 | |
238b424d |
10 | |
11 | =pod |
12 | |
13 | This tests to make sure that the inlined constructor |
14 | has all the type constraints in order, even in the |
15 | cases when there is no type constraint available, such |
16 | as with a Class::MOP::Attribute object. |
17 | |
18 | =cut |
19 | |
20 | { |
21 | package Foo; |
22 | use Moose; |
23 | |
24 | has 'foo' => (is => 'rw', isa => 'Int'); |
25 | has 'baz' => (is => 'rw', isa => 'Int'); |
84981146 |
26 | has 'zot' => (is => 'rw', isa => 'Int', init_arg => undef); |
238b424d |
27 | |
28 | Foo->meta->add_attribute( |
29 | Class::MOP::Attribute->new( |
30 | 'bar' => ( |
31 | accessor => 'bar', |
32 | ) |
33 | ) |
34 | ); |
35 | |
36 | Foo->meta->make_immutable(debug => 0); |
37 | } |
38 | |
39 | lives_ok { |
84981146 |
40 | Foo->new(foo => 10, bar => "Hello World", baz => 10, zot => 4); |
238b424d |
41 | } '... this passes the constuctor correctly'; |
42 | |
84981146 |
43 | lives_ok { |
44 | Foo->new(foo => 10, bar => "Hello World", baz => 10, zot => "not an int"); |
45 | } "... the constructor doesn't care about 'zot'"; |
46 | |
238b424d |
47 | dies_ok { |
48 | Foo->new(foo => "Hello World", bar => 100, baz => "Hello World"); |
49 | } '... this fails the constuctor correctly'; |
50 | |
51 | |
52 | |
53 | |