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