Fail for has '+attr' when attr comes from a Moo role
Tomas Doran [Sat, 5 May 2012 19:34:22 +0000 (20:34 +0100)]
xt/moose-override-attribute-from-moo-role.t [new file with mode: 0644]

diff --git a/xt/moose-override-attribute-from-moo-role.t b/xt/moose-override-attribute-from-moo-role.t
new file mode 100644 (file)
index 0000000..8ba09c9
--- /dev/null
@@ -0,0 +1,41 @@
+use strict;
+use warnings;
+use Test::More;
+use Test::Fatal;
+
+{
+    package MyRole;
+    use Moo::Role;
+
+    has foo => (
+        is => 'ro',
+        required => 1,
+    );
+}
+{
+    package MyClass;
+    use Moose;
+
+    with 'MyRole';
+
+    has '+foo' => (
+        isa => 'Str',
+    );
+}
+
+is(
+    exception { MyClass->new(foo => 'bar') },
+    undef,
+    'construct'
+);
+ok(
+    exception { MyClass->new(foo => []) },
+    'no construct, constraint works'
+);
+ok(
+    exception { MyClass->new() },
+    'no construct - require still works'
+);
+
+done_testing;
+