File Coverage

t/PerlySense-cache.t
Criterion Covered Total %
statement 64 64 100.0
branch 1 2 50.0
condition n/a
subroutine 15 15 100.0
pod n/a
total 80 81 98.7


line stmt bran cond sub pod time code
1             #!/usr/bin/perl -w
2 1     1   108051 use strict;
  1         2  
  1         60  
3              
4 1     1   488 use Test::More tests => 17;
  1         14280  
  1         6  
5 1     1   618 use Test::Exception;
  1         2531  
  1         3  
6              
7 1     1   202 use File::Basename;
  1         1  
  1         99  
8 1     1   262 use File::Spec::Functions;
  1         466  
  1         63  
9 1     1   6 use File::Path;
  1         1  
  1         52  
10 1     1   349 use File::Slurp;
  1         11919  
  1         59  
11 1     1   347 use Cache::FileCache;
  1         31536  
  1         40  
12              
13 1     1   295 use lib "../lib";
  1         546  
  1         4  
14              
15 1     1   97513 use_ok("Devel::PerlySense");
  1         633  
  1         3  
  1         1  
  1         6  
16              
17              
18 1 50   1   2294 BEGIN { -d "t" and chdir("t"); }
19              
20              
21 1         273 ok(my $oPs = Devel::PerlySense->new(), "new ok");
22              
23              
24 1         197 my $dirData = "data/cache/test";
25 1         2 my $file = "data/cache/random_data_file.txt";
26 1     1   77 END { unlink($file); };
27              
28 1         162 rmtree($dirData); ok(! -d $dirData, "Cache dir gone");
  1         6  
29 1         352 mkpath($dirData); ok( -d $dirData, "Cache dir created");
  1         7  
30 1     1   1111 END { rmtree($dirData); };
31              
32 1         192 ok(write_file($file, "whatever"), "Create test file");
33 1         458 ok(-f $file, " Yep, there");
34              
35              
36              
37 1         188 print "\n* No cache active\n";
38              
39 1         10 my $rValue = \"Some text";
40 1         1 my $rGotten;
41              
42 1         4 ok( ! $oPs->cacheSet(file => $file, key => "test", value => $rValue), "Could not set value to emtpy cache");
43 1         196 is($oPs->cacheGet(file => $file, key => "test"), undef, "Could not get value from emtpy cache");
44              
45              
46              
47 1         206 print "\n* Cache active\n";
48              
49 1         10 ok(my $oCache = Cache::FileCache->new({cache_root => $dirData}), "Cache::FileCache->new ok");
50 1         395 ok($oPs->oCache($oCache), "Set oCache");
51              
52              
53 1     1   195 throws_ok(sub { $oPs->cacheSet(file => "$file/missing.lost", key => "test", value => $rValue) }, qr/read timestamp/, "Set died ok on missing file");
  1         28  
54 1     1   214 throws_ok(sub { $oPs->cacheGet(file => "$file/missing.lost", key => "test") }, qr/read timestamp/, "Get died ok on missing file");
  1         17  
55              
56              
57              
58 1         197 ok($oPs->cacheSet(file => $file, key => "test", value => $rValue), "Could set value to cache");
59 1         223 ok($rGotten = $oPs->cacheGet(file => $file, key => "test"), "Could get value from cache");
60 1         191 is($$rGotten, $$rValue, " got back same value");
61              
62              
63              
64 1         192 print "\nExpire file\n";
65 1         1000083 sleep(1);
66 1         18 ok(write_file($file, "whatever"), "Create test file");
67 1         1000773 sleep(1);
68 1         21 ok( ! $oPs->cacheGet(file => $file, key => "test"), "Could not get value from file with new timestamp");
69              
70              
71              
72              
73              
74              
75              
76             __END__