Save message when calling __DIE__ hook
[p5sagit/p5-mst-13.2.git] / t / op / sysio.t
CommitLineData
bbce6d69 1#!./perl
2
3print "1..30\n";
4
5chdir('op') || die "sysio.t: cannot look for myself: $!";
6
7open(I, 'sysio.t') || die "sysio.t: cannot find myself: $!";
8
9$x = 'abc';
10
11# should not be able to do negative lengths
12eval { sysread(I, $x, -1) };
13print 'not ' unless ($@ =~ /^Negative length /);
14print "ok 1\n";
15
16# $x should be intact
17print 'not ' unless ($x eq 'abc');
18print "ok 2\n";
19
20# should not be able to read before the buffer
21eval { sysread(I, $x, 1, -4) };
22print 'not ' unless ($x eq 'abc');
23print "ok 3\n";
24
25# $x should be intact
26print 'not ' unless ($x eq 'abc');
27print "ok 4\n";
28
29$a ='0123456789';
30
31# default offset 0
32print 'not ' unless(sysread(I, $a, 3) == 3);
33print "ok 5\n";
34
35# $a should be as follows
36print 'not ' unless ($a eq '#!.');
37print "ok 6\n";
38
39# reading past the buffer should zero pad
40print 'not ' unless(sysread(I, $a, 2, 5) == 2);
41print "ok 7\n";
42
43# the zero pad should be seen now
44print 'not ' unless ($a eq "#!.\0\0/p");
45print "ok 8\n";
46
47# try changing the last two characters of $a
48print 'not ' unless(sysread(I, $a, 3, -2) == 3);
49print "ok 9\n";
50
51# the last two characters of $a should have changed (into three)
52print 'not ' unless ($a eq "#!.\0\0erl");
53print "ok 10\n";
54
55$outfile = 'sysio.out';
56
57open(O, ">$outfile") || die "sysio.t: cannot write $outfile: $!";
58
59select(O); $|=1; select(STDOUT);
60
61# cannot write negative lengths
62eval { syswrite(O, $x, -1) };
63print 'not ' unless ($@ =~ /^Negative length /);
64print "ok 11\n";
65
66# $x still intact
67print 'not ' unless ($x eq 'abc');
68print "ok 12\n";
69
70# $outfile still intact
71print 'not ' if (-s $outfile);
72print "ok 13\n";
73
74# should not be able to write from after the buffer
75eval { syswrite(O, $x, 1, 3) };
76print 'not ' unless ($@ =~ /^Offset outside string /);
77print "ok 14\n";
78
79# $x still intact
80print 'not ' unless ($x eq 'abc');
81print "ok 15\n";
82
83# $outfile still intact
84print 'not ' if (-s $outfile);
85print "ok 16\n";
86
87# should not be able to write from before the buffer
88
89eval { syswrite(O, $x, 1, -4) };
90print 'not ' unless ($@ =~ /^Offset outside string /);
91print "ok 17\n";
92
93# $x still intact
94print 'not ' unless ($x eq 'abc');
95print "ok 18\n";
96
97# $outfile still intact
98print 'not ' if (-s $outfile);
99print "ok 19\n";
100
101# default offset 0
102print 'not ' unless (syswrite(O, $a, 2) == 2);
103print "ok 20\n";
104
105# $a still intact
106print 'not ' unless ($a eq "#!.\0\0erl");
107print "ok 21\n";
108
109# $outfile should have grown now
110print 'not ' unless (-s $outfile == 2);
111print "ok 22\n";
112
113# with offset
114print 'not ' unless (syswrite(O, $a, 2, 5) == 2);
115print "ok 23\n";
116
117# $a still intact
118print 'not ' unless ($a eq "#!.\0\0erl");
119print "ok 24\n";
120
121# $outfile should have grown now
122print 'not ' unless (-s $outfile == 4);
123print "ok 25\n";
124
125# with negative offset and a bit too much length
126print 'not ' unless (syswrite(O, $a, 5, -3) == 3);
127print "ok 26\n";
128
129# $a still intact
130print 'not ' unless ($a eq "#!.\0\0erl");
131print "ok 27\n";
132
133# $outfile should have grown now
134print 'not ' unless (-s $outfile == 7);
135print "ok 28\n";
136
137close(O);
138
139open(I, $outfile) || die "sysio.t: cannot read $outfile: $!";
140
141$b = 'xyz';
142
143# reading too much only return as much as available
144print 'not ' unless (sysread(I, $b, 100) == 7);
145print "ok 29\n";
146# this we should have
147print 'not ' unless ($b eq '#!ererl');
148print "ok 30\n";
149
150close(I);
151
152unlink $outfile;
153
1541;
155
156# eof