File Coverage

t/PerlySense-Document-cache.t
Criterion Covered Total %
statement 76 76 100.0
branch 1 2 50.0
condition n/a
subroutine 14 14 100.0
pod n/a
total 91 92 98.9


line stmt bran cond sub pod time code
1             #!/usr/bin/perl -w
2 1     1   164168 use strict;
  1         2  
  1         87  
3              
4 1     1   522 use Test::More tests => 20;
  1         18395  
  1         11  
5 1     1   1927 use Test::Exception;
  1         2812  
  1         5  
6              
7 1     1   237 use File::Basename;
  1         0  
  1         126  
8 1     1   354 use File::Spec::Functions;
  1         504  
  1         65  
9 1     1   13 use File::Path;
  1         2  
  1         58  
10 1     1   393 use File::Slurp;
  1         30068  
  1         107  
11 1     1   112046 use Cache::FileCache;
  1         123587  
  1         45  
12              
13 1     1   303 use lib "../lib";
  1         538  
  1         3  
14              
15 1     1   234704 use_ok("Devel::PerlySense::Document");
  1         433  
  1         2  
  1         2  
  1         10  
16              
17              
18 1 50   1   2259 BEGIN { -d "t" and chdir("t"); }
19              
20              
21              
22 1         2095 ok(my $oPs = Devel::PerlySense->new(), "new ok");
23              
24              
25 1         727 my $dirData = "data/cache/test";
26              
27 1         251 rmtree($dirData); ok(! -d $dirData, "Cache dir gone");
  1         7  
28 1         55426 mkpath($dirData); ok( -d $dirData, "Cache dir created");
  1         37  
29 1     1   1462 END { rmtree($dirData); };
30              
31              
32              
33 1         983 ok(my $oCache = Cache::FileCache->new({cache_root => $dirData}), "Cache::FileCache->new ok");
34 1         458 is($oCache->size, 0, " Cache is empty");
35 1         226 ok($oPs->oCache($oCache), "Set oCache");
36              
37              
38 1         190 my $dirSource = "data/project-lib";
39 1         3 my $fileOrigin = "$dirSource/Game/Object/Worm/ShaiHulud.pm";
40              
41 1         2 my $fragment = 'Game::Location->new';
42 1         2 my $module = "Game::Location";
43 1         2 my $method = "new";
44              
45              
46 1         9 ok(my $oDocumentWithout = Devel::PerlySense::Document->new(oPerlySense => $oPs), "new ok");
47 1         189 ok($oDocumentWithout->parse(file => $fileOrigin), "Parsed file ok");
48              
49 1         1097 ok(my $size = $oCache->size," Cache has contents");
50              
51 1         3135 print "Check that somehting known works\n";
52             #is(scalar($oDocumentWithout->moduleMethodCallAt(row => 158, col => 57)), $fragment, "static new found in scalar context");
53             #is_deeply([$oDocumentWithout->moduleMethodCallAt(row => 158, col => 57)], [$module, $method], "static new found in list context");
54              
55 1         9 ok(eq_set([ $oDocumentWithout->aNameBase() ], ["Game::Object::Worm", "Game::Lawn"]), 'Two base classes (@ISA = ...) ok');
56              
57              
58              
59              
60              
61 1         1262 ok(my $oPsWith = Devel::PerlySense->new(), "new ok");
62 1         230 ok(my $oCacheWith = Cache::FileCache->new({cache_root => $dirData}), "Cache::FileCache->new ok");
63 1         402 ok($oPsWith->oCache($oCacheWith), " Set oCache ok");
64              
65 1         3242 ok(my $oDocumentWith = Devel::PerlySense::Document->new(oPerlySense => $oPsWith), "new ok");
66 1         542 ok($oDocumentWith->parse(file => $fileOrigin), "Parsed file ok");
67              
68 1         1901 is($oCacheWith->size, $size, " Cache has same contents");
69              
70 1         277 print "Check that somehting known works with caching\n";
71             #is(scalar($oDocumentWith->moduleMethodCallAt(row => 158, col => 57)), $fragment, "static new found in scalar context");
72             #is_deeply([$oDocumentWith->moduleMethodCallAt(row => 158, col => 57)], [$module, $method], "static new found in list context");
73              
74 1         10 ok(eq_set([ $oDocumentWith->aNameBase() ], ["Game::Object::Worm", "Game::Lawn"]), 'Two base classes (@ISA = ...) ok');
75              
76              
77              
78              
79 1         417 print "Compare with/without\n";
80              
81 1         2 my $countWithout = 0;
82 1         2 my $sourceWithout = "";
83 1     660   9 $oDocumentWithout->aDocumentFind(sub { $sourceWithout .= "<<$_[1]>>"; $countWithout++; 0; } );
  660         4642  
  660         9655  
  660         739  
84              
85 1         22 my $countWith = 0;
86 1         2 my $sourceWith = "";
87 1     660   10 $oDocumentWith->aDocumentFind(sub { $sourceWith .= "<<$_[1]>>"; $countWith++; 0; } );
  660         4432  
  660         8800  
  660         709  
88              
89 1         19 is($countWithout, $countWith, " oDocument nodes same count");
90 1         272 is($sourceWithout, $sourceWith, " oDocument nodes same source");
91             #print "$sourceWith\n";
92              
93              
94              
95              
96              
97              
98             __END__