File: role_check_basic.t

package info (click to toggle)
libmethod-signatures-perl 20170211-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 672 kB
  • sloc: perl: 3,860; makefile: 2
file content (53 lines) | stat: -r--r--r-- 1,651 bytes parent folder | download | duplicates (7)
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 strict;
use warnings;
use lib 't/lib';
use GenErrorRegex qw< badval_error >;

use Test::More;
use Test::Exception;


# This may not be possible.  I'm not sure that Role::Basic and Mouse are going to play nice
# together, and I'm not even sure it's a viable use case.  That is, if you're using
# Method::Signatures, you're already getting Mouse, and, if you're already getting Mouse, why use
# Role::Basic?  Role::Basic's doco itself says that it's designed for people who don't want Mouse
# (or Moose), and, if you don't want Mouse, you might not want to use Method::Signatures, since that
# brings in Mouse whether you like it or not (assuming you're doing type checking, but then, if
# you're not doing type checking, you wouldn't be caring about Role::Basic interaction).
#
# So if we decide we want to pursue this, it may be possible by working with Ovid and creating a
# Mouse subtype to check Role::Basic roles, but in the meantime, I'm just marking this all TODO.
TODO: {
    local $TODO = "Compatibility with Role::Basic unimplemented";


{ package Foo::Bar; sub new { bless {}, __PACKAGE__; } }

SKIP:
{
    eval "use Role::Basic ()" or skip "Role::Basic required for testing basic roles", 2;

    require BasicRoleTest;
    use Method::Signatures;

    my $basic = WithBasicRole->new;
    my $foobar = Foo::Bar->new;


    func basicy (BasicRole $foo) {}


    # positive test
    lives_ok { basicy($basic) } 'Basic role passes okay';

    # negative test
    throws_ok { basicy($foobar) } badval_error(undef, foo => BasicRole => $foobar, 'basicy'),
            'Basic role fails when appropriate';
}

}


done_testing;