--- t/fs.t 2007/07/09 10:35:02 12 +++ t/fs.t 2007/07/09 13:45:45 16 @@ -4,7 +4,7 @@ my $debug = shift @ARGV; -use Test::More tests => 227; +use Test::More tests => 710; use File::Slurp; use IO::File; @@ -21,7 +21,7 @@ ok( open(my $d, '<', "$to/.debug"), 'open debug' ); local $/; my $dump = <$d>; - diag "DEBUG: $msg\n$dump\n"; + diag "DEBUG: $msg\n$dump\n" if $debug; ok( close($d), 'close debug' ); } @@ -63,10 +63,12 @@ ok( -e "$tmp/$path" , "in tmp $tmp/$path" ) if ( $op eq '<' ); # check total size if not append if ( $op ne '>>' ) { - cmp_ok( -s "$tmp/$path", '==', $size, "$tmp/$path = $size bytes" ); + cmp_ok( -s $pack, '==', $size, "$tmp/$path = $size bytes" ); } } else { ok( -e "$from/$path", "on disk $from/$path" ); + diag "$op curr_size: $orig_size size: $size"; + $size += $orig_size if ( $op eq '>>' ); cmp_ok( -s "$from/$path", '==', $size, "$from/$path = $size bytes" ); } @@ -92,20 +94,61 @@ file( '>', $file, '' ); file( '<', $file, '' ); -# file( '>', $file, $content ); -# file( '<', $file, $content ); + file( '>', $file, $content ); + file( '<', $file, $content ); + +} + + +sub multiple_rw { + + diag "multiple read-write"; + 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' ); + dump_debug 'own twice'; + ok( print($fh1 "x" x 65535), 'print 1 64k' ); + ok( close($fh1), 'close 1' ); + dump_debug 'own once'; + ok( close($fh2), 'close 2' ); + dump_debug 'closed'; + + my @sizes; + my $size = 65536; + while ( $size > 1 ) { + push @sizes, $size; + $size /= 2; + } + + foreach my $size ( @sizes ) { + ok( my $fh1 = IO::File->new("> $to/m"), 'open 1' ); + ok( truncate( $fh1, $size ), 'truncate' ); + dump_debug 'truncate'; + ok( close($fh1), 'close 1' ); + cmp_ok( -s "$to/m", '==', $size, "truncated to $size" ); + } + + + foreach my $size ( sort @sizes ) { + my $orig_size = -s "$to/m"; + ok( my $fh1 = IO::File->new(">> $to/m"), 'open 1' ); + ok( print($fh1 "x" x $size), "print $size bytes" ); + dump_debug 'append'; + ok( close($fh1), 'close 1' ); + my $expected_size = $size + $orig_size; + cmp_ok( -s "$to/m", '==', $expected_size, "appended upto $expected_size" ); + } + } -diag "multiple read-write"; +multiple_rw; +multiple_rw; -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' );