From: Jarkko Hietaniemi Date: Mon, 28 May 2001 15:03:35 +0000 (+0000) Subject: Add a test for PerlIO. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ec28694ccbbeb16b6069c4b363ee55512b83376a;hp=0e25c5fd6896160f4115f7b66a6914d9c01ef7df;p=p5sagit%2Fp5-mst-13.2.git Add a test for PerlIO. (I probably got the crlf/raw thing wrong for clrfy platforms...) p4raw-id: //depot/perl@10247 --- diff --git a/MANIFEST b/MANIFEST index 226a312..bef35c7 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1586,6 +1586,7 @@ t/lib/open3.t See if IPC::Open3 works t/lib/ops.t See if Opcode works t/lib/parsewords.t See if Text::ParseWords works t/lib/peek.t See if Devel::Peek works +t/lib/perlio.t See if PerlIO works t/lib/ph.t See if h2ph works t/lib/posix.t See if POSIX works t/lib/safe1.t See if Safe works diff --git a/lib/PerlIO.pm b/lib/PerlIO.pm index 148a5a8..d52d58b 100644 --- a/lib/PerlIO.pm +++ b/lib/PerlIO.pm @@ -39,8 +39,8 @@ PerlIO - On demand loader for PerlIO layers and root of PerlIO::* name space =head1 DESCRIPTION -When an undefined layer 'foo' is encountered in an C or C layer -specification then C code performs the equivalent of: +When an undefined layer 'foo' is encountered in an C or +C layer specification then C code performs the equivalent of: use PerlIO 'foo'; @@ -99,7 +99,7 @@ and then read it back in. =item raw A pseudo-layer which performs two functions (which is messy, but -necessary to maintain compatibility with non-PerlIO builds of perl +necessary to maintain compatibility with non-PerlIO builds of Perl and their way things have been documented elsewhere). Firstly it forces the file handle to be considered binary at that @@ -118,8 +118,8 @@ which would interfere with binary nature of the stream. =head2 Defaults and how to override them -If the platform is MS-DOS like and normally does CRLF to "\n" translation -for text files then the default layers are : +If the platform is MS-DOS like and normally does CRLF to "\n" +translation for text files then the default layers are : unix crlf diff --git a/t/lib/perlio.t b/t/lib/perlio.t new file mode 100644 index 0000000..d71ab8e --- /dev/null +++ b/t/lib/perlio.t @@ -0,0 +1,90 @@ +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; + require Config; import Config; + if ($Config{'extensions'} !~ /\bPerlIO\b/) { + print "1..0 # Skip: PerlIO was not built\n"; + exit 0; + } +} + +use PerlIO; + +print "1..19\n"; + +print "ok 1\n"; + +my $txt = "txt$$"; +my $bin = "bin$$"; +my $utf = "utf$$"; + +my $txtfh; +my $binfh; +my $utffh; + +print "not " unless open($txtfh, ">:crlf", $txt); +print "ok 2\n"; + +print "not " unless open($binfh, ">:raw", $bin); +print "ok 3\n"; + +print "not " unless open($utffh, ">:utf8", $utf); +print "ok 4\n"; + +print $txtfh "foo\n"; +print $txtfh "bar\n"; +print "not " unless close($txtfh); +print "ok 5\n"; + +print $binfh "foo\n"; +print $binfh "bar\n"; +print "not " unless close($binfh); +print "ok 6\n"; + +print $utffh "foo\x{ff}\n"; +print $utffh "bar\x{abcd}\n"; +print "not " unless close($utffh); +print "ok 7\n"; + +print "not " unless open($txtfh, "<:crlf", $txt); +print "ok 8\n"; + +print "not " unless open($binfh, "<:raw", $bin); +print "ok 9\n"; + +print "not " unless open($utffh, "<:utf8", $utf); +print "ok 10\n"; + +print "not " unless <$txtfh> eq "foo\n" && <$txtfh> eq "bar\n"; +print "ok 11\n"; + +print "not " unless <$binfh> eq "foo\n" && <$binfh> eq "bar\n"; +print "ok 12\n"; + +print "not " unless <$utffh> eq "foo\x{ff}\n" && <$utffh> eq "bar\x{abcd}\n"; +print "ok 13\n"; + +print "not " unless eof($txtfh); +print "ok 14\n"; + +print "not " unless eof($binfh); +print "ok 15\n"; + +print "not " unless eof($utffh); +print "ok 16\n"; + +print "not " unless close($txtfh); +print "ok 17\n"; + +print "not " unless close($binfh); +print "ok 18\n"; + +print "not " unless close($utffh); +print "ok 19\n"; + +END { + 1 while unlink $txt; + 1 while unlink $bin; + 1 while unlink $utf; +} +