Commit | Line | Data |
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 |
6 | use strict; |
7 | |
8 | my $File; |
9 | |
10 | BEGIN |
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 |
21 | use Test; |
22 | |
1e374101 |
23 | BEGIN { plan tests => 12 } |
24 | |
25 | use IO::File; |
91cce263 |
26 | |
27 | sub 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 |
37 | my $t; |
38 | |
1e374101 |
39 | open (F, $File) or die $!; |
40 | my $io = IO::File->new($File) or die $!; |
41 | |
42 | <F> for (1 .. 10); |
43 | ok(lineno($io), "10 0 10"); |
91cce263 |
44 | |
1e374101 |
45 | $io->getline for (1 .. 5); |
46 | ok(lineno($io), "5 5 5"); |
91cce263 |
47 | |
1e374101 |
48 | <F>; |
49 | ok(lineno($io), "11 5 11"); |
91cce263 |
50 | |
1e374101 |
51 | $io->getline; |
52 | ok(lineno($io), "6 6 6"); |
91cce263 |
53 | |
1e374101 |
54 | $t = tell F; # tell F; provokes a warning |
55 | ok(lineno($io), "11 6 11"); |
91cce263 |
56 | |
1e374101 |
57 | <F>; |
58 | ok(lineno($io), "12 6 12"); |
91cce263 |
59 | |
1e374101 |
60 | select F; |
61 | ok(lineno($io), "12 6 12"); |
91cce263 |
62 | |
1e374101 |
63 | <F> for (1 .. 10); |
64 | ok(lineno($io), "22 6 22"); |
91cce263 |
65 | |
1e374101 |
66 | $io->getline for (1 .. 5); |
67 | ok(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. |
73 | ok(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 |
81 | ok(lineno($io), "22 16 22"); |