Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Plack::Test::Suite new API. closes #3
- Loading branch information
1 parent
a321c86
commit d92d8c7
Showing
6 changed files
with
50 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,60 +1,52 @@ | |||
use strict; | use strict; | ||
use warnings; | use warnings; | ||
|
|||
use Test::More; | use Test::More; | ||
use File::Temp; | |||
use Plack::Test::Suite; | use Plack::Test::Suite; | ||
use Path::Class; |
|
||
|
warn $ENV{HTTPD}; | ||
our $Port = $ENV{PLACK_TEST_SUITE_PORT} || 8080; | Plack::Test::Suite->run_server_tests(\&run_httpd); | ||
|
done_testing(); | ||
$Plack::Test::Suite::BaseDir = do { |
|
||
my $dir = do { | sub run_httpd { | ||
if ($ENV{PLACK_DIR}) { | my $port = shift; | ||
dir($ENV{PLACK_DIR})->file('t')->stringify; |
|
||
} else { | my $tmpdir = $ENV{APACHE2_TMP_DIR} || File::Temp::tempdir( CLEANUP => 1 ); | ||
my $pmdir = file($INC{'Plack/Test/Suite.pm'})->dir; |
|
||
$pmdir->file('..', '..', '..', 't')->resolve->stringify; | write_file("$tmpdir/app.psgi", _render_psgi()); | ||
} | write_file("$tmpdir/httpd.conf", _render_conf($tmpdir, $port, "$tmpdir/app.psgi")); | ||
}; |
|
||
die "Plack test dir 't' not found" unless -e $dir; | exec "httpd -X -D FOREGROUND -f $tmpdir/httpd.conf"; | ||
$dir; | |||
}; | |||
|
|||
return \&app if $ENV{MOD_PSGI}; | |||
runtests() unless caller; | |||
|
|||
sub app { | |||
my $env = shift; | |||
open my $failure_fh, '>', \my $failure; | |||
local *Test::More::builder = sub { | |||
my $builder = Test::Builder->new; | |||
$builder->failure_output($failure_fh); | |||
$builder; | |||
}; | |||
my $index = $env->{HTTP_X_PLACK_TEST}; | |||
my $test = $Plack::Test::Suite::TEST[$index]; | |||
note $test->[0]; | |||
my $app = $test->[2]; | |||
my $res = $app->($env); | |||
ok $res; | |||
close $failure_fh; | |||
$env->{'psgi.errors'}->print($failure) if $failure; | |||
$res; | |||
} | } | ||
|
|
||
sub runtests { | sub write_file { | ||
require LWP::UserAgent; | my($path, $content) = @_; | ||
my $ua = LWP::UserAgent->new; |
|
||
my $index = 0; | open my $out, ">", $path or die "$path: $!"; | ||
Plack::Test::Suite->runtests(sub { | print $out $content; | ||
my ($name, $reqgen, $handler, $test) = @_; | |||
note $name; | |||
my $req = $reqgen->($Port); | |||
$req->headers->header('X-Plack-Test' => $index++); | |||
my $res = $ua->request($req); | |||
local $Test::Builder::Level = $Test::Builder::Level + 3; | |||
$test->($res, $Port); | |||
}); | |||
done_testing; | |||
} | } | ||
|
|
||
sub _render_psgi { | |||
return <<'EOF'; | |||
use lib "lib"; | |||
use Plack::Test::Suite; | |||
Plack::Test::Suite->test_app_handler; | |||
EOF | |||
} | |||
|
|||
sub _render_conf { | |||
my ($tmpdir, $port, $psgi_path) = @_; | |||
<<"END"; | |||
LoadModule psgi_module modules/mod_psgi.so | |||
PidFile $tmpdir/httpd.pid | |||
LockFile $tmpdir/httpd.lock | |||
ErrorLog $tmpdir/error_log | |||
Listen $port | |||
<Location /> | |||
SetHandler psgi | |||
PSGIApp $tmpdir/app.psgi | |||
</Location> | |||
END | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters