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
November 28, 2000 23:18
net_hostent.t (was Re: [ID 20001128.002] what's the point of example code if it is buggy?)
Message ID:
>>>>> "NC" == Nicholas Clark <> 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 <->
use Socket;

my $h = gethost('localhost');
my $i = gethostbyaddr(inet_aton(""));

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

print "not " if inet_ntoa($i->addr) ne "";
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
# 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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About