Work also without perlio.
[p5sagit/p5-mst-13.2.git] / t / io / tell.t
CommitLineData
8d063cd8 1#!./perl
2
455ece5e 3# $RCSfile: tell.t,v $$Revision$$Date$
8d063cd8 4
58c59f01 5BEGIN {
6 chdir 't' if -d 't';
7 @INC = '../lib';
8}
9
0678cb22 10print "1..27\n";
8d063cd8 11
378cc40b 12$TST = 'tst';
13
2986a63f 14$Is_Dosish = ($^O eq 'MSWin32' or $^O eq 'NetWare' or $^O eq 'dos' or
b82baff6 15 $^O eq 'os2' or $^O eq 'mint' or $^O eq 'cygwin');
8736538c 16
2eb25c99 17open($TST, 'harness') || (die "Can't open harness");
8736538c 18binmode $TST if $Is_Dosish;
8d063cd8 19if (eof(tst)) { print "not ok 1\n"; } else { print "ok 1\n"; }
20
378cc40b 21$firstline = <$TST>;
8d063cd8 22$secondpos = tell;
23
24$x = 0;
25while (<tst>) {
26 if (eof) {$x++;}
27}
28if ($x == 1) { print "ok 2\n"; } else { print "not ok 2\n"; }
29
30$lastpos = tell;
31
32unless (eof) { print "not ok 3\n"; } else { print "ok 3\n"; }
33
378cc40b 34if (seek($TST,0,0)) { print "ok 4\n"; } else { print "not ok 4\n"; }
8d063cd8 35
36if (eof) { print "not ok 5\n"; } else { print "ok 5\n"; }
37
38if ($firstline eq <tst>) { print "ok 6\n"; } else { print "not ok 6\n"; }
39
40if ($secondpos == tell) { print "ok 7\n"; } else { print "not ok 7\n"; }
41
42if (seek(tst,0,1)) { print "ok 8\n"; } else { print "not ok 8\n"; }
43
378cc40b 44if (eof($TST)) { print "not ok 9\n"; } else { print "ok 9\n"; }
8d063cd8 45
46if ($secondpos == tell) { print "ok 10\n"; } else { print "not ok 10\n"; }
47
48if (seek(tst,0,2)) { print "ok 11\n"; } else { print "not ok 11\n"; }
49
50if ($lastpos == tell) { print "ok 12\n"; } else { print "not ok 12\n"; }
51
52unless (eof) { print "not ok 13\n"; } else { print "ok 13\n"; }
455ece5e 53
54if ($. == 0) { print "not ok 14\n"; } else { print "ok 14\n"; }
55
56$curline = $.;
2eb25c99 57open(other, 'harness') || (die "Can't open harness: $!");
2986a63f 58binmode other if (($^O eq 'MSWin32') || ($^O eq 'NetWare'));
455ece5e 59
60{
61 local($.);
62
63 if ($. == 0) { print "not ok 15\n"; } else { print "ok 15\n"; }
64
65 tell other;
66 if ($. == 0) { print "ok 16\n"; } else { print "not ok 16\n"; }
67
68 $. = 5;
69 scalar <other>;
70 if ($. == 6) { print "ok 17\n"; } else { print "not ok 17\n"; }
71}
72
73if ($. == $curline) { print "ok 18\n"; } else { print "not ok 18\n"; }
74
75{
76 local($.);
77
78 scalar <other>;
79 if ($. == 7) { print "ok 19\n"; } else { print "not ok 19\n"; }
80}
81
82if ($. == $curline) { print "ok 20\n"; } else { print "not ok 20\n"; }
83
84{
85 local($.);
86
87 tell other;
88 if ($. == 7) { print "ok 21\n"; } else { print "not ok 21\n"; }
89}
d26ab924 90
91close(other);
92if (tell(other) == -1) { print "ok 22\n"; } else { print "not ok 22\n"; }
93
94if (tell(ether) == -1) { print "ok 23\n"; } else { print "not ok 23\n"; }
95
96# ftell(STDIN) (or any std streams) is undefined, it can return -1 or
97# something else. ftell() on pipes, fifos, and sockets is defined to
98# return -1.
99
0678cb22 100my $written = "tell_write.txt";
101
102END { unlink($written) }
103
104close($tst);
105open($tst,">$written") || die "Cannot open $written:$!";
7bdbfeb7 106binmode $tst if $Is_Dosish;
0678cb22 107
108if (tell($tst) == 0) { print "ok 24\n"; } else { print "not ok 24\n"; }
109
110print $tst "fred\n";
111
112if (tell($tst) == 5) { print "ok 25\n"; } else { print "not ok 25\n"; }
113
114print $tst "more\n";
115
116if (tell($tst) == 10) { print "ok 26\n"; } else { print "not ok 26\n"; }
117
118close($tst);
119
120open($tst,"+>>$written") || die "Cannot open $written:$!";
7bdbfeb7 121binmode $tst if $Is_Dosish;
0678cb22 122
123if (0)
124{
125 # :stdio does not pass these so ignore them for now
126
127if (tell($tst) == 0) { print "ok 27\n"; } else { print "not ok 27\n"; }
128
129$line = <$tst>;
130
131if ($line eq "fred\n") { print "ok 29\n"; } else { print "not ok 29\n"; }
132
133if (tell($tst) == 5) { print "ok 30\n"; } else { print "not ok 30\n"; }
134
135}
136
137print $tst "xxxx\n";
138
c6b46866 139if (tell($tst) == 15 ||
140 tell($tst) == 5) # unset PERLIO or PERLIO=stdio (e.g. HP-UX, Solaris)
141{ print "ok 27\n"; } else { print "not ok 27\n"; }
0678cb22 142
143close($tst);
144
145