CHI/t/Config.pm untested

filter: Statementstmt 0.0% 0 / 80 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 95 CC 1 SCAR 6.9
CC
1
Cov
0%
_create
2.0
test_config
2.0
test_memoize
2.0
CRAP 2.0
1 package CHI::t::Config;
2 $CHI::t::Config::VERSION = '0.61';
3 use CHI::Util qw(dump_one_line);
4 use CHI::Test;
5 use File::Temp qw(tempdir);
6 use strict;
7 use warnings;
8 use base qw(CHI::Test::Class);
9  
10 my $root_dir = tempdir( 'CHI-t-Config-XXXX', TMPDIR => 1, CLEANUP => 1 );
11  
12 my %config = (
13 storage => {
14 memory => { driver => 'Memory', global => 1 },
15 file => { driver => 'File', root_dir => $root_dir },
16 },
17 namespace => {
18 'Foo' => { storage => 'file' },
19 'Bar' => { storage => 'file', depth => 3 },
20 },
21 defaults => { storage => 'memory' },
22 );
23  
24 {
25 package My::CHI;
26 $My::CHI::VERSION = '0.61';
27 use base qw(CHI);
28 My::CHI->config( {%config} );
29 }
30  
31 {
32 package My::CHI::Subclass;
33 $My::CHI::Subclass::VERSION = '0.61';
34 use base qw(My::CHI);
35 }
36  
37 {
38 package My::CHI::Memo;
39 $My::CHI::Memo::VERSION = '0.61';
40 use base qw(CHI);
41 My::CHI::Memo->config( { %config, memoize_cache_objects => 1 } );
42 }
43  
44 sub _create {
45 my ( $params, $checks ) = @_;
46  
47 my $desc = dump_one_line($params);
48 foreach my $class (qw(My::CHI My::CHI::Subclass)) {
49 my $cache = $class->new(%$params);
50 while ( my ( $key, $value ) = each(%$checks) ) {
51 is( $cache->$key, $value, "$key == $value ($desc)" );
52 }
53 }
54 }
55  
56 sub test_config : Tests {
57 my $self = shift;
58  
59 _create(
60 { namespace => 'Foo' },
61 {
62 namespace => 'Foo',
63 storage => 'file',
64 short_driver_name => 'File',
65 root_dir => $root_dir,
66 depth => 2
67 },
68 );
69 _create(
70 { namespace => 'Bar' },
71 {
72 namespace => 'Bar',
73 storage => 'file',
74 short_driver_name => 'File',
75 root_dir => $root_dir,
76 depth => 3
77 }
78 );
79 _create(
80 { namespace => 'Foo', depth => 4 },
81 {
82 namespace => 'Foo',
83 storage => 'file',
84 short_driver_name => 'File',
85 root_dir => $root_dir,
86 depth => 4
87 }
88 );
89 _create(
90 { namespace => 'Bar', depth => 4 },
91 {
92 namespace => 'Bar',
93 storage => 'file',
94 short_driver_name => 'File',
95 root_dir => $root_dir,
96 depth => 4
97 }
98 );
99  
100 my %new_config = %config;
101 $new_config{namespace}->{'Bar'}->{depth} = 5;
102 My::CHI->config( {%new_config} );
103 _create(
104 { namespace => 'Bar' },
105 {
106 namespace => 'Bar',
107 storage => 'file',
108 short_driver_name => 'File',
109 root_dir => $root_dir,
110 depth => 5
111 }
112 );
113 }
114  
115 sub test_memoize : Tests {
116 my $cache1 = My::CHI::Memo->new( namespace => 'Foo' );
117 my $cache2 = My::CHI::Memo->new( namespace => 'Foo' );
118 is( $cache1, $cache2, "same - namespace Foo" );
119  
120 my $cache3 = My::CHI::Memo->new( namespace => 'Bar', depth => 4 );
121 my $cache4 = My::CHI::Memo->new( namespace => 'Bar', depth => 4 );
122 isnt( $cache3, $cache4, "different - namespace Bar" );
123  
124 My::CHI::Memo->clear_memoized_cache_objects();
125 my $cache5 = My::CHI::Memo->new( namespace => 'Foo' );
126 my $cache6 = My::CHI::Memo->new( namespace => 'Foo' );
127 is( $cache5, $cache6, "same - namespace Foo" );
128 isnt( $cache1, $cache3, "different - post-clear" );
129  
130 my $cache7 = My::CHI->new( namespace => 'Foo' );
131 my $cache8 = My::CHI->new( namespace => 'Foo' );
132 isnt( $cache7, $cache8, "different - namespace Foo - no memoization" );
133 }
134  
135 1;