Blame t/inheritance.t

Packit 11f908
use warnings;
Packit 11f908
use strict;
Packit 11f908
Packit 11f908
use Test::MockModule;
Packit 11f908
use Test::More;
Packit 11f908
Packit 11f908
@Bar::ISA = 'Foo';
Packit 11f908
@Baz::ISA = 'Bar';
Packit 11f908
Packit 11f908
sub Foo::motto { 'Foo!' };
Packit 11f908
Packit 11f908
is(Foo->motto(), "Foo!", "pre-mock: Foo original motto is correct");
Packit 11f908
is(Bar->motto(), "Foo!", "pre-mock: Bar inherit's Foo's motto");
Packit 11f908
is(Baz->motto(), "Foo!", "pre-mock: Baz inherit's Bar's inheritance of Foo's motto");
Packit 11f908
Packit 11f908
{
Packit 11f908
	my $mock_bar = Test::MockModule->new('Bar', no_auto => 1);
Packit 11f908
	$mock_bar->mock('motto', sub { 'Bar!' });
Packit 11f908
	is(Foo->motto(), "Foo!", "Foo motto is unchanged post-Bar mock");
Packit 11f908
	is(Bar->motto(), "Bar!", "Bar motto has been mocked");
Packit 11f908
	is(Baz->motto(), "Bar!", "Baz inherits from Bar's mocked motto");
Packit 11f908
	is($mock_bar->original("motto")->(), "Foo!", "Bar's original function can still be reached correctly");
Packit 11f908
	ok($mock_bar->is_mocked("motto"), "Baz's motto is really mocked");
Packit 11f908
Packit 11f908
	my $mock_baz = Test::MockModule->new('Baz', no_auto => 1);
Packit 11f908
	$mock_baz->mock('motto', sub { 'Baz!' });
Packit 11f908
	is(Foo->motto(), "Foo!", "Foo motto is unchanged post-Baz mock");
Packit 11f908
	is(Bar->motto(), "Bar!", "Bar motto is unchanged post-Baz mock");
Packit 11f908
	is(Baz->motto(), "Baz!", "Baz motto has been mocked");
Packit 11f908
Packit 11f908
	is($mock_baz->original("motto")->(), "Bar!", "Baz's original function is Bar's mocked function");
Packit 11f908
	ok($mock_baz->is_mocked("motto"), "Baz's motto is really mocked");
Packit 11f908
Packit 11f908
	$mock_bar->unmock("motto");
Packit 11f908
	is(Bar->motto, "Foo!", "Bar's motto is unmocked");
Packit 11f908
	is($mock_baz->original("motto")->(), "Foo!", "Baz's original function is now magically inherited up to Foo");
Packit 11f908
}
Packit 11f908
Packit 11f908
is(Foo->motto(), "Foo!", "post-unmock: Foo original motto is correct");
Packit 11f908
is(Bar->motto(), "Foo!", "post-unmock: Bar inherit's Foo's motto");
Packit 11f908
is(Baz->motto(), "Foo!", "post-unmock: Baz inherit's Bar's inheritance of Foo's motto");
Packit 11f908
done_testing;