File: 54croak-role.t

package info (click to toggle)
libobject-pad-perl 0.821-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 936 kB
  • sloc: ansic: 3,361; perl: 3,328; pascal: 28; makefile: 3
file content (53 lines) | stat: -rw-r--r-- 1,374 bytes parent folder | download | duplicates (2)
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;