4 |
|
|
5 |
my $debug = shift @ARGV; |
my $debug = shift @ARGV; |
6 |
|
|
7 |
use Test::More tests => 227; |
use Test::More tests => 710; |
8 |
use File::Slurp; |
use File::Slurp; |
9 |
use IO::File; |
use IO::File; |
10 |
|
|
21 |
ok( open(my $d, '<', "$to/.debug"), 'open debug' ); |
ok( open(my $d, '<', "$to/.debug"), 'open debug' ); |
22 |
local $/; |
local $/; |
23 |
my $dump = <$d>; |
my $dump = <$d>; |
24 |
diag "DEBUG: $msg\n$dump\n"; |
diag "DEBUG: $msg\n$dump\n" if $debug; |
25 |
ok( close($d), 'close debug' ); |
ok( close($d), 'close debug' ); |
26 |
} |
} |
27 |
|
|
63 |
ok( -e "$tmp/$path" , "in tmp $tmp/$path" ) if ( $op eq '<' ); |
ok( -e "$tmp/$path" , "in tmp $tmp/$path" ) if ( $op eq '<' ); |
64 |
# check total size if not append |
# check total size if not append |
65 |
if ( $op ne '>>' ) { |
if ( $op ne '>>' ) { |
66 |
cmp_ok( -s "$tmp/$path", '==', $size, "$tmp/$path = $size bytes" ); |
cmp_ok( -s $pack, '==', $size, "$tmp/$path = $size bytes" ); |
67 |
} |
} |
68 |
} else { |
} else { |
69 |
ok( -e "$from/$path", "on disk $from/$path" ); |
ok( -e "$from/$path", "on disk $from/$path" ); |
70 |
|
my $curr_size = -s "$from/$path"; |
71 |
|
diag "$op curr_size: $curr_size size: $size"; |
72 |
|
$size += $curr_size if ( $op eq '>>' ); |
73 |
cmp_ok( -s "$from/$path", '==', $size, "$from/$path = $size bytes" ); |
cmp_ok( -s "$from/$path", '==', $size, "$from/$path = $size bytes" ); |
74 |
} |
} |
75 |
|
|
95 |
file( '>', $file, '' ); |
file( '>', $file, '' ); |
96 |
file( '<', $file, '' ); |
file( '<', $file, '' ); |
97 |
|
|
98 |
# file( '>', $file, $content ); |
file( '>', $file, $content ); |
99 |
# file( '<', $file, $content ); |
file( '<', $file, $content ); |
100 |
|
|
101 |
|
} |
102 |
|
|
103 |
|
|
104 |
|
sub multiple_rw { |
105 |
|
|
106 |
|
diag "multiple read-write"; |
107 |
|
ok( my $fh1 = IO::File->new("> $to/m"), 'open 1' ); |
108 |
|
$fh1->autoflush; |
109 |
|
ok( print($fh1 "1.1\n"), 'print 1.1' ); |
110 |
|
ok( my $fh2 = IO::File->new(">> $to/m"), 'open 2' ); |
111 |
|
$fh2->autoflush; |
112 |
|
ok( print($fh2 "2.1\n"), 'print 2.1' ); |
113 |
|
cmp_ok( read_file("$to/m"), 'eq', "1.1\n2.1\n", 'mixed' ); |
114 |
|
ok( print($fh1 "1.2\n"), 'print 1.2' ); |
115 |
|
cmp_ok( read_file("$to/m"), 'eq', "1.1\n1.2\n", 'just 1' ); |
116 |
|
dump_debug 'own twice'; |
117 |
|
ok( print($fh1 "x" x 65535), 'print 1 64k' ); |
118 |
|
ok( close($fh1), 'close 1' ); |
119 |
|
dump_debug 'own once'; |
120 |
|
ok( close($fh2), 'close 2' ); |
121 |
|
dump_debug 'closed'; |
122 |
|
|
123 |
|
my @sizes; |
124 |
|
my $size = 65536; |
125 |
|
while ( $size > 1 ) { |
126 |
|
push @sizes, $size; |
127 |
|
$size /= 2; |
128 |
|
} |
129 |
|
|
130 |
|
foreach my $size ( @sizes ) { |
131 |
|
ok( my $fh1 = IO::File->new("> $to/m"), 'open 1' ); |
132 |
|
ok( truncate( $fh1, $size ), 'truncate' ); |
133 |
|
dump_debug 'truncate'; |
134 |
|
ok( close($fh1), 'close 1' ); |
135 |
|
cmp_ok( -s "$to/m", '==', $size, "truncated to $size" ); |
136 |
|
} |
137 |
|
|
138 |
|
|
139 |
|
foreach my $size ( sort @sizes ) { |
140 |
|
my $orig_size = -s "$to/m"; |
141 |
|
ok( my $fh1 = IO::File->new(">> $to/m"), 'open 1' ); |
142 |
|
ok( print($fh1 "x" x $size), "print $size bytes" ); |
143 |
|
dump_debug 'append'; |
144 |
|
ok( close($fh1), 'close 1' ); |
145 |
|
my $expected_size = $size + $orig_size; |
146 |
|
cmp_ok( -s "$to/m", '==', $expected_size, "appended upto $expected_size" ); |
147 |
|
} |
148 |
|
|
149 |
|
|
150 |
} |
} |
151 |
|
|
152 |
diag "multiple read-write"; |
multiple_rw; |
153 |
|
multiple_rw; |
154 |
|
|
|
ok( my $fh1 = IO::File->new("> $to/m"), 'open 1' ); |
|
|
$fh1->autoflush; |
|
|
ok( print($fh1 "1.1\n"), 'print 1.1' ); |
|
|
ok( my $fh2 = IO::File->new(">> $to/m"), 'open 2' ); |
|
|
$fh2->autoflush; |
|
|
ok( print($fh2 "2.1\n"), 'print 2.1' ); |
|
|
cmp_ok( read_file("$to/m"), 'eq', "1.1\n2.1\n", 'mixed' ); |
|
|
ok( print($fh1 "1.2\n"), 'print 1.2' ); |
|
|
cmp_ok( read_file("$to/m"), 'eq', "1.1\n1.2\n", 'just 1' ); |
|
155 |
|
|