This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Net-Ping: creating an icmp socket requires admin access on recent cygwin
[perl5.git] / dist / Net-Ping / t / 110_icmp_inst.t
1 # Test to make sure object can be instantiated for icmp protocol.
2 # Root access is required to actually perform icmp testing.
3
4 use strict;
5
6 BEGIN {
7   unless (eval "require Socket") {
8     print "1..0 \# Skip: no Socket\n";
9     exit;
10   }
11 }
12
13 use Test::More tests => 2;
14 BEGIN {use_ok('Net::Ping')};
15
16 SKIP: {
17   skip "icmp ping requires root privileges.", 1
18     if ($> and $^O ne 'VMS' and $^O ne 'cygwin')
19       or (($^O eq 'MSWin32' or $^O eq 'cygwin')
20           and !IsAdminUser())
21         or ($^O eq 'VMS'
22             and (`write sys\$output f\$privilege("SYSPRV")` =~ m/FALSE/));
23   my $p = new Net::Ping "icmp";
24   isa_ok($p, 'Net::Ping', 'object can be instantiated for icmp protocol');
25 }
26
27 sub IsAdminUser {
28   return unless $^O eq 'MSWin32' or $^O eq 'cygwin';
29   return unless eval { require Win32 };
30   return unless defined &Win32::IsAdminUser;
31   return Win32::IsAdminUser();
32 }