(failing) test for runtime roles and non-moose classes + does attrs
[gitmo/Moose.git] / t / 020_attributes / 005_attribute_does.t
CommitLineData
02a0fb52 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
7eaef7ad 6use Test::More tests => 8;
02a0fb52 7use Test::Exception;
8
9BEGIN {
10 use_ok('Moose');
11}
12
13{
14 package Foo::Role;
02a0fb52 15 use Moose::Role;
16
17 # if does() exists on its own, then
18 # we create a type constraint for
19 # it, just as we do for isa()
20 has 'bar' => (is => 'rw', does => 'Bar::Role');
21
22 package Bar::Role;
02a0fb52 23 use Moose::Role;
24
25 # if isa and does appear together, then see if Class->does(Role)
26 # if it does work... then the does() check is actually not needed
27 # since the isa() check will imply the does() check
28 has 'foo' => (is => 'rw', isa => 'Foo::Class', does => 'Foo::Role');
29
30 package Foo::Class;
02a0fb52 31 use Moose;
32
33 with 'Foo::Role';
34
35 package Bar::Class;
02a0fb52 36 use Moose;
37
38 with 'Bar::Role';
39
40}
41
42my $foo = Foo::Class->new;
43isa_ok($foo, 'Foo::Class');
44
45my $bar = Bar::Class->new;
46isa_ok($bar, 'Bar::Class');
47
48lives_ok {
49 $foo->bar($bar);
50} '... bar passed the type constraint okay';
51
52dies_ok {
53 $foo->bar($foo);
54} '... foo did not pass the type constraint okay';
55
56lives_ok {
57 $bar->foo($foo);
58} '... foo passed the type constraint okay';
59
60# some error conditions
61
62{
63 package Baz::Class;
02a0fb52 64 use Moose;
65
66 # if isa and does appear together, then see if Class->does(Role)
67 # if it does not,.. we have a conflict... so we die loudly
68 ::dies_ok {
69 has 'foo' => (isa => 'Foo::Class', does => 'Bar::Class');
70 } '... cannot have a does() which is not done by the isa()';
71}
7eaef7ad 72
73{
74 package Bling;
75 use strict;
76 use warnings;
77
78 sub bling { 'Bling::bling' }
79
80 package Bling::Bling;
7eaef7ad 81 use Moose;
82
83 # if isa and does appear together, then see if Class->does(Role)
84 # if it does not,.. we have a conflict... so we die loudly
85 ::dies_ok {
86 has 'foo' => (isa => 'Bling', does => 'Bar::Class');
87 } '... cannot have a isa() which is cannot does()';
88}
89
90
02a0fb52 91