Re: testing scripts inside your distro

2018-03-05 Thread Olivier Mengué
2018-03-01 15:00 GMT+01:00 yary :

> Something to do in small scripts which don't aren't module material, is to
> put all the "useful" code into subs, put the command-line processing &
> printing into a "sub MAIN", and then have only this top-level statement:
>
> exit MAIN unless caller;
>

This approach is called a "modulino". See those articles:
https://perlmaven.com/modulino-both-script-and-module
https://www.perl.com/article/107/2014/8/7/Rescue-legacy-code-with-modulinos/


Re: testing scripts inside your distro

2018-03-02 Thread yary
I was a little puzzled by the first response, but figured, to each their
own! Glad to know we are all on the same page.

On Fri, Mar 2, 2018, 4:13 PM Jonas B. Nielsen  wrote:

> Huh?
>
> Just must have been drunk or something,
>
> I mean to say, I can ONLY agree with this approach.
>
> Sorry for any confusion and thanks for not roasting me :-)
>
> Have a nice weekend,
>
> jonasbn
>
>
> On 1 Mar 2018, at 17.36, Jonas B. Nielsen  wrote:
>
> I cannot agree with this approach, but sometimes a single file is the
> easiest to distribute.
>
> Currently I am looking at App::Fatpacker -
> https://metacpan.org/pod/App::FatPacker
>
> On 1 Mar 2018, at 15.00, yary  wrote:
>
>
> On Thu, Mar 1, 2018 at 9:56 AM, David Cantrell 
> wrote:
>
>>
>> My approach is to have the script be mostly a wrapper around more
>> easily-testable modules - the script just wrangles arguments and shows
>> results.
>>
>
> +1 for that approach in general. Makes it easy to call the "useful" code
> in the script in other places.
>
> Something to do in small scripts which don't aren't module material, is to
> put all the "useful" code into subs, put the command-line processing &
> printing into a "sub MAIN", and then have only this top-level statement:
>
> exit MAIN unless caller;
>
> That lets the script be called normally, executing when run from the
> command line. On the other hand, another perl program can "require '
> the_code_file.pl'" and load all the subs without anything executing- so
> your test code can call MAIN after setting @ARGV to whatever it wants - or
> can test the other subs as needed.
>
>
>
>
>
> —
> pauseid: JONASBN
> email: jona...@cpan.org 
> twitter: @jonasbn
> blog: https://lastmover.wordpress.com/
>
>
>
>
>
>


Re: testing scripts inside your distro

2018-03-02 Thread Jonas B. Nielsen
Huh?

Just must have been drunk or something,

I mean to say, I can ONLY agree with this approach.

Sorry for any confusion and thanks for not roasting me :-)

Have a nice weekend,

jonasbn

> On 1 Mar 2018, at 17.36, Jonas B. Nielsen  wrote:
> 
> I cannot agree with this approach, but sometimes a single file is the easiest 
> to distribute.
> 
> Currently I am looking at App::Fatpacker - 
> https://metacpan.org/pod/App::FatPacker 
> 
> 
>> On 1 Mar 2018, at 15.00, yary > 
>> wrote:
>> 
>> 
>> On Thu, Mar 1, 2018 at 9:56 AM, David Cantrell > > wrote:
>> 
>> My approach is to have the script be mostly a wrapper around more
>> easily-testable modules - the script just wrangles arguments and shows
>> results.
>> 
>> +1 for that approach in general. Makes it easy to call the "useful" code in 
>> the script in other places.
>> 
>> Something to do in small scripts which don't aren't module material, is to 
>> put all the "useful" code into subs, put the command-line processing & 
>> printing into a "sub MAIN", and then have only this top-level statement:
>> 
>> exit MAIN unless caller;
>> 
>> That lets the script be called normally, executing when run from the command 
>> line. On the other hand, another perl program can "require 'the_code_file.pl 
>> '" and load all the subs without anything 
>> executing- so your test code can call MAIN after setting @ARGV to whatever 
>> it wants - or can test the other subs as needed.
>> 
> 



—
pauseid: JONASBN
email: jona...@cpan.org
twitter: @jonasbn
blog: https://lastmover.wordpress.com/ 







signature.asc
Description: Message signed with OpenPGP


Re: testing scripts inside your distro

2018-03-01 Thread Jonas B. Nielsen
I cannot agree with this approach, but sometimes a single file is the easiest 
to distribute.

Currently I am looking at App::Fatpacker - 
https://metacpan.org/pod/App::FatPacker 


> On 1 Mar 2018, at 15.00, yary  wrote:
> 
> 
> On Thu, Mar 1, 2018 at 9:56 AM, David Cantrell  > wrote:
> 
> My approach is to have the script be mostly a wrapper around more
> easily-testable modules - the script just wrangles arguments and shows
> results.
> 
> +1 for that approach in general. Makes it easy to call the "useful" code in 
> the script in other places.
> 
> Something to do in small scripts which don't aren't module material, is to 
> put all the "useful" code into subs, put the command-line processing & 
> printing into a "sub MAIN", and then have only this top-level statement:
> 
> exit MAIN unless caller;
> 
> That lets the script be called normally, executing when run from the command 
> line. On the other hand, another perl program can "require 'the_code_file.pl 
> '" and load all the subs without anything 
> executing- so your test code can call MAIN after setting @ARGV to whatever it 
> wants - or can test the other subs as needed.
> 



signature.asc
Description: Message signed with OpenPGP


Re: testing scripts inside your distro

2018-03-01 Thread yary
On Thu, Mar 1, 2018 at 9:56 AM, David Cantrell 
wrote:

>
> My approach is to have the script be mostly a wrapper around more
> easily-testable modules - the script just wrangles arguments and shows
> results.
>

+1 for that approach in general. Makes it easy to call the "useful" code in
the script in other places.

Something to do in small scripts which don't aren't module material, is to
put all the "useful" code into subs, put the command-line processing &
printing into a "sub MAIN", and then have only this top-level statement:

exit MAIN unless caller;

That lets the script be called normally, executing when run from the
command line. On the other hand, another perl program can "require '
the_code_file.pl'" and load all the subs without anything executing- so
your test code can call MAIN after setting @ARGV to whatever it wants - or
can test the other subs as needed.


Re: testing scripts inside your distro

2018-03-01 Thread David Cantrell
On Wed, Feb 28, 2018 at 05:10:26PM +, 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
thus:

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

my($stdout, $stderr, @result) = capture { system(
$Config{perlpath}, (map { "-I$_" } (@INC)),
qw(
blib/script/...
...
)
)};

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


Re: testing scripts inside your distro

2018-02-28 Thread Jonas B. Nielsen
I have just recently started using: Test::Script and it has worked fine so far.

> On 28 Feb 2018, at 18.10, 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?
> 
> I took a look at Test-Script, but there are no evaluations about it yet.
> 
> Thanks!
> Alceu



signature.asc
Description: Message signed with OpenPGP


Re: testing scripts inside your distro

2018-02-28 Thread David Golden
Test::Cmd?  If NEILB has taken over maintaining it's probably reasonable,
but you can email him with any questions.

On Wed, Feb 28, 2018 at 12:10 PM, 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?
>
> I took a look at Test-Script, but there are no evaluations about it yet.
>
> Thanks!
> Alceu
>



-- 
David Golden  Twitter/IRC/GitHub: @xdg