tests: Factor out duplicate IPv6 support detection code

This commit is contained in:
Richard Hansen 2024-09-06 15:50:32 -04:00
parent 9c7c0e55c1
commit 62f3759c54
7 changed files with 36 additions and 46 deletions

View file

@ -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-cert.pem \
t/lib/ddclient/Test/Fake/HTTPD/dummy-server-key.pem \ t/lib/ddclient/Test/Fake/HTTPD/dummy-server-key.pem \
t/lib/ddclient/t.pm \ t/lib/ddclient/t.pm \
t/lib/ddclient/t/ip.pm \
t/lib/ok.pm t/lib/ok.pm

View file

@ -2,17 +2,8 @@ use Test::More;
BEGIN { SKIP: { eval { require Test::Warnings; 1; } or skip($@, 1); } } BEGIN { SKIP: { eval { require Test::Warnings; 1; } or skip($@, 1); } }
BEGIN { eval { require 'ddclient'; } or BAIL_OUT($@); } BEGIN { eval { require 'ddclient'; } or BAIL_OUT($@); }
BEGIN { eval { require ddclient::Test::Fake::HTTPD; 1; } or plan(skip_all => $@); } 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 $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 { my $http_daemon_supports_ipv6 = eval {
require HTTP::Daemon; require HTTP::Daemon;
HTTP::Daemon->VERSION(6.12); HTTP::Daemon->VERSION(6.12);

30
t/lib/ddclient/t/ip.pm Normal file
View file

@ -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;

View file

@ -2,15 +2,7 @@ use Test::More;
BEGIN { SKIP: { eval { require Test::Warnings; 1; } or skip($@, 1); } } BEGIN { SKIP: { eval { require Test::Warnings; 1; } or skip($@, 1); } }
BEGIN { eval { require 'ddclient'; } or BAIL_OUT($@); } BEGIN { eval { require 'ddclient'; } or BAIL_OUT($@); }
BEGIN { eval { require ddclient::Test::Fake::HTTPD; 1; } or plan(skip_all => $@); } BEGIN { eval { require ddclient::Test::Fake::HTTPD; 1; } or plan(skip_all => $@); }
my $ipv6_supported = eval { use ddclient::t::ip;
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 { my $http_daemon_supports_ipv6 = eval {
require HTTP::Daemon; require HTTP::Daemon;
HTTP::Daemon->VERSION(6.12); HTTP::Daemon->VERSION(6.12);

View file

@ -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 HTTP::Daemon::SSL; 1; } or plan(skip_all => $@); }
BEGIN { eval { require 'ddclient'; } or BAIL_OUT($@); } BEGIN { eval { require 'ddclient'; } or BAIL_OUT($@); }
BEGIN { eval { require ddclient::Test::Fake::HTTPD; 1; } or plan(skip_all => $@); } BEGIN { eval { require ddclient::Test::Fake::HTTPD; 1; } or plan(skip_all => $@); }
my $ipv6_supported = eval { use ddclient::t::ip;
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 { my $http_daemon_supports_ipv6 = eval {
require HTTP::Daemon; require HTTP::Daemon;
HTTP::Daemon->VERSION(6.12); HTTP::Daemon->VERSION(6.12);

View file

@ -7,15 +7,7 @@ use List::Util qw(max);
use Scalar::Util qw(refaddr); use Scalar::Util qw(refaddr);
BEGIN { eval { require 'ddclient'; } or BAIL_OUT($@); } BEGIN { eval { require 'ddclient'; } or BAIL_OUT($@); }
BEGIN { eval { require ddclient::Test::Fake::HTTPD; 1; } or plan(skip_all => $@); } BEGIN { eval { require ddclient::Test::Fake::HTTPD; 1; } or plan(skip_all => $@); }
my $ipv6_supported = eval { use ddclient::t::ip;
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 { my $http_daemon_supports_ipv6 = eval {
require HTTP::Daemon; require HTTP::Daemon;
HTTP::Daemon->VERSION(6.12); HTTP::Daemon->VERSION(6.12);

View file

@ -3,15 +3,7 @@ BEGIN { SKIP: { eval { require Test::Warnings; 1; } or skip($@, 1); } }
use Scalar::Util qw(blessed); use Scalar::Util qw(blessed);
BEGIN { eval { require 'ddclient'; } or BAIL_OUT($@); } BEGIN { eval { require 'ddclient'; } or BAIL_OUT($@); }
BEGIN { eval { require ddclient::Test::Fake::HTTPD; 1; } or plan(skip_all => $@); } BEGIN { eval { require ddclient::Test::Fake::HTTPD; 1; } or plan(skip_all => $@); }
my $ipv6_supported = eval { use ddclient::t::ip;
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 { my $http_daemon_supports_ipv6 = eval {
require HTTP::Daemon; require HTTP::Daemon;
HTTP::Daemon->VERSION(6.12); HTTP::Daemon->VERSION(6.12);