Add more known sprintf failures.
[p5sagit/p5-mst-13.2.git] / t / op / sysio.t
CommitLineData
bbce6d69 1#!./perl
2
b56ec344 3print "1..39\n";
bbce6d69 4
bfb65faf 5chdir('op') || chdir('t/op') || die "sysio.t: cannot look for myself: $!";
bbce6d69 6
7open(I, 'sysio.t') || die "sysio.t: cannot find myself: $!";
8
57af3f31 9$reopen = ($^O eq 'VMS' || $^O eq 'os2' || $^O eq 'MSWin32' || $^O eq 'dos' ||
10 $^O eq 'mpeix');
9fcfb7d3 11
bbce6d69 12$x = 'abc';
13
14# should not be able to do negative lengths
15eval { sysread(I, $x, -1) };
16print 'not ' unless ($@ =~ /^Negative length /);
17print "ok 1\n";
18
19# $x should be intact
20print 'not ' unless ($x eq 'abc');
21print "ok 2\n";
22
23# should not be able to read before the buffer
24eval { sysread(I, $x, 1, -4) };
25print 'not ' unless ($x eq 'abc');
26print "ok 3\n";
27
28# $x should be intact
29print 'not ' unless ($x eq 'abc');
30print "ok 4\n";
31
32$a ='0123456789';
33
34# default offset 0
35print 'not ' unless(sysread(I, $a, 3) == 3);
36print "ok 5\n";
37
38# $a should be as follows
39print 'not ' unless ($a eq '#!.');
40print "ok 6\n";
41
42# reading past the buffer should zero pad
43print 'not ' unless(sysread(I, $a, 2, 5) == 2);
44print "ok 7\n";
45
46# the zero pad should be seen now
47print 'not ' unless ($a eq "#!.\0\0/p");
48print "ok 8\n";
49
50# try changing the last two characters of $a
51print 'not ' unless(sysread(I, $a, 3, -2) == 3);
52print "ok 9\n";
53
54# the last two characters of $a should have changed (into three)
55print 'not ' unless ($a eq "#!.\0\0erl");
56print "ok 10\n";
57
58$outfile = 'sysio.out';
59
60open(O, ">$outfile") || die "sysio.t: cannot write $outfile: $!";
61
62select(O); $|=1; select(STDOUT);
63
64# cannot write negative lengths
65eval { syswrite(O, $x, -1) };
66print 'not ' unless ($@ =~ /^Negative length /);
67print "ok 11\n";
68
69# $x still intact
70print 'not ' unless ($x eq 'abc');
71print "ok 12\n";
72
73# $outfile still intact
74print 'not ' if (-s $outfile);
75print "ok 13\n";
76
77# should not be able to write from after the buffer
78eval { syswrite(O, $x, 1, 3) };
79print 'not ' unless ($@ =~ /^Offset outside string /);
80print "ok 14\n";
81
82# $x still intact
83print 'not ' unless ($x eq 'abc');
84print "ok 15\n";
85
86# $outfile still intact
9fcfb7d3 87if ($reopen) { # must close file to update EOF marker for stat
88 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
89}
bbce6d69 90print 'not ' if (-s $outfile);
91print "ok 16\n";
92
93# should not be able to write from before the buffer
94
95eval { syswrite(O, $x, 1, -4) };
96print 'not ' unless ($@ =~ /^Offset outside string /);
97print "ok 17\n";
98
99# $x still intact
100print 'not ' unless ($x eq 'abc');
101print "ok 18\n";
102
103# $outfile still intact
9fcfb7d3 104if ($reopen) { # must close file to update EOF marker for stat
105 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
106}
bbce6d69 107print 'not ' if (-s $outfile);
108print "ok 19\n";
109
110# default offset 0
111print 'not ' unless (syswrite(O, $a, 2) == 2);
112print "ok 20\n";
113
114# $a still intact
115print 'not ' unless ($a eq "#!.\0\0erl");
116print "ok 21\n";
117
118# $outfile should have grown now
9fcfb7d3 119if ($reopen) { # must close file to update EOF marker for stat
120 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
121}
bbce6d69 122print 'not ' unless (-s $outfile == 2);
123print "ok 22\n";
124
125# with offset
126print 'not ' unless (syswrite(O, $a, 2, 5) == 2);
127print "ok 23\n";
128
129# $a still intact
130print 'not ' unless ($a eq "#!.\0\0erl");
131print "ok 24\n";
132
133# $outfile should have grown now
9fcfb7d3 134if ($reopen) { # must close file to update EOF marker for stat
135 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
136}
bbce6d69 137print 'not ' unless (-s $outfile == 4);
138print "ok 25\n";
139
140# with negative offset and a bit too much length
141print 'not ' unless (syswrite(O, $a, 5, -3) == 3);
142print "ok 26\n";
143
144# $a still intact
145print 'not ' unless ($a eq "#!.\0\0erl");
146print "ok 27\n";
147
148# $outfile should have grown now
9fcfb7d3 149if ($reopen) { # must close file to update EOF marker for stat
150 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
151}
bbce6d69 152print 'not ' unless (-s $outfile == 7);
153print "ok 28\n";
154
b56ec344 155# with implicit length argument
156print 'not ' unless (syswrite(O, $x) == 3);
157print "ok 29\n";
158
159# $a still intact
160print 'not ' unless ($x eq "abc");
161print "ok 30\n";
162
163# $outfile should have grown now
164if ($reopen) { # must close file to update EOF marker for stat
165 close O; open(O, ">>$outfile") || die "sysio.t: cannot write $outfile: $!";
166}
167print 'not ' unless (-s $outfile == 10);
168print "ok 31\n";
169
bbce6d69 170close(O);
171
172open(I, $outfile) || die "sysio.t: cannot read $outfile: $!";
173
174$b = 'xyz';
175
176# reading too much only return as much as available
b56ec344 177print 'not ' unless (sysread(I, $b, 100) == 10);
178print "ok 32\n";
bbce6d69 179# this we should have
b56ec344 180print 'not ' unless ($b eq '#!ererlabc');
181print "ok 33\n";
bbce6d69 182
8903cb82 183# test sysseek
137443ea 184
8903cb82 185print 'not ' unless sysseek(I, 2, 0) == 2;
b56ec344 186print "ok 34\n";
137443ea 187sysread(I, $b, 3);
188print 'not ' unless $b eq 'ere';
b56ec344 189print "ok 35\n";
137443ea 190
8903cb82 191print 'not ' unless sysseek(I, -2, 1) == 3;
b56ec344 192print "ok 36\n";
137443ea 193sysread(I, $b, 4);
194print 'not ' unless $b eq 'rerl';
b56ec344 195print "ok 37\n";
137443ea 196
8903cb82 197print 'not ' unless sysseek(I, 0, 0) eq '0 but true';
b56ec344 198print "ok 38\n";
8903cb82 199print 'not ' if defined sysseek(I, -1, 1);
b56ec344 200print "ok 39\n";
8903cb82 201
bbce6d69 202close(I);
203
204unlink $outfile;
205
8ebc5c01 206chdir('..');
207
bbce6d69 2081;
209
210# eof