Redid conversion to Test::Fatal
[gitmo/Moose.git] / t / 010_basics / 004_inner_and_augment.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Fatal;
8
9
10 {
11     package Foo;
12     use Moose;
13
14     sub foo { 'Foo::foo(' . (inner() || '') . ')' }
15     sub bar { 'Foo::bar(' . (inner() || '') . ')' }
16     sub baz { 'Foo::baz(' . (inner() || '') . ')' }
17
18     package Bar;
19     use Moose;
20
21     extends 'Foo';
22
23     augment foo => sub { 'Bar::foo(' . (inner() || '') . ')' };
24     augment bar => sub { 'Bar::bar' };
25
26     no Moose; # ensure inner() still works after unimport
27
28     package Baz;
29     use Moose;
30
31     extends 'Bar';
32
33     augment foo => sub { 'Baz::foo' };
34     augment baz => sub { 'Baz::baz' };
35
36     # this will actually never run,
37     # because Bar::bar does not call inner()
38     augment bar => sub { 'Baz::bar' };
39 }
40
41 my $baz = Baz->new();
42 isa_ok($baz, 'Baz');
43 isa_ok($baz, 'Bar');
44 isa_ok($baz, 'Foo');
45
46 is($baz->foo(), 'Foo::foo(Bar::foo(Baz::foo))', '... got the right value from &foo');
47 is($baz->bar(), 'Foo::bar(Bar::bar)', '... got the right value from &bar');
48 is($baz->baz(), 'Foo::baz(Baz::baz)', '... got the right value from &baz');
49
50 my $bar = Bar->new();
51 isa_ok($bar, 'Bar');
52 isa_ok($bar, 'Foo');
53
54 is($bar->foo(), 'Foo::foo(Bar::foo())', '... got the right value from &foo');
55 is($bar->bar(), 'Foo::bar(Bar::bar)', '... got the right value from &bar');
56 is($bar->baz(), 'Foo::baz()', '... got the right value from &baz');
57
58 my $foo = Foo->new();
59 isa_ok($foo, 'Foo');
60
61 is($foo->foo(), 'Foo::foo()', '... got the right value from &foo');
62 is($foo->bar(), 'Foo::bar()', '... got the right value from &bar');
63 is($foo->baz(), 'Foo::baz()', '... got the right value from &baz');
64
65 # some error cases
66
67 {
68     package Bling;
69     use Moose;
70
71     sub bling { 'Bling::bling' }
72
73     package Bling::Bling;
74     use Moose;
75
76     extends 'Bling';
77
78     sub bling { 'Bling::bling' }
79
80     ::isnt( ::exception {
81         augment 'bling' => sub {};
82     }, undef, '... cannot augment a method which has a local equivalent' );
83
84 }
85
86 done_testing;