The test suite tweak in #6101 wasn't quite right.
[p5sagit/p5-mst-13.2.git] / t / lib / socket.t
index afc2a5b..d5e1848 100755 (executable)
@@ -2,10 +2,10 @@
 
 BEGIN {
     chdir 't' if -d 't';
-    @INC = '../lib' if -d '../lib';
+    unshift @INC, '../lib' if -d '../lib';
     require Config; import Config;
     if ($Config{'extensions'} !~ /\bSocket\b/ && 
-        !(($^O eq 'VMS') && $Config{d_has_socket})) {
+        !(($^O eq 'VMS') && $Config{d_socket})) {
        print "1..0\n";
        exit 0;
     }
@@ -13,7 +13,7 @@ BEGIN {
        
 use Socket;
 
-print "1..6\n";
+print "1..8\n";
 
 if (socket(T,PF_INET,SOCK_STREAM,6)) {
   print "ok 1\n";
@@ -26,6 +26,10 @@ if (socket(T,PF_INET,SOCK_STREAM,6)) {
 
        syswrite(T,"hello",5);
        $read = sysread(T,$buff,10);    # Connection may be granted, then closed!
+       while ($read > 0 && length($buff) < 5) {
+           # adjust for fact that TCP doesn't guarantee size of reads/writes
+           $read = sysread(T,$buff,10,length($buff));
+       }
        print(($read == 0 || $buff eq "hello") ? "ok 3\n" : "not ok 3\n");
   }
   else {
@@ -52,6 +56,10 @@ if( socket(S,PF_INET,SOCK_STREAM,6) ){
 
        syswrite(S,"olleh",5);
        $read = sysread(S,$buff,10);    # Connection may be granted, then closed!
+       while ($read > 0 && length($buff) < 5) {
+           # adjust for fact that TCP doesn't guarantee size of reads/writes
+           $read = sysread(S,$buff,10,length($buff));
+       }
        print(($read == 0 || $buff eq "olleh") ? "ok 6\n" : "not ok 6\n");
   }
   else {
@@ -66,3 +74,14 @@ else {
        print "# $!\n";
        print "not ok 4\n";
 }
+
+# warnings
+$SIG{__WARN__} = sub {
+    ++ $w if $_[0] =~ /^6-ARG sockaddr_in call is deprecated/ ;
+} ;
+$w = 0 ;
+sockaddr_in(1,2,3,4,5,6) ;
+print ($w == 1 ? "not ok 7\n" : "ok 7\n") ;
+use warnings 'Socket' ;
+sockaddr_in(1,2,3,4,5,6) ;
+print ($w == 1 ? "ok 8\n" : "not ok 8\n") ;