Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

perl mocking is there a way to mock $?

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 -- $?

like image 642
Jayan Avatar asked Sep 30 '22 12:09

Jayan


1 Answers

my $module = Test::MockModule->new('CCUtil');
$mockModule->mock(cleartool => sub { $? = 0x0100; return 'stream not found' });
like image 128
ikegami Avatar answered Oct 10 '22 11:10

ikegami