complete re-organization of the test suite
[gitmo/Moose.git] / t / 010_basics / 003_super_and_override.t
CommitLineData
b6fe348f 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
d05cd563 6use Test::More tests => 17;
7use Test::Exception;
b6fe348f 8
9BEGIN {
10 use_ok('Moose');
11}
12
13{
14 package Foo;
b6fe348f 15 use Moose;
16
17 sub foo { 'Foo::foo' }
18 sub bar { 'Foo::bar' }
19 sub baz { 'Foo::baz' }
20
21 package Bar;
b6fe348f 22 use Moose;
23
24 extends 'Foo';
25
26 override bar => sub { 'Bar::bar -> ' . super() };
27
28 package Baz;
b6fe348f 29 use Moose;
30
31 extends 'Bar';
32
159da176 33 override bar => sub { 'Baz::bar -> ' . super() };
b6fe348f 34 override baz => sub { 'Baz::baz -> ' . super() };
52c7c330 35
36 no Moose; # ensure super() still works after unimport
b6fe348f 37}
38
39my $baz = Baz->new();
40isa_ok($baz, 'Baz');
41isa_ok($baz, 'Bar');
42isa_ok($baz, 'Foo');
43
44is($baz->foo(), 'Foo::foo', '... got the right value from &foo');
159da176 45is($baz->bar(), 'Baz::bar -> Bar::bar -> Foo::bar', '... got the right value from &bar');
b6fe348f 46is($baz->baz(), 'Baz::baz -> Foo::baz', '... got the right value from &baz');
159da176 47
48my $bar = Bar->new();
49isa_ok($bar, 'Bar');
50isa_ok($bar, 'Foo');
51
52is($bar->foo(), 'Foo::foo', '... got the right value from &foo');
53is($bar->bar(), 'Bar::bar -> Foo::bar', '... got the right value from &bar');
54is($bar->baz(), 'Foo::baz', '... got the right value from &baz');
55
56my $foo = Foo->new();
57isa_ok($foo, 'Foo');
58
59is($foo->foo(), 'Foo::foo', '... got the right value from &foo');
60is($foo->bar(), 'Foo::bar', '... got the right value from &bar');
d05cd563 61is($foo->baz(), 'Foo::baz', '... got the right value from &baz');
62
63# some error cases
64
65{
66 package Bling;
d05cd563 67 use Moose;
68
69 sub bling { 'Bling::bling' }
70
71 package Bling::Bling;
d05cd563 72 use Moose;
73
74 extends 'Bling';
75
76 sub bling { 'Bling::bling' }
77
78 ::dies_ok {
79 override 'bling' => sub {};
80 } '... cannot override a method which has a local equivalent';
81
82}
83