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 -- $?
my $module = Test::MockModule->new('CCUtil');
$mockModule->mock(cleartool => sub { $? = 0x0100; return 'stream not found' });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With