| 1 | package EntityModel::Test::Cache; | ||||||||||||
| 2 | { | ||||||||||||
| 3 | 2 | $EntityModel::Test::Cache::VERSION = '0.102'; | |||||||||||
| 4 | } | ||||||||||||
| 5 | 2 | ▶ | use EntityModel::Class { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 2 | _isa => [qw(Exporter)], | |||||||||||
| 7 | 2 | }; | |||||||||||
| 8 | |||||||||||||
| 9 | =head1 NAME | ||||||||||||
| 10 | |||||||||||||
| 11 | EntityModel::Test::Cache - tests for L<EntityModel::Cache> and subclasses | ||||||||||||
| 12 | |||||||||||||
| 13 | =head1 VERSION | ||||||||||||
| 14 | |||||||||||||
| 15 | version 0.102 | ||||||||||||
| 16 | |||||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||||
| 18 | |||||||||||||
| 19 | use EntityModel::Test::Cache; | ||||||||||||
| 20 | cache_ok('EntityModel::Cache::Perl', '::Perl subclass works'); | ||||||||||||
| 21 | |||||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||||
| 23 | |||||||||||||
| 24 | Provides functions for testing L<EntityModel::Cache> subclasses. | ||||||||||||
| 25 | |||||||||||||
| 26 | =cut | ||||||||||||
| 27 | |||||||||||||
| 28 | 2 | ▶ | use Test::Builder; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 29 | 2 | ▶ | use Module::Load; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 30 | |||||||||||||
| 31 | 2 | ▶ | use constant CACHE_METHODS => qw( | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 32 | new | ||||||||||||
| 33 | get | ||||||||||||
| 34 | set | ||||||||||||
| 35 | 2 | ); | |||||||||||
| 36 | |||||||||||||
| 37 | =head1 EXPORTS | ||||||||||||
| 38 | |||||||||||||
| 39 | Since this is a test class, functions are exported automatically | ||||||||||||
| 40 | to match behaviour of other test modules such as L<Test::More>. | ||||||||||||
| 41 | To disable this, pass an empty list on the C<use> line or | ||||||||||||
| 42 | use C<require> instead: | ||||||||||||
| 43 | |||||||||||||
| 44 | use EntityModel::Test::Cache (); | ||||||||||||
| 45 | EntityModel::Test::Cache::cache_ok(...); | ||||||||||||
| 46 | |||||||||||||
| 47 | =cut | ||||||||||||
| 48 | |||||||||||||
| 49 | 2 | our @EXPORT = qw( | |||||||||||
| 50 | cache_ok | ||||||||||||
| 51 | cache_methods_ok | ||||||||||||
| 52 | ); | ||||||||||||
| 53 | |||||||||||||
| 54 | =head1 FUNCTIONS | ||||||||||||
| 55 | |||||||||||||
| 56 | =cut | ||||||||||||
| 57 | |||||||||||||
| 58 | =head2 cache_ok | ||||||||||||
| 59 | |||||||||||||
| 60 | Runs all available tests (including attempting to load the module) and returns the usual | ||||||||||||
| 61 | L<Test::Builder> ok/fail response. | ||||||||||||
| 62 | |||||||||||||
| 63 | =cut | ||||||||||||
| 64 | |||||||||||||
| 65 | 1 | ▶ | sub cache_ok { | ||||||||||
|
Subroutine
cache_ok: called CC=3 SCAR=13.6
Pod
documented
| |||||||||||||
| 66 | 1 | my $class = shift; | |||||||||||
| 67 | 1 | ▶ | my $msg = shift || "$class is a valid, working EntityModel::Cache (sub)class"; | ||||||||||
|
Condition50%1/2
shift() || "$class is a valid, working EntityModel::Cache (sub)class"
MC/DC0%0/1
shift() || "$class is a valid, working EntityModel::Cache (sub)class"
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 68 | 1 | my $ok = 0; | |||||||||||
| 69 | |||||||||||||
| 70 | |||||||||||||
| 71 | # First we need to be able to load our module | ||||||||||||
| 72 | try { | ||||||||||||
| 73 | 1 | Module::Load::load($class); | |||||||||||
| 74 | 1 | } catch { | |||||||||||
| 75 | 1 | return _report_status($ok, $msg, $_); | |||||||||||
| 76 | }; | ||||||||||||
| 77 | |||||||||||||
| 78 | 0 | ▶ | _methods_ok($class, $msg) or return; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 79 | |||||||||||||
| 80 | 0 | $ok = 1; | |||||||||||
| 81 | 0 | return _report_status($ok, $msg); | |||||||||||
| 82 | } | ||||||||||||
| 83 | |||||||||||||
| 84 | 1 | ▶ | sub cache_methods_ok { | ||||||||||
|
Subroutine
cache_methods_ok: called CC=3 SCAR=14.2
Pod
undocumented
| |||||||||||||
| 85 | 1 | my $class = shift; | |||||||||||
| 86 | 1 | ▶ | my $msg = shift || "$class has all the required methods"; | ||||||||||
|
Condition50%1/2
shift() || "$class has all the required methods"
MC/DC0%0/1
shift() || "$class has all the required methods"
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 87 | 1 | ▶ | return 0 unless _methods_ok($class, $msg); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 88 | 0 | return _report_status(1, $msg); | |||||||||||
| 89 | } | ||||||||||||
| 90 | |||||||||||||
| 91 | 1 | ▶ | sub _methods_ok { | ||||||||||
|
Subroutine
_methods_ok: called CC=5 SCAR=23.7
| |||||||||||||
| 92 | 1 | my $class = shift; | |||||||||||
| 93 | 1 | my $msg = shift; | |||||||||||
| 94 | |||||||||||||
| 95 | 1 | my %failed; | |||||||||||
| 96 | 1 | foreach my $method (CACHE_METHODS) { | |||||||||||
| 97 | try { | ||||||||||||
| 98 | 1 | $class->can($method); | |||||||||||
| 99 | } catch { | ||||||||||||
| 100 | 1 | ▶ | $failed{$method} = $_; | ||||||||||
|
Condition0%0/2
$failed{$method} ||= "not available"
MC/DC0%0/1
$failed{$method} ||= "not available"
$failed{$method}
Truth table0%0/2
A
A= $failed{$method}
| |||||||||||||
| 101 | 1 | ▶ | } or $failed{$method} ||= 'not available'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 102 | } | ||||||||||||
| 103 | 0 | ▶ | if(keys %failed) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 104 | 0 | _report_status(0, $msg, join "\n", map { "Could not ->$_ because: " . $failed{$_} } sort keys %failed); | |||||||||||
| 105 | 0 | return 0; | |||||||||||
| 106 | } | ||||||||||||
| 107 | 0 | return 1; | |||||||||||
| 108 | } | ||||||||||||
| 109 | |||||||||||||
| 110 | 1 | ▶ | sub _report_status { | ||||||||||
|
Subroutine
_report_status: called CC=2 SCAR=7.0
| |||||||||||||
| 111 | 1 | my $ok = shift; | |||||||||||
| 112 | 1 | my $msg = shift; | |||||||||||
| 113 | 1 | my $diag = shift; | |||||||||||
| 114 | |||||||||||||
| 115 | 1 | my $test = Test::Builder->new; | |||||||||||
| 116 | 1 | $test->ok($ok, $msg); | |||||||||||
| 117 | 1 | ▶ | $test->diag($diag) if defined $diag; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 118 | 1 | return $ok; | |||||||||||
| 119 | } | ||||||||||||
| 120 | |||||||||||||
| 121 | 2 | 1; | |||||||||||
| 122 | |||||||||||||
| 123 | __END__ | ||||||||||||