DDG/Test/Spice.pm

filter: Statementstmt 85.5% 59 / 69 Branchbran 25.0% 2 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 93.3% 14 / 15 Podpod n/a totaltotal 81.5% 75 / 92 CC 7 SCAR 16.0
CC
7
Cov
79%
__ANON__
20.0
__ANON__
2.3
__ANON__
2.1
CRAP 4.9
« DDG/Block/Regexp.pm ↑ Summary DDG/ZeroClickInfo/Fathead.pm »
1 package DDG::Test::Spice;
2 3 our $AUTHORITY = 'cpan:DDG';
3 # ABSTRACT: Adds keywords to easily test Spice plugins.
4 3 $DDG::Test::Spice::VERSION = '1017';
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use DDG::Test::Block;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use DDG::ZeroClickInfo::Spice;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use DDG::Meta::ZeroClickInfoSpice;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Package::Stash;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Class::Load 'load_class';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 sub import {
17 3 ▶ my ( $class, %params ) = @_;
Subroutine import: called CC=1 SCAR=0.4
18 3 my $target = caller;
19 3 my $stash = Package::Stash->new($target);
20  
21  
22 3 my %spice_params = (
23 call_type => 'include',
24 );
25  
26 $stash->add_symbol('&test_spice', sub {
27 11 ▶ my $call = shift;
Subroutine __ANON__: called CC=2 SCAR=8.1
28 ref $_[0] eq 'HASH'
29 11 ▶ ? DDG::ZeroClickInfo::Spice->new(%spice_params, %{$_[0]}, call => $call )
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 11 11
30 : DDG::ZeroClickInfo::Spice->new(%spice_params, @_, call => $call )
31 3 });
32  
33  
34 $stash->add_symbol('&spice', sub {
35 0 ▶ if (ref $_[0] eq 'HASH') {
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 0 0
36 0 for (keys %{$_[0]}) {
37 0 $spice_params{$_} = $_[0]->{$_};
38 }
39 } else {
40 0 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
41 0 my $key = shift;
42 0 my $value = shift;
43 0 $spice_params{$key} = $value;
44 }
45 }
46 3 });
47  
48  
49 $stash->add_symbol('&ddg_spice_test', sub { block_test(sub {
50 11 ▶ my $query = shift;
Subroutine __ANON__: called CC=2 SCAR=7.2
51 11 my $answer = shift;
52 11 my $spice = shift;
53 11 ▶ if ($answer) {
Branch: 1 branch
BranchTrueFalseTotal
if ($answer) { } 11 0 11
54 11 is_deeply($answer,$spice,'Testing query '.$query);
55 } else {
56 0 fail('Expected result but dont get one on '.$query);
57 }
58 3 ▶ },@_)});
Subroutine __ANON__: called CC=1 SCAR=0.0
59  
60  
61 $stash->add_symbol('&alt_to_test', sub {
62 1 ▶ my ($spice, $alt_tos) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
63  
64 1 load_class($spice);
65  
66 1 my $rewrites = $spice->alt_rewrites;
67 1 ok($rewrites, "$spice has rewrites");
68  
69 1 ok($spice =~ /^(DDG.+::)/, "Extract base from $spice");
70 1 my $base = $1;
71  
72 1 for my $alt (@$alt_tos){
73 2 my ($cb, $path) = @{DDG::Meta::ZeroClickInfoSpice::params_from_target("$base$alt")};
74 2 my $rw = $rewrites->{$alt};
75 2 ok($rw, "$alt exists");
76 2 ok($rw->callback eq $cb, "$alt callback");
77 2 ok($rw->path eq $path, "$alt path");
78 }
79 3 });
80 }
81  
82 3 1;
83  
84 __END__
« DDG/Block/Regexp.pm ↑ Summary DDG/ZeroClickInfo/Fathead.pm »