Improve and restructure t/op/pat.t and split out some unicode related tests into...
[p5sagit/p5-mst-13.2.git] / t / op / read.t
index 6aab395..23f1b51 100755 (executable)
@@ -1,7 +1,5 @@
 #!./perl
 
-# $RCSfile: read.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:17 $
-
 BEGIN {
     chdir 't';
     @INC = '../lib';
@@ -9,7 +7,7 @@ BEGIN {
 }
 use strict;
 
-plan tests => 1732;
+plan tests => 2564;
 
 open(FOO,'op/read.t') || open(FOO,'t/op/read.t') || open(FOO,':op:read.t') || die "Can't open op.read";
 seek(FOO,4,0) or die "Seek failed: $!";
@@ -25,16 +23,24 @@ $got = read(FOO,$buf,4);
 is ($got, 0);
 is ($buf, "");
 
-my $tmpfile = 'Op_read.tmp';
+# This is true if Config is not built, or if PerlIO is enabled
+# ie assume that PerlIO is present, unless we know for sure otherwise.
+my $has_perlio = !eval {
+    no warnings;
+    require Config;
+    !$Config::Config{useperlio}
+};
 
-1 while unlink $tmpfile;
+my $tmpfile = tempfile();
 
 my (@values, @buffers) = ('', '');
 
-foreach (65, 161, 253) { #  9786) {
+foreach (65, 161, 253, 9786) {
     push @values, join "", map {chr $_} $_ .. $_ + 4;
     push @buffers, join "", map {chr $_} $_ + 5 .. $_ + 20;
 }
+my @offsets = (0, 3, 7, 22, -1, -3, -5, -7);
+my @lengths = (0, 2, 5, 10);
 
 foreach my $value (@values) {
     foreach my $initial_buffer (@buffers) {
@@ -43,14 +49,17 @@ foreach my $value (@values) {
            # It's all 8 bit
            unshift @utf8, 0;
        }
+      SKIP:
        foreach my $utf8 (@utf8) {
-           1 while unlink $tmpfile;
+           skip "Needs :utf8 layer but no perlio", 2 * @offsets * @lengths
+             if $utf8 and !$has_perlio;
+
            open FH, ">$tmpfile" or die "Can't open $tmpfile: $!";
            binmode FH, "utf8" if $utf8;
            print FH $value;
            close FH;
-           foreach my $offset (0, 3, 7, 22, -1, -3, -5, -7) {
-               foreach my $length (0, 2, 5, 10) {
+           foreach my $offset (@offsets) {
+               foreach my $length (@lengths) {
                    # Will read the lesser of the length of the file and the
                    # read length
                    my $will_read = $value;
@@ -76,6 +85,7 @@ foreach my $value (@values) {
                    $got = read (FH, $buffer, $length, $offset);
                    is ($got, length $will_read, "got $what");
                    is ($buffer, $expect, "buffer $what");
+                   close FH;
                }
            }
        }