File: define.t

package info (click to toggle)
libtest-mockmodule-perl 0.178.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 192 kB
  • sloc: perl: 245; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 932 bytes parent folder | download | duplicates (3)
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
use warnings;
use strict;

use Test::More;
use Test::Warnings;

use Test::MockModule;

my $mocker = Test::MockModule->new('Mockee');

$mocker->define( 'doesnt_exist', 2 );
is( Mockee::doesnt_exist(), 2, 'define() allows us to mock nonexistant subroutines.' );

eval { $mocker->define( 'existing_subroutine', 6 ) };
like( $@, qr/Mockee::existing_subroutine exists\!/, 'exception when define()ing an existing subroutine' );

undef $mocker;
is( Mockee->can('doesnt_exist'), undef, "the defined sub went away after mocker is undeffed" );
$mocker = Test::MockModule->new('Mockee');

$mocker->define( 'doesnt_exist', 3 );
is( Mockee::doesnt_exist(), 3, 'The subroutine can be defined again after the mock object goes out of scope and is re-instantiated.' );

done_testing();

#----------------------------------------------------------------------

package Mockee;

our $VERSION;
BEGIN { $VERSION = 1 }

sub existing_subroutine { 1 }

1;