don't use Base as a package name in tests to avoid conflict with base.pm
[gitmo/Role-Tiny.git] / t / compose-modifiers.t
index 8357d05..890391e 100644 (file)
@@ -16,7 +16,7 @@ BEGIN {
   around foo => sub { my $orig = shift; (__PACKAGE__, $orig->(@_)) };
   package Four; use Role::Tiny;
   around foo => sub { my $orig = shift; (__PACKAGE__, $orig->(@_)) };
-  package Base; sub foo { __PACKAGE__ }
+  package BaseClass; sub foo { __PACKAGE__ }
 }
 
 foreach my $combo (
@@ -24,14 +24,31 @@ foreach my $combo (
   [ qw(Two Four Three) ],
   [ qw(One Two) ]
 ) {
-  my $combined = Role::Tiny->create_class_with_roles('Base', @$combo);
+  my $combined = Role::Tiny->create_class_with_roles('BaseClass', @$combo);
   is_deeply(
-    [ $combined->foo ], [ reverse(@$combo), 'Base' ],
+    [ $combined->foo ], [ reverse(@$combo), 'BaseClass' ],
     "${combined} ok"
   );
-  my $object = bless({}, 'Base');
+  my $object = bless({}, 'BaseClass');
   Role::Tiny->apply_roles_to_object($object, @$combo);
   is(ref($object), $combined, 'Object reblessed into correct class');
 }
 
+{
+  package Five; use Role::Tiny;
+  requires 'bar';
+  around bar => sub { my $orig = shift; $orig->(@_) };
+}
+{
+  is eval {
+    package WithFive;
+    use Role::Tiny::With;
+    use base 'BaseClass';
+    with 'Five';
+  }, undef,
+    "composing an around modifier fails when method doesn't exist";
+  like $@, qr/Can't apply Five to WithFive - missing bar/,
+    ' ... with correct error message';
+}
+
 done_testing;