diff --git a/Makefile.am b/Makefile.am index a191082..d80050f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -162,4 +162,5 @@ EXTRA_DIST += $(handwritten_tests) \ t/lib/ddclient/Test/Fake/HTTPD/dummy-server-cert.pem \ t/lib/ddclient/Test/Fake/HTTPD/dummy-server-key.pem \ t/lib/ddclient/t.pm \ + t/lib/ddclient/t/ip.pm \ t/lib/ok.pm diff --git a/t/geturl_connectivity.pl b/t/geturl_connectivity.pl index 300d9d2..db9258a 100644 --- a/t/geturl_connectivity.pl +++ b/t/geturl_connectivity.pl @@ -2,17 +2,8 @@ use Test::More; BEGIN { SKIP: { eval { require Test::Warnings; 1; } or skip($@, 1); } } BEGIN { eval { require 'ddclient'; } or BAIL_OUT($@); } BEGIN { eval { require ddclient::Test::Fake::HTTPD; 1; } or plan(skip_all => $@); } +use ddclient::t::ip; my $has_http_daemon_ssl = eval { require HTTP::Daemon::SSL; 1; }; -my $ipv6_supported = eval { - require IO::Socket::IP; - my $ipv6_socket = IO::Socket::IP->new( - Domain => 'PF_INET6', - LocalHost => '::1', - Listen => 1, - ); - defined($ipv6_socket); -}; - my $http_daemon_supports_ipv6 = eval { require HTTP::Daemon; HTTP::Daemon->VERSION(6.12); diff --git a/t/lib/ddclient/t/ip.pm b/t/lib/ddclient/t/ip.pm new file mode 100644 index 0000000..769e5a9 --- /dev/null +++ b/t/lib/ddclient/t/ip.pm @@ -0,0 +1,30 @@ +package ddclient::t::ip; + +use v5.10.1; +use strict; +use warnings; +use Exporter qw(import); +use Test::More; + +our @EXPORT = qw(ipv6_ok ipv6_required $ipv6_supported $ipv6_support_error); + +our $ipv6_support_error; +our $ipv6_supported = eval { + require IO::Socket::IP; + my $ipv6_socket = IO::Socket::IP->new( + Domain => 'PF_INET6', + LocalHost => '::1', + Listen => 1, + ); + defined($ipv6_socket); +} or $ipv6_support_error = $@; + +sub ipv6_ok { + ok($ipv6_supported, "system supports IPv6") or diag($ipv6_support_error); +} + +sub ipv6_required { + plan(skip_all => $ipv6_support_error) if !$ipv6_supported; +} + +1; diff --git a/t/skip.pl b/t/skip.pl index 3c63f42..536cfd1 100644 --- a/t/skip.pl +++ b/t/skip.pl @@ -2,15 +2,7 @@ use Test::More; BEGIN { SKIP: { eval { require Test::Warnings; 1; } or skip($@, 1); } } BEGIN { eval { require 'ddclient'; } or BAIL_OUT($@); } BEGIN { eval { require ddclient::Test::Fake::HTTPD; 1; } or plan(skip_all => $@); } -my $ipv6_supported = eval { - require IO::Socket::IP; - my $ipv6_socket = IO::Socket::IP->new( - Domain => 'PF_INET6', - LocalHost => '::1', - Listen => 1, - ); - defined($ipv6_socket); -}; +use ddclient::t::ip; my $http_daemon_supports_ipv6 = eval { require HTTP::Daemon; HTTP::Daemon->VERSION(6.12); diff --git a/t/ssl-validate.pl b/t/ssl-validate.pl index 4d9a111..19db0e9 100644 --- a/t/ssl-validate.pl +++ b/t/ssl-validate.pl @@ -3,15 +3,7 @@ BEGIN { SKIP: { eval { require Test::Warnings; 1; } or skip($@, 1); } } BEGIN { eval { require HTTP::Daemon::SSL; 1; } or plan(skip_all => $@); } BEGIN { eval { require 'ddclient'; } or BAIL_OUT($@); } BEGIN { eval { require ddclient::Test::Fake::HTTPD; 1; } or plan(skip_all => $@); } -my $ipv6_supported = eval { - require IO::Socket::IP; - my $ipv6_socket = IO::Socket::IP->new( - Domain => 'PF_INET6', - LocalHost => '::1', - Listen => 1, - ); - defined($ipv6_socket); -}; +use ddclient::t::ip; my $http_daemon_supports_ipv6 = eval { require HTTP::Daemon; HTTP::Daemon->VERSION(6.12); diff --git a/t/update_nics.pl b/t/update_nics.pl index 0538a2e..1e98bc9 100644 --- a/t/update_nics.pl +++ b/t/update_nics.pl @@ -7,15 +7,7 @@ use List::Util qw(max); use Scalar::Util qw(refaddr); BEGIN { eval { require 'ddclient'; } or BAIL_OUT($@); } BEGIN { eval { require ddclient::Test::Fake::HTTPD; 1; } or plan(skip_all => $@); } -my $ipv6_supported = eval { - require IO::Socket::IP; - my $ipv6_socket = IO::Socket::IP->new( - Domain => 'PF_INET6', - LocalHost => '::1', - Listen => 1, - ); - defined($ipv6_socket); -}; +use ddclient::t::ip; my $http_daemon_supports_ipv6 = eval { require HTTP::Daemon; HTTP::Daemon->VERSION(6.12); diff --git a/t/use_web.pl b/t/use_web.pl index 90be8d7..bc9f420 100644 --- a/t/use_web.pl +++ b/t/use_web.pl @@ -3,15 +3,7 @@ BEGIN { SKIP: { eval { require Test::Warnings; 1; } or skip($@, 1); } } use Scalar::Util qw(blessed); BEGIN { eval { require 'ddclient'; } or BAIL_OUT($@); } BEGIN { eval { require ddclient::Test::Fake::HTTPD; 1; } or plan(skip_all => $@); } -my $ipv6_supported = eval { - require IO::Socket::IP; - my $ipv6_socket = IO::Socket::IP->new( - Domain => 'PF_INET6', - LocalHost => '::1', - Listen => 1, - ); - defined($ipv6_socket); -}; +use ddclient::t::ip; my $http_daemon_supports_ipv6 = eval { require HTTP::Daemon; HTTP::Daemon->VERSION(6.12);