| 1 | package DDG::Test::Goodie; | ||||||||||
| 2 | 4 | our $AUTHORITY = 'cpan:DDG'; | |||||||||
| 3 | # ABSTRACT: Adds keywords to easily test Goodie plugins. | ||||||||||
| 4 | 4 | $DDG::Test::Goodie::VERSION = '1017'; | |||||||||
| 5 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 4 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 4 | ▶ | use Test::More; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 4 | ▶ | use Test::Deep; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 4 | ▶ | use DDG::Test::Block; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 4 | ▶ | use DDG::ZeroClickInfo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 4 | ▶ | use Package::Stash; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 4 | binmode STDOUT, ':utf8'; | |||||||||
| 15 | 4 | binmode Test::More->builder->output, ':utf8'; | |||||||||
| 16 | 4 | binmode Test::More->builder->failure_output, ':utf8'; | |||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | sub import { | ||||||||||
| 20 | 4 | ▶ | my ( $class, %params ) = @_; | ||||||||
|
Subroutine
import: called CC=1 SCAR=0.2
| |||||||||||
| 21 | 4 | my $target = caller; | |||||||||
| 22 | 4 | my $stash = Package::Stash->new($target); | |||||||||
| 23 | |||||||||||
| 24 | |||||||||||
| 25 | 4 | my %zci_params; | |||||||||
| 26 | |||||||||||
| 27 | $stash->add_symbol('&test_zci', sub { | ||||||||||
| 28 | 8 | ▶ | my $answer = shift; | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=8.1
| |||||||||||
| 29 | ref $_[0] eq 'HASH' ? | ||||||||||
| 30 | 8 | ▶ | DDG::ZeroClickInfo->new(%zci_params, %{$_[0]}, answer => $answer ) : | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | DDG::ZeroClickInfo->new(%zci_params, @_, answer => $answer ) | ||||||||||
| 32 | 4 | }); | |||||||||
| 33 | |||||||||||
| 34 | |||||||||||
| 35 | $stash->add_symbol('&zci', sub { | ||||||||||
| 36 | 2 | ▶ | if (ref $_[0] eq 'HASH') { | ||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=15.2
Branch: 1 branch
| |||||||||||
| 37 | 0 | for (keys %{$_[0]}) { | |||||||||
| 38 | 0 | $zci_params{$_} = $_[0]->{$_}; | |||||||||
| 39 | } | ||||||||||
| 40 | } else { | ||||||||||
| 41 | 2 | ▶ | while (@_) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 2 | my $key = shift; | |||||||||
| 43 | 2 | my $value = shift; | |||||||||
| 44 | 2 | $zci_params{$key} = $value; | |||||||||
| 45 | } | ||||||||||
| 46 | } | ||||||||||
| 47 | 4 | }); | |||||||||
| 48 | |||||||||||
| 49 | |||||||||||
| 50 | $stash->add_symbol('&ddg_goodie_test', sub { block_test(sub { | ||||||||||
| 51 | 8 | ▶ | my ($query, $answer, $zci) = @_; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.6
| |||||||||||
| 52 | subtest "Query: $query" => sub { | ||||||||||
| 53 | 8 | ▶ | if ($answer) { | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=14.2
Branch: 1 branch
| |||||||||||
| 54 | 8 | $zci->{caller} = $answer->caller; # TODO: Review all this cheating; seriously. | |||||||||
| 55 | 8 | cmp_deeply($answer,$zci,'Deep: full ZCI object'); | |||||||||
| 56 | } else { | ||||||||||
| 57 | 0 | ▶ | fail('Expected result but dont get one on '.$query) unless defined $answer; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | } | ||||||||||
| 59 | 8 | }; | |||||||||
| 60 | 6 | ▶ | },@_) | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 61 | 4 | }); | |||||||||
| 62 | |||||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 4 | 1; | |||||||||
| 66 | |||||||||||
| 67 | __END__ | ||||||||||