From: gfx Date: Tue, 22 Sep 2009 02:41:08 +0000 (+0900) Subject: Add some test files X-Git-Tag: 0.32~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=09584bc5021e29580b6f86ac8b81375d0e84e55a;p=gitmo%2FMouse.git Add some test files --- diff --git a/t/lib/Role/Child.pm b/t/lib/Role/Child.pm new file mode 100644 index 0000000..323eaa1 --- /dev/null +++ b/t/lib/Role/Child.pm @@ -0,0 +1,8 @@ +package Role::Child; +use Mouse::Role; + +with 'Role::Parent' => { alias => { meth1 => 'aliased_meth1', } }; + +sub meth1 { } + +1; diff --git a/t/lib/Role/Interface.pm b/t/lib/Role/Interface.pm new file mode 100644 index 0000000..f081f32 --- /dev/null +++ b/t/lib/Role/Interface.pm @@ -0,0 +1,6 @@ +package Role::Interface; +use Mouse::Role; + +requires "meth2"; + +1; diff --git a/t/lib/Role/Parent.pm b/t/lib/Role/Parent.pm new file mode 100644 index 0000000..04befab --- /dev/null +++ b/t/lib/Role/Parent.pm @@ -0,0 +1,7 @@ +package Role::Parent; +use Mouse::Role; + +sub meth2 { } +sub meth1 { } + +1; diff --git a/t/lib/Test/Mouse.pm b/t/lib/Test/Mouse.pm new file mode 100644 index 0000000..83a5ca0 --- /dev/null +++ b/t/lib/Test/Mouse.pm @@ -0,0 +1,72 @@ +package Test::Mouse; + +use strict; +use warnings; +use Mouse::Util qw(find_meta does_role); + +use base qw(Test::Builder::Module); + +our @EXPORT = qw(meta_ok does_ok has_attribute_ok); + +sub meta_ok ($;$) { + my ($class_or_obj, $message) = @_; + + $message ||= "The object has a meta"; + + if (find_meta($class_or_obj)) { + return __PACKAGE__->builder->ok(1, $message) + } + else { + return __PACKAGE__->builder->ok(0, $message); + } +} + +sub does_ok ($$;$) { + my ($class_or_obj, $does, $message) = @_; + + $message ||= "The object does $does"; + + if (does_ok($class_or_obj)) { + return __PACKAGE__->builder->ok(1, $message) + } + else { + return __PACKAGE__->builder->ok(0, $message); + } +} + +sub has_attribute_ok ($$;$) { + my ($class_or_obj, $attr_name, $message) = @_; + + $message ||= "The object does has an attribute named $attr_name"; + + my $meta = find_meta($class_or_obj); + + if ($meta->find_attribute_by_name($attr_name)) { + return __PACKAGE__->builder->ok(1, $message) + } + else { + return __PACKAGE__->builder->ok(0, $message); + } +} + +1; + +__END__ + +=pod + +=head1 NAME + +Test::Mouse - Test functions for Mouse specific features + +=head1 SYNOPSIS + + use Test::More plan => 1; + use Test::Mouse; + + meta_ok($class_or_obj, "... Foo has a ->meta"); + does_ok($class_or_obj, $role, "... Foo does the Baz role"); + has_attribute_ok($class_or_obj, $attr_name, "... Foo has the 'bar' attribute"); + +=cut +