show the first line here when testing with a harness
[gitmo/Moose.git] / t / bugs / apply_role_to_one_instance_only.t
CommitLineData
a687ab44 1#!/usr/bin/perl
2use strict;
3use warnings;
4use Test::More;
b10dde3a 5use Test::Fatal;
a687ab44 6
7{
8 package MyRole1;
9 use Moose::Role;
10
11 sub a_role_method { 'foo' }
12}
13
14{
15 package MyRole2;
16 use Moose::Role;
17 # empty
18}
19
20{
21 package Foo;
22 use Moose;
23}
24
25my $instance_with_role1 = Foo->new;
26MyRole1->meta->apply($instance_with_role1);
27
28my $instance_with_role2 = Foo->new;
29MyRole2->meta->apply($instance_with_role2);
30
31ok ((not $instance_with_role2->does('MyRole1')),
32 'instance does not have the wrong role');
33
34ok ((not $instance_with_role2->can('a_role_method')),
35 'instance does not have methods from the wrong role');
36
37ok (($instance_with_role1->does('MyRole1')),
38 'role was applied to the correct instance');
39
b10dde3a 40is( exception {
a687ab44 41 is $instance_with_role1->a_role_method, 'foo'
b10dde3a 42}, undef, 'instance has correct role method' );
a687ab44 43
44done_testing;