Commit | Line | Data |
da4b56da |
1 | use strictures; |
2 | use Test::More; |
3 | use Test::Fatal; |
1d17c7c1 |
4 | |
da4b56da |
5 | is(exception { |
1d17c7c1 |
6 | package Local::Test::Role1; |
7 | use Moo::Role; |
8 | has [qw/ attr1 attr2 /] => (is => 'ro'); |
da4b56da |
9 | }, undef, 'has \@attrs works in roles'); |
1d17c7c1 |
10 | |
da4b56da |
11 | is(exception { |
1d17c7c1 |
12 | package Local::Test::Class1; |
13 | use Moo; |
14 | with 'Local::Test::Role1'; |
15 | has [qw/ attr3 attr4 /] => (is => 'ro'); |
da4b56da |
16 | }, undef, 'has \@attrs works in classes'); |
1d17c7c1 |
17 | |
18 | my $obj = new_ok 'Local::Test::Class1' => [ |
19 | attr1 => 1, |
20 | attr2 => 2, |
21 | attr3 => 3, |
22 | attr4 => 4, |
23 | ]; |
24 | |
25 | can_ok( |
26 | $obj, |
27 | qw( attr1 attr2 attr3 attr4 ), |
28 | ); |
da4b56da |
29 | |
bf0e0d7a |
30 | like(exception { |
31 | package Local::Test::Role2; |
32 | use Moo::Role; |
33 | has [qw/ attr1 attr2 /] => (is => 'ro', 'isa'); |
34 | }, qr/^Invalid options for 'attr1', 'attr2' attribute\(s\): even number of arguments expected, got 3/, |
35 | 'correct exception when has given bad parameters in role'); |
36 | |
37 | like(exception { |
38 | package Local::Test::Class2; |
39 | use Moo; |
40 | has [qw/ attr3 attr4 /] => (is => 'ro', 'isa'); |
41 | }, qr/^Invalid options for 'attr3', 'attr4' attribute\(s\): even number of arguments expected, got 3/, |
42 | 'correct exception when has given bad parameters in class'); |
43 | |
da4b56da |
44 | done_testing; |