Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i mock the Exit behaviour in perl?

Tags:

perl

suppose there is one subroutine exam in one of the PERL module-

sub exam  
{  
    ....  
    ....  
    exit 0;  
}

and i want to write test case for this API like-

is('exam',0,"exam subroutine works properly");

but it is not working, because after exit 0, PERL script is coming out.
so my question is how can we mock the behavior of exit?

like image 494
Seetendra Sengar Avatar asked Mar 25 '23 05:03

Seetendra Sengar


1 Answers

Try to use the Test::Exit

    perl  -le 'use Test::More tests => 2; use Test::Exit ; sub s1 { exit $_[0] }; exits_zero( sub{ s1(0)}, q{exit 0}); exits_ok(sub {s1(1)}, q{exit 1}); ' 
    1..2
    ok 1 - exit 0
    ok 2 - exit 1
like image 153
pedro.frazao Avatar answered Mar 26 '23 21:03

pedro.frazao