Reputation: 18459
I am using Test::MockModule
to test perl module. One of the call require checking status of $?
to get error code and program checks for it.
How can I mock the result of $?
Code under test is like below.
my $result = CCUtil::cleartool($cmd);
if ( $? != 0 ) {
confess "Stream $stream not found( $result) ";
}
The api returns string and sets $? for checking status.
Normal method calls and their return values are changed using something like below
my $module = Test::MockModule->new('CCUtil');
$mockModule->mock(cleartool => sub {return 'stream not found'});
The method call is now mocked. Not the value of -- $?
Upvotes: 5
Views: 170
Reputation: 385897
my $module = Test::MockModule->new('CCUtil');
$mockModule->mock(cleartool => sub { $? = 0x0100; return 'stream not found' });
Upvotes: 4