1 |
#!/usr/bin/perl |
2 |
use strict; |
3 |
use warnings; |
4 |
|
5 |
my $debug = shift @ARGV; |
6 |
|
7 |
use Test::More tests => 115; |
8 |
use File::Slurp; |
9 |
|
10 |
my ( $from, $to, $tmp ) = ( '/tmp/comp', '/tmp/no-comp', '/dev/shm/comp' ); |
11 |
|
12 |
ok( -e $from, 'from' ); |
13 |
ok( -e $to, 'to' ); |
14 |
ok( -e $tmp, 'tmp' ); |
15 |
|
16 |
sub file { |
17 |
my ( $op, $path, $content ) = @_; |
18 |
ok( open( my $fh, $op, "$to/$path" ), "open( $op $path )"); |
19 |
if ( $op =~ m/>/ ) { |
20 |
print $fh $content; |
21 |
} else { |
22 |
my $orig_content = $content; |
23 |
local $/; |
24 |
$content = <$fh>; |
25 |
if ( defined( $content ) ) { |
26 |
cmp_ok( $content, 'eq', $orig_content, 'content' ); |
27 |
} else { |
28 |
ok( $content, 'has content' ); |
29 |
} |
30 |
} |
31 |
ok( close($fh), 'close' ); |
32 |
|
33 |
ok ( -e "$to/$path", 'exists' ); |
34 |
|
35 |
my $pack = "$from/${path}.gz"; |
36 |
|
37 |
if ( -e $pack ) { |
38 |
ok( -s $pack, 'on disk packed' ); |
39 |
ok( -e "$tmp/$path" , 'in tmp unpacked' ) if ( $op =~ m/</ ); |
40 |
} else { |
41 |
ok( -e "$from/$path", 'on disk unpacked' ); |
42 |
} |
43 |
|
44 |
return $content; |
45 |
} |
46 |
|
47 |
my $buff = '<<--just a chunk of data-->>'; |
48 |
|
49 |
for my $i ( 1 .. 3 ) { |
50 |
my $content = $buff x int(3 + $i * rand(15)); |
51 |
$content =~ s/\s+/ /gs; |
52 |
|
53 |
my $file = "test.$i"; |
54 |
|
55 |
file( '>', $file, $content ); |
56 |
file( '<', $file, $content ); |
57 |
|
58 |
file( '>>', $file, '+append' ); |
59 |
file( '<', $file, $content . '+append' ); |
60 |
|
61 |
file( '>', $file, '' ); |
62 |
file( '<', $file, '' ); |
63 |
|
64 |
file( '>', $file, $content ); |
65 |
file( '<', $file, $content ); |
66 |
|
67 |
} |