]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/nntpd.t
remove most internal Email::MIME usage
[public-inbox.git] / t / nntpd.t
index 43b14d66389ab6544a38b22d453f33e7295f00f7..69f72ce12163ef453f8171a3494b23b326b7cdf8 100644 (file)
--- a/t/nntpd.t
+++ b/t/nntpd.t
@@ -4,11 +4,10 @@ use strict;
 use warnings;
 use Test::More;
 use PublicInbox::TestCommon;
+use PublicInbox::Spawn qw(which);
 require_mods(qw(DBD::SQLite));
-require PublicInbox::SearchIdx;
-require PublicInbox::Msgmap;
 require PublicInbox::InboxWritable;
-use Email::Simple;
+use PublicInbox::Eml;
 use IO::Socket;
 use Socket qw(IPPROTO_TCP TCP_NODELAY);
 use Net::NNTP;
@@ -48,7 +47,7 @@ $ibx = PublicInbox::Inbox->new($ibx);
        my @cmd = ('-init', $group, $inboxdir, 'http://example.com/', $addr);
        push @cmd, "-V$version", '-Lbasic';
        ok(run_script(\@cmd), 'init OK');
-       is(system(qw(git config), "--file=$home/.public-inbox/config",
+       is(xsys(qw(git config), "--file=$home/.public-inbox/config",
                        "publicinbox.$group.newsgroup", $group),
                0, 'enabled newsgroup');
        my $len;
@@ -58,7 +57,7 @@ $ibx = PublicInbox::Inbox->new($ibx);
 
        # ensure successful message delivery
        {
-               my $mime = Email::MIME->new(<<EOF);
+               my $mime = PublicInbox::Eml->new(<<EOF);
 To: =?utf-8?Q?El=C3=A9anor?= <you\@example.com>
 From: =?utf-8?Q?El=C3=A9anor?= <me\@example.com>
 Cc: $addr
@@ -78,8 +77,8 @@ EOF
                $im->add($mime);
                $im->done;
                if ($version == 1) {
-                       my $s = PublicInbox::SearchIdx->new($ibx, 1);
-                       $s->index_sync;
+                       ok(run_script(['-index', $ibx->{inboxdir}]),
+                               'indexed v1');
                }
        }
 
@@ -242,7 +241,7 @@ EOF
                ok($date <= $t1, 'valid date before stop');
        }
        if ('leafnode interop') {
-               my $for_leafnode = PublicInbox::MIME->new(<<"");
+               my $for_leafnode = PublicInbox::Eml->new(<<"");
 From: longheader\@example.com
 To: $addr
 Subject: none
@@ -253,8 +252,8 @@ Date: Fri, 02 Oct 1993 00:00:00 +0000
                $im->add($for_leafnode);
                $im->done;
                if ($version == 1) {
-                       my $s = PublicInbox::SearchIdx->new($ibx, 1);
-                       $s->index_sync;
+                       ok(run_script(['-index', $ibx->{inboxdir}]),
+                               'indexed v1');
                }
                my $hdr = $n->head("<$long_hdr>");
                my $expect = qr/\AMessage-ID: /i . qr/\Q<$long_hdr>\E/;
@@ -268,7 +267,7 @@ Date: Fri, 02 Oct 1993 00:00:00 +0000
                        $for_leafnode->header_set('Message-ID', @mids);
                        $for_leafnode->body_set('not-a-dupe');
                        my $warn = '';
-                       $SIG{__WARN__} = sub { $warn .= join('', @_) };
+                       local $SIG{__WARN__} = sub { $warn .= join('', @_) };
                        $im->add($for_leafnode);
                        $im->done;
                        like($warn, qr/reused/, 'warned for reused MID');
@@ -304,7 +303,9 @@ Date: Fri, 02 Oct 1993 00:00:00 +0000
                if ($INC{'Search/Xapian.pm'} && ($ENV{TEST_RUN_MODE}//2)) {
                        skip 'Search/Xapian.pm pre-loaded (by t/run.perl?)', 1;
                }
-               my @of = `lsof -p $td->{pid} 2>/dev/null`;
+               my $lsof = which('lsof') or skip 'lsof missing', 1;
+               my $rdr = { 2 => \(my $null) };
+               my @of = xqx([$lsof, '-p', $td->{pid}], undef, $rdr);
                skip('lsof broken', 1) if (!scalar(@of) || $?);
                my @xap = grep m!Search/Xapian!, @of;
                is_deeply(\@xap, [], 'Xapian not loaded in nntpd');
@@ -328,12 +329,12 @@ Date: Fri, 02 Oct 1993 00:00:00 +0000
 
        $n = $s = undef;
        $td->join;
-       my $eout = eval {
-               local $/;
+       is($?, 0, 'no error in exited process');
+       my $eout = do {
                open my $fh, '<', $err or die "open $err failed: $!";
+               local $/;
                <$fh>;
        };
-       is($?, 0, 'no error in exited process');
        unlike($eout, qr/wide/i, 'no Wide character warnings');
 }