simplify more stuff
[gitmo/Class-MOP.git] / t / 030_method.t
index e0dbe62..f70df12 100644 (file)
@@ -1,8 +1,8 @@
 use strict;
 use warnings;
 
-use Test::More tests => 47;
-use Test::Exception;
+use Test::More;
+use Test::Fatal;
 
 use Class::MOP;
 use Class::MOP::Method;
@@ -28,21 +28,14 @@ is( $method->original_fully_qualified_name, 'main::__ANON__',
     '... the original_fully_qualified_name is the same as fully_qualified_name'
 );
 
-dies_ok { Class::MOP::Method->wrap }
-q{... can't call wrap() without some code};
-dies_ok { Class::MOP::Method->wrap( [] ) }
-q{... can't call wrap() without some code};
-dies_ok { Class::MOP::Method->wrap( bless {} => 'Fail' ) }
-q{... can't call wrap() without some code};
-
-dies_ok { Class::MOP::Method->name }
-q{... can't call name() as a class method};
-dies_ok { Class::MOP::Method->body }
-q{... can't call body() as a class method};
-dies_ok { Class::MOP::Method->package_name }
-q{... can't call package_name() as a class method};
-dies_ok { Class::MOP::Method->fully_qualified_name }
-q{... can't call fully_qualified_name() as a class method};
+isnt( exception { Class::MOP::Method->wrap }, undef, q{... can't call wrap() without some code} );
+isnt( exception { Class::MOP::Method->wrap( [] ) }, undef, q{... can't call wrap() without some code} );
+isnt( exception { Class::MOP::Method->wrap( bless {} => 'Fail' ) }, undef, q{... can't call wrap() without some code} );
+
+isnt( exception { Class::MOP::Method->name }, undef, q{... can't call name() as a class method} );
+isnt( exception { Class::MOP::Method->body }, undef, q{... can't call body() as a class method} );
+isnt( exception { Class::MOP::Method->package_name }, undef, q{... can't call package_name() as a class method} );
+isnt( exception { Class::MOP::Method->fully_qualified_name }, undef, q{... can't call fully_qualified_name() as a class method} );
 
 my $meta = Class::MOP::Method->meta;
 isa_ok( $meta, 'Class::MOP::Class' );
@@ -63,41 +56,34 @@ foreach my $method_name (
         '... our sub name is "' . $method_name . '"' );
 }
 
-dies_ok {
+isnt( exception {
     Class::MOP::Method->wrap();
-}
-'... bad args for &wrap';
+}, undef, '... bad args for &wrap' );
 
-dies_ok {
+isnt( exception {
     Class::MOP::Method->wrap('Fail');
-}
-'... bad args for &wrap';
+}, undef, '... bad args for &wrap' );
 
-dies_ok {
+isnt( exception {
     Class::MOP::Method->wrap( [] );
-}
-'... bad args for &wrap';
+}, undef, '... bad args for &wrap' );
 
-dies_ok {
+isnt( exception {
     Class::MOP::Method->wrap( sub {'FAIL'} );
-}
-'... bad args for &wrap';
+}, undef, '... bad args for &wrap' );
 
-dies_ok {
+isnt( exception {
     Class::MOP::Method->wrap( sub {'FAIL'}, package_name => 'main' );
-}
-'... bad args for &wrap';
+}, undef, '... bad args for &wrap' );
 
-dies_ok {
+isnt( exception {
     Class::MOP::Method->wrap( sub {'FAIL'}, name => '__ANON__' );
-}
-'... bad args for &wrap';
+}, undef, '... bad args for &wrap' );
 
-lives_ok {
+is( exception {
     Class::MOP::Method->wrap( bless( sub {'FAIL'}, "Foo" ),
         name => '__ANON__', package_name => 'Foo::Bar' );
-}
-'... blessed coderef to &wrap';
+}, undef, '... blessed coderef to &wrap' );
 
 my $clone = $method->clone(
     package_name => 'NewPackage',
@@ -137,3 +123,27 @@ is( $clone2->original_name, '__ANON__',
     '... original_name follows clone chain' );
 is( $clone2->original_fully_qualified_name, 'main::__ANON__',
     '... original_fully_qualified_name follows clone chain' );
+
+Class::MOP::Class->create(
+    'Method::Subclass',
+    superclasses => ['Class::MOP::Method'],
+    attributes   => [
+        Class::MOP::Attribute->new(
+            foo => (
+                accessor => 'foo',
+            )
+        ),
+    ],
+);
+
+my $wrapped = Method::Subclass->wrap($method, foo => 'bar');
+isa_ok($wrapped, 'Method::Subclass');
+isa_ok($wrapped, 'Class::MOP::Method');
+is($wrapped->foo, 'bar', 'attribute set properly');
+is($wrapped->package_name, 'main', 'package_name copied properly');
+is($wrapped->name, '__ANON__', 'method name copied properly');
+
+my $wrapped2 = Method::Subclass->wrap($method, foo => 'baz', name => 'FOO');
+is($wrapped2->name, 'FOO', 'got a new method name');
+
+done_testing;