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