Make (hopefully) the Windows CR CR LF bug go away
[p5sagit/p5-mst-13.2.git] / t / io / crlf.t
index 084be21..2ee7b83 100644 (file)
@@ -11,11 +11,11 @@ require "test.pl";
 
 my $file = "crlf$$.dat";
 END {
- unlink($file);
+    1 while unlink($file);
 }
 
 if (find PerlIO::Layer 'perlio') {
- plan(tests => 8);
+ plan(tests => 16);
  ok(open(FOO,">:crlf",$file));
  ok(print FOO 'a'.((('a' x 14).qq{\n}) x 2000) || close(FOO));
  ok(open(FOO,"<:crlf",$file));
@@ -47,6 +47,31 @@ if (find PerlIO::Layer 'perlio') {
  }
 
  ok(close(FOO));
+
+ # binmode :crlf should not cumulate.
+ # Try it first once and then twice so that even UNIXy boxes
+ # get to exercise this, for DOSish boxes even once is enough.
+ # Try also pushing :utf8 first so that there are other layers
+ # in between (this should not matter: CRLF layers still should
+ # not accumulate).
+ for my $utf8 ('', ':utf8') {
+     for my $binmode (1..2) {
+        open(FOO, ">$file");
+        # require PerlIO; print PerlIO::get_layers(FOO), "\n";
+        binmode(FOO, "$utf8:crlf") for 1..$binmode;
+        # require PerlIO; print PerlIO::get_layers(FOO), "\n";
+        print FOO "Hello\n";
+        close FOO;
+        open(FOO, "<$file");
+        binmode(FOO);
+        my $foo = scalar <FOO>;
+        close FOO;
+        print join(" ", "#", map { sprintf("%02x", $_) } unpack("C*", $foo)),
+              "\n";
+        ok($foo =~ /\x0d\x0a$/);
+        ok($foo !~ /\x0d\x0d/);
+     }
+ }
 }
 else {
  skip_all("No perlio, so no :crlf");