This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate perl
[perl5.git] / lib / Tie / File / t / 16_handle.t
index cb9aa60..f799496 100644 (file)
@@ -4,6 +4,7 @@
 # instead of from a filename
 
 my $file = "tf$$.txt";
+$: = Tie::File::_default_recsep();
 
 if ($^O =~ /vms/i) {
   print "1..0\n";
@@ -19,9 +20,9 @@ print "ok $N\n"; $N++;
 use Fcntl 'O_CREAT', 'O_RDWR';
 sysopen F, $file, O_CREAT | O_RDWR 
   or die "Couldn't create temp file $file: $!; aborting";
-binmode(F);
+binmode F;
 
-my $o = tie @a, 'Tie::File', \*F;
+my $o = tie @a, 'Tie::File', \*F, autochomp => 0, autodefer => 0;
 print $o ? "ok $N\n" : "not ok $N\n";
 $N++;
 
@@ -55,7 +56,7 @@ check_contents("long0", "longer1", "long2");
 $a[0] = 'longer0';
 check_contents("longer0", "longer1", "long2");
 
-# 25-34 shortening alterations, including truncation
+# 25-38 shortening alterations, including truncation
 $a[0] = 'short0';
 check_contents("short0", "longer1", "long2");
 $a[1] = 'short1';
@@ -77,43 +78,43 @@ close F;
 undef $o;
 untie @a;
 
-# Does it correctly detect a non-seekable handle?
-
-{
-  if ($^O =~ /^(MSWin32|dos)$/) {
-    print "ok $N \# skipped ($^O has broken pipe semantics)\n";
-    last;
-  }
-  my $pipe_succeeded = eval {pipe *R, *W};
-  if ($@) {
-    chomp $@;
-    print "ok $N \# skipped (no pipes: $@)\n";
-        last;
-  } elsif (! $pipe_succeeded) {
-    print "ok $N \# skipped (pipe call failed: $!)\n";
-    last;
-  }
-  close R;
-  $o = eval {tie @a, 'Tie::File', \*W};
-  if ($@) {
-    if ($@ =~ /filehandle does not appear to be seekable/) {
-      print "ok $N\n";
-    } else {
-      chomp $@;
-      print "not ok $N \# \$\@ is $@\n";
-    }
-  } else {
-    print "not ok $N \# passing pipe to TIEARRAY didn't abort program\n";
-  }
-  $N++;
+# (39) Does it correctly detect a non-seekable handle?
+{  if ($^O =~ /^(MSWin32|dos|beos)$/) {
+     print "ok $N # skipped ($^O has broken pipe semantics)\n";
+     last;
+   }
+   if ($] < 5.006) {
+     print "ok $N # skipped - 5.005_03 panics after this test\n";
+     last;
+   }
+   my $pipe_succeeded = eval {pipe *R, *W};
+   if ($@) {
+     chomp $@;
+     print "ok $N # skipped (no pipes: $@)\n";
+     last;
+   } elsif (! $pipe_succeeded) {
+     print "ok $N # skipped (pipe call failed: $!)\n";
+     last;
+   }
+   close R;
+   $o = eval {tie @a, 'Tie::File', \*W};
+   if ($@) {
+     if ($@ =~ /filehandle does not appear to be seekable/) {
+       print "ok $N\n";
+     } else {
+       chomp $@;
+       print "not ok $N \# \$\@ is $@\n";
+     }
+   } else {
+       print "not ok $N \# passing pipe to TIEARRAY didn't abort program\n";
+   }
+   $N++;
 }
 
-# try inserting a record into the middle of an empty file
-
 use POSIX 'SEEK_SET';
 sub check_contents {
   my @c = @_;
-  my $x = join $/, @c, '';
+  my $x = join $:, @c, '';
   local *FH = $o->{fh};
   seek FH, 0, SEEK_SET;
 #  my $open = open FH, "< $file";
@@ -123,8 +124,8 @@ sub check_contents {
   if ($a eq $x) {
     print "ok $N\n";
   } else {
-    s{$/}{\\n}g for $a, $x;
-    print "not ok $N\n# expected <$x>, got <$a>\n";
+    ctrlfix(my $msg = "# expected <$x>, got <$a>");
+    print "not ok $N\n$msg\n";
   }
   $N++;
 
@@ -132,9 +133,9 @@ sub check_contents {
   my $good = 1;
   my $msg;
   for (0.. $#c) {
-    unless ($a[$_] eq "$c[$_]$/") {
-      $msg = "expected $c[$_]$/, got $a[$_]";
-      $msg =~ s{$/}{\\n}g;
+    unless ($a[$_] eq "$c[$_]$:") {
+      $msg = "expected $c[$_]$:, got $a[$_]";
+      ctrlfix($msg);
       $good = 0;
     }
   }
@@ -142,6 +143,14 @@ sub check_contents {
   $N++;
 }
 
+
+sub ctrlfix {
+  for (@_) {
+    s/\n/\\n/g;
+    s/\r/\\r/g;
+  }
+}
+
 END {
   undef $o;
   untie @a;