1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
use warnings;
use strict;
use Test::More;
use Test::Warnings;
use Test::MockModule;
my $mocker = Test::MockModule->new('Mockee');
$mocker->redefine('good', 2);
is( Mockee::good(), 2, 'redefine() redefines the function' );
eval { $mocker->redefine('bad', 6) };
like( $@, qr/Mockee::bad/, 'exception when redefine()ing a nonexistent function' );
my $mocker2 = Test::MockModule->new('MockeeWithDestroy');
eval { $mocker2->redefine('what', 2) };
done_testing();
#----------------------------------------------------------------------
package Mockee;
our $VERSION;
BEGIN { $VERSION = 1 };
sub good { 1 }
#----------------------------------------------------------------------
package MockeeWithDestroy;
our $VERSION;
BEGIN { $VERSION = 1 };
sub DESTROY { print 'bad' if $_[0][1] };
1;
|