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
54
55
56
57
58
59
60
|
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::Fatal;
{
package Foo;
use Moose;
use MooseX::ABC;
requires 'bar', 'baz';
}
{
package Foo::Sub1;
use Moose;
::is(::exception { extends 'Foo' }, undef,
"extending works when the requires are fulfilled");
sub bar { }
sub baz { }
}
{
package Foo::Sub2;
use Moose;
::like(
::exception { extends 'Foo' },
qr/Foo requires Foo::Sub2 to implement baz/,
"extending fails with the correct error when requires are not fulfilled"
);
sub bar { }
}
{
package Foo::Sub::Sub;
use Moose;
::is(::exception { extends 'Foo::Sub1' }, undef,
"extending twice works");
}
{
my $foosub;
is(exception { $foosub = Foo::Sub1->new }, undef,
"instantiating concrete subclasses works");
isa_ok($foosub, 'Foo', 'inheritance is correct');
}
{
my $foosubsub;
is(exception { $foosubsub = Foo::Sub::Sub->new }, undef,
"instantiating deeper concrete subclasses works");
isa_ok($foosubsub, 'Foo', 'inheritance is correct');
isa_ok($foosubsub, 'Foo::Sub1', 'inheritance is correct');
}
like(exception { Foo->new }, qr/Foo is abstract, it cannot be instantiated/,
"instantiating abstract classes fails");
done_testing;
|