From 0a65c7628fa394f7c24a18e023f5ff7b546b52df Mon Sep 17 00:00:00 2001 From: Bastian Blank Date: Thu, 8 Aug 2013 22:38:34 +0200 Subject: [PATCH] Add test for tied file handles --- t/06_streams.t | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 t/06_streams.t diff --git a/t/06_streams.t b/t/06_streams.t new file mode 100644 index 0000000..34aec31 --- /dev/null +++ b/t/06_streams.t @@ -0,0 +1,37 @@ +use strict; +use warnings; +use CGI; +use CGI::Emulate::PSGI; +use Test::More; + +my $app_input = CGI::Emulate::PSGI->handler( + sub { + read(\*STDIN, undef, 0, 0); + }, +); + +my $app_errors = CGI::Emulate::PSGI->handler( + sub { + print STDERR "TEST"; + }, +); + +my $stream_input = StreamInput->new; +$app_input->({ REQUEST_METHOD => 'GET', 'psgi.input' => $stream_input, 'psgi.errors' => \*STDERR }); + +is $stream_input->{CALLED}, 1; + +my $stream_errors = StreamErrors->new; +$app_errors->({ REQUEST_METHOD => 'GET', 'psgi.input' => \*STDIN, 'psgi.errors' => $stream_errors }); + +is $stream_errors->{CALLED}, "TEST"; + +done_testing; + +package StreamInput; +sub new { bless({}, shift) } +sub read { my $self = shift; $self->{CALLED} = 1 } + +package StreamErrors; +sub new { bless({}, shift) } +sub print { my $self = shift; $self->{CALLED} = shift }