be more chatty about dependency installs
[gitmo/Moo.git] / xt / moo-does-moose-role.t
index 4e4fa10..b995e44 100644 (file)
@@ -1,5 +1,6 @@
 use strictures 1;
 use Test::More;
+use Test::Fatal;
 
 BEGIN {
   package Ker;
@@ -191,6 +192,12 @@ BEGIN {
     $spec->{documentation} .= 'child';
   });
 }
+BEGIN{
+  local $SIG{__WARN__} = sub { fail "warning: $_[0]" };
+  package SplatteredMoose;
+  use Moose;
+  extends 'Splattered';
+}
 
 foreach my $s (
     Splattered->new,
@@ -199,14 +206,15 @@ foreach my $s (
     Ker::Splattered2->new,
     KerSplattered->new,
     KerSplattered2->new,
+    SplatteredMoose->new
 ) {
-  ok($s->can('punch'))
+  can_ok($s, 'punch')
     and is($s->punch, 1, 'punch');
-  ok($s->can('jab'))
+  can_ok($s, 'jab')
     and is($s->jab, 3, 'jab');
-  ok($s->can('monkey'))
+  can_ok($s, 'monkey')
     and is($s->monkey, 'OW', 'monkey');
-  ok($s->can('trap'))
+  can_ok($s, 'trap')
     and is($s->trap, -1, 'trap');
 }
 
@@ -216,8 +224,8 @@ foreach my $c (qw/
     KerSplattered
     KerSplattered2
 /) {
-  ok $c->can('has_ker');
-  ok $c->can('has_splat');
+  can_ok($c, 'has_ker');
+  can_ok($c, 'has_splat');
 }
 
 is(Plunker->meta->find_attribute_by_name('pp')->documentation, 'moosify', 'moosify modifies attr specs');
@@ -227,4 +235,57 @@ is( Plonker->meta->find_attribute_by_name('kk')->documentation,
     'parentchild',
     'moosify applies for overridden attributes with roles');
 
+{
+  package MooseAttrTrait;
+  use Moose::Role;
+
+  has 'extra_attr' => (is => 'ro');
+  has 'extra_attr_noinit' => (is => 'ro', init_arg => undef);
+}
+
+{
+  local $SIG{__WARN__} = sub { fail "warning: $_[0]" };
+  package UsingMooseTrait;
+  use Moo;
+
+  has one => (
+    is => 'ro',
+    traits => ['MooseAttrTrait'],
+    extra_attr => 'one',
+    extra_attr_noinit => 'two',
+  );
+}
+
+ok( UsingMooseTrait->meta
+      ->find_attribute_by_name('one')->can('extra_attr'),
+    'trait was properly applied');
+is( UsingMooseTrait->meta->find_attribute_by_name('one')
+      ->extra_attr,
+    'one',
+    'trait attributes maintain values');
+
+{
+  package NeedTrap;
+  use Moo::Role;
+
+  requires 'trap';
+}
+
+is exception {
+  package Splattrap;
+  use Moo;
+  sub monkey {}
+
+  with qw(Splat NeedTrap);
+}, undef, 'requires satisfied by Moose attribute composed at the same time';
+
+{
+  package HasMonkey;
+  use Moo;
+  sub monkey {}
+}
+is exception {
+  Moo::Role->create_class_with_roles('HasMonkey', 'Splat', 'NeedTrap');
+}, undef, ' ... and when created by create_class_with_roles';
+
 done_testing;