• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

inc/Module/H20-Oct-2013-3,3342,497

lib/Test/Script/H20-Oct-2013-511270

t/H20-Oct-2013-12294

xt/H20-Oct-2013-3324

ChangesH A D20-Oct-2013753 3017

MANIFESTH A D26-Oct-2012608 3029

META.ymlH A D20-Oct-2013650 3231

Makefile.PLH A D20-Oct-2013404 1913

READMEH A D20-Oct-20134 KiB10983

README

1NAME
2    Test::Script::Run - test scripts with run
3
4SYNOPSIS
5        use Test::Script::Run;
6        # customized names of bin dirs, default is qw/bin sbin script ./;
7        @Test::Script::Run::BIN_DIRS = qw/bin/;
8        run_ok( 'app_name', [ app's args ], 'you_app runs ok' );
9        my ( $return, $stdout, $stderr ) = run_script( 'app_name', [ app's args ] );
10        run_output_matches(
11            'app_name', [app's args],
12            [ 'out line 1', 'out line 2' ],
13            [ 'err line 1', 'err line 2' ],
14            'run_output_matches'
15        );
16        run_output_matches_unordered(
17            'app_name', [ app's args ],
18            [ 'out line 2', 'out line 1' ],
19            [ 'err line 2', 'err line 1' ],
20            'run_output_matches_unordered'
21        );
22
23DESCRIPTION
24    This module exports some subs to help test and run scripts in your
25    dist's script directory( bin, sbin, script, etc ), if the script path is
26    not absolute.
27
28    Nearly all the essential code is stolen from Prophet::Test, we think
29    subs like those should live below "Test::" namespace, that's why we
30    packed them and created this module.
31
32FUNCTIONS
33  run_script($script, $args, $stdout, $stderr)
34    Runs the script $script as a perl script, setting the @INC to the same
35    as our caller.
36
37    $script is the name of the script to be run (such as 'prophet'). $args
38    is a reference to an array of arguments to pass to the script. $stdout
39    and $stderr are both optional; if passed in, they will be passed to
40    IPC::Run3's run3 subroutine as its $stdout and $stderr args. Otherwise,
41    this subroutine will create scalar references to pass to run3 instead
42    (which are treated as strings for STDOUT/STDERR to be written to).
43
44    Returns run3's return value and, if no $stdout and $stderr were passed
45    in, the STDOUT and STDERR of the script that was run.
46
47  run_ok($script, $args, $msg)
48    Runs the script, checking that it didn't error out.
49
50    $script is the name of the script to be run (e.g. 'prophet'). $args is
51    an optional reference to an array of arguments to pass to the script
52    when it is run. $msg is an optional message to print with the test. If
53    $args is not specified, you can still pass in a $msg.
54
55    Returns nothing of interest.
56
57  run_not_ok($script, $args, $msg)
58    opposite of run_ok
59
60  get_perl_cmd($script, @ARGS)
61    Returns a list suitable for passing to "system", "exec", etc. If you
62    pass $script then we will search upwards for it in @BIN_DIRS
63
64  is_script_output($scriptname \@args, \@stdout_match, \@stderr_match, $msg)
65    Runs $scriptname, checking to see that its output matches.
66
67    $args is an array reference of args to pass to the script. $stdout_match
68    and $stderr_match are references to arrays of expected lines. $msg is a
69    string message to display with the test. $stderr_match and $msg are
70    optional. (As is $stdout_match if for some reason you expect your script
71    to have no output at all. But that would be silly, wouldn't it?)
72
73    Allows regex matches as well as string equality (lines in $stdout_match
74    and $stderr_match may be Regexp objects).
75
76  run_output_matches($script, $args, $exp_stdout, $exp_stderr, $msg)
77    A wrapper around is_script_output that also checks to make sure the test
78    runs without throwing an exception.
79
80  run_output_matches_unordered($script, $args, $exp_stdout, $exp_stderr, $msg)
81    This subroutine has exactly the same functionality as
82    run_output_matches, but doesn't impose a line ordering when comparing
83    the expected and received outputs.
84
85  last_script_stdout
86    return last script's stdout
87
88  last_script_stderr
89    return last script's stderr
90
91  last_script_exit_code
92    return last script's exit code
93
94DEPENDENCIES
95    Test::More, Test::Exception, IPC::Run3, File::Basename, File::Spec
96
97BUGS AND LIMITATIONS
98    No bugs have been reported.
99
100AUTHOR
101    sunnavy <sunnavy@bestpractical.com>
102
103LICENCE AND COPYRIGHT
104    Copyright 2009-2013 Best Practical Solutions.
105
106    This program is free software; you can redistribute it and/or modify it
107    under the same terms as Perl itself.
108
109