Skip to content
Browse files

add is_anon(), is_not_anon() tests

  • Loading branch information...
1 parent 4720d47 commit 79d4452a9cd49c674c564b94facf0d73721962e3 @RsrchBoy committed Oct 21, 2012
Showing with 139 additions and 0 deletions.
  1. +29 −0 lib/Test/Moose/More.pm
  2. +55 −0 t/is_anon.t
  3. +55 −0 t/is_not_anon.t
View
29 lib/Test/Moose/More.pm
@@ -8,6 +8,7 @@ use warnings;
use Sub::Exporter -setup => {
exports => [ qw{
is_role is_class
+ is_anon is_not_anon
has_method_ok
requires_method_ok
check_sugar_ok check_sugar_removed_ok
@@ -211,6 +212,34 @@ sub _is_moosey {
return $tb->ok($meta->isa("Moose::Meta::$type"), "$thing_name is a Moose " . lc $type);
}
+=test is_anon $thing
+
+Passes if $thing is "anonymous".
+
+=test is_not_anon $thing
+
+Passes if $thing is not "anonymous".
+
+=cut
+
+sub is_anon {
+ my ($thing, $message) = @_;
+
+ my $thing_meta = find_meta($thing);
+ $message ||= _thing_name($thing, $thing_meta) . ' is anonymous';
+
+ return $tb->ok(!!$thing_meta->is_anon, $message);
+}
+
+sub is_not_anon {
+ my ($thing, $message) = @_;
+
+ my $thing_meta = find_meta($thing);
+ $message ||= _thing_name($thing, $thing_meta) . ' is not anonymous';
+
+ return $tb->ok(!$thing_meta->is_anon, $message);
+}
+
=test check_sugar_removed_ok $thing
Ensures that all the standard Moose sugar is no longer directly callable on a
View
55 t/is_anon.t
@@ -0,0 +1,55 @@
+use strict;
+use warnings;
+
+use Test::Builder::Tester;
+use Moose::Util 'with_traits';
+use Test::More;
+use Test::Moose::More;
+use TAP::SimpleOutput 'counters';
+
+{ package TestRole; use Moose::Role; use namespace::autoclean; }
+{ package TestClass; use Moose; }
+
+# initial tests, covering the most straight-forward cases (IMHO)
+
+my $anon_class = with_traits('TestClass' => 'TestRole');
+my $anon_role = Moose::Meta::Role
+ ->create_anon_role(weaken => 0)
+ ->name
+ ;
+
+note 'simple anon class';
+{
+ my ($_ok, $_nok, $_skip) = counters();
+ test_out $_ok->("$anon_class is anonymous");
+ is_anon $anon_class;
+ test_test 'is_anon works correctly on anon class';
+}
+
+note 'simple anon role';
+{
+ my ($_ok, $_nok, $_skip) = counters();
+ test_out $_ok->("$anon_role is anonymous");
+ is_anon $anon_role;
+ test_test 'is_anon works correctly on anon role';
+}
+
+note 'simple !anon class';
+{
+ my ($_ok, $_nok, $_skip) = counters();
+ test_out $_nok->('TestClass is anonymous');
+ test_fail 1;
+ is_anon 'TestClass';
+ test_test 'is_anon works correctly on !anon class';
+}
+
+note 'simple !anon role';
+{
+ my ($_ok, $_nok, $_skip) = counters();
+ test_out $_nok->('TestRole is anonymous');
+ test_fail 1;
+ is_anon 'TestRole';
+ test_test 'is_anon works correctly on !anon role';
+}
+
+done_testing;
View
55 t/is_not_anon.t
@@ -0,0 +1,55 @@
+use strict;
+use warnings;
+
+use Test::Builder::Tester;
+use Moose::Util 'with_traits';
+use Test::More;
+use Test::Moose::More;
+use TAP::SimpleOutput 'counters';
+
+{ package TestRole; use Moose::Role; use namespace::autoclean; }
+{ package TestClass; use Moose; }
+
+# initial tests, covering the most straight-forward cases (IMHO)
+
+my $anon_class = with_traits('TestClass' => 'TestRole');
+my $anon_role = Moose::Meta::Role
+ ->create_anon_role(weaken => 0)
+ ->name
+ ;
+
+note 'simple anon class';
+{
+ my ($_ok, $_nok, $_skip) = counters();
+ test_out $_nok->("$anon_class is not anonymous");
+ test_fail 1;
+ is_not_anon $anon_class;
+ test_test 'is_not_anon works correctly on anon class';
+}
+
+note 'simple anon role';
+{
+ my ($_ok, $_nok, $_skip) = counters();
+ test_out $_nok->("$anon_role is not anonymous");
+ test_fail 1;
+ is_not_anon $anon_role;
+ test_test 'is_not_anon works correctly on anon role';
+}
+
+note 'simple !anon class';
+{
+ my ($_ok, $_nok, $_skip) = counters();
+ test_out $_ok->('TestClass is not anonymous');
+ is_not_anon 'TestClass';
+ test_test 'is_not_anon works correctly on !anon class';
+}
+
+note 'simple !anon role';
+{
+ my ($_ok, $_nok, $_skip) = counters();
+ test_out $_ok->('TestRole is not anonymous');
+ is_not_anon 'TestRole';
+ test_test 'is_not_anon works correctly on !anon role';
+}
+
+done_testing;

0 comments on commit 79d4452

Please sign in to comment.
Something went wrong with that request. Please try again.