Integrate with Sarathy.
[p5sagit/p5-mst-13.2.git] / t / lib / io_linenum.t
index 954b05f..3503215 100755 (executable)
@@ -1,17 +1,27 @@
 #!./perl
 
-# test added 29th April 1998 by Paul Johnson (pjcj@transeda.com)
+# test added 29th April 1999 by Paul Johnson (pjcj@transeda.com)
+# updated    28th May   1999 by Paul Johnson
 
-BEGIN {
-    chdir 't' if -d 't';
-    unshift @INC, '../lib' if -d '../lib';
+my $File;
+
+BEGIN
+{
+  $File = __FILE__;
+  if (-d 't')
+  {
+    chdir 't';
+    $File =~ s/^t\W+//;                                 # Remove first directory
+  }
+  unshift @INC, '../lib' if -d '../lib';
+  require strict; import strict;
 }
 
-use strict;
-use IO::File;
 use Test;
 
-BEGIN { plan tests => 10, todo => [10] }
+BEGIN { plan tests => 12 }
+
+use IO::File;
 
 sub lineno
 {
@@ -19,49 +29,52 @@ sub lineno
   my $l;
   $l .= "$. ";
   $l .= $f->input_line_number;
-  $l .= " $.";
+  $l .= " $.";                     # check $. before and after input_line_number
   $l;
 }
 
-sub OK
-{
-  my $s = select STDOUT;                     # work around a bug in Test.pm 1.04
-  &ok;
-  select $s;
-}
-
 my $t;
 
-open (Q, __FILE__) or die $!;
-my $w = IO::File->new(__FILE__) or die $!;
+open (F, $File) or die $!;
+my $io = IO::File->new($File) or die $!;
+
+<F> for (1 .. 10);
+ok(lineno($io), "10 0 10");
 
-<Q> for (1 .. 10);
-OK(lineno($w), "10 0 10");
+$io->getline for (1 .. 5);
+ok(lineno($io), "5 5 5");
 
-$w->getline for (1 .. 5);
-OK(lineno($w), "5 5 5");
+<F>;
+ok(lineno($io), "11 5 11");
 
-<Q>;
-OK(lineno($w), "11 5 11");
+$io->getline;
+ok(lineno($io), "6 6 6");
 
-$w->getline;
-OK(lineno($w), "6 6 6");
+$t = tell F;                                        # tell F; provokes a warning
+ok(lineno($io), "11 6 11");
 
-$t = tell Q;         # tell Q; provokes a warning - the world is full of bugs...
-OK(lineno($w), "11 6 11");
+<F>;
+ok(lineno($io), "12 6 12");
 
-<Q>;
-OK(lineno($w), "12 6 12");
+select F;
+ok(lineno($io), "12 6 12");
 
-select Q;
-OK(lineno($w), "12 6 12");
+<F> for (1 .. 10);
+ok(lineno($io), "22 6 22");
 
-<Q> for (1 .. 10);
-OK(lineno($w), "22 6 22");
+$io->getline for (1 .. 5);
+ok(lineno($io), "11 11 11");
 
-$w->getline for (1 .. 5);
-OK(lineno($w), "11 11 11");
+$t = tell F;
+# We used to have problems here before local $. worked.
+# input_line_number() used to use select and tell.  When we did the
+# same, that mechanism broke.  It should work now.
+ok(lineno($io), "22 11 22");
+
+{
+  local $.;
+  $io->getline for (1 .. 5);
+  ok(lineno($io), "16 16 16");
+}
 
-# This test doesn't work.  It probably won't until local $. does.
-$t = tell Q;
-OK(lineno($w), "22 11 22", 'waiting for local $.');
+ok(lineno($io), "22 16 22");