develooper Front page | perl.cpan.testers.discuss | Postings from March 2018

Re: testing scripts inside your distro

Thread Previous | Thread Next
David Cantrell
March 1, 2018 13:16
Re: testing scripts inside your distro
Message ID:
On Wed, Feb 28, 2018 at 05:10:26PM +0000, Alceu R. de Freitas Jr. via cpan-testers-discuss wrote:
> Hello guys,
> I'm in need to test some scripts inside one of my distributions and I'm bit tired of writing boilerplate code for doing it.
> Maybe you could suggest something available on CPAN for that?

My approach is to have the script be mostly a wrapper around more
easily-testable modules - the script just wrangles arguments and shows
results. So the bulk of the logic can be tested in the usual fashion by
testing the underlying modules. Then to test that it wrangles arguments
and spits out the right results I use Capture::Tiny's "capture" sub

use Capture::Tiny qw(capture);
use Config;

my($stdout, $stderr, @result) = capture { system(
    $Config{perlpath}, (map { "-I$_" } (@INC)),

and just make sure $stderr, $stdout, and @result (which contains the
exit code reported by system()) are as expected.

David Cantrell | Reality Engineer, Ministry of Information

     Repent through spending

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About