1 |
#!/usr/bin/perl |
2 |
use strict; |
3 |
use warnings; |
4 |
|
5 |
my $debug = shift @ARGV; |
6 |
|
7 |
use Test::More tests => 135; |
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 |
local $/; |
23 |
$content = <$fh>; |
24 |
ok( $content, 'has content' ); |
25 |
} |
26 |
ok( close($fh), 'close' ); |
27 |
|
28 |
ok ( -e "$to/$path", 'exists' ); |
29 |
|
30 |
ok( -e "$from/$path" || -e "$from/${path}.gz", 'on disk' ); |
31 |
|
32 |
ok( -e "$tmp/$path" , 'in tmp' ) if ( $op =~ m/</ ); |
33 |
|
34 |
return $content; |
35 |
} |
36 |
|
37 |
my $buff = '<<--just a chunk of data-->>'; |
38 |
|
39 |
for my $i ( 1 .. 3 ) { |
40 |
my $content = $buff x int(3 + $i * rand(15)); |
41 |
$content =~ s/\s+/ /gs; |
42 |
|
43 |
my $file = "test.$i"; |
44 |
|
45 |
file( '>', $file, $content ); |
46 |
cmp_ok( file( '<', $file ), 'eq', $content, "$file content" ); |
47 |
|
48 |
file( '>>', $file, '+append' ); |
49 |
cmp_ok( file( '<', $file ), 'eq', $content . '+append', "$file append" ); |
50 |
|
51 |
file( '>', $file, '' ); |
52 |
cmp_ok( file( '<', $file ), 'eq', '', "$file empty" ); |
53 |
|
54 |
file( '>', $file, $content ); |
55 |
cmp_ok( file( '<', $file ), 'eq', $content, "$file content" ); |
56 |
|
57 |
} |