Subject: Re: testing non-modules
From: Johan Vromans <[EMAIL PROTECTED]>
To: perl-qa@perl.org

}[Quoting Michael G Schwern, on March 6 2005, 10:32, in "Re: testing non-modu"]
}> Or if you want to be super portable you can do this:
}> 
}>      use Test::Output;
}>      local @ARGV = qw(some args);
}>      stdout_is( sub { do "bin/myprogram" }, 'wibble' );
}> 
}> Which has the nice side benefit of making sure your code initialzes itself
}> properly between each run rather than just assuming its in a fresh process
}> each time.
}
}And, hopefully, the program doesn't call 'exit()'...

If you're afraid of that, do this in your test script:

  BEGIN { *CORE::GLOBAL::exit = sub { die("die, not exit\n") } }

That's a 5.6ism, but that will change exit() to die instead of exit.
Edit as appropriate.

I had written a private module for myself that allows exit() to be changed 
on-the-fly so that it could be explicitly changed for shorter periods of 
time than "the entire script".  I never released it, though.

-Pete K
-- 
Pete Krawczyk
    perl at bsod dot net

Reply via email to