use warnings FATAL => 'all';
no warnings::illegalproto;
-use Test::More;
+use Test::More 0.88;
use HTTP::Request::Common qw(GET POST);
use Web::Dispatch;
package MiscTest;
sub dispatch_request { @dispatch }
sub string_method { [ 999, [], [""] ]; }
+
+ sub can {
+ die "Passed undef to can, this blows up on 5.8" unless defined($_[1]);
+ shift->SUPER::can(@_)
+ }
}
my $app = MiscTest->new;
route_returns_middleware_plus_extra();
route_returns_undef();
matcher_nonsub_pair();
+matcher_undef_method();
done_testing();
sub to_app { [ 999, [], ["ok"] ] }
}
- my $d = Web::Dispatch->new( dispatch_object => ObjectApp->new );
+ my $o = ObjectApp->new;
+ my $d = Web::Dispatch->new( dispatch_object => $o );
my $res = $d->call;
cmp_ok $res->[0], '==', 999, "Web::Dispatch can dispatch properly, given only an object with to_app method";
for my $response ( @responses ) {
@dispatch = ( sub (/) { $response->[0] } );
- eval { run_request( GET => 'http://localhost/' ) };
-
- like $@, qr/Can't call method "request" on an undefined value .*MockHTTP/,
- sprintf(
+ my $message = sprintf(
"if a route returns %s, then that is returned as a response by WD, causing HTTP::Message::PSGI to choke",
- $response->[1] );
+ $response->[1]
+ );
+
+ # Somewhere between 1.0028 and 1.0031 Plack changed so that the
+ # FauxObject case became a 500 rather than a die; in case it later does
+ # the same thing for other stuff, just accept either sort of error
+
+ my $res = eval { run_request( GET => 'http://localhost/' ) };
+
+ if ($res) {
+ ok $res->is_error, $message;
+ } else {
+ like $@, qr/Can't call method "request" on an undefined value .*MockHTTP/, $message;
+ }
undef $@;
}
}
like $get->content, qr[No idea how we got here with Web::Dispatch::M],
"the error message points out the broken definition";
}
+
+sub matcher_undef_method {
+ @dispatch = ( 'GET', undef );
+
+ my $get = run_request( GET => 'http://localhost/' );
+
+ cmp_ok $get->code, '==', 500, "a route definition that pairs a WD::Matcher a non-sub dies";
+ like $get->content, qr[No idea how we got here with GET],
+ "the error message points out the broken definition";
+}