generate app for live tests manually rather than using Catalyst::Devel
Graham Knop [Fri, 19 Jun 2020 19:39:31 +0000 (21:39 +0200)]
Most of the files generated by Catalyst::Devel aren't needed, so it's
trivial to replace.  This avoids a circular dependency for developers.

Makefile.PL
t/lib/MakeTestApp.pm [new file with mode: 0644]
t/optional_apache-cgi-rewrite.pl
t/optional_apache-cgi.pl
t/optional_apache-fastcgi-non-root.pl
t/optional_apache-fastcgi.pl
t/optional_http-server-restart.t
t/optional_lighttpd-fastcgi-non-root.t
t/optional_lighttpd-fastcgi.t
xt/author/http-server.t

index 8b366c6..7b22c25 100644 (file)
@@ -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 (file)
index 0000000..c48c501
--- /dev/null
@@ -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;
index abf467e..ebfe69c 100644 (file)
@@ -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';
 
index f81c7c4..09363a6 100644 (file)
@@ -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';
 
index bc1b2a5..3b5eae9 100644 (file)
@@ -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';
 
index 95c3702..adc68ea 100644 (file)
@@ -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';
 
index 9d58e08..ff7049d 100644 (file)
@@ -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 );
index dd70236..c402090 100644 (file)
@@ -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";
index 9e4daf1..1d3ca40 100644 (file)
@@ -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";
index 8667cad..ffd95c0 100644 (file)
@@ -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);