diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2001-06-18 04:17:15 +0000 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2001-06-18 04:17:15 +0000 |
commit | b695f709e8a342e35e482b0437eb6cdacdc58b6b (patch) | |
tree | 2d16192636e6ba806ff7a907f682c74f7705a920 /lib/Net | |
parent | d780cd7a0195e946e636d3ee546f6ef4f21d6acc (diff) | |
download | perl-b695f709e8a342e35e482b0437eb6cdacdc58b6b.tar.gz |
The Grand Trek: move the *.t files from t/ to lib/ and ext/.
No doubt I made some mistakes like missed some files or
misnamed some files. The naming rules were more or less:
(1) if the module is from CPAN, follows its ways, be it
t/*.t or test.pl.
(2) otherwise if there are multiple tests for a module
put them in a t/
(3) otherwise if there's only one test put it in Module.t
(4) helper files go to module/ (locale, strict, warnings)
(5) use longer filenames now that we can (but e.g. the
compat-0.6.t and the Text::Balanced test files still
were renamed to be more civil against the 8.3 people)
installperl was updated appropriately not to install the
*.t files or the help files from under lib.
TODO: some helper files still remain under t/ that could
follow their 'masters'. UPDATE: On second thoughts, why
should they. They can continue to live under t/lib, and
in fact the locale/strict/warnings helpers that were moved
could be moved back. This way the amount of non-installable
stuff under lib/ stays smaller.
p4raw-id: //depot/perl@10676
Diffstat (limited to 'lib/Net')
-rw-r--r-- | lib/Net/hostent.t | 72 | ||||
-rw-r--r-- | lib/Net/netent.t | 36 | ||||
-rw-r--r-- | lib/Net/protoent.t | 38 | ||||
-rw-r--r-- | lib/Net/servent.t | 38 |
4 files changed, 184 insertions, 0 deletions
diff --git a/lib/Net/hostent.t b/lib/Net/hostent.t new file mode 100644 index 0000000000..c3a12194ec --- /dev/null +++ b/lib/Net/hostent.t @@ -0,0 +1,72 @@ +#!./perl -w + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; + 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; + } +} + +BEGIN { $| = 1; print "1..7\n"; } + +END {print "not ok 1\n" unless $loaded;} + +use Net::hostent; + +$loaded = 1; +print "ok 1\n"; + +# 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"; + +print "not " if inet_ntoa($h->addr) ne "127.0.0.1"; +print "ok 4\n"; + +print "not " if inet_ntoa($i->addr) ne "127.0.0.1"; +print "ok 5\n"; + +# need to skip the name comparisons on Win32 because windows will +# return the name of the machine instead of "localhost" when resolving +# 127.0.0.1 or even "localhost" + +# 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; + } + } + 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; + } + } + print "not " if $in_alias; + } else { + print "not " unless $i->name =~ /^localhost(?:\..+)?$/i; + } + print "ok 7 # ",$h->name, " ", join (",", @{$h->aliases}), "\n"; +} diff --git a/lib/Net/netent.t b/lib/Net/netent.t new file mode 100644 index 0000000000..e73122ccc4 --- /dev/null +++ b/lib/Net/netent.t @@ -0,0 +1,36 @@ +#!./perl + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; +} + +BEGIN { + our $hasne; + eval { my @n = getnetbyname "loopback" }; + $hasne = 1 unless $@ && $@ =~ /unimplemented/; + unless ($hasne) { print "1..0 # Skip: no getnetbyname\n"; exit 0 } + use Config; + $hasne = 0 unless $Config{'i_netdb'} eq 'define'; + unless ($hasne) { print "1..0 # Skip: no netdb.h\n"; exit 0 } +} + +BEGIN { + our @netent = getnetbyname "loopback"; # This is the function getnetbyname. + unless (@netent) { print "1..0 # Skip: no loopback net\n"; exit 0 } +} + +print "1..2\n"; + +use Net::netent; + +print "ok 1\n"; + +my $netent = getnetbyname "loopback"; # This is the OO getnetbyname. + +print "not " unless $netent->name eq $netent[0]; +print "ok 2\n"; + +# Testing pretty much anything else is unportable; +# e.g. the canonical name of the "loopback" net may be "loop". + diff --git a/lib/Net/protoent.t b/lib/Net/protoent.t new file mode 100644 index 0000000000..6c5a1547b3 --- /dev/null +++ b/lib/Net/protoent.t @@ -0,0 +1,38 @@ +#!./perl + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; +} + +BEGIN { + our $haspe; + eval { my @n = getprotobyname "tcp" }; + $haspe = 1 unless $@ && $@ =~ /unimplemented/; + unless ($haspe) { print "1..0 # Skip: no getprotobyname\n"; exit 0 } + use Config; + $haspe = 0 unless $Config{'i_netdb'} eq 'define'; + unless ($haspe) { print "1..0 # Skip: no netdb.h\n"; exit 0 } +} + +BEGIN { + our @protoent = getprotobyname "tcp"; # This is the function getprotobyname. + unless (@protoent) { print "1..0 # Skip: no tcp protocol\n"; exit 0 } +} + +print "1..3\n"; + +use Net::protoent; + +print "ok 1\n"; + +my $protoent = getprotobyname "tcp"; # This is the OO getprotobyname. + +print "not " unless $protoent->name eq $protoent[0]; +print "ok 2\n"; + +print "not " unless $protoent->proto == $protoent[2]; +print "ok 3\n"; + +# Testing pretty much anything else is unportable. + diff --git a/lib/Net/servent.t b/lib/Net/servent.t new file mode 100644 index 0000000000..ef4a04dee8 --- /dev/null +++ b/lib/Net/servent.t @@ -0,0 +1,38 @@ +#!./perl + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; +} + +BEGIN { + our $hasse; + eval { my @n = getservbyname "echo", "tcp" }; + $hasse = 1 unless $@ && $@ =~ /unimplemented/; + unless ($hasse) { print "1..0 # Skip: no getservbyname\n"; exit 0 } + use Config; + $hasse = 0 unless $Config{'i_netdb'} eq 'define'; + unless ($hasse) { print "1..0 # Skip: no netdb.h\n"; exit 0 } +} + +BEGIN { + our @servent = getservbyname "echo", "tcp"; # This is the function getservbyname. + unless (@servent) { print "1..0 # Skip: no echo service\n"; exit 0 } +} + +print "1..3\n"; + +use Net::servent; + +print "ok 1\n"; + +my $servent = getservbyname "echo", "tcp"; # This is the OO getservbyname. + +print "not " unless $servent->name eq $servent[0]; +print "ok 2\n"; + +print "not " unless $servent->port == $servent[2]; +print "ok 3\n"; + +# Testing pretty much anything else is unportable. + |