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