]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/cgi.t
tests: move t/common.perl to PublicInbox::TestCommon
[public-inbox.git] / t / cgi.t
diff --git a/t/cgi.t b/t/cgi.t
index 51d649142cabda7aecb2ed453b76d546e475753c..424b738e2c4c68aceaa7a97f42ecc07d86871358 100644 (file)
--- a/t/cgi.t
+++ b/t/cgi.t
@@ -6,12 +6,8 @@ use strict;
 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";
-my $tmpdir = tempdir('pi-cgi-XXXXXX', TMPDIR => 1, CLEANUP => 1);
+use PublicInbox::TestCommon;
+my ($tmpdir, $for_destroy) = tmpdir();
 my $home = "$tmpdir/pi-home";
 my $pi_home = "$home/.public-inbox";
 my $pi_config = "$pi_home/config";
@@ -29,7 +25,7 @@ my $cfgpfx = "publicinbox.test";
        close $fh or die "close: $!\n";
        my %cfg = (
                "$cfgpfx.address" => $addr,
-               "$cfgpfx.mainrepo" => $maindir,
+               "$cfgpfx.inboxdir" => $maindir,
                "$cfgpfx.indexlevel" => 'basic',
        );
        while (my ($k,$v) = each %cfg) {
@@ -145,11 +141,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 +153,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 }
 }