Seetendra Sengar
Seetendra Sengar

Reputation: 61

How can i mock the Exit behaviour in 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?

Upvotes: 4

Views: 353

Answers (1)

pedro.frazao
pedro.frazao

Reputation: 71

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

Upvotes: 7

Related Questions