[libcode-tidyall-perl] 11/374: test backups
Jonas Smedegaard
js at alioth.debian.org
Sun Sep 29 22:25:40 UTC 2013
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository libcode-tidyall-perl.
commit b932587037998860c0f8233ae02034560d8777f6
Author: Jonathan Swartz <swartz at pobox.com>
Date: Tue Jun 12 11:37:15 2012 -0700
test backups
---
lib/Code/TidyAll.pm | 10 +++++++---
lib/Code/TidyAll/t/Basic.pm | 5 +++++
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/lib/Code/TidyAll.pm b/lib/Code/TidyAll.pm
index 26b227f..4df2d15 100644
--- a/lib/Code/TidyAll.pm
+++ b/lib/Code/TidyAll.pm
@@ -158,9 +158,7 @@ sub _process_file {
sub _backup_file {
my ( $self, $file ) = @_;
unless ( $self->no_backups ) {
- my $backup_file = join( "",
- $self->backup_dir, "/", $self->_small_path($file),
- "-", time2str( "%Y-%m-%d-%H-%M-%S", time ), ".bak" );
+ my $backup_file = join( "/", $self->backup_dir, $self->_backup_filename($file) );
mkpath( dirname($backup_file), 0, 0775 );
write_file( $backup_file, read_file($file) );
if ( my $cache = $self->cache ) {
@@ -173,6 +171,12 @@ sub _backup_file {
}
}
+sub _backup_filename {
+ my ( $self, $file ) = @_;
+
+ return join( "", $self->_small_path($file), "-", time2str( "%Y%m%d-%H%M%S", time ), ".bak" );
+}
+
sub _purge_backups {
my ($self) = @_;
$self->msg("purging old backups") if $self->verbose;
diff --git a/lib/Code/TidyAll/t/Basic.pm b/lib/Code/TidyAll/t/Basic.pm
index bf07ea6..7e16402 100644
--- a/lib/Code/TidyAll/t/Basic.pm
+++ b/lib/Code/TidyAll/t/Basic.pm
@@ -84,6 +84,7 @@ sub test_caching_and_backups : Tests {
$go->();
is( $output, '', 'no output' );
+ sleep(1); # to get two backup files
write_file( $file, "def" );
$go->();
@@ -93,6 +94,10 @@ sub test_caching_and_backups : Tests {
my $backup_dir = $ct->data_dir . "/backups";
my @files;
find( { follow => 0, wanted => sub { push @files, $_ if -f }, no_chdir => 1 }, $backup_dir );
+ is( scalar(@files), 2, "2 backup files" );
+ foreach my $file (@files) {
+ like( $file, qr|\.tidyall\.d/backups/foo\.txt-\d+-\d+\.bak|, "backup filename" );
+ }
}
sub test_errors : Tests {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcode-tidyall-perl.git
More information about the Pkg-perl-cvs-commits
mailing list