How can I make fun of Exit behavior in perl?

Suppose that in one of the PERL modules there is one subroutine module -

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

and I want to write a test case for this API as

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

but it does not work, because after exit 0 the PERL script exits.
so my question is: how can we mock exit behavior?

+4
source share
1 answer

Try using 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 
+7
source

All Articles