1 |
#!/usr/bin/perl |
2 |
|
3 |
use warnings; |
4 |
use strict; |
5 |
use autodie; |
6 |
|
7 |
use Test::More tests => 17; |
8 |
use Data::Dump qw/dump/; |
9 |
|
10 |
use_ok 'file'; |
11 |
|
12 |
my $file = '/tmp/test'; |
13 |
|
14 |
ok( ! -e $file, "$file doesn't exist" ); |
15 |
ok( file::append( $file, 'test' ), 'append' ); |
16 |
ok( my $size = -s $file, "size" ); |
17 |
ok( ! file::append( $file, 'test' ), 'append again' ); |
18 |
cmp_ok( -s $file, '==', $size, 'size not changed' ); |
19 |
|
20 |
ok( file::change( $file, 'test' => 'foobar' ), 'change' ); |
21 |
cmp_ok( -s $file, '>', $size, 'size bigger' ); |
22 |
ok( ! file::change( $file, 'test' => 'foobar' ), 'change again' ); |
23 |
|
24 |
ok( file::replace( $file, 'foobar' => 'replaced content' ), 'replace' ); |
25 |
|
26 |
my $file2 = $file . '.2'; |
27 |
|
28 |
ok( file::copy_once( '/etc/rc.local', $file2 ), 'copy_once' ); |
29 |
cmp_ok( -s $file2, '==', -s '/etc/rc.local', 'size' ); |
30 |
ok( file::append( $file2, '# foobar' ), 'append to rc.local' ); |
31 |
ok( my $content = file::read_file($file2), 'read' ); |
32 |
like( $content, qr/foobar.*exit/s, 'foobar before exit' ); |
33 |
|
34 |
ok( unlink($file2), 'unlink' ); |
35 |
|
36 |
ok( unlink($file), 'unlink' ); |