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