This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
(Subsumed by #7664)
[perl5.git] / t / op / tell.t
CommitLineData
3b7ee3f0
JH
1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6}
7
8# NOTE: we cannot use seek() here because using that *portably* would mean
9# using Fcntl and the principle is not to use any extensions in the t/op/*
10
11print "1..6\n";
12
13{
14no warnings 'io';
15print "not " unless tell(TEST) == -1;
16print "ok 1\n";
17}
18
19open(TEST, "TEST") || die "$0: failed to open 'TEST' for reading: $!\n";
20
21print "not " unless tell(TEST) == 0;
22print "ok 2\n";
23
24my ($s, $read);
25
26$read = read(TEST, $s, 2);
27
28$read == 2 || warn "$0: read() returned $read, expected 2\n";
29$s eq '#!' || warn "$0: read() read '$s', expected '#!'\n";
30
31print "not " unless tell(TEST) == 2;
32print "ok 3\n";
33
34print "not " unless tell() == 2;
35print "ok 4\n";
36
37my $TEST = 'TEST';
38
39print "not " unless tell($TEST) == 2;
40print "ok 5\n";
41
42close(TEST) || warn "$0: close() failed: $!\n";
43
44{
45no warnings 'io';
46print "not " unless tell(TEST) == -1;
47print "ok 6\n";
48}
49
50# ftell(STDIN) (or any std streams) is undefined, it can return -1 or
51# something else. ftell() on pipes, fifos, and sockets is defined to
52# return -1.
53