use strict;
use warnings;
+use lib 'lib', 't/lib';
- use Test::More tests => 23;
++use Test::More;
+
-use Test::More tests => 29;
use Test::Exception;
-
-
+use MetaTest;
{
package Foo;
use Moose::Util::TypeConstraints;
}
-can_ok('Foo', 'meta');
-isa_ok(Foo->meta, 'Moose::Meta::Class');
+skip_meta {
+ can_ok('Foo', 'meta');
+ isa_ok(Foo->meta, 'Moose::Meta::Class');
+} 2;
+
-ok(Foo->meta->has_method('meta'), '... we got the &meta method');
+meta_can_ok('Foo', 'meta', '... we got the &meta method');
ok(Foo->isa('Moose::Object'), '... Foo is automagically a Moose::Object');
-dies_ok {
- Foo->meta->has_method()
-} '... has_method requires an arg';
+skip_meta {
+ dies_ok {
+ Foo->meta->has_method()
+ } '... has_method requires an arg';
+
+ dies_ok {
+ Foo->meta->has_method('')
+ } '... has_method requires an arg';
+} 2;
+
can_ok('Foo', 'does');
-foreach my $function (qw(
- extends
- has
- before after around
- blessed confess
- type subtype as where
- coerce from via
- find_type_constraint
- )) {
- ok(!Foo->meta->has_method($function), '... the meta does not treat "' . $function . '" as a method');
-}
+skip_meta {
+ foreach my $function (qw(
+ extends
+ has
+ before after around
+ blessed confess
+ type subtype as where
+ coerce from via
+ find_type_constraint
+ )) {
+ ok(!Foo->meta->has_method($function), '... the meta does not treat "' . $function . '" as a method');
+ }
+} 15;
+ foreach my $import (qw(
+ blessed
+ try
+ catch
+ in_global_destruction
+ )) {
+ ok(!Moose::Object->can($import), "no namespace pollution in Moose::Object ($import)" );
+
+ local $TODO = $import eq 'blessed' ? "no automatic namespace cleaning yet" : undef;
+ ok(!Foo->can($import), "no namespace pollution in Moose::Object ($import)" );
+ }
++
++done_testing;
use strict;
use warnings;
+use lib 't/lib';
+
use Scalar::Util 'isweak';
- use Test::More tests => 42;
+ use Test::More tests => 43;
use Test::Exception;
+use MetaTest;
+
{
use strict;
use warnings;
-use Test::More tests => 48;
+use lib 't/lib';
+
- use Test::More tests => 39;
++use Test::More;
use Test::Exception;
+use MetaTest;
+
=pod
This tests the more complex
can_ok( $p, "child_g_method_1" );
is( $p->child_g_method_1, "g1", "delegate to moose class without reader (child_g_method_1)" );
+
+ can_ok( $p, "child_i_method_1" );
+ is( $p->parent_method_1, "parent_1", "delegate doesn't override existing method" );
++done_testing;
use strict;
use warnings;
-use Test::More tests => 46;
+use lib 't/lib';
+
- use Test::More tests => 35;
++use Test::More;
use Test::Exception;
+use MetaTest;
{
sub role_bar { 'FAIL' }
}
-ok(My::OtherRole->meta->has_method($_), "we have a $_ method") for qw(foo baz role_bar);
-ok(My::OtherRole->meta->requires_method('bar'), '... and the &bar method is required');
-ok(!My::OtherRole->meta->requires_method('role_bar'), '... and the &role_bar method is not required');
+skip_meta {
+ ok(My::OtherRole->meta->has_method($_), "we have a $_ method") for qw(foo baz role_bar);
- ok(!My::OtherRole->meta->requires_method('bar'), '... and the &bar method is not required');
++ ok(My::OtherRole->meta->requires_method('bar'), '... and the &bar method is required');
+ ok(!My::OtherRole->meta->requires_method('role_bar'), '... and the &role_bar method is not required');
+} 5;
{
package My::AliasingRole;
} '... this succeeds';
}
-ok(My::AliasingRole->meta->has_method($_), "we have a $_ method") for qw(foo baz role_bar);
-ok(!My::AliasingRole->meta->requires_method('bar'), '... and the &bar method is not required');
+skip_meta {
+ ok(My::AliasingRole->meta->has_method($_), "we have a $_ method") for qw(foo baz role_bar);
- ok(My::AliasingRole->meta->requires_method('bar'), '... and the &bar method is required');
++ ok(!My::AliasingRole->meta->requires_method('bar'), '... and the &bar method is not required');
+} 4;
{
package Foo::Role;
'Baz::Role';
} '... composed our roles correctly';
}
-
-ok(!My::Foo::Role::Other->meta->has_method('foo_foo'), "we dont have a foo_foo method");
-ok(My::Foo::Role::Other->meta->requires_method('foo_foo'), '... and the &foo method is required');
+skip_meta {
+ ok(!My::Foo::Role::Other->meta->has_method('foo_foo'), "we dont have a foo_foo method");
+ ok(My::Foo::Role::Other->meta->requires_method('foo_foo'), '... and the &foo method is required');
+} 2;
+ {
+ package My::Foo::AliasOnly;
+ use Moose;
+
+ ::lives_ok {
+ with 'Foo::Role' => { -alias => { 'foo' => 'foo_foo' } },
+ } '... composed our roles correctly';
+ }
+
+ ok(My::Foo::AliasOnly->meta->has_method('foo'), 'we have a foo method');
+ ok(My::Foo::AliasOnly->meta->has_method('foo_foo'), '.. and the aliased foo_foo method');
+
+ {
+ package Role::Foo;
+ use Moose::Role;
+
+ sub x1 {}
+ sub y1 {}
+ }
+
+ {
+ package Role::Bar;
+ use Moose::Role;
+
+ use Test::Exception;
+
+ lives_ok {
+ with 'Role::Foo' => {
+ -alias => { x1 => 'foo_x1' },
+ -excludes => ['y1'],
+ };
+ }
+ 'Compose Role::Foo into Role::Bar with alias and exclude';
+
+ sub x1 {}
+ sub y1 {}
+ }
+
+ {
+ my $bar = Role::Bar->meta;
+ ok( $bar->has_method($_), "has $_ method" )
+ for qw( x1 y1 foo_x1 );
+ }
+
+ {
+ package Role::Baz;
+ use Moose::Role;
+
+ use Test::Exception;
+
+ lives_ok {
+ with 'Role::Foo' => {
+ -alias => { x1 => 'foo_x1' },
+ -excludes => ['y1'],
+ };
+ }
+ 'Compose Role::Foo into Role::Baz with alias and exclude';
+ }
+
+ {
+ my $baz = Role::Baz->meta;
+ ok( $baz->has_method($_), "has $_ method" )
+ for qw( x1 foo_x1 );
+ ok( ! $baz->has_method('y1'), 'Role::Baz has no y1 method' );
+ }
++
++done_testing;
BEGIN {
eval "use Test::Output;";
plan skip_all => "Test::Output is required for this test" if $@;
- skip_all_meta 47;
- plan tests => 65;
++ skip_all_meta 65;
}
use Moose::Util::MetaRole;
+use MetaTest;
+
- skip_all_meta 89;
++skip_all_meta 91;
+
{
package My::Meta::Class;
'... bad constructor params';
## test the meta
-
-my $options = $stuff->meta->get_attribute('options');
-does_ok( $options, 'Moose::Meta::Attribute::Native::Trait::Hash' );
-
-is_deeply(
- $options->handles,
- {
- 'set_option' => 'set',
- 'get_option' => 'get',
- 'has_no_options' => 'is_empty',
- 'num_options' => 'count',
- 'clear_options' => 'clear',
- 'delete_option' => 'delete',
- 'has_option' => 'exists',
- 'is_defined' => 'defined',
- 'option_accessor' => 'accessor',
- 'key_value' => 'kv',
- 'options_elements' => 'elements',
- 'quantity' => [ accessor => 'quantity' ],
- },
- '... got the right handles mapping'
-);
-
-is( $options->type_constraint->type_parameter, 'Str',
- '... got the right container type' );
+skip_meta {
+ my $options = $stuff->meta->get_attribute('options');
+ does_ok( $options, 'Moose::Meta::Attribute::Native::Trait::Hash' );
+
+ is_deeply(
+ $options->handles,
+ {
+ 'set_option' => 'set',
+ 'get_option' => 'get',
- 'has_no_options' => 'empty',
++ 'has_no_options' => 'is_empty',
+ 'num_options' => 'count',
+ 'clear_options' => 'clear',
+ 'delete_option' => 'delete',
+ 'has_option' => 'exists',
+ 'is_defined' => 'defined',
+ 'option_accessor' => 'accessor',
+ 'key_value' => 'kv',
+ 'options_elements' => 'elements',
+ 'quantity' => [ accessor => 'quantity' ],
+ },
+ '... got the right handles mapping'
+ );
+
+ is( $options->type_constraint->type_parameter, 'Str',
+ '... got the right container type' );
+} 3;
$stuff->set_option( oink => "blah", xxy => "flop" );
- my @key_value = $stuff->key_value;
+ my @key_value = sort{ $a->[0] cmp $b->[0] } $stuff->key_value;
is_deeply(
\@key_value,
- [ [ 'xxy', 'flop' ], [ 'quantity', 4 ], [ 'oink', 'blah' ] ],
+ [ sort{ $a->[0] cmp $b->[0] } [ 'xxy', 'flop' ], [ 'quantity', 4 ], [ 'oink', 'blah' ] ],
'... got the right key value pairs'
- );
+ ) or do{ require Data::Dumper; diag(Data::Dumper::Dumper(\@key_value)) };
my %options_elements = $stuff->options_elements;
is_deeply(