do not use same variable name twice.
[gitmo/Mouse.git] / t / 025-more-isa.t
CommitLineData
3301fa54 1#!/usr/bin/env perl
2use strict;
3use warnings;
3e8e32b5 4use Test::More tests => 29;
eab81545 5use Test::Exception;
3301fa54 6
7do {
8 package Class;
9 use Mouse;
10
11 has tb => (
12 is => 'rw',
13 isa => 'Test::Builder',
14 );
15};
16
17can_ok(Class => 'tb');
18
19lives_ok {
20 Class->new(tb => Test::Builder->new);
21};
22
23lives_ok {
24 my $class = Class->new;
25 $class->tb(Test::Builder->new);
26 isa_ok($class->tb, 'Test::Builder');
27};
28
29throws_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
33throws_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
38throws_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 42do {
43 package Other;
44 use Mouse;
45
46 has oops => (
47 isa => 'Int',
48 default => "yikes",
49 );
50};
51
52throws_ok {
53 Other->new;
54} qr/Attribute \(oops\) does not pass the type constraint because: Validation failed for 'Int' failed with value yikes/;
55
56lives_ok {
57 Other->new(oops => 10);
58};
59
6feb83f1 60# ClassName coverage tests
61
62do {
63 package A;
3e8e32b5 64 our @VERSION;
6feb83f1 65
66 package B;
3e8e32b5 67 our $VERSION = 1;
6feb83f1 68
69 package C;
3e8e32b5 70 our %ISA;
6feb83f1 71
3e8e32b5 72 package D;
73 our @ISA = 'Mouse::Object';
6feb83f1 74
75 package E;
3e8e32b5 76 sub foo {}
6feb83f1 77
78 package F;
3e8e32b5 79
80 package G::H;
81 sub bar {}
82
83 package I;
6feb83f1 84 our $NOT_CODE = 1;
85};
86
87do {
88 package ClassNameTests;
89 use Mouse;
90
91 has class => (
92 is => 'rw',
93 isa => 'ClassName',
94 );
95};
96
3e8e32b5 97for ('A'..'E', 'G::H') {
6feb83f1 98 lives_ok {
99 ClassNameTests->new(class => $_);
100 };
101
102 lives_ok {
103 my $obj = ClassNameTests->new;
104 $obj->class($_);
105 };
106}
107
3e8e32b5 108for ('F', 'G', 'I', 'Z') {
6feb83f1 109 throws_ok {
110 ClassNameTests->new(class => $_);
111 } qr/Attribute \(class\) does not pass the type constraint because: Validation failed for 'ClassName' failed with value $_/;
112
113 throws_ok {
114 my $obj = ClassNameTests->new;
115 $obj->class($_);
116 } qr/Attribute \(class\) does not pass the type constraint because: Validation failed for 'ClassName' failed with value $_/;
117};
118