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 | my $File; |
7 | |
8 | BEGIN |
9 | { |
10 | $File = __FILE__; |
11 | if (-d 't') |
12 | { |
13 | chdir 't'; |
14 | $File =~ s/^t\W+//; # Remove first directory |
15 | } |
20822f61 |
16 | @INC = '../lib'; |
18bb4703 |
17 | require strict; import strict; |
91cce263 |
18 | } |
19 | |
91cce263 |
20 | use Test; |
21 | |
1e374101 |
22 | BEGIN { plan tests => 12 } |
23 | |
24 | use IO::File; |
91cce263 |
25 | |
26 | sub lineno |
27 | { |
28 | my ($f) = @_; |
29 | my $l; |
30 | $l .= "$. "; |
31 | $l .= $f->input_line_number; |
1e374101 |
32 | $l .= " $."; # check $. before and after input_line_number |
91cce263 |
33 | $l; |
34 | } |
35 | |
91cce263 |
36 | my $t; |
37 | |
1e374101 |
38 | open (F, $File) or die $!; |
39 | my $io = IO::File->new($File) or die $!; |
40 | |
41 | <F> for (1 .. 10); |
42 | ok(lineno($io), "10 0 10"); |
91cce263 |
43 | |
1e374101 |
44 | $io->getline for (1 .. 5); |
45 | ok(lineno($io), "5 5 5"); |
91cce263 |
46 | |
1e374101 |
47 | <F>; |
48 | ok(lineno($io), "11 5 11"); |
91cce263 |
49 | |
1e374101 |
50 | $io->getline; |
51 | ok(lineno($io), "6 6 6"); |
91cce263 |
52 | |
1e374101 |
53 | $t = tell F; # tell F; provokes a warning |
54 | ok(lineno($io), "11 6 11"); |
91cce263 |
55 | |
1e374101 |
56 | <F>; |
57 | ok(lineno($io), "12 6 12"); |
91cce263 |
58 | |
1e374101 |
59 | select F; |
60 | ok(lineno($io), "12 6 12"); |
91cce263 |
61 | |
1e374101 |
62 | <F> for (1 .. 10); |
63 | ok(lineno($io), "22 6 22"); |
91cce263 |
64 | |
1e374101 |
65 | $io->getline for (1 .. 5); |
66 | ok(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. |
72 | ok(lineno($io), "22 11 22"); |
73 | |
74 | { |
75 | local $.; |
76 | $io->getline for (1 .. 5); |
77 | ok(lineno($io), "16 16 16"); |
78 | } |
91cce263 |
79 | |
1e374101 |
80 | ok(lineno($io), "22 16 22"); |