summaryrefslogtreecommitdiff
path: root/t/moose_util/ensure_all_roles.t
diff options
context:
space:
mode:
Diffstat (limited to 't/moose_util/ensure_all_roles.t')
-rw-r--r--t/moose_util/ensure_all_roles.t62
1 files changed, 62 insertions, 0 deletions
diff --git a/t/moose_util/ensure_all_roles.t b/t/moose_util/ensure_all_roles.t
new file mode 100644
index 0000000..9888bfb
--- /dev/null
+++ b/t/moose_util/ensure_all_roles.t
@@ -0,0 +1,62 @@
+use strict;
+use warnings;
+
+use Test::More;
+
+use Moose::Util ':all';
+
+{
+ package Foo;
+ use Moose::Role;
+}
+
+{
+ package Bar;
+ use Moose::Role;
+}
+
+{
+ package Quux;
+ use Moose;
+}
+
+is_deeply(
+ Quux->meta->roles,
+ [],
+ "no roles yet",
+);
+
+Foo->meta->apply(Quux->meta);
+
+is_deeply(
+ Quux->meta->roles,
+ [ Foo->meta ],
+ "applied Foo",
+);
+
+Foo->meta->apply(Quux->meta);
+Bar->meta->apply(Quux->meta);
+is_deeply(
+ Quux->meta->roles,
+ [ Foo->meta, Foo->meta, Bar->meta ],
+ "duplicated Foo",
+);
+
+is(does_role('Quux', 'Foo'), 1, "Quux does Foo");
+is(does_role('Quux', 'Bar'), 1, "Quux does Bar");
+ensure_all_roles('Quux', qw(Foo Bar));
+is_deeply(
+ Quux->meta->roles,
+ [ Foo->meta, Foo->meta, Bar->meta ],
+ "unchanged, since all roles are already applied",
+);
+
+my $obj = Quux->new;
+ensure_all_roles($obj, qw(Foo Bar));
+is_deeply(
+ $obj->meta->roles,
+ [ Foo->meta, Foo->meta, Bar->meta ],
+ "unchanged, since all roles are already applied",
+);
+
+done_testing;