Test::...pt::Run(3pm)
β¨ NAME β¨
Test::Script::Run β test scripts with run π
okay so real talk, this whole page lives inside the perl docs as Test::...pt::Run(3pm) (yes the name got squished, it's the truncated short name of the page, and the section is User Contributed Perl Documentation, so you know it's a community bop π«Ά). Main character of this page: Test::Script::Run. It tests your scripts. With run. Slay.
πΈ SYNOPSIS πΈ
use Test::Script::Run;
# customized names of bin dirs, default is qw/bin sbin script ./;
@Test::Script::Run::BIN_DIRS = qw/bin/;
run_ok( 'app_name', [ app's args ], 'you_app runs ok' );
my ( $return, $stdout, $stderr ) = run_script( 'app_name', [ app's args ] );
run_output_matches(
'app_name', [app's args],
[ 'out line 1', 'out line 2' ],
[ 'err line 1', 'err line 2' ],
'run_output_matches'
);
run_output_matches_unordered(
'app_name', [ app's args ],
[ 'out line 2', 'out line 1' ],
[ 'err line 2', 'err line 1' ],
'run_output_matches_unordered'
);
π DESCRIPTION π
So this module exports a bunch of subs that help you test and run scripts sitting in your dist's script directory (think bin, sbin, script, etc) β but only if the script path isn't absolute. Absolute paths just do their own thing, no search party needed π
Fun little lore drop: nearly all the essential code here is stolen from Prophet::Test π The authors were like "hmm these subs really should live under the Test:: namespace," so they packed them up and created this module. Respect the hustle fr fr.
π¦ FUNCTIONS π¦
run_script($script, $args, $stdout, $stderr)
Runs the script $script as a perl script, and sets @INC to be exactly the same as our caller's. No cap, it matches your caller's @INC.
$scriptβ the name of the script to be run (such as'prophet').$argsβ a reference to an array of arguments to pass to the script.$stdoutand$stderrβ both optional. If you pass them in, they get handed straight toIPC::Run3'srun3subroutine as its$stdoutand$stderrargs. If you don't pass them, this subroutine makes its own scalar references to pass torun3instead (and those get treated as strings for STDOUT/STDERR to be written to).
Returns run3's return value, and β if no $stdout and $stderr were passed in β the STDOUT and STDERR of the script that was run. It's giving "you get the receipts back" π§Ύ
run_ok($script, $args, $msg)
Runs the script and checks that it didn't error out. Vibe check on your script, basically.
$scriptβ the name of the script to be run (e.g.'prophet').$argsβ an optional reference to an array of arguments to pass to the script when it is run.$msgβ an optional message to print with the test.
Little tip: if $args is not specified, you can still pass in a $msg. So don't let the optional-ness stress you out π
Returns nothing of interest. Like, genuinely nothing. Move along.
run_not_ok($script, $args, $msg)
opposite of run_ok π
get_perl_cmd($script, @ARGS)
Returns a list suitable for passing to "system", "exec", etc. And if you pass $script, we will search upwards for it in @BIN_DIRS π
is_script_output($scriptname \@args, \@stdout_match, \@stderr_match, $msg)
Runs $scriptname and checks to see that its output matches. The moment of truth β¨
$argsβ an array reference of args to pass to the script.$stdout_matchand$stderr_matchβ references to arrays of expected lines.$msgβ a string message to display with the test.
Now the optionality tea β: $stderr_match and $msg are optional. (As is $stdout_match if for some reason you expect your script to have no output at all. But that would be silly, wouldn't it? π)
And yes, this allows regex matches as well as string equality β lines in $stdout_match and $stderr_match may be Regexp objects. Iconic.
run_output_matches($script, $args, $exp_stdout, $exp_stderr, $msg)
A wrapper around is_script_output that also checks to make sure the test runs without throwing an exception. Double protection, we love to see it π‘οΈ
run_output_matches_unordered($script, $args, $exp_stdout, $exp_stderr, $msg)
This subroutine has exactly the same functionality as run_output_matches, but it doesn't impose a line ordering when comparing the expected and received outputs. Chaos-friendly. Order is a social construct π
last_script_stdout
return last script's stdout π€
last_script_stderr
return last script's stderr π₯
last_script_exit_code
return last script's exit code πͺ
π DEPENDENCIES π
Test::More, Test::Exception, IPC::Run3, File::Basename, File::Spec
The squad. The whole squad. π
π BUGS AND LIMITATIONS π
No bugs have been reported.
(Translation: zero bugs reported, which is either flawless code or everyone's too shy. We don't know. We simply don't know. π)
β AUTHOR β
sunnavy <sunnavy@bestpractical.com>
π LICENCE AND COPYRIGHT π
Copyright 2009-2013 Best Practical Solutions.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
okay bestie that's the whole page, go forth and test your scripts, you absolute legend π«Άβ¨
this page came to you courtesy of the User Contributed Perl Documentation for Test::...pt::Run(3pm), generated by perl v5.36.0 on 2022-12-08 β mwah, no notes π
π
π¦ where this page comes from
- debian bookworm: libtest-script-run-perl 0.08-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libtest-script-run-perl 0.08-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libtest-script-run-perl 0.08-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtest-script-run-perl 0.08-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtest-script-run-perl 0.08-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms