1#!./perl 2 3# test added 29th April 1999 by Paul Johnson (pjcj@transeda.com) 4# updated 28th May 1999 by Paul Johnson 5 6my $File; 7 8BEGIN 9{ 10 $File = __FILE__; 11 if (-d 't') 12 { 13 chdir 't'; 14 $File =~ s/^t\W+//; # Remove first directory 15 } 16 @INC = '../lib'; 17 require strict; import strict; 18} 19 20use Test; 21 22BEGIN { plan tests => 12 } 23 24use IO::File; 25 26sub lineno 27{ 28 my ($f) = @_; 29 my $l; 30 $l .= "$. "; 31 $l .= $f->input_line_number; 32 $l .= " $."; # check $. before and after input_line_number 33 $l; 34} 35 36my $t; 37 38open (F, $File) or die $!; 39my $io = IO::File->new($File) or die $!; 40 41<F> for (1 .. 10); 42ok(lineno($io), "10 0 10"); 43 44$io->getline for (1 .. 5); 45ok(lineno($io), "5 5 5"); 46 47<F>; 48ok(lineno($io), "11 5 11"); 49 50$io->getline; 51ok(lineno($io), "6 6 6"); 52 53$t = tell F; # tell F; provokes a warning 54ok(lineno($io), "11 6 11"); 55 56<F>; 57ok(lineno($io), "12 6 12"); 58 59select F; 60ok(lineno($io), "12 6 12"); 61 62<F> for (1 .. 10); 63ok(lineno($io), "22 6 22"); 64 65$io->getline for (1 .. 5); 66ok(lineno($io), "11 11 11"); 67 68$t = tell F; 69# We used to have problems here before local $. worked. 70# input_line_number() used to use select and tell. When we did the 71# same, that mechanism broke. It should work now. 72ok(lineno($io), "22 11 22"); 73 74{ 75 local $.; 76 $io->getline for (1 .. 5); 77 ok(lineno($io), "16 16 16"); 78} 79 80ok(lineno($io), "22 16 22"); 81