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
1 #!./perl
2
3 BEGIN {
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
11 print "1..6\n";
12
13 {
14 no warnings 'io';
15 print "not " unless tell(TEST) == -1;
16 print "ok 1\n";
17 }
18
19 open(TEST, "TEST")      || die "$0: failed to open 'TEST' for reading: $!\n";
20
21 print "not " unless tell(TEST) == 0;
22 print "ok 2\n";
23
24 my ($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
31 print "not " unless tell(TEST)  == 2;
32 print "ok 3\n";
33
34 print "not " unless tell()      == 2;
35 print "ok 4\n";
36
37 my $TEST = 'TEST';
38
39 print "not " unless tell($TEST) == 2;
40 print "ok 5\n";
41
42 close(TEST)             || warn "$0: close() failed: $!\n";
43
44 {
45 no warnings 'io';
46 print "not " unless tell(TEST) == -1;
47 print "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