Permalink
Browse files

Lots of aliased-function tests

  • Loading branch information...
1 parent 87f231a commit 6feac9c6c814b76a25543550fca1f445d96e51f0 @sartak committed Apr 2, 2010
Showing with 77 additions and 10 deletions.
  1. +34 −5 t/005-aliases-moose.t
  2. +34 −5 t/005-aliases-mouse.t
  3. +9 −0 t/lib/AnyMooseTest.pm
View
@@ -8,12 +8,41 @@ BEGIN { delete $ENV{ANY_MOOSE} }
BEGIN {
eval 'require Moose;';
plan skip_all => 'Moose not available' if $@;
- plan tests => 3;
+ plan tests => 20;
}
-package MyFoo;
+package MyClass;
use Any::Moose;
-::ok Any::Moose::is_class_loaded('Moose');
-::ok Any::Moose::is_class_loaded('MyFoo');
-::ok !Any::Moose::is_class_loaded('Meese');
+
+package main;
+
+ok(Any::Moose::is_class_loaded('Moose'), 'Moose is loaded');
+ok(Any::Moose::is_class_loaded('MyClass'), 'MyClass is loaded');
+ok(!Any::Moose::is_class_loaded('NonexistentPackage'), 'NonexistentPackage is not loaded');
+
+push @INC, 't/lib';
+
+ok(!Any::Moose::is_class_loaded('AnyMooseTest'), 'AnyMooseTest not yet loaded');
+ok(Any::Moose::load_class('AnyMooseTest'), 'Loading AnyMooseTest');
+ok(Any::Moose::is_class_loaded('AnyMooseTest'), 'AnyMooseTest now loaded');
+
+is(eval { Any::Moose::load_class('NonexistentTest'); 1 }, undef, 'load_class on nonexistent module fails');
+ok(!Any::Moose::is_class_loaded('NonexistentTest'), 'and it is still not loaded');
+
+like(Any::Moose::class_of('MyClass'), qr/Moose::Meta::Class=HASH/, 'metaclass check');
+is(Any::Moose::class_of('NonexistentTest'), undef, 'class_of nonexistent class is undef');
+like(Any::Moose::class_of(MyClass->new), qr/Moose::Meta::Class=HASH/, 'metaclass check via object');
+
+like(Any::Moose::get_metaclass_by_name('MyClass'), qr/Moose::Meta::Class=HASH/, 'metaclass check');
+is(Any::Moose::get_metaclass_by_name('NonexistentTest'), undef, 'class_of nonexistent class is undef');
+is(Any::Moose::get_metaclass_by_name(MyClass->new), undef, 'get_metaclass_by_name via object returns undef');
+
+my %metaclasses = map { $_->name => $_ } Any::Moose::get_all_metaclass_instances();
+is($metaclasses{MyClass}, MyClass->meta);
+is($metaclasses{AnyMooseTest}, AnyMooseTest->meta);
+is($metaclasses{NonexistentTest}, undef);
+
+is((grep { $_ eq 'MyClass' } Any::Moose::get_all_metaclass_names()), 1);
+is((grep { $_ eq 'AnyMooseTest' } Any::Moose::get_all_metaclass_names()), 1);
+is((grep { $_ eq 'NonexistentTest' } Any::Moose::get_all_metaclass_names()), 0);
View
@@ -8,12 +8,41 @@ BEGIN { delete $ENV{ANY_MOOSE} }
BEGIN {
eval 'require Mouse;';
plan skip_all => 'Mouse not available' if $@;
- plan tests => 3;
+ plan tests => 20;
}
-package MyFoo;
+package MyClass;
use Any::Moose;
-::ok Any::Moose::is_class_loaded('Mouse');
-::ok Any::Moose::is_class_loaded('MyFoo');
-::ok !Any::Moose::is_class_loaded('Meese');
+
+package main;
+
+ok(Any::Moose::is_class_loaded('Mouse'), 'Mouse is loaded');
+ok(Any::Moose::is_class_loaded('MyClass'), 'MyClass is loaded');
+ok(!Any::Moose::is_class_loaded('NonexistentPackage'), 'NonexistentPackage is not loaded');
+
+push @INC, 't/lib';
+
+ok(!Any::Moose::is_class_loaded('AnyMooseTest'), 'AnyMooseTest not yet loaded');
+ok(Any::Moose::load_class('AnyMooseTest'), 'Loading AnyMooseTest');
+ok(Any::Moose::is_class_loaded('AnyMooseTest'), 'AnyMooseTest now loaded');
+
+is(eval { Any::Moose::load_class('NonexistentTest'); 1 }, undef, 'load_class on nonexistent module fails');
+ok(!Any::Moose::is_class_loaded('NonexistentTest'), 'and it is still not loaded');
+
+like(Any::Moose::class_of('MyClass'), qr/Mouse::Meta::Class=HASH/, 'metaclass check');
+is(Any::Moose::class_of('NonexistentTest'), undef, 'class_of nonexistent class is undef');
+like(Any::Moose::class_of(MyClass->new), qr/Mouse::Meta::Class=HASH/, 'metaclass check via object');
+
+like(Any::Moose::get_metaclass_by_name('MyClass'), qr/Mouse::Meta::Class=HASH/, 'metaclass check');
+is(Any::Moose::get_metaclass_by_name('NonexistentTest'), undef, 'class_of nonexistent class is undef');
+is(Any::Moose::get_metaclass_by_name(MyClass->new), undef, 'get_metaclass_by_name via object returns undef');
+
+my %metaclasses = map { $_->name => $_ } Any::Moose::get_all_metaclass_instances();
+is($metaclasses{MyClass}, MyClass->meta);
+is($metaclasses{AnyMooseTest}, AnyMooseTest->meta);
+is($metaclasses{NonexistentTest}, undef);
+
+is((grep { $_ eq 'MyClass' } Any::Moose::get_all_metaclass_names()), 1);
+is((grep { $_ eq 'AnyMooseTest' } Any::Moose::get_all_metaclass_names()), 1);
+is((grep { $_ eq 'NonexistentTest' } Any::Moose::get_all_metaclass_names()), 0);
View
@@ -0,0 +1,9 @@
+package AnyMooseTest;
+use Any::Moose;
+
+has an_attribute => (
+ is => 'ro',
+);
+
+1;
+

0 comments on commit 6feac9c

Please sign in to comment.