fixing tests for new output method
This commit is contained in:
parent
74381281fa
commit
d2116bf797
3 changed files with 31 additions and 16 deletions
|
|
@ -35,33 +35,31 @@ my $recentVersion = $^V gt v5.8;
|
|||
SKIP: {
|
||||
skip "You have an old perl", $skip_tests unless $recentVersion;
|
||||
|
||||
my $stdoutBuffer;
|
||||
close STDOUT;
|
||||
open STDOUT, '>', \$stdoutBuffer or die "Unable to tie STDOUT to a variable: $!\n";
|
||||
|
||||
my $otherHandleBuffer;
|
||||
open my $otherHandle, '>', \$otherHandleBuffer or die "Unable to create second filehandle: $!\n";
|
||||
|
||||
$output->setHandle(undef);
|
||||
my $request = $session->request;
|
||||
|
||||
$output->setHandle(undef);
|
||||
is($output->{_handle}, undef, 'setHandle: handle cleared');
|
||||
|
||||
$output->print('Hello STDOUT');
|
||||
is($stdoutBuffer, 'Hello STDOUT', 'print with no handle goes to STDOUT');
|
||||
is($request->get_output, 'Hello STDOUT', 'print with no handle goes to STDOUT');
|
||||
|
||||
$output->print(' more stuff');
|
||||
is($stdoutBuffer, 'Hello STDOUT more stuff', 'print: tied variables accumulate');
|
||||
is($request->get_output, 'Hello STDOUT more stuff', 'print: tied variables accumulate');
|
||||
|
||||
$session->user({userId => 3});
|
||||
$output->print('^#;');
|
||||
like($stdoutBuffer, qr/3\Z/, 'print: macro processing');
|
||||
like($request->get_output, qr/3\Z/, 'print: macro processing');
|
||||
|
||||
$output->print('^#;', 1);
|
||||
like($stdoutBuffer, qr/\^#;\Z/, 'print: macro processing skipped');
|
||||
like($request->get_output, qr/\^#;\Z/, 'print: macro processing skipped');
|
||||
|
||||
$output->setHandle($otherHandle);
|
||||
$output->print('New content');
|
||||
is($otherHandleBuffer, 'New content', 'print: set to explicit handle');
|
||||
unlike($stdoutBuffer, qr/New content\Z/, 'print: no leakage back to STDOUT');
|
||||
unlike($request->get_output, qr/New content\Z/, 'print: no leakage back to STDOUT');
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -452,15 +452,12 @@ sub sendImmediate {
|
|||
|
||||
SKIP: {
|
||||
skip "You have an old perl", 1 if $crappyPerl;
|
||||
close STDOUT;
|
||||
my $buffer;
|
||||
open STDOUT, '>', \$buffer or die "Unable to point handle at variable: $!\n";
|
||||
my $request = $style->session->request;
|
||||
$request->clear_output;
|
||||
$style->sent(1);
|
||||
$style->$action($output);
|
||||
like($buffer, qr/$output/, $comment);
|
||||
like($request->get_output, qr/$output/, $comment);
|
||||
$style->sent(0);
|
||||
close STDOUT;
|
||||
open STDOUT, '>-' or die "Unable to restore STDOUT: $!\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -349,6 +349,26 @@ sub setup_param {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
sub clear_output {
|
||||
my $self = shift;
|
||||
$self->{output} = '';
|
||||
}
|
||||
|
||||
sub get_output {
|
||||
my $self = shift;
|
||||
return $self->{output};
|
||||
}
|
||||
|
||||
sub print {
|
||||
my $self = shift;
|
||||
$self->{output} ||= '';
|
||||
for my $p (@_) {
|
||||
$self->{output} .= $p;
|
||||
}
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 protocol ( $value )
|
||||
|
||||
Getter and setter for protocol. If $value is passed in, it will set the protocol of
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue