line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
19
|
|
|
19
|
|
1369686
|
use 5.008; |
|
19
|
|
|
|
|
228
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Test::Output; |
4
|
|
|
|
|
|
|
|
5
|
19
|
|
|
19
|
|
122
|
use warnings; |
|
19
|
|
|
|
|
35
|
|
|
19
|
|
|
|
|
542
|
|
6
|
19
|
|
|
19
|
|
100
|
use strict; |
|
19
|
|
|
|
|
33
|
|
|
19
|
|
|
|
|
463
|
|
7
|
|
|
|
|
|
|
|
8
|
19
|
|
|
19
|
|
110
|
use Test::Builder; |
|
19
|
|
|
|
|
31
|
|
|
19
|
|
|
|
|
578
|
|
9
|
19
|
|
|
19
|
|
10559
|
use Capture::Tiny qw/capture capture_stdout capture_stderr capture_merged/; |
|
19
|
|
|
|
|
551327
|
|
|
19
|
|
|
|
|
2720
|
|
10
|
19
|
|
|
|
|
443
|
use Sub::Exporter -setup => { |
11
|
|
|
|
|
|
|
exports => [ |
12
|
|
|
|
|
|
|
qw(output_is output_isnt output_like output_unlike |
13
|
|
|
|
|
|
|
stderr_is stderr_isnt stderr_like stderr_unlike |
14
|
|
|
|
|
|
|
stdout_is stdout_isnt stdout_like stdout_unlike |
15
|
|
|
|
|
|
|
combined_is combined_isnt combined_like combined_unlike |
16
|
|
|
|
|
|
|
output_from stderr_from stdout_from combined_from |
17
|
|
|
|
|
|
|
) |
18
|
|
|
|
|
|
|
], |
19
|
|
|
|
|
|
|
groups => { |
20
|
|
|
|
|
|
|
stdout => [ |
21
|
|
|
|
|
|
|
qw( |
22
|
|
|
|
|
|
|
stdout_is stdout_isnt stdout_like stdout_unlike |
23
|
|
|
|
|
|
|
) |
24
|
|
|
|
|
|
|
], |
25
|
|
|
|
|
|
|
stderr => [ |
26
|
|
|
|
|
|
|
qw( |
27
|
|
|
|
|
|
|
stderr_is stderr_isnt stderr_like stderr_unlike |
28
|
|
|
|
|
|
|
) |
29
|
|
|
|
|
|
|
], |
30
|
|
|
|
|
|
|
output => [ |
31
|
|
|
|
|
|
|
qw( |
32
|
|
|
|
|
|
|
output_is output_isnt output_like output_unlike |
33
|
|
|
|
|
|
|
) |
34
|
|
|
|
|
|
|
], |
35
|
|
|
|
|
|
|
combined => [ |
36
|
|
|
|
|
|
|
qw( |
37
|
|
|
|
|
|
|
combined_is combined_isnt combined_like combined_unlike |
38
|
|
|
|
|
|
|
) |
39
|
|
|
|
|
|
|
], |
40
|
|
|
|
|
|
|
functions => [ |
41
|
|
|
|
|
|
|
qw( |
42
|
|
|
|
|
|
|
output_from stderr_from stdout_from combined_from |
43
|
|
|
|
|
|
|
) |
44
|
|
|
|
|
|
|
], |
45
|
|
|
|
|
|
|
tests => [ |
46
|
|
|
|
|
|
|
qw( |
47
|
|
|
|
|
|
|
output_is output_isnt output_like output_unlike |
48
|
|
|
|
|
|
|
stderr_is stderr_isnt stderr_like stderr_unlike |
49
|
|
|
|
|
|
|
stdout_is stdout_isnt stdout_like stdout_unlike |
50
|
|
|
|
|
|
|
combined_is combined_isnt combined_like combined_unlike |
51
|
|
|
|
|
|
|
) |
52
|
|
|
|
|
|
|
], |
53
|
|
|
|
|
|
|
default => [ '-tests' ], |
54
|
|
|
|
|
|
|
}, |
55
|
19
|
|
|
19
|
|
10950
|
}; |
|
19
|
|
|
|
|
217097
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $Test = Test::Builder->new; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=encoding utf8 |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 NAME |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Test::Output - Utilities to test STDOUT and STDERR messages. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 VERSION |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Version 0.16 |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
our $VERSION = '1.032'; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 SYNOPSIS |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
use Test::More tests => 4; |
76
|
|
|
|
|
|
|
use Test::Output; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub writer { |
79
|
|
|
|
|
|
|
print "Write out.\n"; |
80
|
|
|
|
|
|
|
print STDERR "Error out.\n"; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
stdout_is(\&writer,"Write out.\n",'Test STDOUT'); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
stderr_isnt(\&writer,"No error out.\n",'Test STDERR'); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
combined_is( |
88
|
|
|
|
|
|
|
\&writer, |
89
|
|
|
|
|
|
|
"Write out.\nError out.\n", |
90
|
|
|
|
|
|
|
'Test STDOUT & STDERR combined' |
91
|
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
output_is( |
94
|
|
|
|
|
|
|
\&writer, |
95
|
|
|
|
|
|
|
"Write out.\n", |
96
|
|
|
|
|
|
|
"Error out.\n", |
97
|
|
|
|
|
|
|
'Test STDOUT & STDERR' |
98
|
|
|
|
|
|
|
); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# Use bare blocks. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
stdout_is { print "test" } "test", "Test STDOUT"; |
103
|
|
|
|
|
|
|
stderr_isnt { print "bad test" } "test", "Test STDERR"; |
104
|
|
|
|
|
|
|
output_is { print 'STDOUT'; print STDERR 'STDERR' } |
105
|
|
|
|
|
|
|
"STDOUT", "STDERR", "Test output"; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 DESCRIPTION |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Test::Output provides a simple interface for testing output sent to STDOUT |
110
|
|
|
|
|
|
|
or STDERR. A number of different utilities are included to try and be as |
111
|
|
|
|
|
|
|
flexible as possible to the tester. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Originally this module was designed not to have external requirements, |
114
|
|
|
|
|
|
|
however, the features provided by L over what L |
115
|
|
|
|
|
|
|
provides is just to great to pass up. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Likewise, Capture::Tiny provides a much more robust capture mechanism without |
118
|
|
|
|
|
|
|
than the original Test::Output::Tie. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 TESTS |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=cut |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 STDOUT |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=over 4 |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item B |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item B |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
stdout_is ( $coderef, $expected, 'description' ); |
135
|
|
|
|
|
|
|
stdout_is { ... } $expected, 'description'; |
136
|
|
|
|
|
|
|
stdout_isnt( $coderef, $expected, 'description' ); |
137
|
|
|
|
|
|
|
stdout_isnt { ... } $expected, 'description'; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
stdout_is() captures output sent to STDOUT from $coderef and compares |
140
|
|
|
|
|
|
|
it against $expected. The test passes if equal. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
stdout_isnt() passes if STDOUT is not equal to $expected. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub stdout_is (&$;$$) { |
147
|
6
|
|
|
6
|
1
|
12627
|
my $test = shift; |
148
|
6
|
|
|
|
|
14
|
my $expected = shift; |
149
|
6
|
50
|
|
|
|
20
|
my $options = shift if ( ref( $_[0] ) ); |
150
|
6
|
|
|
|
|
11
|
my $description = shift; |
151
|
|
|
|
|
|
|
|
152
|
6
|
|
|
|
|
15
|
my $stdout = stdout_from($test); |
153
|
|
|
|
|
|
|
|
154
|
6
|
|
|
|
|
19
|
my $ok = ( $stdout eq $expected ); |
155
|
|
|
|
|
|
|
|
156
|
6
|
100
|
|
|
|
55
|
$Test->ok( $ok, $description ) |
157
|
|
|
|
|
|
|
|| $Test->diag("STDOUT is:\n$stdout\nnot:\n$expected\nas expected"); |
158
|
|
|
|
|
|
|
|
159
|
6
|
|
|
|
|
2943
|
return $ok; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub stdout_isnt (&$;$$) { |
163
|
6
|
|
|
6
|
1
|
15413
|
my $test = shift; |
164
|
6
|
|
|
|
|
9
|
my $expected = shift; |
165
|
6
|
50
|
|
|
|
16
|
my $options = shift if ( ref( $_[0] ) ); |
166
|
6
|
|
|
|
|
12
|
my $description = shift; |
167
|
|
|
|
|
|
|
|
168
|
6
|
|
|
|
|
17
|
my $stdout = stdout_from($test); |
169
|
|
|
|
|
|
|
|
170
|
6
|
|
|
|
|
15
|
my $ok = ( $stdout ne $expected ); |
171
|
|
|
|
|
|
|
|
172
|
6
|
100
|
|
|
|
45
|
$Test->ok( $ok, $description ) |
173
|
|
|
|
|
|
|
|| $Test->diag("STDOUT:\n$stdout\nmatching:\n$expected\nnot expected"); |
174
|
|
|
|
|
|
|
|
175
|
6
|
|
|
|
|
2805
|
return $ok; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item B |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item B |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
stdout_like ( $coderef, qr/$expected/, 'description' ); |
183
|
|
|
|
|
|
|
stdout_like { ... } qr/$expected/, 'description'; |
184
|
|
|
|
|
|
|
stdout_unlike( $coderef, qr/$expected/, 'description' ); |
185
|
|
|
|
|
|
|
stdout_unlike { ... } qr/$expected/, 'description'; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
stdout_like() captures the output sent to STDOUT from $coderef and compares |
188
|
|
|
|
|
|
|
it to the regex in $expected. The test passes if the regex matches. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
stdout_unlike() passes if STDOUT does not match the regex. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=back |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=cut |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
sub stdout_like (&$;$$) { |
197
|
6
|
|
|
6
|
1
|
15774
|
my $test = shift; |
198
|
6
|
|
|
|
|
13
|
my $expected = shift; |
199
|
6
|
50
|
|
|
|
15
|
my $options = shift if ( ref( $_[0] ) ); |
200
|
6
|
|
|
|
|
11
|
my $description = shift; |
201
|
|
|
|
|
|
|
|
202
|
6
|
100
|
|
|
|
15
|
unless ( my $regextest = _chkregex( 'stdout_like' => $expected ) ) { |
203
|
2
|
|
|
|
|
7
|
return $regextest; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
4
|
|
|
|
|
11
|
my $stdout = stdout_from($test); |
207
|
|
|
|
|
|
|
|
208
|
4
|
|
|
|
|
31
|
my $ok = ( $stdout =~ $expected ); |
209
|
|
|
|
|
|
|
|
210
|
4
|
100
|
|
|
|
31
|
$Test->ok( $ok, $description ) |
211
|
|
|
|
|
|
|
|| $Test->diag("STDOUT:\n$stdout\ndoesn't match:\n$expected\nas expected"); |
212
|
|
|
|
|
|
|
|
213
|
4
|
|
|
|
|
2078
|
return $ok; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub stdout_unlike (&$;$$) { |
217
|
6
|
|
|
6
|
1
|
15838
|
my $test = shift; |
218
|
6
|
|
|
|
|
13
|
my $expected = shift; |
219
|
6
|
50
|
|
|
|
16
|
my $options = shift if ( ref( $_[0] ) ); |
220
|
6
|
|
|
|
|
10
|
my $description = shift; |
221
|
|
|
|
|
|
|
|
222
|
6
|
100
|
|
|
|
14
|
unless ( my $regextest = _chkregex( 'stdout_unlike' => $expected ) ) { |
223
|
2
|
|
|
|
|
8
|
return $regextest; |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|
226
|
4
|
|
|
|
|
11
|
my $stdout = stdout_from($test); |
227
|
|
|
|
|
|
|
|
228
|
4
|
|
|
|
|
30
|
my $ok = ( $stdout !~ $expected ); |
229
|
|
|
|
|
|
|
|
230
|
4
|
100
|
|
|
|
31
|
$Test->ok( $ok, $description ) |
231
|
|
|
|
|
|
|
|| $Test->diag("STDOUT:\n$stdout\nmatches:\n$expected\nnot expected"); |
232
|
|
|
|
|
|
|
|
233
|
4
|
|
|
|
|
2057
|
return $ok; |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head2 STDERR |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=over 4 |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=item B |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=item B |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
stderr_is ( $coderef, $expected, 'description' ); |
245
|
|
|
|
|
|
|
stderr_is {... } $expected, 'description'; |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
stderr_isnt( $coderef, $expected, 'description' ); |
248
|
|
|
|
|
|
|
stderr_isnt {... } $expected, 'description'; |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
stderr_is() is similar to stdout_is, except that it captures STDERR. The |
251
|
|
|
|
|
|
|
test passes if STDERR from $coderef equals $expected. |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
stderr_isnt() passes if STDERR is not equal to $expected. |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=cut |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
sub stderr_is (&$;$$) { |
258
|
6
|
|
|
6
|
1
|
15468
|
my $test = shift; |
259
|
6
|
|
|
|
|
13
|
my $expected = shift; |
260
|
6
|
50
|
|
|
|
18
|
my $options = shift if ( ref( $_[0] ) ); |
261
|
6
|
|
|
|
|
9
|
my $description = shift; |
262
|
|
|
|
|
|
|
|
263
|
6
|
|
|
|
|
14
|
my $stderr = stderr_from($test); |
264
|
|
|
|
|
|
|
|
265
|
6
|
|
|
|
|
15
|
my $ok = ( $stderr eq $expected ); |
266
|
|
|
|
|
|
|
|
267
|
6
|
100
|
|
|
|
48
|
$Test->ok( $ok, $description ) |
268
|
|
|
|
|
|
|
|| $Test->diag("STDERR is:\n$stderr\nnot:\n$expected\nas expected"); |
269
|
|
|
|
|
|
|
|
270
|
6
|
|
|
|
|
2899
|
return $ok; |
271
|
|
|
|
|
|
|
} |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
sub stderr_isnt (&$;$$) { |
274
|
4
|
|
|
4
|
1
|
12188
|
my $test = shift; |
275
|
4
|
|
|
|
|
7
|
my $expected = shift; |
276
|
4
|
50
|
|
|
|
13
|
my $options = shift if ( ref( $_[0] ) ); |
277
|
4
|
|
|
|
|
8
|
my $description = shift; |
278
|
|
|
|
|
|
|
|
279
|
4
|
|
|
|
|
10
|
my $stderr = stderr_from($test); |
280
|
|
|
|
|
|
|
|
281
|
4
|
|
|
|
|
10
|
my $ok = ( $stderr ne $expected ); |
282
|
|
|
|
|
|
|
|
283
|
4
|
100
|
|
|
|
34
|
$Test->ok( $ok, $description ) |
284
|
|
|
|
|
|
|
|| $Test->diag("STDERR:\n$stderr\nmatches:\n$expected\nnot expected"); |
285
|
|
|
|
|
|
|
|
286
|
4
|
|
|
|
|
2098
|
return $ok; |
287
|
|
|
|
|
|
|
} |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=item B |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=item B |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
stderr_like ( $coderef, qr/$expected/, 'description' ); |
294
|
|
|
|
|
|
|
stderr_like { ...} qr/$expected/, 'description'; |
295
|
|
|
|
|
|
|
stderr_unlike( $coderef, qr/$expected/, 'description' ); |
296
|
|
|
|
|
|
|
stderr_unlike { ...} qr/$expected/, 'description'; |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
stderr_like() is similar to stdout_like() except that it compares the regex |
299
|
|
|
|
|
|
|
$expected to STDERR captured from $codref. The test passes if the regex |
300
|
|
|
|
|
|
|
matches. |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
stderr_unlike() passes if STDERR does not match the regex. |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
=back |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
=cut |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
sub stderr_like (&$;$$) { |
309
|
6
|
|
|
6
|
1
|
19436
|
my $test = shift; |
310
|
6
|
|
|
|
|
11
|
my $expected = shift; |
311
|
6
|
50
|
|
|
|
17
|
my $options = shift if ( ref( $_[0] ) ); |
312
|
6
|
|
|
|
|
12
|
my $description = shift; |
313
|
|
|
|
|
|
|
|
314
|
6
|
100
|
|
|
|
14
|
unless ( my $regextest = _chkregex( 'stderr_like' => $expected ) ) { |
315
|
2
|
|
|
|
|
6
|
return $regextest; |
316
|
|
|
|
|
|
|
} |
317
|
|
|
|
|
|
|
|
318
|
4
|
|
|
|
|
10
|
my $stderr = stderr_from($test); |
319
|
|
|
|
|
|
|
|
320
|
4
|
|
|
|
|
29
|
my $ok = ( $stderr =~ $expected ); |
321
|
|
|
|
|
|
|
|
322
|
4
|
100
|
|
|
|
36
|
$Test->ok( $ok, $description ) |
323
|
|
|
|
|
|
|
|| $Test->diag("STDERR:\n$stderr\ndoesn't match:\n$expected\nas expected"); |
324
|
|
|
|
|
|
|
|
325
|
4
|
|
|
|
|
2039
|
return $ok; |
326
|
|
|
|
|
|
|
} |
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
sub stderr_unlike (&$;$$) { |
329
|
6
|
|
|
6
|
1
|
15483
|
my $test = shift; |
330
|
6
|
|
|
|
|
9
|
my $expected = shift; |
331
|
6
|
50
|
|
|
|
18
|
my $options = shift if ( ref( $_[0] ) ); |
332
|
6
|
|
|
|
|
9
|
my $description = shift; |
333
|
|
|
|
|
|
|
|
334
|
6
|
100
|
|
|
|
14
|
unless ( my $regextest = _chkregex( 'stderr_unlike' => $expected ) ) { |
335
|
2
|
|
|
|
|
7
|
return $regextest; |
336
|
|
|
|
|
|
|
} |
337
|
|
|
|
|
|
|
|
338
|
4
|
|
|
|
|
10
|
my $stderr = stderr_from($test); |
339
|
|
|
|
|
|
|
|
340
|
4
|
|
|
|
|
30
|
my $ok = ( $stderr !~ $expected ); |
341
|
|
|
|
|
|
|
|
342
|
4
|
100
|
|
|
|
31
|
$Test->ok( $ok, $description ) |
343
|
|
|
|
|
|
|
|| $Test->diag("STDERR:\n$stderr\nmatches:\n$expected\nnot expected"); |
344
|
|
|
|
|
|
|
|
345
|
4
|
|
|
|
|
2003
|
return $ok; |
346
|
|
|
|
|
|
|
} |
347
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
=head2 COMBINED OUTPUT |
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
=over 4 |
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
=item B |
353
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
=item B |
355
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
combined_is ( $coderef, $expected, 'description' ); |
357
|
|
|
|
|
|
|
combined_is {... } $expected, 'description'; |
358
|
|
|
|
|
|
|
combined_isnt ( $coderef, $expected, 'description' ); |
359
|
|
|
|
|
|
|
combined_isnt {... } $expected, 'description'; |
360
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
combined_is() directs STDERR to STDOUT then captures STDOUT. This is |
362
|
|
|
|
|
|
|
equivalent to UNIXs 2>&1. The test passes if the combined STDOUT |
363
|
|
|
|
|
|
|
and STDERR from $coderef equals $expected. |
364
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
combined_isnt() passes if combined STDOUT and STDERR are not equal |
366
|
|
|
|
|
|
|
to $expected. |
367
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
=cut |
369
|
|
|
|
|
|
|
|
370
|
|
|
|
|
|
|
sub combined_is (&$;$$) { |
371
|
14
|
|
|
14
|
1
|
39781
|
my $test = shift; |
372
|
14
|
|
|
|
|
26
|
my $expected = shift; |
373
|
14
|
50
|
|
|
|
35
|
my $options = shift if ( ref( $_[0] ) ); |
374
|
14
|
|
|
|
|
24
|
my $description = shift; |
375
|
|
|
|
|
|
|
|
376
|
14
|
|
|
|
|
27
|
my $combined = combined_from($test); |
377
|
|
|
|
|
|
|
|
378
|
14
|
|
|
|
|
39
|
my $ok = ( $combined eq $expected ); |
379
|
|
|
|
|
|
|
|
380
|
14
|
100
|
|
|
|
105
|
$Test->ok( $ok, $description ) |
381
|
|
|
|
|
|
|
|| $Test->diag( |
382
|
|
|
|
|
|
|
"STDOUT & STDERR are:\n$combined\nnot:\n$expected\nas expected"); |
383
|
|
|
|
|
|
|
|
384
|
14
|
|
|
|
|
6667
|
return $ok; |
385
|
|
|
|
|
|
|
} |
386
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
sub combined_isnt (&$;$$) { |
388
|
14
|
|
|
14
|
1
|
39546
|
my $test = shift; |
389
|
14
|
|
|
|
|
24
|
my $expected = shift; |
390
|
14
|
50
|
|
|
|
39
|
my $options = shift if ( ref( $_[0] ) ); |
391
|
14
|
|
|
|
|
23
|
my $description = shift; |
392
|
|
|
|
|
|
|
|
393
|
14
|
|
|
|
|
32
|
my $combined = combined_from($test); |
394
|
|
|
|
|
|
|
|
395
|
14
|
|
|
|
|
41
|
my $ok = ( $combined ne $expected ); |
396
|
|
|
|
|
|
|
|
397
|
14
|
100
|
|
|
|
105
|
$Test->ok( $ok, $description ) |
398
|
|
|
|
|
|
|
|| $Test->diag( |
399
|
|
|
|
|
|
|
"STDOUT & STDERR:\n$combined\nmatching:\n$expected\nnot expected"); |
400
|
|
|
|
|
|
|
|
401
|
14
|
|
|
|
|
6688
|
return $ok; |
402
|
|
|
|
|
|
|
} |
403
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
=item B |
405
|
|
|
|
|
|
|
|
406
|
|
|
|
|
|
|
=item B |
407
|
|
|
|
|
|
|
|
408
|
|
|
|
|
|
|
combined_like ( $coderef, qr/$expected/, 'description' ); |
409
|
|
|
|
|
|
|
combined_like { ...} qr/$expected/, 'description'; |
410
|
|
|
|
|
|
|
combined_unlike ( $coderef, qr/$expected/, 'description' ); |
411
|
|
|
|
|
|
|
combined_unlike { ...} qr/$expected/, 'description'; |
412
|
|
|
|
|
|
|
|
413
|
|
|
|
|
|
|
combined_like() is similar to combined_is() except that it compares a regex |
414
|
|
|
|
|
|
|
($expected) to STDOUT and STDERR captured from $codref. The test passes if |
415
|
|
|
|
|
|
|
the regex matches. |
416
|
|
|
|
|
|
|
|
417
|
|
|
|
|
|
|
combined_unlike() passes if the combined STDOUT and STDERR does not match |
418
|
|
|
|
|
|
|
the regex. |
419
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
=back |
421
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
=cut |
423
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
sub combined_like (&$;$$) { |
425
|
7
|
|
|
7
|
1
|
18759
|
my $test = shift; |
426
|
7
|
|
|
|
|
13
|
my $expected = shift; |
427
|
7
|
50
|
|
|
|
22
|
my $options = shift if ( ref( $_[0] ) ); |
428
|
7
|
|
|
|
|
10
|
my $description = shift; |
429
|
|
|
|
|
|
|
|
430
|
7
|
100
|
|
|
|
16
|
unless ( my $regextest = _chkregex( 'combined_like' => $expected ) ) { |
431
|
2
|
|
|
|
|
9
|
return $regextest; |
432
|
|
|
|
|
|
|
} |
433
|
|
|
|
|
|
|
|
434
|
5
|
|
|
|
|
10
|
my $combined = combined_from($test); |
435
|
|
|
|
|
|
|
|
436
|
5
|
|
|
|
|
36
|
my $ok = ( $combined =~ $expected ); |
437
|
|
|
|
|
|
|
|
438
|
5
|
100
|
|
|
|
38
|
$Test->ok( $ok, $description ) |
439
|
|
|
|
|
|
|
|| $Test->diag( |
440
|
|
|
|
|
|
|
"STDOUT & STDERR:\n$combined\ndon't match:\n$expected\nas expected"); |
441
|
|
|
|
|
|
|
|
442
|
5
|
|
|
|
|
2414
|
return $ok; |
443
|
|
|
|
|
|
|
} |
444
|
|
|
|
|
|
|
|
445
|
|
|
|
|
|
|
sub combined_unlike (&$;$$) { |
446
|
7
|
|
|
7
|
1
|
18444
|
my $test = shift; |
447
|
7
|
|
|
|
|
12
|
my $expected = shift; |
448
|
7
|
50
|
|
|
|
19
|
my $options = shift if ( ref( $_[0] ) ); |
449
|
7
|
|
|
|
|
12
|
my $description = shift; |
450
|
|
|
|
|
|
|
|
451
|
7
|
100
|
|
|
|
17
|
unless ( my $regextest = _chkregex( 'combined_unlike' => $expected ) ) { |
452
|
2
|
|
|
|
|
7
|
return $regextest; |
453
|
|
|
|
|
|
|
} |
454
|
|
|
|
|
|
|
|
455
|
5
|
|
|
|
|
14
|
my $combined = combined_from($test); |
456
|
|
|
|
|
|
|
|
457
|
5
|
|
|
|
|
35
|
my $ok = ( $combined !~ $expected ); |
458
|
|
|
|
|
|
|
|
459
|
5
|
100
|
|
|
|
45
|
$Test->ok( $ok, $description ) |
460
|
|
|
|
|
|
|
|| $Test->diag( |
461
|
|
|
|
|
|
|
"STDOUT & STDERR:\n$combined\nmatching:\n$expected\nnot expected"); |
462
|
|
|
|
|
|
|
|
463
|
5
|
|
|
|
|
2496
|
return $ok; |
464
|
|
|
|
|
|
|
} |
465
|
|
|
|
|
|
|
|
466
|
|
|
|
|
|
|
=head2 OUTPUT |
467
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
=over 4 |
469
|
|
|
|
|
|
|
|
470
|
|
|
|
|
|
|
=item B |
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
=item B |
473
|
|
|
|
|
|
|
|
474
|
|
|
|
|
|
|
output_is ( $coderef, $expected_stdout, $expected_stderr, 'description' ); |
475
|
|
|
|
|
|
|
output_is {... } $expected_stdout, $expected_stderr, 'description'; |
476
|
|
|
|
|
|
|
output_isnt( $coderef, $expected_stdout, $expected_stderr, 'description' ); |
477
|
|
|
|
|
|
|
output_isnt {... } $expected_stdout, $expected_stderr, 'description'; |
478
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
The output_is() function is a combination of the stdout_is() and stderr_is() |
480
|
|
|
|
|
|
|
functions. For example: |
481
|
|
|
|
|
|
|
|
482
|
|
|
|
|
|
|
output_is(sub {print "foo"; print STDERR "bar";},'foo','bar'); |
483
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
is functionally equivalent to |
485
|
|
|
|
|
|
|
|
486
|
|
|
|
|
|
|
stdout_is(sub {print "foo";},'foo') |
487
|
|
|
|
|
|
|
&& stderr_is(sub {print STDERR "bar";},'bar'); |
488
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
except that $coderef is only executed once. |
490
|
|
|
|
|
|
|
|
491
|
|
|
|
|
|
|
Unlike, stdout_is() and stderr_is() which ignore STDERR and STDOUT |
492
|
|
|
|
|
|
|
respectively, output_is() requires both STDOUT and STDERR to match in order |
493
|
|
|
|
|
|
|
to pass. Setting either $expected_stdout or $expected_stderr to C |
494
|
|
|
|
|
|
|
ignores STDOUT or STDERR respectively. |
495
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
output_is(sub {print "foo"; print STDERR "bar";},'foo',undef); |
497
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
is the same as |
499
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
stdout_is(sub {print "foo";},'foo') |
501
|
|
|
|
|
|
|
|
502
|
|
|
|
|
|
|
output_isnt() provides the opposite function of output_is(). It is a |
503
|
|
|
|
|
|
|
combination of stdout_isnt() and stderr_isnt(). |
504
|
|
|
|
|
|
|
|
505
|
|
|
|
|
|
|
output_isnt(sub {print "foo"; print STDERR "bar";},'bar','foo'); |
506
|
|
|
|
|
|
|
|
507
|
|
|
|
|
|
|
is functionally equivalent to |
508
|
|
|
|
|
|
|
|
509
|
|
|
|
|
|
|
stdout_isnt(sub {print "foo";},'bar') |
510
|
|
|
|
|
|
|
&& stderr_isnt(sub {print STDERR "bar";},'foo'); |
511
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
As with output_is(), setting either $expected_stdout or $expected_stderr to |
513
|
|
|
|
|
|
|
C ignores the output to that facility. |
514
|
|
|
|
|
|
|
|
515
|
|
|
|
|
|
|
output_isnt(sub {print "foo"; print STDERR "bar";},undef,'foo'); |
516
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
is the same as |
518
|
|
|
|
|
|
|
|
519
|
|
|
|
|
|
|
stderr_is(sub {print STDERR "bar";},'foo') |
520
|
|
|
|
|
|
|
|
521
|
|
|
|
|
|
|
=cut |
522
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
sub output_is (&$$;$$) { |
524
|
24
|
|
|
24
|
1
|
70433
|
my $test = shift; |
525
|
24
|
|
|
|
|
77
|
my $expout = shift; |
526
|
24
|
|
|
|
|
34
|
my $experr = shift; |
527
|
24
|
50
|
|
|
|
66
|
my $options = shift if ( ref( $_[0] ) ); |
528
|
24
|
|
|
|
|
62
|
my $description = shift; |
529
|
|
|
|
|
|
|
|
530
|
24
|
|
|
|
|
50
|
my ( $stdout, $stderr ) = output_from($test); |
531
|
|
|
|
|
|
|
|
532
|
24
|
|
|
|
|
51
|
my $ok = 1; |
533
|
24
|
|
|
|
|
44
|
my $diag; |
534
|
|
|
|
|
|
|
|
535
|
24
|
100
|
100
|
|
|
136
|
if ( defined($experr) && defined($expout) ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
536
|
14
|
100
|
|
|
|
36
|
unless ( $stdout eq $expout ) { |
537
|
4
|
|
|
|
|
7
|
$ok = 0; |
538
|
4
|
|
|
|
|
15
|
$diag .= "STDOUT is:\n$stdout\nnot:\n$expout\nas expected"; |
539
|
|
|
|
|
|
|
} |
540
|
14
|
100
|
|
|
|
34
|
unless ( $stderr eq $experr ) { |
541
|
4
|
100
|
|
|
|
14
|
$diag .= "\n" unless ($ok); |
542
|
4
|
|
|
|
|
7
|
$ok = 0; |
543
|
4
|
|
|
|
|
14
|
$diag .= "STDERR is:\n$stderr\nnot:\n$experr\nas expected"; |
544
|
|
|
|
|
|
|
} |
545
|
|
|
|
|
|
|
} |
546
|
|
|
|
|
|
|
elsif ( defined($expout) ) { |
547
|
2
|
|
|
|
|
8
|
$ok = ( $stdout eq $expout ); |
548
|
2
|
|
|
|
|
8
|
$diag .= "STDOUT is:\n$stdout\nnot:\n$expout\nas expected"; |
549
|
|
|
|
|
|
|
} |
550
|
|
|
|
|
|
|
elsif ( defined($experr) ) { |
551
|
2
|
|
|
|
|
6
|
$ok = ( $stderr eq $experr ); |
552
|
2
|
|
|
|
|
41
|
$diag .= "STDERR is:\n$stderr\nnot:\n$experr\nas expected"; |
553
|
|
|
|
|
|
|
} |
554
|
|
|
|
|
|
|
else { |
555
|
6
|
100
|
|
|
|
24
|
unless ( $stdout eq '' ) { |
556
|
2
|
|
|
|
|
6
|
$ok = 0; |
557
|
2
|
|
|
|
|
8
|
$diag .= "STDOUT is:\n$stdout\nnot:\n\nas expected"; |
558
|
|
|
|
|
|
|
} |
559
|
6
|
100
|
|
|
|
16
|
unless ( $stderr eq '' ) { |
560
|
4
|
100
|
|
|
|
13
|
$diag .= "\n" unless ($ok); |
561
|
4
|
|
|
|
|
7
|
$ok = 0; |
562
|
4
|
|
|
|
|
12
|
$diag .= "STDERR is:\n$stderr\nnot:\n\nas expected"; |
563
|
|
|
|
|
|
|
} |
564
|
|
|
|
|
|
|
} |
565
|
|
|
|
|
|
|
|
566
|
24
|
100
|
|
|
|
238
|
$Test->ok( $ok, $description ) || $Test->diag($diag); |
567
|
|
|
|
|
|
|
|
568
|
24
|
|
|
|
|
11496
|
return $ok; |
569
|
|
|
|
|
|
|
} |
570
|
|
|
|
|
|
|
|
571
|
|
|
|
|
|
|
sub output_isnt (&$$;$$) { |
572
|
24
|
|
|
24
|
1
|
69655
|
my $test = shift; |
573
|
24
|
|
|
|
|
48
|
my $expout = shift; |
574
|
24
|
|
|
|
|
37
|
my $experr = shift; |
575
|
24
|
50
|
|
|
|
58
|
my $options = shift if ( ref( $_[0] ) ); |
576
|
24
|
|
|
|
|
38
|
my $description = shift; |
577
|
|
|
|
|
|
|
|
578
|
24
|
|
|
|
|
49
|
my ( $stdout, $stderr ) = output_from($test); |
579
|
|
|
|
|
|
|
|
580
|
24
|
|
|
|
|
54
|
my $ok = 1; |
581
|
24
|
|
|
|
|
49
|
my $diag; |
582
|
|
|
|
|
|
|
|
583
|
24
|
100
|
100
|
|
|
133
|
if ( defined($experr) && defined($expout) ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
584
|
8
|
100
|
|
|
|
30
|
if ( $stdout eq $expout ) { |
585
|
4
|
|
|
|
|
9
|
$ok = 0; |
586
|
4
|
|
|
|
|
12
|
$diag .= "STDOUT:\n$stdout\nmatching:\n$expout\nnot expected"; |
587
|
|
|
|
|
|
|
} |
588
|
8
|
100
|
|
|
|
22
|
if ( $stderr eq $experr ) { |
589
|
4
|
100
|
|
|
|
12
|
$diag .= "\n" unless ($ok); |
590
|
4
|
|
|
|
|
8
|
$ok = 0; |
591
|
4
|
|
|
|
|
12
|
$diag .= "STDERR:\n$stderr\nmatching:\n$experr\nnot expected"; |
592
|
|
|
|
|
|
|
} |
593
|
|
|
|
|
|
|
} |
594
|
|
|
|
|
|
|
elsif ( defined($expout) ) { |
595
|
4
|
|
|
|
|
7
|
$ok = ( $stdout ne $expout ); |
596
|
4
|
|
|
|
|
21
|
$diag = "STDOUT:\n$stdout\nmatching:\n$expout\nnot expected"; |
597
|
|
|
|
|
|
|
} |
598
|
|
|
|
|
|
|
elsif ( defined($experr) ) { |
599
|
4
|
|
|
|
|
10
|
$ok = ( $stderr ne $experr ); |
600
|
4
|
|
|
|
|
14
|
$diag = "STDERR:\n$stderr\nmatching:\n$experr\nnot expected"; |
601
|
|
|
|
|
|
|
} |
602
|
|
|
|
|
|
|
else { |
603
|
8
|
100
|
|
|
|
26
|
if ( $stdout eq '' ) { |
604
|
4
|
|
|
|
|
8
|
$ok = 0; |
605
|
4
|
|
|
|
|
13
|
$diag = "STDOUT:\n$stdout\nmatching:\n\nnot expected"; |
606
|
|
|
|
|
|
|
} |
607
|
8
|
100
|
|
|
|
21
|
if ( $stderr eq '' ) { |
608
|
4
|
100
|
|
|
|
13
|
$diag .= "\n" unless ($ok); |
609
|
4
|
|
|
|
|
6
|
$ok = 0; |
610
|
4
|
|
|
|
|
12
|
$diag .= "STDERR:\n$stderr\nmatching:\n\nnot expected"; |
611
|
|
|
|
|
|
|
} |
612
|
|
|
|
|
|
|
} |
613
|
|
|
|
|
|
|
|
614
|
24
|
100
|
|
|
|
168
|
$Test->ok( $ok, $description ) || $Test->diag($diag); |
615
|
|
|
|
|
|
|
|
616
|
24
|
|
|
|
|
11767
|
return $ok; |
617
|
|
|
|
|
|
|
} |
618
|
|
|
|
|
|
|
|
619
|
|
|
|
|
|
|
=item B |
620
|
|
|
|
|
|
|
|
621
|
|
|
|
|
|
|
=item B |
622
|
|
|
|
|
|
|
|
623
|
|
|
|
|
|
|
output_like ( $coderef, $regex_stdout, $regex_stderr, 'description' ); |
624
|
|
|
|
|
|
|
output_like { ... } $regex_stdout, $regex_stderr, 'description'; |
625
|
|
|
|
|
|
|
output_unlike( $coderef, $regex_stdout, $regex_stderr, 'description' ); |
626
|
|
|
|
|
|
|
output_unlike { ... } $regex_stdout, $regex_stderr, 'description'; |
627
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
output_like() and output_unlike() follow the same principles as output_is() |
629
|
|
|
|
|
|
|
and output_isnt() except they use a regular expression for matching. |
630
|
|
|
|
|
|
|
|
631
|
|
|
|
|
|
|
output_like() attempts to match $regex_stdout and $regex_stderr against |
632
|
|
|
|
|
|
|
STDOUT and STDERR produced by $coderef. The test passes if both match. |
633
|
|
|
|
|
|
|
|
634
|
|
|
|
|
|
|
output_like(sub {print "foo"; print STDERR "bar";},qr/foo/,qr/bar/); |
635
|
|
|
|
|
|
|
|
636
|
|
|
|
|
|
|
The above test is successful. |
637
|
|
|
|
|
|
|
|
638
|
|
|
|
|
|
|
Like output_is(), setting either $regex_stdout or $regex_stderr to |
639
|
|
|
|
|
|
|
C ignores the output to that facility. |
640
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
output_like(sub {print "foo"; print STDERR "bar";},qr/foo/,undef); |
642
|
|
|
|
|
|
|
|
643
|
|
|
|
|
|
|
is the same as |
644
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
stdout_like(sub {print "foo"; print STDERR "bar";},qr/foo/); |
646
|
|
|
|
|
|
|
|
647
|
|
|
|
|
|
|
output_unlike() test pass if output from $coderef doesn't match |
648
|
|
|
|
|
|
|
$regex_stdout and $regex_stderr. |
649
|
|
|
|
|
|
|
|
650
|
|
|
|
|
|
|
=back |
651
|
|
|
|
|
|
|
|
652
|
|
|
|
|
|
|
=cut |
653
|
|
|
|
|
|
|
|
654
|
|
|
|
|
|
|
sub output_like (&$$;$$) { |
655
|
22
|
|
|
22
|
1
|
73567
|
my $test = shift; |
656
|
22
|
|
|
|
|
40
|
my $expout = shift; |
657
|
22
|
|
|
|
|
34
|
my $experr = shift; |
658
|
22
|
50
|
|
|
|
64
|
my $options = shift if ( ref( $_[0] ) ); |
659
|
22
|
|
|
|
|
40
|
my $description = shift; |
660
|
|
|
|
|
|
|
|
661
|
22
|
|
|
|
|
53
|
my ( $stdout, $stderr ) = output_from($test); |
662
|
|
|
|
|
|
|
|
663
|
22
|
|
|
|
|
52
|
my $ok = 1; |
664
|
|
|
|
|
|
|
|
665
|
22
|
100
|
|
|
|
83
|
unless ( |
666
|
|
|
|
|
|
|
my $regextest = _chkregex( |
667
|
|
|
|
|
|
|
'output_like_STDERR' => $experr, |
668
|
|
|
|
|
|
|
'output_like_STDOUT' => $expout |
669
|
|
|
|
|
|
|
) |
670
|
|
|
|
|
|
|
) |
671
|
|
|
|
|
|
|
{ |
672
|
4
|
|
|
|
|
13
|
return $regextest; |
673
|
|
|
|
|
|
|
} |
674
|
|
|
|
|
|
|
|
675
|
18
|
|
|
|
|
28
|
my $diag; |
676
|
18
|
100
|
100
|
|
|
97
|
if ( defined($experr) && defined($expout) ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
677
|
9
|
100
|
|
|
|
63
|
unless ( $stdout =~ $expout ) { |
678
|
4
|
|
|
|
|
8
|
$ok = 0; |
679
|
4
|
|
|
|
|
19
|
$diag .= "STDOUT:\n$stdout\ndoesn't match:\n$expout\nas expected"; |
680
|
|
|
|
|
|
|
} |
681
|
9
|
100
|
|
|
|
46
|
unless ( $stderr =~ $experr ) { |
682
|
4
|
100
|
|
|
|
13
|
$diag .= "\n" unless ($ok); |
683
|
4
|
|
|
|
|
6
|
$ok = 0; |
684
|
4
|
|
|
|
|
14
|
$diag .= "STDERR:\n$stderr\ndoesn't match:\n$experr\nas expected"; |
685
|
|
|
|
|
|
|
} |
686
|
|
|
|
|
|
|
} |
687
|
|
|
|
|
|
|
elsif ( defined($expout) ) { |
688
|
2
|
|
|
|
|
13
|
$ok = ( $stdout =~ $expout ); |
689
|
2
|
|
|
|
|
9
|
$diag .= "STDOUT:\n$stdout\ndoesn't match:\n$expout\nas expected"; |
690
|
|
|
|
|
|
|
} |
691
|
|
|
|
|
|
|
elsif ( defined($experr) ) { |
692
|
1
|
|
|
|
|
7
|
$ok = ( $stderr =~ $experr ); |
693
|
1
|
|
|
|
|
5
|
$diag .= "STDERR:\n$stderr\ndoesn't match:\n$experr\nas expected"; |
694
|
|
|
|
|
|
|
} |
695
|
|
|
|
|
|
|
else { |
696
|
6
|
100
|
|
|
|
18
|
unless ( $stdout eq '' ) { |
697
|
2
|
|
|
|
|
6
|
$ok = 0; |
698
|
2
|
|
|
|
|
8
|
$diag .= "STDOUT is:\n$stdout\nnot:\n\nas expected"; |
699
|
|
|
|
|
|
|
} |
700
|
6
|
100
|
|
|
|
19
|
unless ( $stderr eq '' ) { |
701
|
4
|
100
|
|
|
|
12
|
$diag .= "\n" unless ($ok); |
702
|
4
|
|
|
|
|
8
|
$ok = 0; |
703
|
4
|
|
|
|
|
13
|
$diag .= "STDERR is:\n$stderr\nnot:\n\nas expected"; |
704
|
|
|
|
|
|
|
} |
705
|
|
|
|
|
|
|
} |
706
|
|
|
|
|
|
|
|
707
|
18
|
100
|
|
|
|
96
|
$Test->ok( $ok, $description ) || $Test->diag($diag); |
708
|
|
|
|
|
|
|
|
709
|
18
|
|
|
|
|
9190
|
return $ok; |
710
|
|
|
|
|
|
|
} |
711
|
|
|
|
|
|
|
|
712
|
|
|
|
|
|
|
sub output_unlike (&$$;$$) { |
713
|
16
|
|
|
16
|
1
|
45421
|
my $test = shift; |
714
|
16
|
|
|
|
|
29
|
my $expout = shift; |
715
|
16
|
|
|
|
|
24
|
my $experr = shift; |
716
|
16
|
50
|
|
|
|
41
|
my $options = shift if ( ref( $_[0] ) ); |
717
|
16
|
|
|
|
|
20
|
my $description = shift; |
718
|
|
|
|
|
|
|
|
719
|
16
|
|
|
|
|
36
|
my ( $stdout, $stderr ) = output_from($test); |
720
|
|
|
|
|
|
|
|
721
|
16
|
|
|
|
|
38
|
my $ok = 1; |
722
|
|
|
|
|
|
|
|
723
|
16
|
100
|
|
|
|
52
|
unless ( |
724
|
|
|
|
|
|
|
my $regextest = _chkregex( |
725
|
|
|
|
|
|
|
'output_unlike_STDERR' => $experr, |
726
|
|
|
|
|
|
|
'output_unlike_STDOUT' => $expout |
727
|
|
|
|
|
|
|
) |
728
|
|
|
|
|
|
|
) |
729
|
|
|
|
|
|
|
{ |
730
|
4
|
|
|
|
|
13
|
return $regextest; |
731
|
|
|
|
|
|
|
} |
732
|
|
|
|
|
|
|
|
733
|
12
|
|
|
|
|
19
|
my $diag; |
734
|
12
|
100
|
100
|
|
|
62
|
if ( defined($experr) && defined($expout) ) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
735
|
8
|
100
|
|
|
|
49
|
if ( $stdout =~ $expout ) { |
736
|
4
|
|
|
|
|
8
|
$ok = 0; |
737
|
4
|
|
|
|
|
16
|
$diag .= "STDOUT:\n$stdout\nmatches:\n$expout\nnot expected"; |
738
|
|
|
|
|
|
|
} |
739
|
8
|
100
|
|
|
|
37
|
if ( $stderr =~ $experr ) { |
740
|
4
|
100
|
|
|
|
13
|
$diag .= "\n" unless ($ok); |
741
|
4
|
|
|
|
|
7
|
$ok = 0; |
742
|
4
|
|
|
|
|
15
|
$diag .= "STDERR:\n$stderr\nmatches:\n$experr\nnot expected"; |
743
|
|
|
|
|
|
|
} |
744
|
|
|
|
|
|
|
} |
745
|
|
|
|
|
|
|
elsif ( defined($expout) ) { |
746
|
2
|
|
|
|
|
12
|
$ok = ( $stdout !~ $expout ); |
747
|
2
|
|
|
|
|
9
|
$diag .= "STDOUT:\n$stdout\nmatches:\n$expout\nnot expected"; |
748
|
|
|
|
|
|
|
} |
749
|
|
|
|
|
|
|
elsif ( defined($experr) ) { |
750
|
2
|
|
|
|
|
12
|
$ok = ( $stderr !~ $experr ); |
751
|
2
|
|
|
|
|
10
|
$diag .= "STDERR:\n$stderr\nmatches:\n$experr\nnot expected"; |
752
|
|
|
|
|
|
|
} |
753
|
|
|
|
|
|
|
|
754
|
12
|
100
|
|
|
|
54
|
$Test->ok( $ok, $description ) || $Test->diag($diag); |
755
|
|
|
|
|
|
|
|
756
|
12
|
|
|
|
|
5735
|
return $ok; |
757
|
|
|
|
|
|
|
} |
758
|
|
|
|
|
|
|
|
759
|
|
|
|
|
|
|
=head1 EXPORTS |
760
|
|
|
|
|
|
|
|
761
|
|
|
|
|
|
|
By default, all tests are exported, however with the switch to L |
762
|
|
|
|
|
|
|
export groups are now available to better limit imports. |
763
|
|
|
|
|
|
|
|
764
|
|
|
|
|
|
|
To import tests for STDOUT: |
765
|
|
|
|
|
|
|
|
766
|
|
|
|
|
|
|
use Test::Output qw(:stdout); |
767
|
|
|
|
|
|
|
|
768
|
|
|
|
|
|
|
To import tests STDERR: |
769
|
|
|
|
|
|
|
|
770
|
|
|
|
|
|
|
use Test::Output qw(:stderr); |
771
|
|
|
|
|
|
|
|
772
|
|
|
|
|
|
|
To import just the functions: |
773
|
|
|
|
|
|
|
|
774
|
|
|
|
|
|
|
use Test::Output qw(:functions); |
775
|
|
|
|
|
|
|
|
776
|
|
|
|
|
|
|
And to import all tests: |
777
|
|
|
|
|
|
|
|
778
|
|
|
|
|
|
|
use Test::Output; |
779
|
|
|
|
|
|
|
|
780
|
|
|
|
|
|
|
The following is a list of group names and which functions are exported: |
781
|
|
|
|
|
|
|
|
782
|
|
|
|
|
|
|
=over 4 |
783
|
|
|
|
|
|
|
|
784
|
|
|
|
|
|
|
=item stdout |
785
|
|
|
|
|
|
|
|
786
|
|
|
|
|
|
|
stdout_is stdout_isnt stdout_like stdout_unlike |
787
|
|
|
|
|
|
|
|
788
|
|
|
|
|
|
|
=item stderr |
789
|
|
|
|
|
|
|
|
790
|
|
|
|
|
|
|
stderr_is stderr_isnt stderr_like stderr_unlike |
791
|
|
|
|
|
|
|
|
792
|
|
|
|
|
|
|
=item output |
793
|
|
|
|
|
|
|
|
794
|
|
|
|
|
|
|
output_is output_isnt output_like output_unlike |
795
|
|
|
|
|
|
|
|
796
|
|
|
|
|
|
|
=item combined |
797
|
|
|
|
|
|
|
|
798
|
|
|
|
|
|
|
combined_is combined_isnt combined_like combined_unlike |
799
|
|
|
|
|
|
|
|
800
|
|
|
|
|
|
|
=item tests |
801
|
|
|
|
|
|
|
|
802
|
|
|
|
|
|
|
All of the above, this is the default when no options are given. |
803
|
|
|
|
|
|
|
|
804
|
|
|
|
|
|
|
=back |
805
|
|
|
|
|
|
|
|
806
|
|
|
|
|
|
|
L allows for many other options, I encourage reading its |
807
|
|
|
|
|
|
|
documentation. |
808
|
|
|
|
|
|
|
|
809
|
|
|
|
|
|
|
=cut |
810
|
|
|
|
|
|
|
|
811
|
|
|
|
|
|
|
=head1 FUNCTIONS |
812
|
|
|
|
|
|
|
|
813
|
|
|
|
|
|
|
=cut |
814
|
|
|
|
|
|
|
|
815
|
|
|
|
|
|
|
=head2 stdout_from |
816
|
|
|
|
|
|
|
|
817
|
|
|
|
|
|
|
my $stdout = stdout_from($coderef) |
818
|
|
|
|
|
|
|
my $stdout = stdout_from { ... }; |
819
|
|
|
|
|
|
|
|
820
|
|
|
|
|
|
|
stdout_from() executes $coderef and captures STDOUT. |
821
|
|
|
|
|
|
|
|
822
|
|
|
|
|
|
|
=cut |
823
|
|
|
|
|
|
|
|
824
|
|
|
|
|
|
|
sub stdout_from (&) { |
825
|
20
|
|
|
20
|
1
|
32
|
my $test = shift; |
826
|
|
|
|
|
|
|
|
827
|
|
|
|
|
|
|
my $stdout = capture_stdout { |
828
|
20
|
|
|
20
|
|
16151
|
select( ( select(STDOUT), $| = 1 )[0] ); |
829
|
20
|
|
|
|
|
89
|
$test->() |
830
|
20
|
|
|
|
|
524
|
}; |
831
|
|
|
|
|
|
|
|
832
|
20
|
|
|
|
|
10793
|
return $stdout; |
833
|
|
|
|
|
|
|
} |
834
|
|
|
|
|
|
|
|
835
|
|
|
|
|
|
|
=head2 stderr_from |
836
|
|
|
|
|
|
|
|
837
|
|
|
|
|
|
|
my $stderr = stderr_from($coderef) |
838
|
|
|
|
|
|
|
my $stderr = stderr_from { ... }; |
839
|
|
|
|
|
|
|
|
840
|
|
|
|
|
|
|
stderr_from() executes $coderef and captures STDERR. |
841
|
|
|
|
|
|
|
|
842
|
|
|
|
|
|
|
=cut |
843
|
|
|
|
|
|
|
|
844
|
|
|
|
|
|
|
sub stderr_from (&) { |
845
|
19
|
|
|
19
|
1
|
2492
|
my $test = shift; |
846
|
|
|
|
|
|
|
|
847
|
|
|
|
|
|
|
# XXX why is this here and not in output_from or combined_from -- xdg, 2012-05-13 |
848
|
0
|
|
|
0
|
|
0
|
local $SIG{__WARN__} = sub { print STDERR @_ } |
849
|
19
|
50
|
|
|
|
51
|
if $] < 5.008; |
850
|
|
|
|
|
|
|
|
851
|
|
|
|
|
|
|
my $stderr = capture_stderr { |
852
|
19
|
|
|
19
|
|
15414
|
select( ( select(STDERR), $| = 1 )[0] ); |
853
|
19
|
|
|
|
|
97
|
$test->() |
854
|
19
|
|
|
|
|
534
|
}; |
855
|
|
|
|
|
|
|
|
856
|
19
|
|
|
|
|
10370
|
return $stderr; |
857
|
|
|
|
|
|
|
} |
858
|
|
|
|
|
|
|
|
859
|
|
|
|
|
|
|
=head2 output_from |
860
|
|
|
|
|
|
|
|
861
|
|
|
|
|
|
|
my ($stdout, $stderr) = output_from($coderef) |
862
|
|
|
|
|
|
|
my ($stdout, $stderr) = output_from {...}; |
863
|
|
|
|
|
|
|
|
864
|
|
|
|
|
|
|
output_from() executes $coderef one time capturing both STDOUT and STDERR. |
865
|
|
|
|
|
|
|
|
866
|
|
|
|
|
|
|
=cut |
867
|
|
|
|
|
|
|
|
868
|
|
|
|
|
|
|
sub output_from (&) { |
869
|
86
|
|
|
86
|
1
|
138
|
my $test = shift; |
870
|
|
|
|
|
|
|
|
871
|
|
|
|
|
|
|
my ($stdout, $stderr) = capture { |
872
|
86
|
|
|
86
|
|
96192
|
select( ( select(STDOUT), $| = 1 )[0] ); |
873
|
86
|
|
|
|
|
348
|
select( ( select(STDERR), $| = 1 )[0] ); |
874
|
86
|
|
|
|
|
296
|
$test->(); |
875
|
86
|
|
|
|
|
2389
|
}; |
876
|
|
|
|
|
|
|
|
877
|
86
|
|
|
|
|
73257
|
return ( $stdout, $stderr ); |
878
|
|
|
|
|
|
|
} |
879
|
|
|
|
|
|
|
|
880
|
|
|
|
|
|
|
=head2 combined_from |
881
|
|
|
|
|
|
|
|
882
|
|
|
|
|
|
|
my $combined = combined_from($coderef); |
883
|
|
|
|
|
|
|
my $combined = combined_from {...}; |
884
|
|
|
|
|
|
|
|
885
|
|
|
|
|
|
|
combined_from() executes $coderef one time combines STDOUT and STDERR, and |
886
|
|
|
|
|
|
|
captures them. combined_from() is equivalent to using 2>&1 in UNIX. |
887
|
|
|
|
|
|
|
|
888
|
|
|
|
|
|
|
=cut |
889
|
|
|
|
|
|
|
|
890
|
|
|
|
|
|
|
sub combined_from (&) { |
891
|
38
|
|
|
38
|
1
|
60
|
my $test = shift; |
892
|
|
|
|
|
|
|
|
893
|
|
|
|
|
|
|
my $combined = capture_merged { |
894
|
38
|
|
|
38
|
|
42444
|
select( ( select(STDOUT), $| = 1 )[0] ); |
895
|
38
|
|
|
|
|
152
|
select( ( select(STDERR), $| = 1 )[0] ); |
896
|
38
|
|
|
|
|
154
|
$test->(); |
897
|
38
|
|
|
|
|
1028
|
}; |
898
|
|
|
|
|
|
|
|
899
|
38
|
|
|
|
|
31778
|
return $combined; |
900
|
|
|
|
|
|
|
} |
901
|
|
|
|
|
|
|
|
902
|
|
|
|
|
|
|
sub _chkregex { |
903
|
76
|
|
|
76
|
|
248
|
my %regexs = @_; |
904
|
|
|
|
|
|
|
|
905
|
76
|
|
|
|
|
234
|
foreach my $test ( keys(%regexs) ) { |
906
|
108
|
100
|
|
|
|
307
|
next unless ( defined( $regexs{$test} ) ); |
907
|
|
|
|
|
|
|
|
908
|
89
|
|
|
|
|
594
|
my $usable_regex = $Test->maybe_regex( $regexs{$test} ); |
909
|
89
|
100
|
|
|
|
3280
|
unless ( defined($usable_regex) ) { |
910
|
20
|
|
|
|
|
98
|
my $ok = $Test->ok( 0, $test ); |
911
|
|
|
|
|
|
|
|
912
|
20
|
|
|
|
|
8191
|
$Test->diag("'$regexs{$test}' doesn't look much like a regex to me."); |
913
|
|
|
|
|
|
|
# unless $ok; |
914
|
|
|
|
|
|
|
|
915
|
20
|
|
|
|
|
2896
|
return $ok; |
916
|
|
|
|
|
|
|
} |
917
|
|
|
|
|
|
|
} |
918
|
56
|
|
|
|
|
205
|
return 1; |
919
|
|
|
|
|
|
|
} |
920
|
|
|
|
|
|
|
|
921
|
|
|
|
|
|
|
=head1 AUTHOR |
922
|
|
|
|
|
|
|
|
923
|
|
|
|
|
|
|
Currently maintained by brian d foy, C. |
924
|
|
|
|
|
|
|
|
925
|
|
|
|
|
|
|
Shawn Sorichetti, C<< >> |
926
|
|
|
|
|
|
|
|
927
|
|
|
|
|
|
|
=head1 SOURCE AVAILABILITY |
928
|
|
|
|
|
|
|
|
929
|
|
|
|
|
|
|
This module is in Github: |
930
|
|
|
|
|
|
|
|
931
|
|
|
|
|
|
|
http://github.com/briandfoy/test-output |
932
|
|
|
|
|
|
|
|
933
|
|
|
|
|
|
|
=head1 BUGS |
934
|
|
|
|
|
|
|
|
935
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
936
|
|
|
|
|
|
|
C, or through the web interface at |
937
|
|
|
|
|
|
|
L. I will be notified, and then you'll automatically |
938
|
|
|
|
|
|
|
be notified of progress on your bug as I make changes. |
939
|
|
|
|
|
|
|
|
940
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
941
|
|
|
|
|
|
|
|
942
|
|
|
|
|
|
|
Thanks to chromatic whose TieOut.pm was the basis for capturing output. |
943
|
|
|
|
|
|
|
|
944
|
|
|
|
|
|
|
Also thanks to rjbs for his help cleaning the documentation, and pushing me to |
945
|
|
|
|
|
|
|
L. |
946
|
|
|
|
|
|
|
|
947
|
|
|
|
|
|
|
Thanks to David Wheeler for providing code block support and tests. |
948
|
|
|
|
|
|
|
|
949
|
|
|
|
|
|
|
Thanks to Michael G Schwern for the solution to combining STDOUT and STDERR. |
950
|
|
|
|
|
|
|
|
951
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
952
|
|
|
|
|
|
|
|
953
|
|
|
|
|
|
|
Copyright 2005-2021 Shawn Sorichetti, All Rights Reserved. |
954
|
|
|
|
|
|
|
|
955
|
|
|
|
|
|
|
This module is licensed under the Artistic License 2.0. |
956
|
|
|
|
|
|
|
|
957
|
|
|
|
|
|
|
=cut |
958
|
|
|
|
|
|
|
|
959
|
|
|
|
|
|
|
1; # End of Test::Output |