},
develop => {
requires => {
- 'CatalystX::LeakChecker' => '0.05',
- 'Catalyst::Devel' => '1.0', # For http server test
- 'Test::WWW::Mechanize::Catalyst' => '0.51',
- 'Test::TCP' => '2.00', # ditto, ships Net::EmptyPort
+ 'Test::TCP' => '2.00',
'File::Copy::Recursive' => '0.40',
'Starman' => 0,
'MooseX::Daemonize' => 0,
'Test::Pod::Coverage' => 0,
'Test::Spelling' => 0,
'Pod::Coverage::TrustPod' => 0,
- 'Catalyst::Plugin::Params::Nested' => 0,
- 'Catalyst::Plugin::ConfigLoader' => 0,
'Compress::Zlib' => 0,
- 'Catalyst::Action::REST' => 0,
'Type::Tiny' => 0,
'Proc::ProcessTable' => 0,
},
manifest_include script => 'catalyst.pl';
manifest_include t => 'catalyst_130pix.gif';
manifest_include 't/conf' => 'extra.conf.in';
-manifest_include 't/lib/TestAppEncodingSetInConfig' => 'testappencodingsetinconfig.json';
manifest_include 't/lib/TestContentNegotiation/share', 'file.txt';
manifest_include 't/lib/TestMiddleware/share' => qr/.*/;
-manifest_include 't/lib/TestMiddlewareFromConfig/share' => qr/.*/;
-manifest_include 't/lib/TestMiddlewareFromConfig' => 'testmiddlewarefromconfig.pl';
+manifest_include 't/lib/TestMiddlewareFromPlugin/share' => qr/.*/;
+manifest_include 't/lib/TestMiddlewareFromPlugin' => 'testmiddlewarefromplugin.pl';
manifest_include t => qr/optional_apache-.*\.pl/;
manifest_include t => 'optional_stress.json';
manifest_include t => 'something/Makefile.PL';
use Class::MOP;
BEGIN {
- use Test::More;
- eval "use Catalyst::Action::REST; 1" || do {
- plan skip_all => "Trouble loading Catalyst::Action::REST => $@";
- };
-}
-
-BEGIN {
my %hidden = map { (my $m = "$_.pm") =~ s{::}{/}g; $m => 1 } qw(
Foo
Bar
+++ /dev/null
-use strict;
-use warnings;
-
-use FindBin '$Bin';
-use lib "$Bin/lib";
-
-use Test::More;
-
-BEGIN { eval { require Catalyst::Plugin::ConfigLoader; 1; } ||
- plan skip_all => 'Need Catalyst::Plugin::ConfigLoader' }
-
-#for this test encoding => 'UTF-8' is set in testappencodingsetinconfig.json
-use Catalyst::Test 'TestAppEncodingSetInConfig';
-
-my ( undef, $c ) = ctx_request('/');
-isa_ok( $c->encoding, 'Encode::utf8', '$c->encoding' );
-
-done_testing;
--- /dev/null
+use strict;
+use warnings;
+
+use FindBin '$Bin';
+use lib "$Bin/lib";
+
+use Test::More;
+
+#for this test encoding => 'UTF-8' is set in a plugin
+use Catalyst::Test 'TestAppEncodingSetInPlugin';
+
+my ( undef, $c ) = ctx_request('/');
+isa_ok( $c->encoding, 'Encode::utf8', '$c->encoding' );
+
+done_testing;
--- /dev/null
+package MakeTestApp;
+use strict;
+use warnings;
+
+use Exporter 'import';
+use Cwd qw(abs_path);
+use File::Spec::Functions qw(updir catdir);
+use File::Basename qw(dirname);
+use File::Path qw(rmtree);
+use File::Copy::Recursive qw(dircopy);
+
+our @EXPORT = qw(make_test_app);
+
+our $root = abs_path(catdir(dirname(__FILE__), (updir) x 2));
+
+sub make_test_app {
+ my $tmp = "$root/t/tmp";
+ rmtree $tmp if -d $tmp;
+ mkdir $tmp;
+
+ # create a TestApp and copy the test libs into it
+ my $testapp = "$tmp/TestApp";
+ mkdir $testapp;
+
+ mkdir "$testapp/lib";
+ mkdir "$testapp/script";
+
+ for my $command (qw(CGI FastCGI Server)) {
+ my $script = "$testapp/script/testapp_\L$command\E.pl";
+ open my $fh, '>:raw', $script
+ or die "can't create $script: $!";
+ print $fh <<"END_CODE";
+#!/usr/bin/env perl
+
+use Catalyst::ScriptRunner;
+Catalyst::ScriptRunner->run('TestApp', '$command');
+
+1;
+END_CODE
+ close $fh;
+ chmod 0755, $script;
+ }
+
+ open my $fh, '>:raw', "$testapp/cpanfile";
+ close $fh;
+
+ File::Copy::Recursive::dircopy( "$root/t/lib", "$testapp/lib" );
+
+ return $testapp;
+}
+
+1;
# above ->setup so we have some generated methods to be double sure.
has an_attribute_before_we_change_base_classes => ( is => 'ro');
-if ($::setup_leakchecker && try_load_class('CatalystX::LeakChecker')) {
- with 'CatalystX::LeakChecker';
+if ($::setup_leakchecker) {
+ require Scalar::Util;
+ require Devel::Cycle;
has leaks => (
is => 'ro',
default => sub { [] },
);
-}
-sub found_leaks {
- my ($ctx, @leaks) = @_;
- push @{ $ctx->leaks }, @leaks;
-}
+ sub count_leaks {
+ my ($ctx) = @_;
+ return scalar @{ $ctx->leaks };
+ }
+
+ after finalize => sub {
+ my ($ctx) = @_;
+ my @leaks;
+
+ my $weak_ctx = $ctx;
+ Scalar::Util::weaken $weak_ctx;
+
+ Devel::Cycle::find_cycle($ctx, sub {
+ my ($path) = @_;
+ push @leaks, $path
+ if $path->[0]->[2] == $weak_ctx;
+ });
-sub count_leaks {
- my ($ctx) = @_;
- return scalar @{ $ctx->leaks };
+ push @{ $ctx->leaks }, @leaks;
+ };
}
TestApp->setup;
+++ /dev/null
-package TestApp2;
-use strict;
-use warnings;
-use base qw/Catalyst/;
-use Catalyst qw/Params::Nested/;
-
-__PACKAGE__->config(
- 'name' => 'TestApp2',
- encoding => 'UTF-8',
-);
-
-__PACKAGE__->setup;
-
-sub handle_unicode_encoding_exception {
- my ( $self, $param_value, $error_msg ) = @_;
- return $param_value;
-}
-
-1;
+++ /dev/null
-package TestApp2::Controller::Root;
-use strict;
-use warnings;
-use utf8;
-
-__PACKAGE__->config(namespace => q{});
-
-use base 'Catalyst::Controller';
-
-# your actions replace this one
-sub main :Path('') {
- $_[1]->res->body('<h1>It works</h1>');
- $_[1]->res->content_type('text/html');
-}
-
-1;
+++ /dev/null
-package TestAppEncodingSetInConfig;
-use Moose;
-
-use Catalyst qw/ConfigLoader/;
-
-extends 'Catalyst';
-
-__PACKAGE__->setup;
-
-1;
+++ /dev/null
-{
- "encoding": "UTF-8"
-}
--- /dev/null
+package TestAppEncodingSetInPlugin;
+use Moose;
+
+use Catalyst qw/+TestAppEncodingSetInPlugin::SetEncoding/;
+
+extends 'Catalyst';
+
+__PACKAGE__->setup;
+
+1;
-package TestAppEncodingSetInConfig::Controller::Root;
+package TestAppEncodingSetInPlugin::Controller::Root;
use Moose;
-use namespace::clean -except => [ 'meta' ];
+use namespace::autoclean;
BEGIN { extends 'Catalyst::Controller'; }
--- /dev/null
+package TestAppEncodingSetInPlugin::SetEncoding;
+use strict;
+use warnings;
+
+sub setup {
+ my $c = shift;
+ $c->config(encoding => 'UTF-8');
+ $c->next::method(@_);
+}
+
+1;
-package TestMiddlewareFromConfig;
+package TestMiddlewareFromPlugin;
-use Catalyst qw/ConfigLoader/;
+use Catalyst qw/+TestMiddlewareFromPlugin::SetMiddleware/;
## Proof this is good config
-##__PACKAGE__->config( do TestMiddlewareFromConfig->path_to('testmiddlewarefromconfig.pl') );
+##__PACKAGE__->config( do TestMiddlewareFromConfig->path_to('testmiddlewarefromplugin.pl') );
__PACKAGE__->setup_middleware('Head');
__PACKAGE__->setup;
+1;
-package TestMiddlewareFromConfig::Controller::Root;
+package TestMiddlewareFromPlugin::Controller::Root;
use Moose;
use MooseX::MethodAttributes;
-package TestMiddlewareFromConfig::Custom;
+package TestMiddlewareFromPlugin::Custom;
use strict;
use warnings;
--- /dev/null
+package TestMiddlewareFromPlugin::SetMiddleware;
+use strict;
+use warnings;
+use File::Spec;
+use File::Basename ();
+
+my $config_path = File::Spec->catfile(File::Basename::dirname(__FILE__), 'testmiddlewarefromplugin.pl');
+
+sub setup {
+ my $c = shift;
+ $c->config(do $config_path);
+ $c->next::method(@_);
+}
+
+1;
use Plack::Middleware::Static;
my $static = Plack::Middleware::Static->new(
- path => qr{^/static/}, root => TestMiddlewareFromConfig->path_to('share'));
+ path => qr{^/static/}, root => TestMiddlewareFromPlugin->path_to('share'));
my $conf = +{
'Controller::Root', { namespace => '' },
'psgi_middleware', [
$static,
- 'Static', { path => qr{^/static2/}, root => TestMiddlewareFromConfig->path_to('share') },
+ 'Static', { path => qr{^/static2/}, root => TestMiddlewareFromPlugin->path_to('share') },
'Runtime',
- '+TestMiddleware::Custom', { path => qr{^/static3/}, root => TestMiddlewareFromConfig->path_to('share') },
+ '+TestMiddleware::Custom', { path => qr{^/static3/}, root => TestMiddlewareFromPlugin->path_to('share') },
sub {
my $app = shift;
return sub {
my $env = shift;
if($env->{PATH_INFO} =~m/forced/) {
- Plack::App::File->new(file=>TestMiddlewareFromConfig->path_to(qw/share static forced.txt/))
+ Plack::App::File->new(file=>TestMiddlewareFromPlugin->path_to(qw/share static forced.txt/))
->call($env);
} else {
return $app->($env);
use Test::More;
BEGIN {
- unless (eval 'use CatalystX::LeakChecker 0.05; 1') {
- plan skip_all => 'CatalystX::LeakChecker 0.05 required for this test';
+ unless (eval 'use Devel::Cycle 1.11; 1') {
+ plan skip_all => 'Devel::Cycle 1.11 required for this test';
}
plan tests => 6;
use FindBin;
use IO::Socket;
-# clean up
-rmtree "$FindBin::Bin/../t/tmp" if -d "$FindBin::Bin/../t/tmp";
-
-# create a TestApp and copy the test libs into it
-mkdir "$FindBin::Bin/../t/tmp";
-chdir "$FindBin::Bin/../t/tmp";
-system "$FindBin::Bin/../script/catalyst.pl TestApp";
-chdir "$FindBin::Bin/..";
-File::Copy::Recursive::dircopy( 't/lib', 't/tmp/TestApp/lib' );
-
-# remove TestApp's tests so Apache::Test doesn't try to run them
-rmtree 't/tmp/TestApp/t';
+use lib 't/lib';
+use MakeTestApp;
+
+make_test_app;
$ENV{CATALYST_SERVER} = 'http://localhost:8529/rewrite';
use FindBin;
use IO::Socket;
-# clean up
-rmtree "$FindBin::Bin/../t/tmp" if -d "$FindBin::Bin/../t/tmp";
-
-# create a TestApp and copy the test libs into it
-mkdir "$FindBin::Bin/../t/tmp";
-chdir "$FindBin::Bin/../t/tmp";
-system "$FindBin::Bin/../script/catalyst.pl TestApp";
-chdir "$FindBin::Bin/..";
-File::Copy::Recursive::dircopy( 't/lib', 't/tmp/TestApp/lib' );
-
-# remove TestApp's tests so Apache::Test doesn't try to run them
-rmtree 't/tmp/TestApp/t';
+use lib 't/lib';
+use MakeTestApp;
+
+make_test_app;
$ENV{CATALYST_SERVER} = 'http://localhost:8529/cgi';
use FindBin;
use IO::Socket;
-# clean up
-rmtree "$FindBin::Bin/../t/tmp" if -d "$FindBin::Bin/../t/tmp";
-
-# create a TestApp and copy the test libs into it
-mkdir "$FindBin::Bin/../t/tmp";
-chdir "$FindBin::Bin/../t/tmp";
-system "$FindBin::Bin/../script/catalyst.pl TestApp";
-chdir "$FindBin::Bin/..";
-File::Copy::Recursive::dircopy( 't/lib', 't/tmp/TestApp/lib' );
-
-# remove TestApp's tests so Apache::Test doesn't try to run them
-rmtree 't/tmp/TestApp/t';
+use lib 't/lib';
+use MakeTestApp;
+
+make_test_app;
$ENV{CATALYST_SERVER} = 'http://localhost:8529/fastcgi/deep/path';
use FindBin;
use IO::Socket;
-# clean up
-rmtree "$FindBin::Bin/../t/tmp" if -d "$FindBin::Bin/../t/tmp";
-
-# create a TestApp and copy the test libs into it
-mkdir "$FindBin::Bin/../t/tmp";
-chdir "$FindBin::Bin/../t/tmp";
-system "$FindBin::Bin/../script/catalyst.pl TestApp";
-chdir "$FindBin::Bin/..";
-File::Copy::Recursive::dircopy( 't/lib', 't/tmp/TestApp/lib' );
-
-# remove TestApp's tests so Apache::Test doesn't try to run them
-rmtree 't/tmp/TestApp/t';
+use lib 't/lib';
+use MakeTestApp;
+
+make_test_app;
$ENV{CATALYST_SERVER} = 'http://localhost:8529';
use IO::Socket;
use IPC::Open3;
use Time::HiRes qw/sleep/;
-eval {require Catalyst::Devel; Catalyst::Devel->VERSION(1.0);};
-plan skip_all => 'Catalyst::Devel required' if $@;
-plan skip_all => 'Catalyst::Devel >= 1.04 required' if $Catalyst::Devel::VERSION <= 1.03;
-eval "use File::Copy::Recursive";
-plan skip_all => 'File::Copy::Recursive required' if $@;
-
-my $tmpdir = "$FindBin::Bin/../t/tmp";
-
-# clean up
-rmtree $tmpdir if -d $tmpdir;
-
-# create a TestApp and copy the test libs into it
-mkdir $tmpdir;
-chdir $tmpdir;
-
-system( $^X, "-I$FindBin::Bin/../lib", '-MFile::Spec', '-e', "\@ARGV=('TestApp'); my \$devnull = File::Spec->devnull; open my \$fh, '>', \$devnull or die \"Cannot write to \$devnull: \$!\"; *STDOUT = \$fh; do \"$FindBin::Bin/../script/catalyst.pl\"");
+BEGIN {
+ eval "use File::Copy::Recursive";
+ plan skip_all => 'File::Copy::Recursive required' if $@;
+}
-chdir "$FindBin::Bin/..";
-File::Copy::Recursive::dircopy( 't/lib', 't/tmp/TestApp/lib' );
+use lib 't/lib';
+use MakeTestApp;
-# remove TestApp's tests
-rmtree 't/tmp/TestApp/t';
+make_test_app;
# spawn the standalone HTTP server
my $port = 30000 + int rand( 1 + 10000 );
use File::Path;
use FindBin;
use IO::Socket;
+use Config ();
-eval "use FCGI";
-plan skip_all => 'FCGI required' if $@;
+BEGIN {
+ eval "use FCGI";
+ plan skip_all => 'FCGI required' if $@;
-eval "use Catalyst::Devel 1.0";
-plan skip_all => 'Catalyst::Devel required' if $@;
+ eval "use File::Copy::Recursive";
+ plan skip_all => 'File::Copy::Recursive required' if $@;
-eval "use File::Copy::Recursive";
-plan skip_all => 'File::Copy::Recursive required' if $@;
+ eval "use Test::Harness";
+ plan skip_all => 'Test::Harness required' if $@;
+}
-eval "use Test::Harness";
-plan skip_all => 'Test::Harness required' if $@;
+use lib 't/lib';
+use MakeTestApp;
my $lighttpd_bin = $ENV{LIGHTTPD_BIN} || `which lighttpd`;
chomp $lighttpd_bin;
plan tests => 1;
-# clean up
-rmtree "$FindBin::Bin/../t/tmp" if -d "$FindBin::Bin/../t/tmp";
-
-# create a TestApp and copy the test libs into it
-mkdir "$FindBin::Bin/../t/tmp";
-chdir "$FindBin::Bin/../t/tmp";
-system "$^X -I$FindBin::Bin/../lib $FindBin::Bin/../script/catalyst.pl TestApp";
-chdir "$FindBin::Bin/..";
-File::Copy::Recursive::dircopy( 't/lib', 't/tmp/TestApp/lib' );
-
-# remove TestApp's tests
-rmtree 't/tmp/TestApp/t';
+make_test_app;
# Create a temporary lighttpd config
my $docroot = "$FindBin::Bin/../t/tmp";
my $port = 8529;
# Clean up docroot path
-$docroot =~ s{/t/..}{};
+$docroot =~ s{/t/\.\.}{};
+
+my $perl5lib = join($Config::Config{path_sep}, "$docroot/../../lib", $ENV{PERL5LIB} || ());
my $conf = <<"END";
# basic lighttpd config file for testing fcgi+catalyst
"max-procs" => 1,
"idle-timeout" => 20,
"bin-environment" => (
- "PERL5LIB" => "$docroot/../../lib"
+ "PERL5LIB" => "$perl5lib"
)
)
)
use File::Path;
use FindBin;
use IO::Socket;
+use Config ();
-eval "use FCGI";
-plan skip_all => 'FCGI required' if $@;
+BEGIN {
+ eval "use FCGI";
+ plan skip_all => 'FCGI required' if $@;
-eval "use Catalyst::Devel 1.0";
-plan skip_all => 'Catalyst::Devel required' if $@;
+ eval "use File::Copy::Recursive";
+ plan skip_all => 'File::Copy::Recursive required' if $@;
-eval "use File::Copy::Recursive";
-plan skip_all => 'File::Copy::Recursive required' if $@;
+ eval "use Test::Harness";
+ plan skip_all => 'Test::Harness required' if $@;
+}
-eval "use Test::Harness";
-plan skip_all => 'Test::Harness required' if $@;
+use lib 't/lib';
+use MakeTestApp;
my $lighttpd_bin = $ENV{LIGHTTPD_BIN} || `which lighttpd`;
chomp $lighttpd_bin;
plan tests => 1;
-# clean up
-rmtree "$FindBin::Bin/../t/tmp" if -d "$FindBin::Bin/../t/tmp";
-
-# create a TestApp and copy the test libs into it
-mkdir "$FindBin::Bin/../t/tmp";
-chdir "$FindBin::Bin/../t/tmp";
-system "$^X -I$FindBin::Bin/../lib $FindBin::Bin/../script/catalyst.pl TestApp";
-chdir "$FindBin::Bin/..";
-File::Copy::Recursive::dircopy( 't/lib', 't/tmp/TestApp/lib' );
-
-# remove TestApp's tests
-rmtree 't/tmp/TestApp/t';
+# this creates t/tmp/TestApp
+make_test_app;
# Create a temporary lighttpd config
my $docroot = "$FindBin::Bin/../t/tmp";
my $port = 8529;
# Clean up docroot path
-$docroot =~ s{/t/..}{};
+$docroot =~ s{/t/\.\.}{};
+
+my $perl5lib = join($Config::Config{path_sep}, "$docroot/../../lib", $ENV{PERL5LIB} || ());
my $conf = <<"END";
# basic lighttpd config file for testing fcgi+catalyst
"max-procs" => 1,
"idle-timeout" => 20,
"bin-environment" => (
- "PERL5LIB" => "$docroot/../../lib"
+ "PERL5LIB" => "$perl5lib"
)
)
)
use Test::More;
use HTTP::Request::Common;
-BEGIN { eval { require Catalyst::Plugin::ConfigLoader; 1; } ||
- plan skip_all => 'Need Catalyst::Plugin::ConfigLoader' }
-
use lib "$FindBin::Bin/lib";
-use Catalyst::Test 'TestMiddlewareFromConfig';
+use Catalyst::Test 'TestMiddlewareFromPlugin';
ok my($res, $c) = ctx_request('/');
use FindBin qw($Bin);
use lib "$Bin/lib";
-BEGIN {
-if ( !eval { require Test::WWW::Mechanize::Catalyst; Test::WWW::Mechanize::Catalyst->VERSION('0.51')} ) {
- plan skip_all => 'Need Test::WWW::Mechanize::Catalyst for this test';
-}
-}
-
-# make sure testapp works
-use_ok('TestAppUnicode');
-
-use Test::WWW::Mechanize::Catalyst 'TestAppUnicode';
-my $mech = Test::WWW::Mechanize::Catalyst->new;
+use Catalyst::Test 'TestAppUnicode';
{
TestAppUnicode->encoding('UTF-8');
- $mech->get_ok('http://localhost/unicode', 'encoding configured ok');
+ action_ok('/unicode', 'encoding configured ok');
}
done_testing;
use FindBin qw($Bin);
use lib "$Bin/lib";
-BEGIN {
- if ( !eval { require Test::WWW::Mechanize::Catalyst; Test::WWW::Mechanize::Catalyst->VERSION('0.51') } ) {
- plan skip_all => 'Need Test::WWW::Mechanize::Catalyst for this test';
- }
-}
-
-# make sure testapp works
-use_ok('TestAppUnicode') or BAIL_OUT($@);
+use Catalyst::Test qw(TestAppUnicode);
-# a live test against TestAppUnicode, the test application
-use Test::WWW::Mechanize::Catalyst 'TestAppUnicode';
-my $mech = Test::WWW::Mechanize::Catalyst->new;
-$mech->get_ok('http://localhost/', 'get main page');
-$mech->content_like(qr/it works/i, 'see if it has our text');
-is ($mech->response->header('Content-Type'), 'text/html; charset=UTF-8',
- 'Content-Type with charset'
-);
+{
+ my $res = request('/');
+ ok($res->is_success, 'get main page');
+ like($res->decoded_content, qr/it works/i, 'see if it has our text');
+ is ($res->header('Content-Type'), 'text/html; charset=UTF-8',
+ 'Content-Type with charset'
+ );
+}
{
- $mech->get_ok('http://localhost/unicode_no_enc', 'get unicode_no_enc');
+ my $res = request('/unicode_no_enc');
+ ok($res->is_success, 'get unicode_no_enc');
my $exp = "\xE3\x81\xBB\xE3\x81\x92";
- my $got = Encode::encode_utf8($mech->content);
+ my $got = Encode::encode_utf8($res->decoded_content);
- is ($mech->response->header('Content-Type'), 'text/plain',
+ is ($res->header('Content-Type'), 'text/plain',
'Content-Type with no charset');
is($got, $exp, 'content contains hoge');
}
{
- $mech->get_ok('http://localhost/unicode', 'get unicode');
+ my $res = request('/unicode');
+ ok( $res->is_success, 'get unicode');
- is ($mech->response->header('Content-Type'), 'text/plain; charset=UTF-8',
+ is ($res->header('Content-Type'), 'text/plain; charset=UTF-8',
'Content-Type with charset');
my $exp = "\xE3\x81\xBB\xE3\x81\x92";
- my $got = Encode::encode_utf8($mech->content);
+ my $got = Encode::encode_utf8($res->decoded_content);
is($got, $exp, 'content contains hoge');
}
{
- $mech->get_ok('http://localhost/not_unicode', 'get bytes');
+ my $res = request('/not_unicode');
+ ok($res->is_success, 'get bytes');
my $exp = "\xE1\x88\xB4\xE5\x99\xB8";
- my $got = Encode::encode_utf8($mech->content);
+ my $got = Encode::encode_utf8($res->decoded_content);
is($got, $exp, 'got 1234 5678');
}
{
- $mech->get_ok('http://localhost/file', 'get file');
- $mech->content_like(qr/this is a test/, 'got filehandle contents');
+ my $res = request('/file');
+ ok($res->is_success, 'get file');
+ like($res->decoded_content, qr/this is a test/, 'got filehandle contents');
}
{
# The latin 1 case is the one everyone forgets. I want to really make sure
# its right, so lets check the damn bytes.
- $mech->get_ok('http://localhost/latin1', 'get latin1');
- is ($mech->response->header('Content-Type'), 'text/plain; charset=UTF-8',
+ my $res = request('/latin1');
+ ok($res->is_success, 'get latin1');
+ is ($res->header('Content-Type'), 'text/plain; charset=UTF-8',
'Content-Type with charset');
my $exp = "LATIN SMALL LETTER E WITH ACUTE: \xC3\xA9";
- my $got = Encode::encode_utf8($mech->content);
+ my $got = Encode::encode_utf8($res->decoded_content);
is ($got, $exp, 'content octets are UTF-8');
}
{
- $mech->get_ok('http://localhost/shift_jis', 'get shift_jis');
- is ($mech->response->header('Content-Type'), 'text/plain; charset=Shift_JIS', 'Content-Type with charset');
+ my $res = request('/shift_jis');
+ ok($res->is_success, 'get shift_jis');
+ is ($res->header('Content-Type'), 'text/plain; charset=Shift_JIS', 'Content-Type with charset');
my $exp = "\xE3\x81\xBB\xE3\x81\x92";
- my $got = Encode::encode_utf8($mech->content);
+ my $got = Encode::encode_utf8($res->decoded_content);
is ($got, $exp, 'content octets are Shift_JIS');
}
use Net::EmptyPort qw(wait_port empty_port);
use Try::Tiny;
use Plack::Builder;
-
-eval { require Catalyst::Devel; Catalyst::Devel->VERSION(1.0); 1; } || do {
- fail("Could not load Catalyst::Devel: $@");
- exit 1;
-};
-
-eval { require File::Copy::Recursive; 1 } || do {
- fail("Could not load File::Copy::Recursive: $@");
- exit 1;
-};
+use lib 't/lib';
+use MakeTestApp;
# Run a single test by providing it as the first arg
my $single_test = shift;
-my $tmpdir = "$FindBin::Bin/../../t/tmp";
-
-# clean up
-rmtree $tmpdir if -d $tmpdir;
-
-# create a TestApp and copy the test libs into it
-mkdir $tmpdir;
-chdir $tmpdir;
-system( $^X, "-I$FindBin::Bin/../../lib", "$FindBin::Bin/../../script/catalyst.pl", 'TestApp' );
-chdir "$FindBin::Bin/..";
-File::Copy::Recursive::dircopy( '../t/lib', '../t/tmp/TestApp/lib' ) or die;
-
-# remove TestApp's tests
-rmtree '../t/tmp/TestApp/t' or die;
+my $test_app_dir = make_test_app;
# spawn the standalone HTTP server
my $port = empty_port;
wait_port_timeout($port, 30);
} elsif ($pid == 0) {
# child process
- unshift @INC, "$tmpdir/TestApp/lib", "$FindBin::Bin/../../lib";
+ unshift @INC, "$test_app_dir/lib", "$FindBin::Bin/../../lib";
require TestApp;
my $psgi_app = TestApp->apply_default_middlewares(TestApp->psgi_app);
+++ /dev/null
-use strict;
-use warnings;
-use Test::More;
-use utf8;
-
-# setup library path
-use FindBin qw($Bin);
-use lib "$Bin/../../t/lib";
-
-BEGIN { eval { require Catalyst::Plugin::Params::Nested; 1; } ||
- plan skip_all => 'Need Catalyst::Plugin::Params::Nested' }
-
-use Catalyst::Test 'TestApp2';
-use Encode;
-use HTTP::Request::Common;
-use URI::Escape qw/uri_escape_utf8/;
-use HTTP::Status 'is_server_error';
-
-my $encode_str = "\x{e3}\x{81}\x{82}"; # e38182 is japanese 'あ'
-my $decode_str = Encode::decode('utf-8' => $encode_str);
-my $escape_str = uri_escape_utf8($decode_str);
-
-BEGIN {
- eval 'require Catalyst::Plugin::Params::Nested';
- plan skip_all => 'Catalyst::Plugin::Params::Nested is required' if $@;
-}
-
-{
- my ($res, $c) = ctx_request("/?foo.1=bar&foo.2=$escape_str");
- is( $c->res->output, '<h1>It works</h1>', 'Content displayed' );
-
- my $got = $c->request->parameters;
- my $expected = {
- 'foo.1' => 'bar',
- 'foo.2' => $decode_str,
- 'foo' => [undef, 'bar', $decode_str],
- };
-
- is( $got->{foo}->[0], undef, '{foo}->[0] is undef' );
- is( $got->{foo}->[1], 'bar', '{foo}->[1] is bar' );
- ok( utf8::is_utf8( $got->{'foo.2'} ), '{foo.2} is utf8' );
- ok( utf8::is_utf8( $got->{foo}->[2] ), '{foo}->[2] is utf8' );
- is_deeply($got, $expected, 'nested params' );
-}
-
-{
- my ($res, $c) = ctx_request("/?foo.1=bar&foo.2=$escape_str&bar.baz=$escape_str&baz.bar.foo=$escape_str&&arr.0.1=$escape_str");
-
- my $got = $c->request->parameters;
- my $expected = {
- 'foo.1' => 'bar',
- 'foo.2' => $decode_str,
- 'bar.baz' => $decode_str,
- 'baz.bar.foo' => $decode_str,
- 'arr.0.1' => $decode_str,
- 'arr' => [ [undef, $decode_str] ],
- 'foo' => [undef, 'bar', $decode_str],
- 'bar' => { baz => $decode_str },
- 'baz' => { bar => { foo => $decode_str } },
- };
-
- is( ref $got->{arr}->[0], 'ARRAY', '{arr}->[0] is ARRAY' );
- ok( utf8::is_utf8( $got->{arr}->[0]->[1] ), '{arr}->[0]->[1] is utf8' );
- ok( utf8::is_utf8( $got->{bar}{baz} ), '{bar}{baz} is utf8' );
- ok( utf8::is_utf8( $got->{baz}{bar}{foo} ), '{baz}{bar}{foo} is utf8' );
- is_deeply($got, $expected, 'nested params' );
-}
-
-done_testing();