diff options
author | Eric Wong <e@80x24.org> | 2019-11-15 09:50:43 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2019-11-16 11:05:23 +0000 |
commit | 181f477a67c1c1f2f91e03d02987bfc7cb67af43 (patch) | |
tree | 8ec2fd34992094c8e037cd90a5eb0219910019da /t/cgi.t | |
parent | 2df8cfd320dc9efdf3c2764b2c60ec457c1b024f (diff) | |
download | public-inbox-181f477a67c1c1f2f91e03d02987bfc7cb67af43.tar.gz |
This will give us a consistent interface for running test scripts in more performant ways while still giving us a consistent interface to recreate real-world behavior via spawn() (fork + execve), if needed. The default run_mode (1) is faster and can run within the test process with some minor adjustments to our code to avoid global state. This avoids the significante overhead of Perl code loading, parsing and compilation phases.
Diffstat (limited to 't/cgi.t')
-rw-r--r-- | t/cgi.t | 16 |
1 files changed, 5 insertions, 11 deletions
@@ -7,10 +7,7 @@ use warnings; use Test::More; use Email::MIME; use File::Temp qw/tempdir/; -eval { require IPC::Run }; -plan skip_all => "missing IPC::Run for t/cgi.t" if $@; - -use constant CGI => "blib/script/public-inbox.cgi"; +require './t/common.perl'; my $tmpdir = tempdir('pi-cgi-XXXXXX', TMPDIR => 1, CLEANUP => 1); my $home = "$tmpdir/pi-home"; my $pi_home = "$home/.public-inbox"; @@ -145,11 +142,6 @@ EOF done_testing(); -sub run_with_env { - my ($env, @args) = @_; - IPC::Run::run(@args, init => sub { %ENV = (%ENV, %$env) }); -} - sub cgi_run { my %env = ( PATH_INFO => $_[0], @@ -162,7 +154,9 @@ sub cgi_run { HTTP_HOST => 'test.example.com', ); my ($in, $out, $err) = ("", "", ""); - my $rc = run_with_env(\%env, [CGI], \$in, \$out, \$err); + my $rdr = { 0 => \$in, 1 => \$out, 2 => \$err }; + run_script(['.cgi'], \%env, $rdr); + die "unexpected error: \$?=$?" if $?; my ($head, $body) = split(/\r\n\r\n/, $out, 2); - { head => $head, body => $body, rc => $rc, err => $err } + { head => $head, body => $body, err => $err } } |