Use minimal @INC in tests, most of the time just '../lib',
[p5sagit/p5-mst-13.2.git] / t / lib / io_sock.t
index b1189a0..5a8e16c 100755 (executable)
@@ -3,7 +3,7 @@
 BEGIN {
     unless(grep /blib/, @INC) {
        chdir 't' if -d 't';
-       unshift @INC, '../lib' if -d '../lib';
+       @INC = '../lib';
     }
 }
 
@@ -11,11 +11,19 @@ use Config;
 
 BEGIN {
     if (-d "lib" && -f "TEST") {
-        if (!$Config{'d_fork'} ||
-           (($Config{'extensions'} !~ /\bSocket\b/ ||
-             $Config{'extensions'} !~ /\bIO\b/) &&
-            !(($^O eq 'VMS') && $Config{d_socket}))) {
-           print "1..0\n";
+       my $reason;
+       if (! $Config{'d_fork'}) {
+           $reason = 'no fork';
+       }
+       elsif ($Config{'extensions'} !~ /\bSocket\b/) {
+           $reason = 'Socket extension unavailable';
+       }
+       elsif ($Config{'extensions'} !~ /\bIO\b/) {
+           $reason = 'IO extension unavailable';
+       }
+       undef $reason if $^O eq 'VMS' and $Config{d_socket};
+       if ($reason) {
+           print "1..0 # Skip: $reason\n";
            exit 0;
         }
     }
@@ -28,7 +36,9 @@ use IO::Socket;
 
 $listen = IO::Socket::INET->new(Listen => 2,
                                Proto => 'tcp',
-                               Timeout => 2,
+                               # some systems seem to need as much as 10,
+                               # so be generous with the timeout
+                               Timeout => 15,
                               ) or die "$!";
 
 print "ok 1\n";
@@ -44,7 +54,7 @@ $port = $listen->sockport;
 
 if($pid = fork()) {
 
-    $sock = $listen->accept();
+    $sock = $listen->accept() or die "accept failed: $!";
     print "ok 2\n";
 
     $sock->autoflush(1);
@@ -87,7 +97,7 @@ if($pid = fork()) {
 
 # Test various other ways to create INET sockets that should
 # also work.
-$listen = IO::Socket::INET->new(Listen => '', Timeout => 2) or die "$!";
+$listen = IO::Socket::INET->new(Listen => '', Timeout => 15) or die "$!";
 $port = $listen->sockport;
 
 if($pid = fork()) {
@@ -124,7 +134,7 @@ if($pid = fork()) {
     }
 
     # some machines seem to suffer from a race condition here
-#    sleep(1);
+    sleep(2);
 
     $sock = IO::Socket::INET->new("127.0.0.1:$port");
     if ($sock) {
@@ -138,7 +148,7 @@ if($pid = fork()) {
     }
 
     # some machines seem to suffer from a race condition here
-#    sleep(1);
+    sleep(1);
 
     $sock = IO::Socket->new(Domain => AF_INET,
                             PeerAddr => "localhost:$port");
@@ -159,20 +169,24 @@ $server = IO::Socket->new(Domain => AF_INET,
                           LocalAddr => 'localhost');
 $port = $server->sockport;
 
-if ($pid = fork()) {
-    my $buf;
-    $server->recv($buf, 100);
-    print $buf;
-} elsif (defined($pid)) {
-    #child
-    $sock = IO::Socket::INET->new(Proto => 'udp',
-                                  PeerAddr => "localhost:$port");
-    $sock->send("ok 12\n");
-    sleep(1);
-    $sock->send("ok 12\n");  # send another one to be sure
-    exit;
+if ($^O eq 'mpeix') {
+    print("ok 12 # skipped\n")
 } else {
-    die;
+    if ($pid = fork()) {
+        my $buf;
+        $server->recv($buf, 100);
+        print $buf;
+    } elsif (defined($pid)) {
+        #child
+        $sock = IO::Socket::INET->new(Proto => 'udp',
+                                      PeerAddr => "localhost:$port");
+        $sock->send("ok 12\n");
+        sleep(1);
+        $sock->send("ok 12\n");  # send another one to be sure
+        exit;
+    } else {
+        die;
+    }
 }
 
 print "not " unless $server->blocking;