This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate CPAN release of version.pm 0.9905
[perl5.git] / cpan / libnet / t / hostname.t
CommitLineData
302cc833
GB
1#!./perl -w
2
3BEGIN {
4 unless (-d 'blib') {
5 chdir 't' if -d 't';
6 @INC = '../lib';
7 }
1a8dcddb
JH
8 if (!eval "require Socket") {
9 print "1..0 # no Socket\n"; exit 0;
10 }
8b14f033
JH
11 if (ord('A') == 193 && !eval "require Convert::EBCDIC") {
12 print "1..0 # EBCDIC but no Convert::EBCDIC\n"; exit 0;
13 }
302cc833 14}
406c51ee 15
c20cde70 16use Net::Domain qw(hostname domainname hostdomain hostfqdn);
406c51ee
JH
17use Net::Config;
18
19unless($NetConfig{test_hosts}) {
20 print "1..0\n";
21 exit 0;
22}
23
c20cde70 24print "1..5\n";
406c51ee
JH
25
26$domain = domainname();
27
28if(defined $domain && $domain ne "") {
adeb9412
RS
29 print "ok 1 - defined, non-empty domainname\n";
30}
31elsif (not defined $domain) {
32 print "ok 1 # SKIP domain not fully defined\n";
406c51ee
JH
33}
34else {
35 print "not ok 1\n";
36}
0d375cdb 37
f92f3fcb 38# This checks thats hostanme does not overwrite $_
0d375cdb
GB
39my @domain = qw(foo.example.com bar.example.jp);
40my @copy = @domain;
41
f92f3fcb 42my @dummy = grep { defined hostname() and hostname() eq $_ } @domain;
0d375cdb
GB
43
44($domain[0] && $domain[0] eq $copy[0])
45 ? print "ok 2\n"
46 : print "not ok 2\n";
c20cde70
SP
47
48@dummy = grep { defined hostdomain() and hostdomain() eq $_ } @domain;
49
50($domain[0] && $domain[0] eq $copy[0])
51 ? print "ok 3\n"
52 : print "not ok 3\n";
53
efa2a43b
SP
54my $name = hostname();
55my $domain = hostdomain();
56if(defined $domain && defined $name && $name ne "" && $domain ne "") {
57 hostfqdn() eq $name . "." . $domain ? print "ok 4\n" : print "not ok 4\n";
58 domainname() eq $name . "." . $domain ? print "ok 5\n" : print "not ok 5\n";} else {
59 print "ok 4 # SKIP domain not fully defined\n";
60 print "ok 5 # SKIP domain not fully defined\n";
61}