Commit | Line | Data |
3301fa54 |
1 | #!/usr/bin/env perl |
2 | use strict; |
3 | use warnings; |
7ecc2123 |
4 | use Test::More tests => 23; |
3301fa54 |
5 | use Test::Exception; |
6 | |
7 | do { |
8 | package Class; |
9 | use Mouse; |
10 | |
11 | has tb => ( |
12 | is => 'rw', |
13 | isa => 'Test::Builder', |
14 | ); |
15 | }; |
16 | |
17 | can_ok(Class => 'tb'); |
18 | |
19 | lives_ok { |
20 | Class->new(tb => Test::Builder->new); |
21 | }; |
22 | |
23 | lives_ok { |
24 | my $class = Class->new; |
25 | $class->tb(Test::Builder->new); |
26 | isa_ok($class->tb, 'Test::Builder'); |
27 | }; |
28 | |
29 | throws_ok { |
30 | Class->new(tb => 3); |
31 | } qr/Attribute \(tb\) does not pass the type constraint because: Validation failed for 'Test::Builder' failed with value 3/; |
32 | |
33 | throws_ok { |
34 | my $class = Class->new; |
35 | $class->tb(3); |
36 | } qr/Attribute \(tb\) does not pass the type constraint because: Validation failed for 'Test::Builder' failed with value 3/; |
37 | |
38 | throws_ok { |
39 | Class->new(tb => Class->new); |
40 | } qr/Attribute \(tb\) does not pass the type constraint because: Validation failed for 'Test::Builder' failed with value Class=HASH\(\w+\)/; |
41 | |
e3d9dc7b |
42 | do { |
43 | package Other; |
44 | use Mouse; |
45 | |
46 | has oops => ( |
47 | isa => 'Int', |
48 | default => "yikes", |
49 | ); |
50 | }; |
51 | |
52 | throws_ok { |
53 | Other->new; |
54 | } qr/Attribute \(oops\) does not pass the type constraint because: Validation failed for 'Int' failed with value yikes/; |
55 | |
56 | lives_ok { |
57 | Other->new(oops => 10); |
58 | }; |
59 | |
6feb83f1 |
60 | # ClassName coverage tests |
61 | |
62 | do { |
63 | package A; |
7ecc2123 |
64 | our $VERSION = 1; |
6feb83f1 |
65 | |
66 | package B; |
7ecc2123 |
67 | our @ISA = 'Mouse::Object'; |
6feb83f1 |
68 | |
69 | package C; |
7ecc2123 |
70 | sub foo {} |
6feb83f1 |
71 | |
7ecc2123 |
72 | package D::Child; |
73 | sub bar {} |
6feb83f1 |
74 | |
75 | package E; |
6feb83f1 |
76 | |
77 | package F; |
6feb83f1 |
78 | our $NOT_CODE = 1; |
79 | }; |
80 | |
81 | do { |
82 | package ClassNameTests; |
83 | use Mouse; |
84 | |
85 | has class => ( |
86 | is => 'rw', |
87 | isa => 'ClassName', |
88 | ); |
89 | }; |
90 | |
7ecc2123 |
91 | for ('A'..'C', 'D::Child') { |
6feb83f1 |
92 | lives_ok { |
93 | ClassNameTests->new(class => $_); |
94 | }; |
95 | |
96 | lives_ok { |
97 | my $obj = ClassNameTests->new; |
98 | $obj->class($_); |
99 | }; |
100 | } |
101 | |
7ecc2123 |
102 | for ('E'..'F', 'NonExistentClass') { |
6feb83f1 |
103 | throws_ok { |
104 | ClassNameTests->new(class => $_); |
105 | } qr/Attribute \(class\) does not pass the type constraint because: Validation failed for 'ClassName' failed with value $_/; |
106 | |
107 | throws_ok { |
108 | my $obj = ClassNameTests->new; |
109 | $obj->class($_); |
110 | } qr/Attribute \(class\) does not pass the type constraint because: Validation failed for 'ClassName' failed with value $_/; |
111 | }; |
112 | |