Permalink
Browse files

unuse Test::Base

  • Loading branch information...
miyagawa committed Jan 31, 2010
1 parent 01d6453 commit 2e332e2b55acdf933b238bd77d1cfe8ffca7d64b
View
@@ -24,9 +24,7 @@ requires 'Filesys::Notify::Simple'; # plackup -r
requires 'Hash::MultiValue', 0.05; # Plack::Request
requires 'HTTP::Body'; # Plack::Request
-# TODO: they can go away once we create Plack-Middlewares dist
-# Middleware::Static and App::File
-requires 'Path::Class';
+requires 'Path::Class'; # App::File
build_requires 'Test::More', 0.88;
build_requires 'Test::TCP', 0.11;
@@ -38,7 +36,6 @@ author_tests 'xt';
install_share 'share';
install_script 'scripts/plackup';
-use_test_base;
auto_include;
auto_install;
auto_set_repository;
@@ -1,97 +1,61 @@
use strict;
use warnings;
-use Test::Base;
use Plack::Builder;
-
-filters {
- app => 'eval',
- env => 'yaml',
- headers => 'yaml',
-};
-
-plan tests => 2 * blocks;
-
-run {
- my $block = shift;
+use Test::More;
+
+my @tests = (
+ {
+ app => sub { [ 200, [ 'Content-Type' => 'text/plain' ], [ 'OK' ] ] },
+ env => { REQUEST_METHOD => 'GET' },
+ status => 200,
+ headers => [ 'Content-Type', 'text/plain' ],
+ },
+ {
+ app => sub { [ 200, [ 'ETag' => 'Foo', 'Content-Type' => 'text/plain' ], [ 'OK' ] ] },
+ env => { REQUEST_METHOD => "GET", HTTP_IF_NONE_MATCH => "Foo" },
+ status => 304,
+ headers => [ ETag => 'Foo' ],
+ },
+ {
+ app => sub { [ 200, [ 'Last-Modified' => 'Wed, 23 Sep 2009 13:36:33 GMT', 'Content-Type' => 'text/plain' ], [ 'OK' ] ] },
+ env => { REQUEST_METHOD => "GET", HTTP_IF_MODIFIED_SINCE => "Wed, 23 Sep 2009 13:36:33 GMT" },
+ status => 304,
+ headers => [ "Last-Modified" => "Wed, 23 Sep 2009 13:36:33 GMT" ],
+ },
+ {
+ app => sub { [ 200, [ 'Last-Modified' => 'Wed, 23 Sep 2009 13:36:33 GMT', 'Content-Type' => 'text/plain' ], [ 'OK' ] ] },
+ env => { REQUEST_METHOD => "GET", HTTP_IF_MODIFIED_SINCE => "Wed, 23 Sep 2009 13:36:32 GMT" },
+ status => 200,
+ headers => [
+ "Last-Modified", "Wed, 23 Sep 2009 13:36:33 GMT", "Content-Type", "text/plain",
+ ],
+ },
+ {
+ app => sub { [ 200, [ 'Last-Modified' => 'Wed, 23 Sep 2009 13:36:33 GMT', 'Content-Type' => 'text/plain' ], [ 'OK' ] ] },
+ env => { REQUEST_METHOD => "GET", HTTP_IF_MODIFIED_SINCE => "Wed, 23 Sep 2009 13:36:33 GMT; length=2" },
+ status => 304,
+ headers => [ "Last-Modified", "Wed, 23 Sep 2009 13:36:33 GMT" ],
+ },
+ {
+ app => sub { [ 200, [ 'ETag' => 'Foo', 'Content-Type' => 'text/plain' ], [ 'OK' ] ] },
+ env => { REQUEST_METHOD => "POST", HTTP_IF_NONE_MATCH => "Foo" },
+ status => 200,
+ headers => [ ETag => "Foo", "Content-Type" => "text/plain" ],
+ }
+);
+
+plan tests => 2*@tests;
+
+for my $block (@tests) {
my $handler = builder {
enable "Plack::Middleware::ConditionalGET";
- $block->app;
+ $block->{app};
};
- my $res = $handler->($block->env);
- is $res->[0], $block->status;
- is_deeply $res->[1], $block->headers;
-};
-
-__END__
-
-=== 200 response
---- app
-sub { [ 200, [ 'Content-Type' => 'text/plain' ], [ 'OK' ] ] }
---- env
-REQUEST_METHOD: GET
---- status: 200
---- headers
-- Content-Type
-- text/plain
-
-=== ETag match
---- app
-sub { [ 200, [ 'ETag' => 'Foo', 'Content-Type' => 'text/plain' ], [ 'OK' ] ] }
---- env
-REQUEST_METHOD: GET
-HTTP_IF_NONE_MATCH: Foo
---- status: 304
---- headers
-- ETag
-- Foo
-
-=== If-Modified-Since match
---- app
-sub { [ 200, [ 'Last-Modified' => 'Wed, 23 Sep 2009 13:36:33 GMT', 'Content-Type' => 'text/plain' ], [ 'OK' ] ] }
---- env
-REQUEST_METHOD: GET
-HTTP_IF_MODIFIED_SINCE: Wed, 23 Sep 2009 13:36:33 GMT
---- status: 304
---- headers
-- Last-Modified
-- Wed, 23 Sep 2009 13:36:33 GMT
-
-=== If-Modified-Since mismatch
---- app
-sub { [ 200, [ 'Last-Modified' => 'Wed, 23 Sep 2009 13:36:33 GMT', 'Content-Type' => 'text/plain' ], [ 'OK' ] ] }
---- env
-REQUEST_METHOD: GET
-HTTP_IF_MODIFIED_SINCE: Wed, 23 Sep 2009 13:36:32 GMT
---- status: 200
---- headers
-- Last-Modified
-- Wed, 23 Sep 2009 13:36:33 GMT
-- Content-Type
-- text/plain
-
-=== If-Modified-Since match ie bug
---- app
-sub { [ 200, [ 'Last-Modified' => 'Wed, 23 Sep 2009 13:36:33 GMT', 'Content-Type' => 'text/plain' ], [ 'OK' ] ] }
---- env
-REQUEST_METHOD: GET
-HTTP_IF_MODIFIED_SINCE: Wed, 23 Sep 2009 13:36:33 GMT; length=2
---- status: 304
---- headers
-- Last-Modified
-- Wed, 23 Sep 2009 13:36:33 GMT
+ my $res = $handler->($block->{env});
+ is $res->[0], $block->{status};
+ is_deeply $res->[1], $block->{headers};
+}
-=== non-GET reqs
---- app
-sub { [ 200, [ 'ETag' => 'Foo', 'Content-Type' => 'text/plain' ], [ 'OK' ] ] }
---- env
-REQUEST_METHOD: POST
-HTTP_IF_NONE_MATCH: Foo
---- status: 200
---- headers
-- ETag
-- Foo
-- Content-Type
-- text/plain
@@ -1,85 +1,53 @@
use strict;
-use Test::Base;
+use Test::More;
use Plack::Builder;
-filters {
- app => 'eval',
- env => 'yaml',
- headers => 'yaml',
-};
-
-plan tests => 1 * blocks;
-
-run {
- my $block = shift;
+my @tests = (
+ {
+ app => sub { [ 200, [ 'Content-Type' => 'text/plain' ], [ 'OK' ] ] },
+ env => { REQUEST_METHOD => 'GET' },
+ headers=> [ 'Content-Type' => 'text/plain', 'Content-Length' => 2 ],
+ },
+ {
+ app => sub {
+ open my $fh, "<", "share/kyoto.jpg";
+ [ 200, [ 'Content-Type' => 'image/jpeg' ], $fh ];
+ },
+ env => { REQUEST_METHOD => 'GET' },
+ headers => [ 'Content-Type' => 'image/jpeg', 'Content-Length' => 2397701 ],
+ },
+ {
+ app => sub {
+ [ 304, [ ETag => 'Foo' ], [] ];
+ },
+ env => { REQUEST_METHOD => 'GET' },
+ headers => [ ETag => 'Foo' ],
+ },
+ {
+ app => sub {
+ my $body = "Hello World";
+ open my $fh, "<", \$body;
+ [ 200, [ 'Content-Type' => 'text/plain' ], $fh ];
+ },
+ env => { REQUEST_METHOD => 'GET' },
+ headers => [ 'Content-Type' => 'text/plain' ],
+ },
+ {
+ app => sub {
+ [ 200, [ 'Content-Type' => 'text/plain', 'Content-Length' => 11 ], [ "Hello World" ] ];
+ },
+ env => { REQUEST_METHOD => 'GET' },
+ headers => [ 'Content-Type' => 'text/plain', 'Content-Length', 11 ],
+ },
+);
+
+plan tests => 1 * @tests;
+
+for my $block (@tests) {
my $handler = builder {
enable "Plack::Middleware::ContentLength";
- $block->app;
+ $block->{app};
};
- my $res = $handler->($block->env);
- is_deeply $res->[1], $block->headers;
+ my $res = $handler->($block->{env});
+ is_deeply $res->[1], $block->{headers};
};
-
-__END__
-
-=== 200 response
---- app
-sub { [ 200, [ 'Content-Type' => 'text/plain' ], [ 'OK' ] ] }
---- env
-REQUEST_METHOD: GET
---- headers
-- Content-Type
-- text/plain
-- Content-Length
-- 2
-
-=== 200 response with filehandle
---- app
-sub {
- open my $fh, "<", "share/kyoto.jpg";
- [ 200, [ 'Content-Type' => 'image/jpeg' ], $fh ];
-}
---- env
-REQUEST_METHOD: GET
---- headers
-- Content-Type
-- image/jpeg
-- Content-Length
-- 2397701
-
-=== 304 no entity header
---- app
-sub {
- [ 304, [ ETag => 'Foo' ], [] ];
-}
---- env
-REQUEST_METHOD: GET
---- headers
-- ETag
-- Foo
-
-=== 200 not calculatable
---- app
-sub {
- my $body = "Hello World";
- open my $fh, "<", \$body;
- [ 200, [ 'Content-Type' => 'text/plain' ], $fh ];
-}
---- env
-REQUEST_METHOD: GET
---- headers
-- Content-Type
-- text/plain
-
-=== 200 with C-L
---- app
-sub {
- [ 200, [ 'Content-Type' => 'text/plain', 'Content-Length' => 11 ], [ "Hello World" ] ];
-}
---- env
-REQUEST_METHOD: GET
---- headers
-- Content-Type
-- text/plain
-- Content-Length
-- 11
@@ -1,58 +1,42 @@
use strict;
-use Test::Base;
+use Test::More;
use Plack::Builder;
-filters {
- app => 'eval',
- env => 'yaml',
- headers => 'yaml',
-};
+my @tests = (
+ {
+ app => sub {
+ return sub {
+ $_[0]->([ 200, [ 'Content-Type' => 'text/plain' ], [ 'OK' ] ]);
+ },
+ },
+ env => { REQUEST_METHOD => 'GET' },
+ headers => [ 'Content-Type' => 'text/plain' ],
+ body => 'OK',
+ },
+ {
+ app => sub {
+ return sub {
+ my $writer = $_[0]->([ 200, [ 'Content-Type' => 'text/plain' ]]);
+ $writer->write("O");
+ $writer->write("K");
+ $writer->close();
+ },
+ },
+ env => { REQUEST_METHOD => 'GET' },
+ headers => [ 'Content-Type', 'text/plain' ],
+ body => 'OK',
+ },
+);
+
-plan tests => 2 * blocks;
+plan tests => 2 * @tests;
-run {
- my $block = shift;
+for my $block (@tests) {
my $handler = builder {
enable "Plack::Middleware::Writer";
- $block->app;
+ $block->{app};
};
- my $res = $handler->($block->env);
- is_deeply $res->[1], $block->headers, "headers passed through";
- is join("", @{ $res->[2] }) . "\n", $block->body, "body accumulated";
+ my $res = $handler->($block->{env});
+ is_deeply $res->[1], $block->{headers}, "headers passed through";
+ is join("", @{ $res->[2] }), $block->{body}, "body accumulated";
};
-
-__END__
-
-=== simple write
---- app
-sub {
- return sub {
- $_[0]->([ 200, [ 'Content-Type' => 'text/plain' ], [ 'OK' ] ]);
- }
-}
---- env
-REQUEST_METHOD: GET
---- headers
-- Content-Type
-- text/plain
---- body
-OK
-
-=== iterative write
---- app
-sub {
- return sub {
- my $writer = $_[0]->([ 200, [ 'Content-Type' => 'text/plain' ]]);
-
- $writer->write("O");
- $writer->write("K");
- $writer->close();
- }
-}
---- env
-REQUEST_METHOD: GET
---- headers
-- Content-Type
-- text/plain
---- body
-OK
Oops, something went wrong.

0 comments on commit 2e332e2

Please sign in to comment.