]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/nntpd.t
tests: skip properly with git <2.6
[public-inbox.git] / t / nntpd.t
index 14db1a93019771426635cecc8fafedd9d2c7c920..18aaccbea50f6c0a7a5c853c9ee75df5b5abb007 100644 (file)
--- a/t/nntpd.t
+++ b/t/nntpd.t
@@ -1,4 +1,4 @@
-# Copyright (C) 2015-2020 all contributors <meta@public-inbox.org>
+# Copyright (C) 2015-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use warnings;
@@ -8,17 +8,16 @@ use PublicInbox::Spawn qw(which);
 require_mods(qw(DBD::SQLite));
 require PublicInbox::InboxWritable;
 use PublicInbox::Eml;
-use IO::Socket;
 use Socket qw(IPPROTO_TCP TCP_NODELAY);
 use Net::NNTP;
 use Sys::Hostname;
 use POSIX qw(_exit);
 use Digest::SHA;
-use_ok 'PublicInbox::Msgmap';
 
 # t/nntpd-v2.t wraps this for v2
 my $version = $ENV{PI_TEST_VERSION} || 1;
 require_git('2.6') if $version == 2;
+use_ok 'PublicInbox::Msgmap';
 my $lsof = which('lsof');
 my $fast_idle = eval { require Linux::Inotify2; 1 } //
                eval { require IO::KQueue; 1 };
@@ -34,6 +33,7 @@ my $addr = $group . '@example.com';
 
 my %opts;
 my $sock = tcp_server();
+my $host_port = tcp_host_port($sock);
 my $td;
 my $len;
 
@@ -96,10 +96,8 @@ EOF
                }
        }
 
-       ok($sock, 'sock created');
        my $cmd = [ '-nntpd', '-W0', "--stdout=$out", "--stderr=$err" ];
        $td = start_script($cmd, undef, { 3 => $sock });
-       my $host_port = $sock->sockhost . ':' . $sock->sockport;
        my $n = Net::NNTP->new($host_port);
        my $list = $n->list;
        ok(delete $list->{'x.y.z'}, 'deleted x.y.z group');
@@ -349,7 +347,7 @@ Date: Fri, 02 Oct 1993 00:00:00 +0000
        # -compact requires Xapian
        SKIP: {
                require_mods('Search::Xapian', 2);
-               which('xapian-compact') or skip 'xapian-compact missing', 2;
+               have_xapian_compact or skip 'xapian-compact missing', 2;
                is(xsys(qw(git config), "--file=$home/.public-inbox/config",
                                "publicinbox.$group.indexlevel", 'medium'),
                        0, 'upgraded indexlevel');
@@ -376,7 +374,7 @@ Date: Fri, 02 Oct 1993 00:00:00 +0000
                my @of = xqx([$lsof, '-p', $td->{pid}], undef, $noerr);
                is(scalar(grep(/\(deleted\)/, @of)), 0, 'no deleted files');
        };
-       SKIP: { test_watch($tmpdir, $sock, $group) };
+       SKIP: { test_watch($tmpdir, $host_port, $group) };
        {
                setsockopt($s, IPPROTO_TCP, TCP_NODELAY, 1);
                syswrite($s, 'HDR List-id 1-');
@@ -417,7 +415,7 @@ sub read_til_dot {
 }
 
 sub test_watch {
-       my ($tmpdir, $sock, $group) = @_;
+       my ($tmpdir, $host_port, $group) = @_;
        use_ok 'PublicInbox::Watch';
        use_ok 'PublicInbox::InboxIdle';
        use_ok 'PublicInbox::Config';
@@ -432,8 +430,7 @@ sub test_watch {
        my $url = "http://example.com/i1";
        my $inboxdir = "$tmpdir/watchnntp";
        my $cmd = ['-init', '-V1', '-Lbasic', $name, $inboxdir, $url, $addr];
-       my ($ihost, $iport) = ($sock->sockhost, $sock->sockport);
-       my $nntpurl = "nntp://$ihost:$iport/$group";
+       my $nntpurl = "nntp://$host_port/$group";
        run_script($cmd) or BAIL_OUT("init $name");
        xsys(qw(git config), "--file=$home/.public-inbox/config",
                        "publicinbox.$name.watch",