Skip to content

Commit

Permalink
Support Plack::Test::Suite new API. closes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
spiritloose committed Oct 9, 2009
1 parent a321c86 commit d92d8c7
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -5,7 +5,7 @@
*.o *.o
*.slo *.slo
/t/test.conf /t/test.conf
/Makefile Makefile
/autom4te*.cache /autom4te*.cache
/config.log /config.log
/config.status /config.status
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Expand Up @@ -33,7 +33,7 @@ if test "$PERL" = no; then
fi fi
AC_SUBST(PERL) AC_SUBST(PERL)


AC_OUTPUT(Makefile) AC_OUTPUT([Makefile t/Makefile])


echo " echo "
$PACKAGE_NAME $PACKAGE_VERSION configuration: $PACKAGE_NAME $PACKAGE_VERSION configuration:
Expand Down
4 changes: 4 additions & 0 deletions t/Makefile → t/Makefile.in
@@ -1,3 +1,7 @@
APXS=@APXS@
AP_SBINDIR=$(shell $(APXS) -q sbindir)
AP_PROGNAME=$(shell $(APXS) -q progname)
HTTPD=$(AP_SBINDIR)/$(AP_PROGNAME)
all: conf all: conf
test: test.conf test: test.conf
prove -I.. . prove -I.. .
Expand Down
2 changes: 0 additions & 2 deletions t/mkconf.pl
Expand Up @@ -43,14 +43,12 @@ sub make_params {
chdir_do $Bin => sub { chdir_do $Bin => sub {
push @files, $_ while <[0-9]*.t>; push @files, $_ while <[0-9]*.t>;
$dir = getcwd; $dir = getcwd;
require 'suite.t';
}; };
no warnings 'once'; no warnings 'once';
+{ +{
dir => $dir, dir => $dir,
files => \@files, files => \@files,
path => $t::TestModPSGI::Path, path => $t::TestModPSGI::Path,
port => $main::Port,
}; };
} }


Expand Down
96 changes: 44 additions & 52 deletions t/suite.t
@@ -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
}
10 changes: 0 additions & 10 deletions t/test.conf.tt
Expand Up @@ -6,13 +6,3 @@ PassEnv PERL5LIB
PSGIApp [% dir %]/[% file %] PSGIApp [% dir %]/[% file %]
</Location> </Location>
[% END -%] [% END -%]

NameVirtualHost *:[% port %]
Listen [% port %]
<VirtualHost *:[% port %]>
ServerName plack.test.suite
<Location />
SetHandler psgi
PSGIApp [% dir %]/suite.t
</Location>
</VirtualHost>

0 comments on commit d92d8c7

Please sign in to comment.