develooper Front page | perl.perl5.porters | Postings from August 2001

[PATCH] (was Re: PerlIO regerssion tests?)

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
August 22, 2001 15:29
Subject:
[PATCH] (was Re: PerlIO regerssion tests?)
Message ID:
20010822232906.Z82818@plum.flirble.org
On Wed, Aug 22, 2001 at 05:17:44PM -0400, Michael G Schwern wrote:
> On Wed, Aug 22, 2001 at 09:59:16PM +0100, Nicholas Clark wrote:
> > ./perl -lwe 'binmode STDERR, ":unix"'
> > Segmentation fault
> > 
> > This would be a bad thing, wouldn't it?
> > However it's not as bad as the fact that we don't have regression tests for
> > this sort of thing, is it? :-(
> > 
> > Where should they go?
> 
> t/op/binmode.t for tests of just binmode().
> 
> t/io/perlio.t for tests of perlio specific stuff.
> 
> It's okay if there's some duplication.

Not a fantastic binmode test, but it does check for a was-bug.
perlfunc.pod seemed to be a bit out of date. It could probably do
with a more complete editorial re-write.

Nicholas Clark

--- perlio.c.orig	Thu Aug  2 15:29:10 2001
+++ perlio.c	Wed Aug 22 23:07:14 2001
@@ -1968,7 +1968,10 @@
   {
    PerlIOUnix *s = PerlIOSelf(f,PerlIOUnix);
    s->fd     = PerlIO_fileno(PerlIONext(f));
-   s->oflags = PerlIOUnix_oflags(mode);
+   /* XXX could (or should) we retrieve the oflags from the open file handle
+      rather than believing the "mode" we are passed in?
+      XXX Should the value on NULL mode be 0 or -1?  */
+   s->oflags = mode ? PerlIOUnix_oflags(mode) : -1;
   }
  PerlIOBase(f)->flags |= PERLIO_F_OPEN;
  return code;
--- pod/perlfunc.pod.orig	Sun Aug 12 16:20:18 2001
+++ pod/perlfunc.pod	Wed Aug 22 23:04:05 2001
@@ -450,13 +450,12 @@
 text files.  If FILEHANDLE is an expression, the value is taken as the
 name of the filehandle.  DISCIPLINE can be either of C<":raw"> for
 binary mode or C<":crlf"> for "text" mode.  If the DISCIPLINE is
-omitted, it defaults to C<":raw">.
+omitted, it defaults to C<":raw">.  Returns true on success, C<undef> on
+failure.
 
 binmode() should be called after open() but before any I/O is done on
 the filehandle.
 
-On many systems binmode() currently has no effect, but in future, it
-will be extended to support user-defined input and output disciplines.
 On some systems binmode() is necessary when you're not working with a
 text file.  For the sake of portability it is a good idea to always use
 it when appropriate, and to never use it when it isn't appropriate.
--- /dev/null	Mon Jul 16 22:57:44 2001
+++ t/io/binmode.t	Wed Aug 22 23:02:41 2001
@@ -0,0 +1,23 @@
+#!./perl
+
+BEGIN {
+    chdir 't' if -d 't';
+    @INC = '../lib';
+}
+
+$|  = 1;
+use warnings;
+
+print "1..3\n";
+
+my $test = 1;
+
+sub ok { print "ok $test\n"; $test++ }
+sub notok { print "not ok $test\n"; $test++ }
+
+binmode (STDERR) ? ok : notok;
+# Even if this one fails then STDOUT will report OK
+binmode (STDERR, ":unix") ? ok : notok;
+# If this one fails and renders STDOUT dead then we rely on the test harness
+# to spot a missing test.
+binmode (STDOUT, ":unix") ? ok : notok;

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About