develooper Front page | perl.perl5.porters | Postings from November 2000

net_hostent.t (was Re: [ID 20001128.002] what's the point of example code if it is buggy?)

Thread Previous | Thread Next
From:
rspier
Date:
November 28, 2000 23:18
Subject:
net_hostent.t (was Re: [ID 20001128.002] what's the point of example code if it is buggy?)
Message ID:
14884.44445.760322.278647@localhost.localdomain
>>>>> "NC" == Nicholas Clark <nick@ccl4.org> writes:

NC> On Tue, Nov 28, 2000 at 09:43:40AM -0600, Jarkko Hietaniemi wrote:
>> On Tue, Nov 28, 2000 at 11:16:57AM +0000, Nicholas Clark wrote:

>> > 3: Net::hostent doesn't have a regression test to detected that
>> it's shagged.
>> 
>> Writing a portable test that still tests anything useful for the
>> gethost* is tough.  Remember that the contents or the existence of
>> the /etc/hosts file might be largely irrelevant to to results of
>> the gethost* calls.

NC> $ cat t/lib/net_hostent.t #!./perl -w BEGIN { $| = 1; print
NC> "1..1\n"; } END {print "not ok 1\n" unless $loaded;} use
NC> Net::hostent; $loaded = 1; print "ok 1\n";

NC> It's better than nothing? (cribbed from h2xs)


What about this one?  I added some really really simple functionality
tests, just to go a little further than simple compilation.  Tested on 
Win32 and Linux.

#!./perl -w
BEGIN { $| = 1; print "1..5\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');
my $i = gethostbyaddr(inet_aton("127.0.0.1"));

print "not " if inet_ntoa($h->addr) ne "127.0.0.1";
print "ok 2\n";

print "not " if inet_ntoa($i->addr) ne "127.0.0.1";
print "ok 3\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"

if ($^O eq 'MSWin32') {
  print "ok $_ # skipped on win32\n" for (4,5);
} else {
  print "not " if $h->name ne "localhost";
  print "ok 4\n";

  print "not " if $i->name ne "localhost";
  print "ok 5\n";
}



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About