Permalink
Browse files

Support Plack::Test::Suite new API. closes #3

  • Loading branch information...
1 parent a321c86 commit d92d8c76c1b1013bcc3f9fb2fdb1a8da7c9d7399 @spiritloose committed Oct 9, 2009
Showing with 50 additions and 66 deletions.
  1. +1 −1 .gitignore
  2. +1 −1 configure.ac
  3. +4 −0 t/{Makefile → Makefile.in}
  4. +0 −2 t/mkconf.pl
  5. +44 −52 t/suite.t
  6. +0 −10 t/test.conf.tt
View
@@ -5,7 +5,7 @@
*.o
*.slo
/t/test.conf
-/Makefile
+Makefile
/autom4te*.cache
/config.log
/config.status
View
@@ -33,7 +33,7 @@ if test "$PERL" = no; then
fi
AC_SUBST(PERL)
-AC_OUTPUT(Makefile)
+AC_OUTPUT([Makefile t/Makefile])
echo "
$PACKAGE_NAME $PACKAGE_VERSION configuration:
@@ -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
test: test.conf
prove -I.. .
View
@@ -43,14 +43,12 @@ sub make_params {
chdir_do $Bin => sub {
push @files, $_ while <[0-9]*.t>;
$dir = getcwd;
- require 'suite.t';
};
no warnings 'once';
+{
dir => $dir,
files => \@files,
path => $t::TestModPSGI::Path,
- port => $main::Port,
};
}
View
@@ -1,60 +1,52 @@
use strict;
use warnings;
-
use Test::More;
+use File::Temp;
use Plack::Test::Suite;
-use Path::Class;
-
-our $Port = $ENV{PLACK_TEST_SUITE_PORT} || 8080;
-
-$Plack::Test::Suite::BaseDir = do {
- my $dir = do {
- if ($ENV{PLACK_DIR}) {
- dir($ENV{PLACK_DIR})->file('t')->stringify;
- } else {
- my $pmdir = file($INC{'Plack/Test/Suite.pm'})->dir;
- $pmdir->file('..', '..', '..', 't')->resolve->stringify;
- }
- };
- die "Plack test dir 't' not found" unless -e $dir;
- $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;
+
+warn $ENV{HTTPD};
+Plack::Test::Suite->run_server_tests(\&run_httpd);
+done_testing();
+
+sub run_httpd {
+ my $port = shift;
+
+ my $tmpdir = $ENV{APACHE2_TMP_DIR} || File::Temp::tempdir( CLEANUP => 1 );
+
+ write_file("$tmpdir/app.psgi", _render_psgi());
+ write_file("$tmpdir/httpd.conf", _render_conf($tmpdir, $port, "$tmpdir/app.psgi"));
+
+ exec "httpd -X -D FOREGROUND -f $tmpdir/httpd.conf";
}
-sub runtests {
- require LWP::UserAgent;
- my $ua = LWP::UserAgent->new;
- my $index = 0;
- Plack::Test::Suite->runtests(sub {
- 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 write_file {
+ my($path, $content) = @_;
+
+ open my $out, ">", $path or die "$path: $!";
+ print $out $content;
}
+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
+}
View
@@ -6,13 +6,3 @@ PassEnv PERL5LIB
PSGIApp [% dir %]/[% file %]
</Location>
[% 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.