From: Graham Knop Date: Fri, 19 Jun 2020 19:39:31 +0000 (+0200) Subject: generate app for live tests manually rather than using Catalyst::Devel X-Git-Tag: v5.90_127~10^2~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=8ae46e9876d7f0285d7a71eb3669a593a26ef4bb generate app for live tests manually rather than using Catalyst::Devel Most of the files generated by Catalyst::Devel aren't needed, so it's trivial to replace. This avoids a circular dependency for developers. --- diff --git a/Makefile.PL b/Makefile.PL index 8b366c6..7b22c25 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -85,9 +85,8 @@ my %META = ( 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, diff --git a/t/lib/MakeTestApp.pm b/t/lib/MakeTestApp.pm new file mode 100644 index 0000000..c48c501 --- /dev/null +++ b/t/lib/MakeTestApp.pm @@ -0,0 +1,52 @@ +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; diff --git a/t/optional_apache-cgi-rewrite.pl b/t/optional_apache-cgi-rewrite.pl index abf467e..ebfe69c 100644 --- a/t/optional_apache-cgi-rewrite.pl +++ b/t/optional_apache-cgi-rewrite.pl @@ -16,18 +16,10 @@ use File::Copy::Recursive; 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'; diff --git a/t/optional_apache-cgi.pl b/t/optional_apache-cgi.pl index f81c7c4..09363a6 100644 --- a/t/optional_apache-cgi.pl +++ b/t/optional_apache-cgi.pl @@ -16,18 +16,10 @@ use File::Copy::Recursive; 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'; diff --git a/t/optional_apache-fastcgi-non-root.pl b/t/optional_apache-fastcgi-non-root.pl index bc1b2a5..3b5eae9 100644 --- a/t/optional_apache-fastcgi-non-root.pl +++ b/t/optional_apache-fastcgi-non-root.pl @@ -16,18 +16,10 @@ use File::Copy::Recursive; 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'; diff --git a/t/optional_apache-fastcgi.pl b/t/optional_apache-fastcgi.pl index 95c3702..adc68ea 100644 --- a/t/optional_apache-fastcgi.pl +++ b/t/optional_apache-fastcgi.pl @@ -16,18 +16,10 @@ use File::Copy::Recursive; 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'; diff --git a/t/optional_http-server-restart.t b/t/optional_http-server-restart.t index 9d58e08..ff7049d 100644 --- a/t/optional_http-server-restart.t +++ b/t/optional_http-server-restart.t @@ -14,29 +14,16 @@ use LWP::Simple; 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 ); diff --git a/t/optional_lighttpd-fastcgi-non-root.t b/t/optional_lighttpd-fastcgi-non-root.t index dd70236..c402090 100644 --- a/t/optional_lighttpd-fastcgi-non-root.t +++ b/t/optional_lighttpd-fastcgi-non-root.t @@ -12,17 +12,19 @@ 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; @@ -32,18 +34,7 @@ plan skip_all => 'Please set LIGHTTPD_BIN to the path to lighttpd' 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"; diff --git a/t/optional_lighttpd-fastcgi.t b/t/optional_lighttpd-fastcgi.t index 9e4daf1..1d3ca40 100644 --- a/t/optional_lighttpd-fastcgi.t +++ b/t/optional_lighttpd-fastcgi.t @@ -12,17 +12,19 @@ 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; @@ -32,18 +34,8 @@ plan skip_all => 'Please set LIGHTTPD_BIN to the path to lighttpd' 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"; diff --git a/xt/author/http-server.t b/xt/author/http-server.t index 8667cad..ffd95c0 100644 --- a/xt/author/http-server.t +++ b/xt/author/http-server.t @@ -9,34 +9,13 @@ use FindBin; 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; @@ -48,7 +27,7 @@ if ($pid) { 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);