[Bps-public-commit] Plack-Middleware-Test-StashWarnings branch, master, created. 2d074b6299dc699c16e27fdcab6b2baf8581ece6

Shawn Moore sartak at bestpractical.com
Thu Oct 7 14:59:17 EDT 2010


The branch, master has been created
        at  2d074b6299dc699c16e27fdcab6b2baf8581ece6 (commit)

- Log -----------------------------------------------------------------
commit 6cee32bb73df4ca8d6b635d131112c766291a345
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Thu Oct 7 14:39:50 2010 -0400

    First cut of StashWarnings

diff --git a/lib/Plack/Middleware/Test/StashWarnings.pm b/lib/Plack/Middleware/Test/StashWarnings.pm
new file mode 100644
index 0000000..bb24da2
--- /dev/null
+++ b/lib/Plack/Middleware/Test/StashWarnings.pm
@@ -0,0 +1,81 @@
+package Plack::Middleware::Test::StashWarnings;
+
+use strict;
+use 5.008_001;
+our $VERSION = '0.01';
+
+use parent qw(Plack::Middleware);
+use Carp ();
+use Storable 'nfreeze';
+
+sub call {
+    my ($self, $env) = @_;
+
+    if ($env->{PATH_INFO} eq '/__test_warnings') {
+        Carp::carp("Use a single process server like Standalone to run Test::StashWarnings middleware")
+            if $env->{'psgi.multiprocess'} && $self->{multiprocess_warn}++ == 0;
+
+        return [ 200, ["Content-Type", "application/x-storable"], [ $self->dump_warnings ] ];
+    }
+
+    local $SIG{__WARN__} = sub {
+        push @{ $self->{stashed_warnings} }, @_;
+        warn @_ if $ENV{TEST_VERBOSE};
+    };
+
+    $self->app->($env);
+}
+
+sub dump_warnings {
+    my $self = shift;
+
+    return nfreeze([ splice @{ $self->{stashed_warnings} } ]);
+}
+
+sub DESTROY {
+    my $self = shift;
+    for (@{ $self->{stashed_warnings} }) {
+        warn "Unhandled warning: $_";
+    }
+}
+
+1;
+__END__
+
+=encoding utf-8
+
+=for stopwords
+
+=head1 NAME
+
+Plack::Middleware::Test::StashWarnings - Test your application's warnings
+
+=head1 SYNOPSIS
+
+  enable "Test::StashWarnings";
+
+  # access /__test_warnings to retrieve warnings
+
+=head1 DESCRIPTION
+
+Plack::Middleware::Test::StashWarnings is a Plack middleware component to
+record warnings generated by your application so that you can test them to make
+sure your application complains about the right things.
+
+=head1 AUTHOR
+
+Shawn M Moore C<sartak at bestpractical.com>
+
+Tatsuhiko Miyagawa wrote L<Plack::Middleware::Test::Recordings> which served as
+a model for this module.
+
+=head1 LICENSE
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=head1 SEE ALSO
+
+L<Test::HTTP::Server::Simple::StashWarnings>
+
+=cut

commit 7ec3bad778d4f430ec2b1fb0b5e219e215ec0222
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Thu Oct 7 14:43:16 2010 -0400

    Makefile.PL

diff --git a/Makefile.PL b/Makefile.PL
new file mode 100644
index 0000000..60456c0
--- /dev/null
+++ b/Makefile.PL
@@ -0,0 +1,13 @@
+use inc::Module::Install;
+name 'Plack-Middleware-Test-StashWarnings';
+all_from 'lib/Plack/Middleware/Test/StashWarnings.pm';
+readme_from 'lib/Plack/Middleware/Test/StashWarnings.pm';
+auto_set_repository;
+
+requires 'Storable';
+requires 'Plack::Test';
+test_requires 'Test::More';
+
+author_tests('xt');
+
+WriteAll;

commit 854f8bd52bf2b61fadf3d241abb9c9f72cf384b9
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Thu Oct 7 14:43:21 2010 -0400

    Changes

diff --git a/Changes b/Changes
new file mode 100644
index 0000000..8f663d3
--- /dev/null
+++ b/Changes
@@ -0,0 +1,4 @@
+Revision history for Perl extension Plack::Middleware::Test::StashWarnings
+
+0.01  2010-10-07
+        - original version

commit 1aac1b5657380e0eeedbf34c2c55224aaf6d4f7e
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Thu Oct 7 14:43:53 2010 -0400

    gitignore

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0b51617
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,6 @@
+META.yml
+Makefile
+inc/
+blib/
+pm_to_blib
+*~

commit 7d7756b6e563f2e10b3224b68c49f8b8ccce5bee
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Thu Oct 7 14:43:59 2010 -0400

    xt

diff --git a/xt/perlcritic.t b/xt/perlcritic.t
new file mode 100644
index 0000000..950f64f
--- /dev/null
+++ b/xt/perlcritic.t
@@ -0,0 +1,5 @@
+use strict;
+use Test::More;
+eval q{ use Test::Perl::Critic };
+plan skip_all => "Test::Perl::Critic is not installed." if $@;
+all_critic_ok("lib");
diff --git a/xt/pod.t b/xt/pod.t
new file mode 100644
index 0000000..437887a
--- /dev/null
+++ b/xt/pod.t
@@ -0,0 +1,4 @@
+use Test::More;
+eval "use Test::Pod 1.00";
+plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
+all_pod_files_ok();
diff --git a/xt/podspell.t b/xt/podspell.t
new file mode 100644
index 0000000..cfa60e6
--- /dev/null
+++ b/xt/podspell.t
@@ -0,0 +1,11 @@
+use Test::More;
+eval q{ use Test::Spelling };
+plan skip_all => "Test::Spelling is not installed." if $@;
+add_stopwords(<DATA>);
+set_spell_cmd("aspell -l en list");
+all_pod_files_spelling_ok('lib');
+__DATA__
+Miyagawa
+Plack
+Tatsuhiko
+middleware
diff --git a/xt/synopsis.t b/xt/synopsis.t
new file mode 100644
index 0000000..07aa750
--- /dev/null
+++ b/xt/synopsis.t
@@ -0,0 +1,4 @@
+use Test::More;
+eval "use Test::Synopsis";
+plan skip_all => "Test::Synopsis required" if $@;
+all_synopsis_ok();

commit fee4a2d1006aa4668d9298eeffbc879e71392f92
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Thu Oct 7 14:52:11 2010 -0400

    Basic tests

diff --git a/t/basic.t b/t/basic.t
new file mode 100644
index 0000000..f3e14e1
--- /dev/null
+++ b/t/basic.t
@@ -0,0 +1,46 @@
+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 [ 200, ["Content-Type", "text/plain"], ["Hello $name!"] ];
+};
+
+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!/;
+
+    $res = $cb->(GET "/__test_warnings");
+    is_deeply thaw($res->content), [];
+    is $res->content_type, 'application/x-storable';
+
+    $res = $cb->(GET "/");
+    like $res->content, qr/Hello !/;
+
+    $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 concatenation/;
+    is $res->content_type, 'application/x-storable';
+};
+
+done_testing;
+

commit 1ea6b0763f63412cb9aca9df927af2343ef5d536
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Thu Oct 7 14:53:21 2010 -0400

    More tests

diff --git a/t/basic.t b/t/basic.t
index f3e14e1..a9312da 100644
--- a/t/basic.t
+++ b/t/basic.t
@@ -27,13 +27,15 @@ test_psgi $t, sub {
 
     $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), [];
+    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) };

commit dcfa502fd727e4dec9261cd3a31c2da3f06b0bc9
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Thu Oct 7 14:55:35 2010 -0400

    Test that we complain about leftover warnings

diff --git a/t/destroy.t b/t/destroy.t
new file mode 100644
index 0000000..0a33d58
--- /dev/null
+++ b/t/destroy.t
@@ -0,0 +1,43 @@
+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 [ 200, ["Content-Type", "text/plain"], ["Hello $name!"] ];
+};
+
+my @warnings;
+local $SIG{__WARN__} = sub {
+    push @warnings, @_;
+};
+
+{
+    my $t = builder {
+        enable "Test::StashWarnings";
+        $app;
+    };
+
+    test_psgi $t, sub {
+        my $cb = shift;
+
+        my $res = $cb->(GET "/");
+        like $res->content, qr/Hello !/;
+        is $res->content_type, 'text/plain';
+    };
+
+    is @warnings, 0, "no warnings yet";
+}
+
+is @warnings, 1, "caught one warning";
+like $warnings[0], qr/Unhandled warning: Use of uninitialized value (?:\$name )?in concatenation/;
+
+done_testing;
+

commit b868ecfbbb118fb3f312b441ec1a5ed43063eff8
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Thu Oct 7 14:56:10 2010 -0400

    Compilation test

diff --git a/t/00_compile.t b/t/00_compile.t
new file mode 100644
index 0000000..9ec0553
--- /dev/null
+++ b/t/00_compile.t
@@ -0,0 +1,4 @@
+use strict;
+use Test::More tests => 1;
+
+BEGIN { use_ok 'Plack::Middleware::Test::StashWarnings' }

commit beda67083a6476e5966bccfe5513e1020405c371
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Thu Oct 7 14:56:20 2010 -0400

    Whitespace nit

diff --git a/t/basic.t b/t/basic.t
index a9312da..e3c7626 100644
--- a/t/basic.t
+++ b/t/basic.t
@@ -5,6 +5,7 @@ use HTTP::Request::Common;
 
 use Plack::Builder;
 use Plack::Request;
+
 use Storable 'thaw';
 
 my $app = sub {

commit 2d074b6299dc699c16e27fdcab6b2baf8581ece6
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Thu Oct 7 14:59:33 2010 -0400

    Better synopsis

diff --git a/lib/Plack/Middleware/Test/StashWarnings.pm b/lib/Plack/Middleware/Test/StashWarnings.pm
index bb24da2..6bb9a42 100644
--- a/lib/Plack/Middleware/Test/StashWarnings.pm
+++ b/lib/Plack/Middleware/Test/StashWarnings.pm
@@ -54,7 +54,11 @@ Plack::Middleware::Test::StashWarnings - Test your application's warnings
 
   enable "Test::StashWarnings";
 
-  # access /__test_warnings to retrieve warnings
+
+  use Storable 'thaw';
+  $mech->get('/__test_warnings');
+  my @warnings = thaw($mech->content);
+  like(@warnings[0], qr/No private key/);
 
 =head1 DESCRIPTION
 

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list