diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2020-01-19 14:02:26 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2020-01-19 14:03:55 +0200 |
commit | 4e1f50027c7d6fc59d47d932a2a37860e928ebb5 (patch) | |
tree | 022335ab7b86361950ae133de493fc76d33b05b0 /t | |
parent | fdea256ea75e0ca072915d7522564052a9f683f0 (diff) | |
download | file-backup-4e1f50027c7d6fc59d47d932a2a37860e928ebb5.tar.gz file-backup-4e1f50027c7d6fc59d47d932a2a37860e928ebb5.tar.bz2 |
Improve the API
Optional keyword arguments can be used to control error handling and
to specify the directory where to create backup copies.
Diffstat (limited to 't')
-rw-r--r-- | t/00simple.t | 24 | ||||
-rw-r--r-- | t/01numbered.t | 15 | ||||
-rw-r--r-- | t/02auto.t | 24 | ||||
-rw-r--r-- | t/03backup.t | 33 |
4 files changed, 90 insertions, 6 deletions
diff --git a/t/00simple.t b/t/00simple.t index e6d3630..bf4f71a 100644 --- a/t/00simple.t +++ b/t/00simple.t @@ -4,7 +4,7 @@ use strict; use TestBackup; use File::Backup qw(backup_simple); -plan test => 4; +plan test => 9; makefile('a'); @@ -15,5 +15,23 @@ fileok('a', $name); $name = backup_simple('a'); ok($name, 'a~'); fileok('a', $name); - - + +mkdir "subdir"; +$name = backup_simple('a', dir => 'subdir'); +ok($name, File::Spec->catfile('subdir','a~')); +fileok('a', $name); + +eval { + backup_simple('a', dir => 'nonexisting'); +}; +ok(!!$@); + +$name = backup_simple('a', dir => 'nonexisting', error => \my $err); +ok(!defined($name)); +ok(defined($err) && $err ne ''); + +# chmod 0, 'subdir'; +# $name = backup_simple('a', dir => 'subdir', error => \$err); +# ok(!defined($name)); +# print "$err\n"; + diff --git a/t/01numbered.t b/t/01numbered.t index 26a89b6..c4cd06a 100644 --- a/t/01numbered.t +++ b/t/01numbered.t @@ -4,7 +4,7 @@ use strict; use TestBackup; use File::Backup qw(backup_numbered); -plan test => 4; +plan test => 9; makefile('a'); @@ -16,4 +16,17 @@ $name = backup_numbered('a'); ok($name, 'a.~2~'); fileok('a', $name); +mkdir "subdir"; +$name = backup_numbered('a', dir => 'subdir'); +ok($name, File::Spec->catfile('subdir','a.~1~')); +fileok('a', $name); + +eval { + backup_numbered('a', dir => 'nonexisting'); +}; +ok(!!$@); + +$name = backup_numbered('a', dir => 'nonexisting', error => \my $err); +ok(!defined($name)); +ok(defined($err) && $err ne ''); @@ -4,7 +4,7 @@ use strict; use TestBackup; use File::Backup qw(backup_numbered backup_auto); -plan test => 6; +plan test => 16; makefile('a'); @@ -20,3 +20,25 @@ $name = backup_auto('a'); ok($name, 'a.~2~'); fileok('a', $name); +mkdir "subdir"; +$name = backup_auto('a', dir => 'subdir'); +ok($name, File::Spec->catfile('subdir','a~')); +fileok('a', $name); + +$name = backup_auto('a', dir => 'subdir'); +ok($name, File::Spec->catfile('subdir','a~')); +fileok('a', $name); + +ok(open(FH, '>', File::Spec->catfile('subdir','a.~1~'))); +$name = backup_auto('a', dir => 'subdir'); +ok($name, File::Spec->catfile('subdir','a.~2~')); +fileok('a', $name); + +eval { + backup_auto('a', dir => 'nonexisting'); +}; +ok(!!$@); + +$name = backup_auto('a', dir => 'nonexisting', error => \my $err); +ok(!defined($name)); +ok(defined($err) && $err ne ''); diff --git a/t/03backup.t b/t/03backup.t index 136294f..2b9297d 100644 --- a/t/03backup.t +++ b/t/03backup.t @@ -4,7 +4,7 @@ use strict; use TestBackup; use File::Backup; -plan test => 11; +plan test => 24; makefile('a'); @@ -30,3 +30,34 @@ fileok('a', $name); $name = backup('a'); ok($name, 'a.~3~'); fileok('a', $name); + +$name = backup('a', type => BACKUP_SIMPLE); +ok($name, 'a~'); +fileok('a', $name); + +mkdir "subdir"; +$name = backup('a', dir => 'subdir', type => BACKUP_SIMPLE); +ok($name, File::Spec->catfile('subdir','a~')); +fileok('a', $name); + +$name = backup('a', dir => 'subdir', type => BACKUP_AUTO); +ok($name, File::Spec->catfile('subdir','a~')); +fileok('a', $name); + +$name = backup('a', dir => 'subdir', type => BACKUP_NUMBERED); +ok($name, File::Spec->catfile('subdir','a.~1~')); +fileok('a', $name); + +$name = backup('a', dir => 'subdir', type => BACKUP_AUTO); +ok($name, File::Spec->catfile('subdir','a.~2~')); +fileok('a', $name); + +eval { + backup('a', dir => 'nonexisting'); +}; +ok(!!$@); + +$name = backup('a', dir => 'nonexisting', error => \my $err); +ok(!defined($name)); +ok(defined($err) && $err ne ''); + |