Commit | Line | Data |
---|---|---|
8d063cd8 LW |
1 | #!./perl |
2 | ||
58c59f01 NC |
3 | BEGIN { |
4 | chdir 't' if -d 't'; | |
5 | @INC = '../lib'; | |
6 | } | |
7 | ||
c2fcde81 | 8 | print "1..28\n"; |
8d063cd8 | 9 | |
3fb41248 | 10 | $TST = 'TST'; |
378cc40b | 11 | |
2986a63f | 12 | $Is_Dosish = ($^O eq 'MSWin32' or $^O eq 'NetWare' or $^O eq 'dos' or |
cebd85e6 JH |
13 | $^O eq 'os2' or $^O eq 'mint' or $^O eq 'cygwin' or |
14 | $^O =~ /^uwin/); | |
8736538c | 15 | |
2eb25c99 | 16 | open($TST, 'harness') || (die "Can't open harness"); |
8736538c | 17 | binmode $TST if $Is_Dosish; |
3fb41248 | 18 | if (eof(TST)) { print "not ok 1\n"; } else { print "ok 1\n"; } |
8d063cd8 | 19 | |
378cc40b | 20 | $firstline = <$TST>; |
8d063cd8 LW |
21 | $secondpos = tell; |
22 | ||
23 | $x = 0; | |
3fb41248 | 24 | while (<TST>) { |
8d063cd8 LW |
25 | if (eof) {$x++;} |
26 | } | |
27 | if ($x == 1) { print "ok 2\n"; } else { print "not ok 2\n"; } | |
28 | ||
29 | $lastpos = tell; | |
30 | ||
31 | unless (eof) { print "not ok 3\n"; } else { print "ok 3\n"; } | |
32 | ||
378cc40b | 33 | if (seek($TST,0,0)) { print "ok 4\n"; } else { print "not ok 4\n"; } |
8d063cd8 LW |
34 | |
35 | if (eof) { print "not ok 5\n"; } else { print "ok 5\n"; } | |
36 | ||
3fb41248 | 37 | if ($firstline eq <TST>) { print "ok 6\n"; } else { print "not ok 6\n"; } |
8d063cd8 LW |
38 | |
39 | if ($secondpos == tell) { print "ok 7\n"; } else { print "not ok 7\n"; } | |
40 | ||
3fb41248 | 41 | if (seek(TST,0,1)) { print "ok 8\n"; } else { print "not ok 8\n"; } |
8d063cd8 | 42 | |
378cc40b | 43 | if (eof($TST)) { print "not ok 9\n"; } else { print "ok 9\n"; } |
8d063cd8 LW |
44 | |
45 | if ($secondpos == tell) { print "ok 10\n"; } else { print "not ok 10\n"; } | |
46 | ||
3fb41248 | 47 | if (seek(TST,0,2)) { print "ok 11\n"; } else { print "not ok 11\n"; } |
8d063cd8 LW |
48 | |
49 | if ($lastpos == tell) { print "ok 12\n"; } else { print "not ok 12\n"; } | |
50 | ||
51 | unless (eof) { print "not ok 13\n"; } else { print "ok 13\n"; } | |
455ece5e AD |
52 | |
53 | if ($. == 0) { print "not ok 14\n"; } else { print "ok 14\n"; } | |
54 | ||
55 | $curline = $.; | |
3fb41248 SP |
56 | open(OTHER, 'harness') || (die "Can't open harness: $!"); |
57 | binmode OTHER if (($^O eq 'MSWin32') || ($^O eq 'NetWare')); | |
455ece5e AD |
58 | |
59 | { | |
60 | local($.); | |
61 | ||
62 | if ($. == 0) { print "not ok 15\n"; } else { print "ok 15\n"; } | |
63 | ||
3fb41248 | 64 | tell OTHER; |
455ece5e AD |
65 | if ($. == 0) { print "ok 16\n"; } else { print "not ok 16\n"; } |
66 | ||
67 | $. = 5; | |
3fb41248 | 68 | scalar <OTHER>; |
455ece5e AD |
69 | if ($. == 6) { print "ok 17\n"; } else { print "not ok 17\n"; } |
70 | } | |
71 | ||
72 | if ($. == $curline) { print "ok 18\n"; } else { print "not ok 18\n"; } | |
73 | ||
74 | { | |
75 | local($.); | |
76 | ||
3fb41248 | 77 | scalar <OTHER>; |
455ece5e AD |
78 | if ($. == 7) { print "ok 19\n"; } else { print "not ok 19\n"; } |
79 | } | |
80 | ||
81 | if ($. == $curline) { print "ok 20\n"; } else { print "not ok 20\n"; } | |
82 | ||
83 | { | |
84 | local($.); | |
85 | ||
3fb41248 | 86 | tell OTHER; |
455ece5e AD |
87 | if ($. == 7) { print "ok 21\n"; } else { print "not ok 21\n"; } |
88 | } | |
d26ab924 | 89 | |
3fb41248 SP |
90 | close(OTHER); |
91 | { | |
92 | no warnings 'closed'; | |
93 | if (tell(OTHER) == -1) { print "ok 22\n"; } else { print "not ok 22\n"; } | |
94 | } | |
95 | { | |
96 | no warnings 'unopened'; | |
97 | if (tell(ETHER) == -1) { print "ok 23\n"; } else { print "not ok 23\n"; } | |
98 | } | |
d26ab924 JH |
99 | |
100 | # ftell(STDIN) (or any std streams) is undefined, it can return -1 or | |
101 | # something else. ftell() on pipes, fifos, and sockets is defined to | |
102 | # return -1. | |
103 | ||
0678cb22 NIS |
104 | my $written = "tell_write.txt"; |
105 | ||
4e7ee149 | 106 | END { 1 while unlink($written) } |
0678cb22 | 107 | |
3fb41248 | 108 | close($TST); |
0678cb22 | 109 | open($tst,">$written") || die "Cannot open $written:$!"; |
7bdbfeb7 | 110 | binmode $tst if $Is_Dosish; |
0678cb22 NIS |
111 | |
112 | if (tell($tst) == 0) { print "ok 24\n"; } else { print "not ok 24\n"; } | |
113 | ||
114 | print $tst "fred\n"; | |
115 | ||
116 | if (tell($tst) == 5) { print "ok 25\n"; } else { print "not ok 25\n"; } | |
117 | ||
118 | print $tst "more\n"; | |
119 | ||
120 | if (tell($tst) == 10) { print "ok 26\n"; } else { print "not ok 26\n"; } | |
121 | ||
122 | close($tst); | |
123 | ||
124 | open($tst,"+>>$written") || die "Cannot open $written:$!"; | |
7bdbfeb7 | 125 | binmode $tst if $Is_Dosish; |
0678cb22 NIS |
126 | |
127 | if (0) | |
128 | { | |
129 | # :stdio does not pass these so ignore them for now | |
130 | ||
131 | if (tell($tst) == 0) { print "ok 27\n"; } else { print "not ok 27\n"; } | |
132 | ||
133 | $line = <$tst>; | |
134 | ||
135 | if ($line eq "fred\n") { print "ok 29\n"; } else { print "not ok 29\n"; } | |
136 | ||
137 | if (tell($tst) == 5) { print "ok 30\n"; } else { print "not ok 30\n"; } | |
138 | ||
139 | } | |
140 | ||
141 | print $tst "xxxx\n"; | |
142 | ||
c6b46866 JH |
143 | if (tell($tst) == 15 || |
144 | tell($tst) == 5) # unset PERLIO or PERLIO=stdio (e.g. HP-UX, Solaris) | |
145 | { print "ok 27\n"; } else { print "not ok 27\n"; } | |
0678cb22 NIS |
146 | |
147 | close($tst); | |
148 | ||
c2fcde81 JH |
149 | open($tst,">$written") || die "Cannot open $written:$!"; |
150 | print $tst "foobar"; | |
151 | close $tst; | |
152 | open($tst,">>$written") || die "Cannot open $written:$!"; | |
153 | ||
e4fdb327 YST |
154 | # This test makes a questionable assumption that the file pointer will |
155 | # be at eof after opening a file but before seeking, reading, or writing. | |
156 | # Only known failure is on cygwin. | |
92770387 YST |
157 | my $todo = $^O eq "cygwin" && &PerlIO::get_layers($tst) eq 'stdio' |
158 | && ' # TODO: file pointer not at eof'; | |
e4fdb327 | 159 | |
c2fcde81 | 160 | if (tell($tst) == 6) |
92770387 | 161 | { print "ok 28$todo\n"; } else { print "not ok 28$todo\n"; } |
c2fcde81 | 162 | close $tst; |
0678cb22 | 163 |