Subject: | t/html.t should skip tests if there is no net connection (code provided) |
If you can predict when tests will fail (detect pre-condition),
you need to skip them :)
use warnings;
use strict;
use Test::More tests => 2;
use URI::Title qw(title);
SKIP: {
require IO::Socket;
my $s = IO::Socket::INET->new(
PeerAddr => "www.yahoo.com:80",
Timeout => 10,
);
if ($s) {
close($s);
} else {
skip 2, " no net connection available";
}
is(
title('http://jerakeen.org'),
"jerakeen.org",
"got title for jerakeen.org");
is(
title('http://theregister.co.uk/content/6/34549.html'),
"Warning: lack of technology may harm your prospects",
"got register title");
}