[Bps-public-commit] Plack-Middleware-Test-StashWarnings branch, master, updated. c811a159ce72cfcd51db2f0464459f9bf9f3ed9a
Shawn Moore
sartak at bestpractical.com
Tue Oct 19 07:27:18 EDT 2010
The branch, master has been updated
via c811a159ce72cfcd51db2f0464459f9bf9f3ed9a (commit)
via 6db7fddb6c0b54255c7bbaf50087acaf9d43ee24 (commit)
from 96455460bddf90296c47b4653821273ce95d31b4 (commit)
Summary of changes:
lib/Plack/Middleware/Test/StashWarnings.pm | 17 ++++++++++++++++-
t/{basic.t => stream.t} | 13 +++++++++++--
2 files changed, 27 insertions(+), 3 deletions(-)
copy t/{basic.t => stream.t} (80%)
- Log -----------------------------------------------------------------
commit 6db7fddb6c0b54255c7bbaf50087acaf9d43ee24
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Tue Oct 19 20:22:01 2010 +0900
Failing test for stream warnings
diff --git a/t/stream.t b/t/stream.t
new file mode 100644
index 0000000..4d36b39
--- /dev/null
+++ b/t/stream.t
@@ -0,0 +1,58 @@
+use strict;
+use Plack::Test;
+use Test::More;
+use HTTP::Request::Common;
+
+use Plack::Builder;
+use Plack::Request;
+
+use Storable 'thaw';
+
+my $app = sub {
+ my $req = Plack::Request->new(shift);
+ my $name = $req->param('name');
+ return sub {
+ my $responder = shift;
+ my $writer = $responder->([200, ["Content-Type", "text/plain"]]);
+
+ $writer->write("Hello ");
+ $writer->write("$name");
+ $writer->write("!");
+ $writer->close;
+ };
+};
+
+my $t = builder {
+ enable "Test::StashWarnings";
+ $app;
+};
+
+test_psgi $t, sub {
+ my $cb = shift;
+
+ my $res = $cb->(GET "/__test_warnings");
+ is_deeply thaw($res->content), [];
+ is $res->content_type, 'application/x-storable';
+
+ $res = $cb->(GET "/?name=foo");
+ like $res->content, qr/Hello foo!/;
+ is $res->content_type, 'text/plain';
+
+ $res = $cb->(GET "/__test_warnings");
+ is_deeply thaw($res->content), [], 'no warnings';
+ is $res->content_type, 'application/x-storable';
+
+ $res = $cb->(GET "/");
+ like $res->content, qr/Hello !/;
+ is $res->content_type, 'text/plain';
+
+ $res = $cb->(GET "/__test_warnings");
+ my @warnings = @{ thaw($res->content) };
+ is @warnings, 1, "one warning";
+ like $warnings[0], qr/Use of uninitialized value (?:\$name )?in string/;
+ is $res->content_type, 'application/x-storable';
+};
+
+done_testing;
+
+
commit c811a159ce72cfcd51db2f0464459f9bf9f3ed9a
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Tue Oct 19 20:26:50 2010 +0900
Wrap streaming responses with sigwarn properly
diff --git a/lib/Plack/Middleware/Test/StashWarnings.pm b/lib/Plack/Middleware/Test/StashWarnings.pm
index d912617..4d2d470 100644
--- a/lib/Plack/Middleware/Test/StashWarnings.pm
+++ b/lib/Plack/Middleware/Test/StashWarnings.pm
@@ -23,7 +23,22 @@ sub call {
warn @_ if $ENV{TEST_VERBOSE};
};
- $self->app->($env);
+ my $ret = $self->app->($env);
+
+ # for the streaming API, we need to re-instate the dynamic sigwarn handler
+ # around the streaming callback
+ if (ref($ret) eq 'CODE') {
+ my $original_ret = $ret;
+ $ret = sub {
+ local $SIG{__WARN__} = sub {
+ push @{ $self->{stashed_warnings} }, @_;
+ warn @_ if $ENV{TEST_VERBOSE};
+ };
+ $original_ret->(@_);
+ };
+ }
+
+ return $ret;
}
sub dump_warnings {
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list