File: no_clobber.t

package info (click to toggle)
libfile-slurp-perl 9999.32-2.1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 412 kB
  • sloc: perl: 650; makefile: 39
file content (35 lines) | stat: -rw-r--r-- 1,047 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use strict;
use warnings;

use File::Basename ();
use File::Spec ();
use lib File::Spec->catdir(File::Spec->rel2abs(File::Basename::dirname(__FILE__)), 'lib');
use FileSlurpTest qw(temp_file_path trap_function);

use File::Slurp;
use Test::More;

plan(tests => 6);

my $file = temp_file_path();

my $data = <<TEXT ;
line 1
more text
TEXT

{
    my ($res, $warn, $err) = trap_function(\&write_file, $file, {no_clobber=>1}, $data);
    ok($res, 'write_file: no_clobber opt - new file');
    ok(!$warn, 'write_file: no_clobber opt - new file - no warnings!');
    ok(!$err, 'write_file: no_clobber opt - new file - no exceptions!');
}

{
    my ($res, $warn, $err) = trap_function(\&write_file, $file, {no_clobber=>1, err_mode=>'quiet'}, $data);
    ok(!$res, 'write_file: no_clobber, err_mode quiet opts - existing file - no added content');
    ok(!$warn, 'write_file: no_clobber, err_mode quiet opts - existing file - no warnings!');
    ok(!$err, 'write_file: no_clobber, err_mode quiet opts - existing file - no exceptions!');
}

unlink $file ;