xref: /openbsd-src/gnu/usr.bin/perl/cpan/libnet/t/nntp.t (revision eac174f2741a08d8deb8aae59a7f778ef9b5d770)
1b8851fccSafresh1#!perl
2b8851fccSafresh1
3b8851fccSafresh1use 5.008001;
4b8851fccSafresh1
5b8851fccSafresh1use strict;
6b8851fccSafresh1use warnings;
7b39c5158Smillert
8b39c5158SmillertBEGIN {
9b8851fccSafresh1    if (!eval { require Socket }) {
10*eac174f2Safresh1        print "1..0 # Skip: no Socket\n"; exit 0;
11b39c5158Smillert    }
12b8851fccSafresh1    if (ord('A') == 193 && !eval { require Convert::EBCDIC }) {
13*eac174f2Safresh1        print "1..0 # Skip: EBCDIC but no Convert::EBCDIC\n"; exit 0;
14b39c5158Smillert    }
15b39c5158Smillert}
16b39c5158Smillert
17b39c5158Smillertuse Net::Config;
18b39c5158Smillertuse Net::NNTP;
19b39c5158Smillertuse Net::Cmd qw(CMD_REJECT);
20b39c5158Smillert
21*eac174f2Safresh1unless(@{$NetConfig{nntp_hosts}}) {
22*eac174f2Safresh1    print "1..0 # Skip: no nntp_hosts defined in config\n";
23*eac174f2Safresh1    exit;
24*eac174f2Safresh1}
25*eac174f2Safresh1
26*eac174f2Safresh1unless($NetConfig{test_hosts}) {
27*eac174f2Safresh1    print "1..0 # Skip: test_hosts not enabled in config\n";
28b39c5158Smillert    exit;
29b39c5158Smillert}
30b39c5158Smillert
31b39c5158Smillertprint "1..4\n";
32b39c5158Smillert
33b39c5158Smillertmy $i = 1;
34b39c5158Smillert
35b8851fccSafresh1my $nntp = Net::NNTP->new(Debug => 0)
36b39c5158Smillert        or (print("not ok 1\n"), exit);
37b39c5158Smillert
38b39c5158Smillertprint "ok 1\n";
39b39c5158Smillert
40b8851fccSafresh1my @grp;
41b8851fccSafresh1foreach my $grp (qw(test alt.test control news.announce.newusers)) {
42b39c5158Smillert    @grp = $nntp->group($grp);
43b39c5158Smillert    last if @grp;
44b39c5158Smillert}
45b39c5158Smillert
46b39c5158Smillertif($nntp->status == CMD_REJECT) {
47b39c5158Smillert    # Command was rejected, probably because we need authinfo
48b39c5158Smillert    map { print "ok ",$_,"\n" } 2,3,4;
49b39c5158Smillert    exit;
50b39c5158Smillert}
51b39c5158Smillert
52b39c5158Smillertprint "not " unless @grp;
53b39c5158Smillertprint "ok 2\n";
54b39c5158Smillert
55b39c5158Smillert
56b39c5158Smillertif(@grp && $grp[2] > $grp[1]) {
57b39c5158Smillert    $nntp->head($grp[1]) or print "not ";
58b39c5158Smillert}
59b39c5158Smillertprint "ok 3\n";
60b39c5158Smillert
61b39c5158Smillertif(@grp) {
62b39c5158Smillert    $nntp->quit or print "not ";
63b39c5158Smillert}
64b39c5158Smillertprint "ok 4\n";
65b39c5158Smillert
66