1 |
#!/usr/bin/perl |
2 |
use test::helper qw($_real $_point); |
3 |
use Test::More; |
4 |
plan tests => 15; |
5 |
my ($data); |
6 |
chdir($_point); |
7 |
undef $/; # slurp it all |
8 |
# create file |
9 |
system("echo frogbing >writefile"); |
10 |
|
11 |
# fetch contents of file |
12 |
ok(open(FILE,"writefile"),"open"); |
13 |
$data = <FILE>; |
14 |
close(FILE); |
15 |
is(length($data),9,"right amount read"); |
16 |
is($data,"frogbing\n","right data read"); |
17 |
|
18 |
# overwrite part |
19 |
ok(open(FILE,'+<',"writefile"),"open"); |
20 |
ok(seek(FILE,2,0),"seek"); |
21 |
ok(print(FILE "ib"),"print"); |
22 |
close(FILE); |
23 |
|
24 |
# fetch contents of file |
25 |
ok(open(FILE,"writefile"),"open"); |
26 |
$data = <FILE>; |
27 |
close(FILE); |
28 |
is(length($data),9,"right amount read"); |
29 |
is($data,"fribbing\n","right data read"); |
30 |
|
31 |
# overwrite part, append some |
32 |
ok(open(FILE,'+<',"writefile"),"open"); |
33 |
ok(seek(FILE,7,0),"seek"); |
34 |
ok(print(FILE "gle"),"print"); |
35 |
close(FILE); |
36 |
|
37 |
# fetch contents of file |
38 |
ok(open(FILE,"writefile"),"open"); |
39 |
$data = <FILE>; |
40 |
close(FILE); |
41 |
is(length($data),10,"right amount read"); |
42 |
is($data,"fribbingle","right data read"); |
43 |
|
44 |
# kill file |
45 |
unlink("writefile"); |