From c708681021c7832a231b199e0e15159b8d75f3d0 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 17 May 2011 23:43:58 +0200 Subject: Further tests --- lib/App/Hashl.pm | 3 ++- t/29-app-hashl.t | 42 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/lib/App/Hashl.pm b/lib/App/Hashl.pm index 58af4a6..8d3187c 100644 --- a/lib/App/Hashl.pm +++ b/lib/App/Hashl.pm @@ -149,7 +149,8 @@ sub ignored { sub ignore { my ($self, $file) = @_; - push(@{ $self->{ignored}->{hashes} }, $file); + $self->delete_file($file); + push(@{ $self->{ignored}->{hashes} }, $self->hash_file($file)); } sub save { diff --git a/t/29-app-hashl.t b/t/29-app-hashl.t index fbd2e99..fffe9cc 100644 --- a/t/29-app-hashl.t +++ b/t/29-app-hashl.t @@ -3,10 +3,12 @@ use strict; use warnings; use 5.010; -use Test::More tests => 13; +use Test::More tests => 22; use_ok('App::Hashl'); +my $IGNORED = '// ignored'; + my $hashl = App::Hashl->new(); isa_ok($hashl, 'App::Hashl'); @@ -26,5 +28,39 @@ is($hashl->file_in_db('t/in/4'), undef, 'file not in db'); is_deeply([$hashl->files()], [], 'no files in empty db'); is_deeply([$hashl->ignored()], [], 'no ignored files in empty db'); -ok($hashl->ignore('hash123'), 'ignore hash'); -is_deeply([$hashl->ignored()], ['hash123'], 'ignore hash'); +my $test_hash = $hashl->hash_file('t/in/4'); +ok($hashl->add_file( + file => 't/in/4', + path => 't/in/4', + mtime => 123, + size => 4, + ), + 'Add new file' +); +is_deeply($hashl->file('t/in/4'), + { + hash => $test_hash, + size => 4, + mtime => 123, + }, + 'hashl->file okay' +); + +ok($hashl->file_in_db('t/in/4'), 'file is now in db'); +ok($hashl->hash_in_db($test_hash), 'hash is in db'); + +ok($hashl->ignore('t/in/4'), 'ignore file'); +is($hashl->file_in_db('t/in/4'), $IGNORED, 'file no longer in db'); + +is_deeply([$hashl->ignored()], [$test_hash], 'file is ignored'); + +ok($hashl->save('t/in/hashl.db'), 'save db'); + +undef $hashl; + +$hashl = App::Hashl->new_from_file('t/in/hashl.db'); +isa_ok($hashl, 'App::Hashl'); +unlink('t/in/hashl.db'); + +is($hashl->file_in_db('t/in/4'), $IGNORED, 'file still ignored'); +is_deeply([$hashl->files()], [], 'no files in db'); -- cgit v1.2.3