1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#!/usr/bin/perl
use v5.18;
use warnings;
use Test2::V0;
use Object::Pad 0.800;
{
role ARole { method m {} }
my $warnings;
$SIG{__WARN__} = sub { $warnings .= join "", @_ };
like( dies { ARole->new },
qr/^Cannot directly construct an instance of role 'ARole' /,
'failure from directly create a role instance' );
ok( !eval <<'EOPERL',
class AClass { apply ARole; method m {} }
EOPERL
'class with clashing method name fails' );
like( $@, qr/^Method 'm' clashes with the one provided by role ARole /,
'message from failure of clashing method' );
ok( !eval { ( bless {}, "ARole" )->m() },
'direct invoke on role method fails' );
like( $@, qr/^Cannot invoke a role method directly /,
'message from failure to directly invoke role method' );
}
{
role BRole { method bmeth; }
ok( !eval <<'EOPERL',
class BClass { apply BRole; }
EOPERL
'class with missing required method fails' );
like( $@, qr/^Class BClass does not provide a required method named 'bmeth' /,
'message from failure of missing method' );
}
{
ok( !eval <<'EOPERL',
role CRole :compat(invokable) { field $field; }
EOPERL
'invokable role with field fails' );
like( $@, qr/^Cannot add field data to an invokable role /,
'message from failure of invokable role with field' );
}
done_testing;
|