Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Portably unit testing scripts

by Discipulus (Canon)
on Oct 26, 2019 at 12:11 UTC ( [id://11107989]=note: print w/replies, xml ) Need Help??


in reply to Portably unit testing scripts

Hello wanna_code_perl,

First I second what haukex said. If you have a library, a perl module, test what this module exports. The cli is just an interface.

Second: your example is not a modulino. A modulino is a perl module .pm file that can be invoked as a program via a trick. A modulino should end with the famous 1; or cannot be loaded.

If your is a modulino you can use it in your testing program and play with their subs, testing them as you wish.

In both cases, modulino or standalone script, you can test it somehow, using Capture::Tiny (without embarking yourself in a fight with Run3 modules.. ;). you can also launch the script and inspect the exit values.

Few example I have in some test on github something you can adapt:

use strict; use warnings; use Test::More; use Test::Exception; use Capture::Tiny qw(capture); ... # expected death my ($out, $err, @res) = capture { dies_ok { a_sub_that_dies() } 'expected to die without argumen +ts'; }; # verbosity check ($out, $err, @res) = capture { $obj->method( verbose => 2 ); }; ok ((split "\n", $out) > 30 , "30+ lines expected with verbosity = 2") +; # checking exit status (you can check 'perl your_modulino_or_script ar +g1 arg2..' ) my $exit = system "$program /? >nul 2>&1"; ok ( 16 == ($exit>>8), "[$program /? >nul 2>&1] returned the expected +value");

See also testing in my bibliotheca and Test::Script from CPAN.

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11107989]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-25 22:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found