with DEBUG_LEAKING_SCALARS, dump multiply-freed scalars
[p5sagit/p5-mst-13.2.git] / ext / IO / t / io_linenum.t
1 #!./perl
2
3 # test added 29th April 1999 by Paul Johnson (pjcj@transeda.com)
4 # updated    28th May   1999 by Paul Johnson
5
6 my $File;
7
8 BEGIN {
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;
16 }
17
18 use Test;
19
20 BEGIN { plan tests => 12 }
21
22 use IO::File;
23
24 sub lineno
25 {
26   my ($f) = @_;
27   my $l;
28   $l .= "$. ";
29   $l .= $f->input_line_number;
30   $l .= " $.";                     # check $. before and after input_line_number
31   $l;
32 }
33
34 my $t;
35
36 open (F, $File) or die $!;
37 my $io = IO::File->new($File) or die $!;
38
39 <F> for (1 .. 10);
40 ok(lineno($io), "10 0 10");
41
42 $io->getline for (1 .. 5);
43 ok(lineno($io), "5 5 5");
44
45 <F>;
46 ok(lineno($io), "11 5 11");
47
48 $io->getline;
49 ok(lineno($io), "6 6 6");
50
51 $t = tell F;                                        # tell F; provokes a warning
52 ok(lineno($io), "11 6 11");
53
54 <F>;
55 ok(lineno($io), "12 6 12");
56
57 select F;
58 ok(lineno($io), "12 6 12");
59
60 <F> for (1 .. 10);
61 ok(lineno($io), "22 6 22");
62
63 $io->getline for (1 .. 5);
64 ok(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.
70 ok(lineno($io), "22 11 22");
71
72 {
73   local $.;
74   $io->getline for (1 .. 5);
75   ok(lineno($io), "16 16 16");
76 }
77
78 ok(lineno($io), "22 16 22");