source: trunk/essentials/dev-lang/perl/t/op/sysio.t

Last change on this file was 3181, checked in by bird, 19 years ago

perl 5.8.8

File size: 5.6 KB
Line 
1#!./perl
2
3print "1..42\n";
4
5chdir('op') || chdir('t/op') || die "sysio.t: cannot look for myself: $!";
6@INC = '../../lib';
7
8open(I, 'sysio.t') || die "sysio.t: cannot find myself: $!";
9
10$reopen = ($^O eq 'VMS' ||
11 $^O eq 'os2' ||
12 $^O eq 'MSWin32' ||
13 $^O eq 'NetWare' ||
14 $^O eq 'dos' ||
15 $^O eq 'mpeix');
16
17$x = 'abc';
18
19# should not be able to do negative lengths
20eval { sysread(I, $x, -1) };
21print 'not ' unless ($@ =~ /^Negative length /);
22print "ok 1\n";
23
24# $x should be intact
25print 'not ' unless ($x eq 'abc');
26print "ok 2\n";
27
28# should not be able to read before the buffer
29eval { sysread(I, $x, 1, -4) };
30print 'not ' unless ($x eq 'abc');
31print "ok 3\n";
32
33# $x should be intact
34print 'not ' unless ($x eq 'abc');
35print "ok 4\n";
36
37$a ='0123456789';
38
39# default offset 0
40print 'not ' unless(sysread(I, $a, 3) == 3);
41print "ok 5\n";
42
43# $a should be as follows
44print 'not ' unless ($a eq '#!.');
45print "ok 6\n";
46
47# reading past the buffer should zero pad
48print 'not ' unless(sysread(I, $a, 2, 5) == 2);
49print "ok 7\n";
50
51# the zero pad should be seen now
52print 'not ' unless ($a eq "#!.\0\0/p");
53print "ok 8\n";
54
55# try changing the last two characters of $a
56print 'not ' unless(sysread(I, $a, 3, -2) == 3);
57print "ok 9\n";
58
59# the last two characters of $a should have changed (into three)
60print 'not ' unless ($a eq "#!.\0\0erl");
61print "ok 10\n";