summaryrefslogtreecommitdiff
path: root/lib/Net/hostent.t
diff options
context:
space:
mode:
authorMichael G. Schwern <schwern@pobox.com>2001-12-08 10:26:59 -0500
committerJarkko Hietaniemi <jhi@iki.fi>2001-12-09 15:37:48 +0000
commit0dcb34088dd10b0566805e3f894a623ad1b79305 (patch)
treefe7110ff61c91908bc12e1fbedf0716fc7ca36d6 /lib/Net/hostent.t
parentf672c0274dfe1442442c80713ab62885cdad273b (diff)
downloadperl-0dcb34088dd10b0566805e3f894a623ad1b79305.tar.gz
Cleanup and Cygwin98 oddity
Message-ID: <20011208202659.GA9017@blackrider> p4raw-id: //depot/perl@13548
Diffstat (limited to 'lib/Net/hostent.t')
-rw-r--r--lib/Net/hostent.t98
1 files changed, 56 insertions, 42 deletions
diff --git a/lib/Net/hostent.t b/lib/Net/hostent.t
index c3a12194ec..c6c721dfe8 100644
--- a/lib/Net/hostent.t
+++ b/lib/Net/hostent.t
@@ -3,36 +3,42 @@
BEGIN {
chdir 't' if -d 't';
@INC = '../lib';
+}
+
+use Test::More tests => 7;
+
+BEGIN {
require Config; import Config;
if ($Config{'extensions'} !~ /\bSocket\b/ &&
- !(($^O eq 'VMS') && $Config{d_socket})) {
- print "1..0 # Test uses Socket, Socket not built\n";
- exit 0;
+ !(($^O eq 'VMS') && $Config{d_socket}))
+ {
+ plan skip_all => "Test uses Socket, Socket not built";
}
}
-BEGIN { $| = 1; print "1..7\n"; }
-END {print "not ok 1\n" unless $loaded;}
+BEGIN { use_ok 'Net::hostent' }
-use Net::hostent;
-
-$loaded = 1;
-print "ok 1\n";
+# Remind me to add this to Test::More.
+sub BAILOUT {
+ print "Bail Out! @_\n";
+ exit;
+}
# test basic resolution of localhost <-> 127.0.0.1
use Socket;
my $h = gethost('localhost');
-print +(defined $h ? '' : 'not ') . "ok 2\n";
-my $i = gethostbyaddr(inet_aton("127.0.0.1"));
-print +(!defined $i ? 'not ' : '') . "ok 3\n";
+ok(defined $h, "gethost('localhost')") ||
+ BAILOUT("Can't continue without working gethost: $!");
-print "not " if inet_ntoa($h->addr) ne "127.0.0.1";
-print "ok 4\n";
+is( inet_ntoa($h->addr), "127.0.0.1", 'addr from gethost' );
-print "not " if inet_ntoa($i->addr) ne "127.0.0.1";
-print "ok 5\n";
+my $i = gethostbyaddr(inet_aton("127.0.0.1"));
+ok(defined $i, "gethostbyaddr('127.0.0.1')") ||
+ BAILOUT("Can't continue without working gethostbyaddr: $!");
+
+is( inet_ntoa($i->addr), "127.0.0.1", 'addr from gethostbyaddr' );
# need to skip the name comparisons on Win32 because windows will
# return the name of the machine instead of "localhost" when resolving
@@ -41,32 +47,40 @@ print "ok 5\n";
# VMS returns "LOCALHOST" under tcp/ip services V4.1 ECO 2, possibly others
# OS/390 returns localhost.YADDA.YADDA
-if ($^O eq 'MSWin32' or $^O eq 'NetWare' or $^O eq 'cygwin') {
- print "ok $_ # skipped on win32\n" for (6,7);
-} else {
- my $in_alias;
- unless ($h->name =~ /^localhost(?:\..+)?$/i) {
- foreach (@{$h->aliases}) {
- if (/^localhost(?:\..+)?$/i) {
- $in_alias = 1;
- last;
- }
+SKIP: {
+ skip "Windows will return the machine name instead of 'localhost'", 2
+ if $^O eq 'MSWin32' or $^O eq 'NetWare' or $^O eq 'cygwin';
+
+ my $in_alias;
+ unless ($h->name =~ /^localhost(?:\..+)?$/i) {
+ foreach (@{$h->aliases}) {
+ if (/^localhost(?:\..+)?$/i) {
+ $in_alias = 1;
+ last;
+ }
+ }
+ }
+
+ unless( ok( $in_alias ) ) {
+ print "# ",$h->name, " ", join (",", @{$h->aliases}), "\n";
+ }
+
+ if ($in_alias) {
+ # If we found it in the aliases before, expect to find it there again.
+ foreach (@{$h->aliases}) {
+ if (/^localhost(?:\..+)?$/i) {
+ # This time, clear the flag if we see "localhost"
+ undef $in_alias;
+ last;
+ }
+ }
+ }
+
+ if( $in_alias ) {
+ like( $i->name, qr/^localhost(?:\..+)?$/i );
}
- print "not " unless $in_alias;
- } # Else we found it as the hostname
- print "ok 6 # ",$h->name, " ", join (",", @{$h->aliases}), "\n";
-
- if ($in_alias) {
- # If we found it in the aliases before, expect to find it there again.
- foreach (@{$h->aliases}) {
- if (/^localhost(?:\..+)?$/i) {
- undef $in_alias; # This time, clear the flag if we see "localhost"
- last;
- }
+ else {
+ ok( !$in_alias );
+ print "# ",$h->name, " ", join (",", @{$h->aliases}), "\n";
}
- print "not " if $in_alias;
- } else {
- print "not " unless $i->name =~ /^localhost(?:\..+)?$/i;
- }
- print "ok 7 # ",$h->name, " ", join (",", @{$h->aliases}), "\n";
}