X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F32_next_method_edge_cases.t;h=1f312eedd21f9e8edd459e23f8ea0e7d0e7308ee;hb=ef29cd706106f8ab6e7b0c25e8dc832bb337c5ed;hp=4f85e74dd0d464bd0748bf70198aa652758642cb;hpb=5d5c86d9474664bced2e5285fdffb07e2613aee5;p=gitmo%2FClass-C3.git diff --git a/t/32_next_method_edge_cases.t b/t/32_next_method_edge_cases.t index 4f85e74..1f312ee 100644 --- a/t/32_next_method_edge_cases.t +++ b/t/32_next_method_edge_cases.t @@ -3,11 +3,7 @@ use strict; use warnings; -use Test::More tests => 9; - -BEGIN { - use_ok('Class::C3'); -} +use Test::More tests => 11; { @@ -36,23 +32,55 @@ BEGIN { use warnings; use Class::C3; our @ISA = ('Foo'); + } + + my $bar = Bar->new(); + isa_ok($bar, 'Bar'); + isa_ok($bar, 'Foo'); + + # test it working with with Sub::Name + SKIP: { + eval 'use Sub::Name'; + skip "Sub::Name is required for this test", 3 if $@; + + my $m = sub { (shift)->next::method() }; + Sub::Name::subname('Bar::bar', $m); + { + no strict 'refs'; + *{'Bar::bar'} = $m; + } + + Class::C3::initialize(); + + can_ok($bar, 'bar'); + my $value = eval { $bar->bar() }; + ok(!$@, '... calling bar() succedded') || diag $@; + is($value, 'Foo::bar', '... got the right return value too'); } - use Sub::Name; + # test it failing without Sub::Name + { + package Baz; + use strict; + use warnings; + use Class::C3; + our @ISA = ('Foo'); + } + + my $baz = Baz->new(); + isa_ok($baz, 'Baz'); + isa_ok($baz, 'Foo'); - my $m = sub { (shift)->next::method() }; - subname('Bar::bar', $m); { - no strict 'refs'; - *{'Bar::bar'} = $m; - } + my $m = sub { (shift)->next::method() }; + { + no strict 'refs'; + *{'Baz::bar'} = $m; + } - my $bar = Bar->new(); - isa_ok($bar, 'Bar'); - isa_ok($bar, 'Foo'); + Class::C3::initialize(); - can_ok($bar, 'bar'); - my $value = eval { $bar->bar() }; - ok(!$@, '... calling bar() succedded') || diag $@; - is($value, 'Foo::bar', '... got the right return value too'); -} \ No newline at end of file + eval { $baz->bar() }; + ok($@, '... calling bar() with next::method failed') || diag $@; + } +}